Repository navigation
WIP: niu history pollution fixes (#569 #570 #571 #572) - #583
Merged
Merged
Conversation
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.
…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.
Member
Author
集成完成(主会话集成棒):合并当前 master + pin 升版 + 合并树全门重跑集成动作
集成中补的两处(均为本线代码在合并树/CI 上暴露的自身缺陷,非新分歧)
合并树门(最终头
GitHub CI(run 40465096005,头
PR 保持 draft、未自合,待主会话合并。正文关单词未动。 |
caomengxuan666
marked this pull request as ready for review
October 27, 2026 07:14
This was referenced Oct 27, 2026
Merged
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
history -c清掉的行仍留在共享历史文件(已清行复活) #569 [P1] —history -ccleared lines resurrected in the shared history file at session end. Fix: shared session ledger between the provider and editor history instances; the session-end write removes this session's cleared lines (forward subsequence from the session base) instead of only appending.history -a/-w/-r/-n恒失败:HISTFILE 被宿主 unset 且无 backing 文件回退 #571 [P1] — barehistory -a/-w/-r/-nalways failed in the interactive REPL (filename not specified). Fix:enter_interactivenow setsHISTFILEto the provider's backing file instead of unsetting it;read_new_historybacking-file fast path is reload-only (no more duplicate pickup).NIU_HISTORY_MODEretired in full (enum, config, shell field, call sites, docs). History behavior is now uniformly the GNU model; the leftover env var is silently ignored. Docs updated (docs/src/advanced-usage.md).Commits
0324e02fix(history): bare history -a/-w/-r/-n work in the interactive REPL ([P1][history] 交互 REPL 中裸history -a/-w/-r/-n恒失败:HISTFILE 被宿主 unset 且无 backing 文件回退 #571)c05bee2refactor(history): retire NIU_HISTORY_MODE, align with GNU history ([P2][history] NIU_HISTORY_MODE 为 GNU 无对应物的新造语义,且文档与实现双脱节(rc 设值无效;session 模式文档承诺未实现) #572)caa475cfix(history): keep same-text lines positionally across sessions ([P1][history][历史污染残留] 双会话同文命令被内容去重吞掉一份(丢失) #570)74c5d9cfix(history): cleared lines do not survive the session-end write ([P1][history][历史污染残留]history -c清掉的行仍留在共享历史文件(已清行复活) #569)d8c0f86test(driver): non-Windows pty tests can spawn with default path_dirs — harness enablement only (pre-existingJoinPathsErroron Linux blocked every default-path pty test); droppable/replaceable by a fuller driver fix.Progress
cargo check --locked --workspace --all-targetsgreencargo build --locked, runtime lib history tests (failure set must equal the pristine set — sole known exception:session_end_write_appends_missing_entries_without_duplicatesfails under uid 0, an environment artifact also present pre-fix), new pty suitesissue569/570/571REPORT.mdfinalized in the cluster workspaceNot ready for review; verification gate and merge go through the integration pass — please do not merge directly.