Skip to content

fix(history): entries added before HISTTIMEFORMAT carry no stamp (rubash#3392) - #3757

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3392
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3392

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Root cause

GNU stamps an entry at creation from history_comment_char (lib/readline/history.c hist_inittime): the stamp's first char IS the comment char, '\\0' while no HISTTIMEFORMAT bind has armed it. SessionHistory::record() stamped every add with the wall clock unconditionally, so entries created before HISTTIMEFORMAT was set rendered a real date instead of ??, and history -a/-w wrote spurious #<epoch> lines for them.

Fix

record() takes the live comment-char latch (sticky arming from the first HISTTIMEFORMAT bind, or HISTTIMEFORMAT existing right now — variables.c sv_histtimefmt: history_write_timestamps = (v != 0), latch never disarmed) and stores the empty stamp while unarmed. Callers updated: history -s, the reader recording paths (run_history_group, record_stdin_group_if_armed), and fc re-execution. Display (??) and the -a/-w write gates already skipped empty stamps.

No new API items; the provider-plane stamp ledger is untouched.

Verification (GNU bash 5.2.21 oracle, script files)

  • history -s 'echo new'; HISTTIMEFORMAT='%F '; history → ??echo new (was a real date)
  • -a/-w for an unarmed entry → 1 line, 0 # lines (was 2/1)
  • Mixed entries: unarmed ??, armed dated; -a writes the stamp line only for the armed one (3 lines / 1 hash)
  • Sticky latch verified: entry added after unset HISTTIMEFORMAT (once armed) still stamps; -a after unset writes no stamp lines; empty HISTTIMEFORMAT='' bind arms
  • New suite tests/issue3392_history_unarmed_entries_have_no_stamp.rs: 9/9 green (5 fail-first on baseline)
  • cargo test --lib: 1249 passed, 0 failed; 16 neighbouring history suites (91 tests): all green

Fixes #3392.

…ash#3392)

GNU stamps an entry at creation from history_comment_char
(lib/readline/history.c hist_inittime): the stamp's first char IS the
comment char, '\0' while no HISTTIMEFORMAT bind has armed it, so an
unarmed entry renders '??' and history -a/-w write no '#<epoch>' line
for it. SessionHistory::record() stamped every add with the wall
clock unconditionally; it now takes the live comment-char latch
(sticky arming, or HISTTIMEFORMAT existing right now) from its
callers - history -s, the reader recording paths, and fc
re-execution - and stores the empty stamp while unarmed.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 labels Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666 caomengxuan666 added the area:interactive REPL: prompt, completion, paste, history, terminal integration label Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR, @arookieofc-ai — and for the GNU-oracle notes (readline hist_inittime, sv_histtimefmt) and the fail-first nail stem.

First pass from intake (not a merge review):

  • I read the full diff: SessionHistory::record() now takes the sticky history_comment_char_armed latch and stores an empty stamp while unarmed; the history -s, fc, and script-driver recording call sites pass it through, and the display / -a / -w gates already skip empty stamps. The mechanism matches the PR body, and the new stem tests/issue3392_history_unarmed_entries_have_no_stamp.rs covers the unarmed display, -a/-w write gates, mixed entries, and the sticky latch after unset HISTTIMEFORMAT.
  • CI: the four failing checks all trace to known pre-existing reds, not to this change — the Linux, macOS, and GNU-goldens legs each fail only on api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell (missing rubash binary precondition), and the niu-canary leg fails on the ledger-coverage step. No failure names the new issue3392 stem or any history test. Note the new stem does not visibly run in CI's selected Rust-tests table, so its 9/9 currently rests on the author's local run.
  • This is queued for captain review — external PRs are reviewed by the captain first, per repo rules. Nothing is merged or requested-changed here. One point for that review: please re-run the new stem on the tip, and double-check the arming site of history_comment_char_armed (first HISTTIMEFORMAT bind, including the empty-string bind) against sv_histtimefmt.
  • Note: Fixes #3392 in the body will auto-close history 条目在 HISTTIMEFORMAT 设定前创建仍被盖墙钟戳(GNU 为空戳、显示 ??、-a/-w 不写 # 行) #3392 on merge.

@caomengxuan666
caomengxuan666 merged commit 109ab51 into master Nov 16, 2026
11 of 15 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s2

PR #3757 第1轮 — 建议:PASS(已合并 109ab51)
head: 7e83e3f;base(merge-base): 8100d76;文件 7 个 +246/-19
关联 issue: #3392(open → 合并后 closed)

机制核查:

  • GNU 在 add_history 时由 lib/readline/history.c:322-337 hist_inittime 生成戳,戳首字节 = history_comment_char(未 armed 时为 '\0');arming 出自 variables.c:6168 sv_histtimefmt:HISTTIMEFORMAT 存在即把 comment char 置 '#' 且从不回退(只写 history_write_timestamps = (v != 0))。本 PR 正是把这条「粘性 latch + 当前存在性」双条件接进 SessionHistory::record,未 armed 则存空戳;显示 ?? 与 -a/-w 不写戳行走既有空戳门。机制与 GNU 源码逐条对应。
  • 既有测试 script_driver_history_in_regressions.rs 的两处改动只是 record() 新增 bool 参数的签名适配(传 true 保持旧语义),不是放宽断言。
  • 无删除、无无关面改动。

腿:

  • 钉自跑:issue3392_history_unarmed_entries_have_no_stamp 9/9 pass(head)。
  • fail-first:base 8100d76 同文件 4 passed / 5 failed,红名 = {unarmed_entry_displays_question_marks, append_writes_no_stamp_line_for_unarmed_entry, write_writes_no_stamp_line_for_unarmed_entry, mixed_entries_only_armed_one_displays_a_date, mixed_entries_append_writes_stamp_only_for_armed_one},与 PR 正文 5 红一致。
  • 被改的老钉:script_driver_history_in_regressions 12/12 绿。
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base {issue2084..., pathmatrix_bridge_legacy_dialect_restores_funnel} → 差集 ∅。
  • -D warnings:bin+lib 与 PR stem 0 警告;全仓 --tests 的 issue1794/2278 dead-code 为基线。
  • 卫生:rustfmt 七文件 0 差异;marker-lint OK;utf8 clean。
  • CI(run 43789928935):Rust tests = issue2875;macOS 1245/1 = issue2875;GNU goldens 1351/1 = issue2875;niubash = MISSING Session::cwd(ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 面);其余绿。无 PR 专属红。API ledger tripwire pass(record 为内部签名,未破 ledger)。
  • GNU 对照(WSL GNU bash 5.3.20(1)):五形状
    a) history -s 'echo new'; HISTTIMEFORMAT='%F '; history → 1 ??echo new
    b) HISTFILE=h1; history -s 'echo a'; HISTTIMEFORMAT=...; history -a → echo a(无 # 行)
    c) -w 同上
    d) 混合条目 → 第1条 ??、第2条日期
    e) armed 后 -a → echo m1 / #1794826189 / echo m2
    五形状 stdout 与 rubash 逐字节一致(含 ?? 与 #epoch 行)。探针 target/s2/probes/h3392/{a..e}.sh。

F 点:无

合并:109ab513b0f273f8711900514d258c46b636cea3(squash,未删分支)

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

Labels

area:interactive REPL: prompt, completion, paste, history, terminal integration bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

history 条目在 HISTTIMEFORMAT 设定前创建仍被盖墙钟戳(GNU 为空戳、显示 ??、-a/-w 不写 # 行)

2 participants