Files
fish-shell/tests
Johannes Altmanninger c8d7476576 history: don't ignore re-added history items after vacuum
As root-caused in
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-4674848354,
we sometimes temporarily forget about history items:

Steps:

	1. start fish1
	2. fish1: run "echo remember me"
	3. start fish2
	4. fish1: run "echo something else"
	5. fish1: run "echo remember me"
	6. fish1: run up to VACUUM_FREQUENCY commands, until vacuum happens
	   (can watch ~/.config/fish/${fish_history:-fish}_history)
	7. fish2: run "echo reload"

Now fish2 can't recall "echo remember me" anymore.

This is because when re-running that command, fish1 updates the
command's history entry's "when" timestamp to something younger
than fish2.  When fish2 reloads the history, it ignores history
entries younger than itself (except for the entries created by itself).

Fix this by introducing a second timestamp called "added_when",
the immutable creation time.  Use this for determining the cutoff,
fixing the above scenario.

Keep the "when" key for forward compatibility.  Keep its semantics
(update it whenever we re-run a command; used for sorting); if we'd
instead let "when" be the creation time, then old fish will sort
wrongly commands that are run again in concurrent new fish. (If new
fish vacuums again, it will correct the ordering automatically.)

Alternatively, we could replace "added_when" with another
monotonically increasing number, maybe a integer sequence, with the
per-history next number stored on disk.  We only use it to compare
against the boundary timestamp in "offset_of_next_item_fish_2_0()"
and "rewrite_to_temporary_file()".  I haven't explored this yet because
"SystemTime" is easy and already used for "last added time".

Assisted-by: Theo Beers
Assisted-by: Daniel Rainer

Closes #10300
Closes #12817
2026-06-18 14:09:43 +08:00
..
2026-06-18 14:09:43 +08:00