Short answers:

On Mon, Oct 28, 2024 at 8:06 AM Langbart <Langbart@protonmail.com> wrote:

is it a bug that when the 'sharehistory' option is enabled, commands from other shells ('foreign') aren't included in the 'history' array until the user enters a command?

No.
 
Prepending 'fc -RI' before accessing the 'history' array seems to resolve the issue. Is this the recommended workaround to ensure that the 'history' array lists its resuls like 'fc -rl ...'  does ?

Yes.

Longer answer:

When you're at a prompt, two things are going on.  First, a history position (the "next" number) has already been allocated for expansion of the %h prompt escape, and loading from the shared history would have to somehow fit "above" that.  Second, the line editor is blocked on the terminal driver waiting for input, it's not burning CPU in the background polling the history file, etc., so you have to explicitly wake it up.