Skip to content

WIP: niu history pollution fixes (#569 #570 #571 #572) - #583

Merged
caomengxuan666 merged 10 commits into
masterfrom
niu-history-stack
Oct 27, 2026
Merged

caomengxuan666 merged 10 commits into
masterfrom
niu-history-stack

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Cluster: niu-history — niubash history-pollution fixes from the full-audit dynamic verification batch.
Baseline: master d3e7103. One commit per issue, each with regression tests (dual-session pty probes shaped after the audit's; history-file assertions byte-exact). GNU oracle: bash 5.3.20.

Coverage

Fixes #569
Fixes #570
Fixes #571
Fixes #572

Commits

Progress

  • All four fixes implemented and stacked
  • cargo check --locked --workspace --all-targets green
  • Full verification in progress: cargo build --locked, runtime lib history tests (failure set must equal the pristine set — sole known exception: session_end_write_appends_missing_entries_without_duplicates fails under uid 0, an environment artifact also present pre-fix), new pty suites issue569/570/571
  • REPORT.md finalized in the cluster workspace

Not ready for review; verification gate and merge go through the integration pass — please do not merge directly.

GNU interactive shells always have a HISTFILE default, and the bare
history forms resolve their filename from it. The REPL unset HISTFILE
on interactive entry, so every bare form failed with
'history: filename not specified' and bash-it-style per-prompt hooks
(history -a; history -c; history -r) broke at the first leg.

Default HISTFILE to the host history's backing file in
enter_interactive: the engine history machinery stays off via the
flag, but the builtins now resolve to the one file the provider
already owns. The inherited-HISTFILE single-stream choice is
unchanged (an exported HISTFILE was already ignored by the old
unset).

Also correct the read_new_history backing-file fast path: missing
lines are, by construction, already in the backing file, so the
path only reloads the reader. Appending them first duplicated every
line picked up by history -n.

Fixes #571
The NIU_HISTORY_MODE shared/session/private switch was a GNU-less
invention, and its documented behaviors did not match the
implementation: a value written into ~/.niubashrc could never take
effect (it was read from process env before the rc ran), and the
session mode's 'builtins can observe later file updates' promise was
not implemented (refresh short-circuited for every non-shared mode).
Its private mode's near-unbounded capacity was also silently
truncated on reload.

Remove the switch entirely (enum, config field, shell field, all
call sites): there is exactly one sharing semantics now, GNU's —
one live file every session appends to and refreshes from, with
history -a/-n/-r as the explicit sync verbs. The capacity is the
uniform HistoryConfig.max_size (default 10000), the GNU HISTFILESIZE
analog. A leftover NIU_HISTORY_MODE in the environment is silently
ignored, with no startup diagnostic. The docs' History Modes section
is rewritten to the GNU model plus a retirement note; the old
private-mode test becomes a uniform-refresh test (another session's
later appends are visible here).

Fixes #572
Reedline's save drops an entry identical to the previous one, but
GNU history is positional: consecutive duplicates in one session,
and the same line typed in two sessions, are all kept. In the
dual-same probe two sessions typing 'echo SAMECMD' left one copy
in the shared file where GNU leaves two.

When the new line equals the last entry, bypass reedline's filter:
append the reedline-encoded line to the file directly and rebuild
the reader from disk (the load path applies no duplicate filter),
returning the new entry with its proper id. Empty lines keep
reedline's drop (GNU records no empty lines either). The degraded
path (no backing file, or an unappendable file) keeps reedline's
drop, exactly the pre-existing behavior.

This must not return to the old #181/#182 interlock road: no exit
full overwrite, no never-read-back — the fix is inside save, and
the session-end write is untouched.

Fixes #570
The host history syncs every typed line to the file immediately, so
history -c only cleared the in-memory list: the cleared lines were
already on disk, and the session-end write left them there for the
next session to read back (the h5 probe: MARKER_H5 and the history
-c line itself survived exit, where GNU drops them).

Track this session's own lines in a SessionLedger shared between
the provider instance and the editor history instance (distinct
objects over one file; Arc<Mutex<...>> so no Send regression):
saved lines are pending until -a/-w commits them, -c moves pending
to cleared, and the session-end write reconciles the file — it
appends pending lines the live sync never wrote, then removes
exactly the cleared lines as a forward subsequence from the
session's base line count (seeds and other sessions' lines before
the base are never touched; -a/-w-committed lines are not in the
cleared set and survive). The legacy empty-list truncate branch is
preserved exactly: it applies only when nothing was cleared, so a
cleared session with an empty list removes only its cleared lines
instead of truncating seeds and foreign lines. After any file
change the reader is rebuilt so reedline's len_on_disk accounting
cannot re-append the reconciled lines.

-a is re-based on the ledger too (it used to subtract by content,
which dropped a second session's same-text line): to the backing
file it appends only unsynced pending lines, to a foreign file all
pending lines, committing only after a successful append. -w
encodes multi-line entries the way reedline stores them.

Fixes #569
On a non-Windows host the driver's SystemRoot fallback (C:\Windows)
breaks std::env::join_paths — 'C:' contains the Unix separator —
so every pty test using spawn_shared_home with default path_dirs
failed with JoinPathsError before the shell even spawned. This
blocked the niu-history cluster's pty regression tests on Linux
(they use builtins only, so the spawned PATH is irrelevant).

Use a colon-free placeholder on non-Windows only; Windows behavior
is unchanged. This is test-harness enablement for the history
cluster's pty tests, not a product change; it is kept as a separate
commit so it can be dropped or replaced by a fuller driver fix.
@caomengxuan666 caomengxuan666 changed the title WIP: niu-history-stack WIP: niu history pollution fixes (#569 #570 #571 #572) Oct 26, 2026
…w appends (#569)

The ledger reconcile appended unsynced lines to the file directly,
leaving reedline's on-disk accounting stale: the reader's Drop-time
sync then wrote the same lines a second time (FileBackedHistory
syncs on drop). Windows CI caught the duplication in
session_end_write_appends_missing_entries_without_duplicates; the
local uid-0 read-only artifact masks that leg. Writing through
history.sync() advances the accounting as it writes, so the lines
land exactly once.
@caomengxuan666

Copy link
Copy Markdown
Member Author

集成完成(主会话集成棒):合并当前 master + pin 升版 + 合并树全门重跑

集成动作

集成中补的两处(均为本线代码在合并树/CI 上暴露的自身缺陷,非新分歧)

  • 2fef5d2 + 676c933:CI clippy(-D warnings)在 [P1][history] 交互 REPL 中裸 history -a/-w/-r/-n 恒失败:HISTFILE 被宿主 unset 且无 backing 文件回退 #571 的 HISTFILE set 处报 unnecessary_to_owned,本地门不跑 clippy 故未拦下;已按 clippy 建议去 into_owned() 并 rustfmt 收形。
  • 6986924:[P1][history][历史污染残留] history -c 清掉的行仍留在共享历史文件(已清行复活) #569 会话终写的一个真重复追加。第一轮 CI 的 lib 比 master 基线多红一条 session_end_write_appends_missing_entries_without_duplicates(master 同 run 635/8、本线 642/9)。定性(代码级坐实):ledger 对账原先用 raw append 把未同步行直写文件,reedline 的 on-disk 账目未同步推进,reader 随后被重建替换时旧 reader 的 Drop-time sync(reedline 0.52 FileBackedHistory 有 Drop-sync)把同一行再写一遍 → echo lost 出现两份。修复 = 对账改走 state.history.sync()(经 reader 写、账目随写推进);本地 uid-0 只读伪影只掩第一腿、第二腿仅在只读语义真实生效的 Windows runner 上暴露,修复后该钉在 runner 上转 ok。

合并树门(最终头 6986924;本地单槽 JOBS=1 净化环境、日志 + .done 实存于集成簇目录)

  • cargo build --locked rc=0
  • lib 定向:history 过滤 34 过 / 1 败、新钉多过滤 14 过 / 1 败——唯一败均为同一条 session_end_write_... 的 uid-0 只读伪影(root 绕 DAC,审计批已裁定、master 同形),与基线失败集全等
  • pty 三套件全绿:issue569 1/1、issue570 1/1、issue571 2/2
  • rustfmt 改动文件全清、CR=0

GitHub CI(run 40465096005,头 6986924)

  • 除 build-and-test 外全 success(含 API ledger、双 cross-check、五 cross-target)
  • build-and-test 的 lib:646 过 / 8 败,8 条逐名 = 已裁定 runner 环境集(6× plugins::sources + 1× plugins::sync 的 git-not-found 族 + 1× shell cd 短名形),与 master 自身 run 40450355977(635/8)逐名全等、集外新红 0;本线新钉在 runner 上全过(lib history 族 + issue569/570/571 pty 二进制 + issue182 bash-it 互锁钉 1/1,旧污染三机制无回归)

PR 保持 draft、未自合,待主会话合并。正文关单词未动。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment