Skip to content

feat(nudge): persist nudge injections as display-only session entries (closes #326) - #552

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-23_persist-nudge-records
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-23_persist-nudge-records

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Supersedes #515 (original author @liu-zhengdong — full design and description below belong to them). Maintainer-side rebase onto current master 40670ca (v0.1.78, acp-kernel 0.0.94): the fork head had conflicts in src/messages.ts (ACP_RULE_CUSTOM_TYPE from #526 vs this PR's ACP_NUDGE_CUSTOM_TYPE) — resolved by union.

Closes #326.

Summary (from #515)

When a context-limit nudge is injected, it was previously only shown transiently via ctx.ui.notify() (if debug mode was on), and never written to the session log. Restarts or resuming sessions would wipe all injection history, and multi-line nudge logs spilled onto un-tagged physical lines in acp.log.

Changes

  1. Persistence & TUI rendering (src/index.ts): append compact record ([ACP nudge] EMERGENCY 95% · T1 · top range m00120–m00168) via pi.appendEntry("acp-nudge", { text }); deduped per user turn via runtime.markNudgeRecorded(); dim-box entry renderer via @earendil-works/pi-tui; zero LLM context pollution (custom entries excluded from core projection).
  2. Single-line logging (src/log.ts): escape \r/\n in string fields — one physical line per log entry.
  3. Tests & Docs: tests/nudge-record.test.ts + tests/log.test.ts; CHANGELOG + README×2.

Rebase verification (this branch)

  • npm run typecheck: 0 errors
  • env -u BILLION_CONTEXT_PROXY npm test: 979 tests / 973 pass / 0 fail
  • npm run build: PASS

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-23_persist-nudge-records (24a953d)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-552

Each push to this PR publishes a new version under the pr-552 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr552.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始 review PR #552。初步状态:

  • 分支 2026-09-23_persist-nudge-records @ f07dee4,base 为 master 40670ca(v0.1.78),单 commit,9 文件 +227/-8。
  • ⚠️ master 已前进到 6de008a(v0.1.79 刚发版)——base 已过期,我会核对 v0.1.79 的变更是否与本 PR 触碰路径冲突,并验证 rebase 到当前 master 后的 typecheck/test/build。
  • 审查顺序按规范走:原 issue [feat] Persist nudge echoes as session entries (survive restarts, grep-able log) #326 方向 → 回归清点 → 代码 → 测试有效性 → diff 整洁度。结论稍后更新。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — verified, can merge. Full audit below (issue direction → regression inventory → code → tests → diff).

① Issue direction (#326) — correct, root-cause level. Verified pre-fix state on master: zero appendEntry/registerEntryRenderer usages repo-wide; nudges were transient ctx.ui.notify() (debug-only) and log.ts had no newline escaping (multi-line bodies spilled onto un-tagged physical lines). The fix targets the mechanism, not symptoms: pi's official display-only persistence path (appendEntry → type:"custom" entry) instead of sendMessage, which would fall back to steer() mid-turn. This matches the design settled in #326 floors 3–4; original agent attempt #329 was closed unmerged and #515 is superseded by this PR.

② Regression inventory — every pre-existing behavior the diff touches, with verdicts:

  • Nudge injection flow (src/index.ts context handler): unchanged — same text, same steering; persistence block runs after debug.event("nudge-injected") inside try/catch, so an append failure degrades to a warn log and never breaks injection. Guarded by typeof pi.appendEntry === "function" so older hosts without the API keep working. Preserved.
  • Model context / prefix cache: zero impact. Verified against installed pi 0.83.0 types: CustomEntry doc says "Does NOT participate in LLM context (ignored by buildSessionContext)" (dist/core/session-manager.d.ts), and appendEntry's own doc says "not sent to LLM" (dist/core/extensions/types.d.ts:923). Repo-side: entriesToCoreMessages projects only message/custom_message; every raw-entry scan filters those two types (src/live-only-tail.ts:64). This answers the one open question from my first pass — ACP_NUDGE_CUSTOM_TYPE correctly does not need to join CONTEXT_EXCLUDED_CUSTOM_TYPES (src/messages.ts:40), which gates custom_message projection only.
  • Session file format: purely additive — new type:"custom" lines; sidecar .acp.json untouched. Dedup state (nudgeRecordedTurns) is in-memory only, keyed by the same turnKey as display-dedup (lastTurnBoundaryId, src/index.ts:672), so post-restart behavior mirrors the existing nudgeShownTurns reset semantics. Consistent, no drift.
  • TUI rendering: new renderer registered at factory time (required — unrendered custom entries are dropped from live view and rebuild); malformed data returns undefined (invisible but persisted), no crash path. Theme keys customMessageBg/dim and Box(1,1,bgFn)/Text(text,0,0) constructors all verified against pi-tui 0.83.0 type defs.
  • Host paths (Pi / OMP refusal / proxy stand-down / thin-plugin coexistence): detection logic untouched; new wiring is unconditional-but-guarded, safe on every host path. Stand-down suites pass within the 979.
  • Auto-update / kernel pin: untouched — no package.json or lock changes, acp-kernel stays 0.0.94.

⚠️ Behavior changes (old → new, per reporting policy):

  1. acp.log format: multi-line string field values (nudge body, stack traces) previously spilled onto un-tagged physical lines → now CR/LF escaped to literal \r/\n, exactly one physical line per entry. Applies to all string fields, not just nudges. Intended — this is [feat] Persist nudge echoes as session entries (survive restarts, grep-able log) #326's secondary ask; disclosed in CHANGELOG + both READMEs.
  2. Session JSONL: gains acp-nudge entry lines (additive).
  3. TUI scrollback: nudge records now survive restart/rebuild (was: transient, debug-mode only).

③ Code review — clean. Mark-after-success ordering means a failed append retries on the next fire (no silent loss); formatNudgeRecord output matches the issue's example verbatim; union resolution of the #526 ACP_RULE_CUSTOM_TYPE vs this PR's constant in src/messages.ts is present and correct.

④ Test validity — real teeth, not ceremony: exact-string assertions against the #326 example incl. tier/no-range variants; integration test drives actual kernel overflow (~270K sent view vs 180K window → EMERGENCY) through the real factory and asserts exactly-one-record-per-turn while emergency re-injection still reaches the model, plus new-turn → new record; log test asserts one tagged physical line per entry with escaped literals and stack co-located. These fail on pre-fix code.

⑤ Diff cleanliness — 9 files, +227/-8, every line serves #326. No unrelated churn, no whitespace noise, no lockfile drift.

Verification evidence (rebased head): clean rebase onto origin/master @ 6de008a (v0.1.79 — release commit touched only version lines, zero conflicts); then locally: typecheck 0 errors, env -u BILLION_CONTEXT_PROXY npm test 979/973 pass / 0 fail / 6 skipped (identical to your claim), build PASS, and dist confirmed zero-runtime-deps (pi-tui inlined — only remaining external import is @earendil-works/pi-coding-agent; the 13 pi-tui strings in dist are bundler source-marker comments). GitHub CI on head f07dee4: E2E ✅ CI ✅ Build Artifact ✅; PR reports mergeable against current master, so no force-push needed.

Notes: (a) this is a feat: touching load-bearing event wiring → human merge per §7.4 anyway; (b) please close #515 as superseded once this merges.

中文摘要: 审核通过——nudge 注入持久化方案打在根因上(pi 官方 display-only custom entry,零模型上下文污染,已对照 pi 0.83.0 类型定义逐条核实),唯一行为变更是 acp.log 多行值转义为单物理行(即 #326 的次要诉求,已披露);rebase 后本地三关全绿且与 CI 一致,可以合并。

@ranxianglei
ranxianglei force-pushed the 2026-09-23_persist-nudge-records branch from f07dee4 to 3e00a63 Compare September 26, 2026 00:52
@ranxianglei
ranxianglei force-pushed the 2026-09-23_persist-nudge-records branch from 3e00a63 to 40670ca Compare September 26, 2026 02:17
@ranxianglei ranxianglei reopened this Sep 26, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Re-reviewed the force-pushed head (f07dee4 → 24a953d, rebased onto master 198149c / v0.1.80) — still good, can merge. Delta audit below; my earlier review's conclusions carry over unchanged.

What the new push contains: maintainer-side rebase onto current master. Verified via range-diff that it is a pure move, not a content change:

What moved on master since my last pass (v0.1.79 → v0.1.80): #215 overflow-nobody-arm, #328 post-compress-token-floor, #430/#429 surface section-whitelist retirement, release v0.1.80. None touch this PR's paths in a conflicting way; package.json delta is version-only — acp-kernel pin unchanged at 0.0.94, so no pin-discipline re-audit needed. The #215 overflow logic lands adjacent to the injection branch but the nudge-record block sits after nudge-injected logging and is independent of the armed-self-heal path.

Validation on new head 24a953d (local, fresh npm ci): typecheck 0 errors · env -u BILLION_CONTEXT_PROXY npm test 997 / 994 pass / 0 fail / 3 skipped (count grew 979→997 purely from master's newly merged test suites — all green) · build PASS · dist still zero-runtime-deps (only external import remains @earendil-works/pi-coding-agent; pi-tui inlined).

GitHub state: CI on 24a953d — E2E ✅ CI ✅ Build Artifact ✅; PR reports mergeable: True against base 198149c.

Reminder from last round: close #515 as superseded once this merges. Merge stays human-side per §7.4 (feat + load-bearing wiring).

中文摘要: 复审了 force-push 后的新 head——rebase 为纯位移(代码 hunk 逐字节未变,仅行号偏移),master 新增的 #215/#328/#430 均无冲突且 acp-kernel pin 未动;新 head 上本地三关全绿(997/994/0)、CI 全绿、dist 零运行时依赖,结论不变,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Superseded by the in-place rebase of #515 (now at 927cde2, parented directly on current master e5c2476).

Verified: #515's rebased diff is line-for-line identical to this PR's content (only delta: one cosmetic blank line in src/messages.ts), plus the four union resolutions required by newer master (index.ts import with #561's liveOnlyTailCached, runtime.ts return object with sent-view metering methods, messages.ts beside #526's ACP_RULE_CUSTOM_TYPE, CHANGELOG position). CI on 927cde2: 9/9 green.

This branch (based on 198149c) is now dirty/conflicting against master. Closing to leave a single canonical PR (#515) for the merge. Reopen if anything is missing.

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.

[feat] Persist nudge echoes as session entries (survive restarts, grep-able log)

2 participants