Skip to content

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

Description

@ranxianglei

Summary

With debug: true, nudge injections are echoed to the TUI via ctx.ui.notify() → pi's showStatus() → a transient dim Text child appended to chatContainer. These echoes are never written to the session log, so:

  1. Every process restart (pi --session <id> resume, agent process restart) runs chatContainer.clear() + rebuildChatFromMessages() (pi interactive-mode.js), wiping the entire injection history from view.
  2. ~/.pi/acp.log keeps only the first physical line of each nudge: log.ts:50 formats entries as a single line (`${ts()} [${level}] [${scope}] ${body}\n`), and the multi-line nudge body spills onto subsequent untagged physical lines — so grep nudge-injected shows only the headline ("⚠️ Context limit reached — compress now..."), not the tier/breakdown/ranges that make the entry useful.

Observed impact: in a long-running session with 5 process starts (sid 01a07b3c-ab19-7b19-8290-f7967a8221a6, see #325), the user could not reconstruct which nudges had fired and when — on-screen evidence was gone after each restart, and the log was not grep-able for full nudge content.

Request

Make nudge injections durable and auditable:

Primary: persist a compact nudge record as a session entry on injection (the if (turn.nudge?.shouldInject) block in src/index.ts), surviving restarts and visible in TUI scrollback + session file. Precedent: /acp and /acp-status are already shown as persistent custom messages (commit 0ff701e, issue #255).

Constraints:

  • Keep the persisted record short (e.g. [ACP nudge] EMERGENCY 95% · T1 · top range m00120–m00168) — the full multi-line nudge text must NOT be added to model context (it would pollute context every turn).
  • If pi's session-entry mechanism always feeds entries back into model context, prefer a display-only entry type; otherwise gate persistence behind the existing debug flag.

Secondary (small): escape newlines when writing debug events to acp.log (one physical line per entry) so nudge-injected / nudge-suppressed entries are self-contained and grep-able.

Repro / evidence

  • Any session with debug: true in ~/.pi/acp.json: trigger a nudge (usage above band), observe the on-screen block, restart pi → block gone; grep nudge-injected ~/.pi/acp.log → headline only.
  • Session sid 01a07b3c-ab19-7b19-8290-f7967a8221a6: 4 emergency injections (acp.log lines 13504-05, 13848-49, 13922-23, 14122) across 5 process starts; none recoverable from TUI or log after restart.
  • Related: [bug] Post-compression sent-view undercounts prompt by ~70–80K → false idle → host-floor emergency re-nudge loop #325 (post-compression sent-view undercount driving repeated emergency injections in that session).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions