Skip to content

fix(history): grouped readers must not shadow a host HistoryProvider (#1007) - #1008

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/508-history-reset
Oct 22, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/508-history-reset

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1007. Fixes the history half of unixwin/niubash#508.

Root cause

Interactive niu routes ;-batches and alias-name-matching lines (omb's alias 1='cd -1' makes history 1 qualify) through run_script_with_history_at_line_offset, which unconditionally installed a fresh empty SessionHistory. execute_history/fc prefer an installed session over the host HistoryProvider, so the scratch permanently shadowed the provider's live list — history/fc read empty for the rest of the session.

Fix — one invariant: an installed provider is never shadowed

  • src/script_driver.rs: run_script_grouped_at_line_offset gains install_session keyed on has_history_provider(); new run_script_with_fresh_history_in_tracked for the PROMPT_COMMAND empty-session arm; prepare_interactive_history skips session creation under a provider.
  • src/executor/public_accessors.rs: pub(crate) has_history_provider().
  • src/executor/prompt_command.rs: empty-session arm uses the guarded fresh-scratch runner.
  • tests/script_driver_history_in_regressions.rs: +4 tests (provider survives grouped batch; providerless still installs; PROMPT_COMMAND both arms).

Providerless behavior unchanged: the scratch still installs as GNU's fresh per-shell list (bashhist.c pre_process_line). Embedding-contract fix, not a GNU semantic divergence — GNU has exactly one history list; the provider IS that list for the host.

Verification

  • cargo test --locked --test script_driver_history_in_regressions: 12/12
  • cargo test --locked --lib: 771/771 (1 pre-existing ignore)
  • prompt_command/fc/script_driver focused suites: green
  • End-to-end against niubash@23a1278 (temporary local path patch, reverted): echo a; echo b, alias 1='cd -1' + history 1 prints the provider entry, subsequent history intact.

No niubash-side change required — the existing call site already routes through the fixed driver; consumption rides the normal release pin lane.

…nixwin/niubash#508)

Interactive niu REPL: a line routed through the engine's grouped reader —
a `;` batch, or any token matching an alias name (oh-my-bash's
`alias 1='cd -1'` makes `history 1` qualify) — ran
run_script_with_history_at_line_offset, which unconditionally installed a
fresh empty SessionHistory on the executor. job_builtins execute_history
(builtins/history.def reads the shell's ONE list) and fc both prefer an
installed session over the host HistoryProvider, so the scratch shadowed
the provider's real list for the rest of the session: `history`/`fc`
went permanently empty — the reported wipe.

The provider IS the_history_list in the embedding (the precedence in
execute_history already encodes it), so a per-read scratch must never be
installed over it. run_script_grouped_at_line_offset gains an
install_session flag keyed on has_history_provider; the scratch still
backs the batch's expansion/record mechanics without becoming the shell's
list. The PROMPT_COMMAND runner's empty-session arm moves to
run_script_with_fresh_history_in_tracked with the same guard, and
prepare_interactive_history no longer creates a session over a provider
either — one invariant: an installed provider is never shadowed.

Without a provider the scratch still installs, matching GNU's fresh
per-shell history list (bashhist.c pre_process_line / shell.c reader).

Regressions in tests/script_driver_history_in_regressions.rs cover both
shapes: provider list surviving a grouped batch and a PROMPT_COMMAND run,
plus the providerless fresh-install arms.
@caomengxuan666
caomengxuan666 merged commit 493ebb2 into master Oct 22, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/508-history-reset branch October 23, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grouped readers / PROMPT_COMMAND shadow a host HistoryProvider and wipe interactive history (niubash#508 part B)

1 participant