Skip to content

fix(agents): route CLI bootstrap truncation notice into the system prompt - #130325

Merged
jalehman merged 2 commits into
mainfrom
fix/cli-bootstrap-warning-system-prompt
Aug 26, 2026
Merged

jalehman merged 2 commits into
mainfrom
fix/cli-bootstrap-warning-system-prompt

Conversation

@jalehman

Copy link
Copy Markdown
Contributor

What

Routes the CLI runner's bootstrap truncation warning through the shared system prompt builder's bootstrapTruncationNotice slot (the same path the embedded runner uses) and deletes the per-turn append of the detailed warning block onto the wire prompt.

Why

CLI-backed sessions (claude-cli/*, codex-cli/*, …) appended the full [Bootstrap truncation warning] block to every turn's user prompt via appendBootstrapPromptWarning in cli-runner/execute.ts. Because the composed wire prompt is what transcript-rendering surfaces display, the warning block appeared inside the user's chat bubble on every message — a UX regression relative to API-backed models, where the embedded runner places a compact notice in the (invisible) system prompt. Truncation state is computed from the same bootstrap files each turn and does not change mid-session, so the per-turn repetition bought nothing.

Changes

  • CLI system prompt now carries the compact truncation notice
  • Deleted per-turn appendBootstrapPromptWarning wire-prompt append
  • Deleted now-dead bootstrapPromptWarningLines context plumbing
  • Deleted appendBootstrapPromptWarning (execute.ts was its only consumer)
  • Reworked prompt-composition scenario to the system-prompt contract
  • Added prepare-level regression test (fails pre-fix)

Detailed per-file truncation stats still land in the system-prompt report (buildBootstrapTruncationReportMeta), so diagnostics lose nothing. Production LOC delta: −27 (+8/−35); tests −51.

Testing

  • pnpm vitest run over the 21 affected agent test files: 1073 passed
  • pnpm check:changed: all lanes green (format, typecheck core + tests, lint, guards)
  • New regression test routes bootstrap truncation notices into the system prompt, not the turn prompt verified to fail against pre-fix prepare.ts/helpers.ts

Live verification: not run against a live gateway — this machine's gateway is serving the session driving this work, and restarting it from the branch would kill that session. The changed seam is covered end-to-end at the prepare/execute boundary by the tests above; happy to live-verify on a session switched to a claude-cli model after landing.

Review notes

Autoreview (Codex, gpt-5.5) raised one P2: a before_prompt_build hook returning systemPrompt replaces the built system prompt, discarding the notice, whereas the old body append survived hook replacement. Rejected as parity-consistent: the embedded runner has identical semantics (attempt-prompt-build.ts — legacy full-replacement systemPrompt hooks discard the entire built prompt, including the injected Project Context itself). A hook that replaces the system prompt owns all of it; retaining a truncation warning for context the hook already discarded would be misleading.

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@jalehman
jalehman marked this pull request as ready for review August 26, 2026 19:44
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 5:46 PM ET / 21:46 UTC.

ClawSweeper review

What this changes

The PR moves CLI bootstrap-truncation guidance from each user turn into the shared system prompt and refreshes first-only resumed CLI sessions when truncation begins or ends.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still appends the detailed truncation warning to CLI turn prompts; this branch moves it through the existing shared system-prompt path and adds session-drift handling. No blocking source defect surfaced, but the documented one-time soft resume for existing bindings remains a merge-visible session-state change.

Priority: P2
Reviewed head: 0407fc0b066f150220634b6eda6d81505f9e0b75

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent net-negative repair with focused owner-boundary and session-drift coverage, pending routine maintainer review and exact-head CI.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body also gives a concrete reason that live gateway verification was infeasible.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body also gives a concrete reason that live gateway verification was infeasible.
Evidence reviewed 7 items Current-main behavior: Current main still imports and applies the detailed bootstrap warning to the CLI body prompt, establishing that the reported user-visible behavior remains unfixed there.
Changed owner boundary: The branch derives the compact notice from the existing bootstrap analysis, passes it to the shared CLI system-prompt builder, and includes its presence in the reuse fingerprint.
Shared-runner parity: The embedded runner already passes the compact notice into the same system-prompt surface, and the common builder renders it under Bootstrap Context Notice.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/agents/cli-runner/prepare.test.ts -- --reporter=verbose

Result: FAIL (failed) — step 1 run pnpm test src/agents/cli-runner/prepare.test.ts -- --reporter=verbose: previous terminal command was still running after 30 seconds: "pnpm test src/agents/cli-runner/prepare.test.ts -- --reporter=verbose"

$ node --import tsx scripts/test-projects.mts src/agents/cli-runner/prepare.test.ts -- --reporter=verbose
[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130325-Oy8X7A/target

 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › preserves outer fallback route provenance through CLI admission 413ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › passes high thinking through the CLI backend execution seam 324ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › passes off thinking through the CLI backend execution seam 239ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › uses the prepared model context budget before discovery cache settlement 246m
s
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › resolves canonical model budgets for 'a Claude CLI user alias' 238ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › resolves canonical model budgets for 'a Claude CLI-native alias' 223ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › resolves canonical model budgets for 'a generic CLI backend alias' 220ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › caps the context budget with 'the session-selected 200k option' from catalog
contextWindows 212ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › caps the context budget with 'the declared default option when unse…' from ca
talog contextWindows 211ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › carries the session-key-derived workspace owner into prepared params 131ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › honors an explicit auth agent directory independently of session identity 220
ms
 ✓  agents-support  src/agents/cli-runner/prepare.test.ts › prepareCliRunContext › passes expired Gemini CLI OAuth fields to CLI-owned refresh 505ms

Assertions:

  • FAIL expect_output: routes bootstrap truncation notices into the system prompt, not the turn prompt

How this fits together

The CLI agent runner analyzes truncated workspace bootstrap files while preparing a run, then supplies a system prompt and a user-turn prompt to a configured CLI backend. Transcript-facing surfaces render the turn prompt, so routing the notice through the system prompt keeps diagnostic guidance out of user chat bubbles.

flowchart LR
  A[Workspace bootstrap files] --> B[Bootstrap budget analysis]
  B --> C[Truncation notice]
  C --> D[CLI system prompt]
  U[User turn] --> E[CLI turn prompt]
  D --> F[CLI backend session]
  E --> F
  F --> G[Transcript rendering]
Loading

Before merge

  • Resolve merge risk (P1) - Existing bindings created while bootstrap mode was active use the prior fingerprint shape, so their next eligible turn soft-resumes once and receives the current system prompt.
Agent review details

Security

None.

PR surface

Source -22, Tests +19. Total -3 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 6 17 39 -22
Tests 11 138 119 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 155 158 -3

Review metrics

Metric Value Why it matters
Production versus test LOC production +17/−38 (net −21); tests +116/−91; test support +22/−29 The bug repair is net-negative in production; the remaining additions are focused prompt and resumed-session regression coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/cli-runner/prepare.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept the one-time prompt refresh (recommended)
    Accept the documented soft resume for eligible existing bindings, which refreshes current system context without discarding the CLI transcript.
  2. Add upgrade-shape coverage
    Add a focused compatibility test that starts from a binding carrying the prior bootstrap-mode fingerprint shape and proves the single soft-resume behavior.

Technical review

Best possible solution:

Retain the shared system-prompt route and the truncation-aware reuse fingerprint, with maintainers knowingly accepting the documented one-time soft resume before merge.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible with high confidence: current main appends the detailed truncation block to the CLI body prompt, while a truncated bootstrap fixture reaches that code path.

Is this the best way to solve the issue?

Yes. Reusing the shared system-prompt notice already used by the embedded runner removes the transcript leak at the producer boundary, and the fingerprint update prevents stale first-only resumed sessions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 54db7d4f99e8.

Labels

Label justifications:

  • P2: This repairs a user-visible CLI-agent prompt regression with bounded impact and no demonstrated data-loss, security, or availability failure.
  • merge-risk: 🚨 session-state: The reuse fingerprint changes persisted CLI-session behavior and deliberately causes one soft resume for affected existing bindings.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body also gives a concrete reason that live gateway verification was infeasible.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Feature history shows repeated substantial work in the CLI runner and the recent Claude-session refactor. (role: major agent-runtime contributor; confidence: medium; commits: 12d0fd2ef8af, f5aba5443734; files: src/agents/cli-runner/prepare.ts, src/agents/cli-runner/execute.ts)
  • Vito Cappello: Recent history includes CLI recovery, compaction, and prompt-cache work adjacent to the resumed-session behavior changed here. (role: recent CLI-session contributor; confidence: medium; commits: 1b9d3ac57d13, f5c46de8ac50; files: src/agents/cli-runner/execute.ts, src/agents/cli-session.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-26T19:53:44.095Z sha 0bb6bc6 :: found issues before merge. :: [P2] Track truncation notice changes in session reuse
  • reviewed 2026-08-26T21:00:23.259Z sha a792630 :: needs maintainer review before merge. :: none

@jalehman

Copy link
Copy Markdown
Contributor Author

Addressed the ClawSweeper review (all three checklist items reduce to the one P2 finding):

Track truncation notice changes in session reuse — fixed in a792630. Truncation-notice presence is now folded into the CLI session reuse fingerprint (extraSystemPromptHash), mirroring the existing bootstrapMode hashing at the same site. When an AGENTS.md edit starts or ends truncation mid-session, a resumed systemPromptWhen: "first" backend now gets reuse-with-drift → soft-resume system-prompt resend instead of silently reusing the stale prompt. Presence (not text) is hashed because the compact notice text is constant; only entering/leaving truncation changes resumable system context.

Two-turn regression added (drifts a resumed first-only session when truncation starts mid-session): turn 1 un-truncated establishes the binding hash, turn 2 crosses the threshold and asserts the notice in the system prompt plus reuse-with-drift with reason system-prompt. Verified to fail against the pre-fix fingerprint.

One-time migration note: existing bindings for sessions in bootstrapMode !== "none" or with active truncation hash under the old shape, so their next turn takes a single benign soft resume that delivers the current system prompt — desirable for truncated workspaces, harmless otherwise.

Fresh autoreview (Codex, gpt-5.5) on the updated branch: clean, no actionable findings. pnpm check:changed green; 568 tests across the affected files pass.

🤖 Generated with Claude Code

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
jalehman and others added 2 commits August 26, 2026 14:31
…ompt

CLI-backed runs appended the detailed bootstrap truncation warning to
every turn's wire prompt, which surfaced the warning block inside user
chat bubbles on transcript-rendering surfaces. The embedded runner
already routes a compact notice through the shared system prompt
builder's bootstrapTruncationNotice slot.

Route the CLI runner through the same slot and delete the per-turn
prompt append plus its context plumbing. Detailed per-file stats still
land in the system prompt report for diagnostics.

Co-Authored-By: Claude Fable 5 <[email protected]>
Fold bootstrap truncation-notice presence into the CLI session reuse
fingerprint, mirroring the existing bootstrapMode hashing. Without this,
a systemPromptWhen:"first" backend resuming an existing session never
receives the updated system prompt when an AGENTS.md edit crosses the
truncation threshold mid-session — a path the removed per-turn body
append used to cover. Two-turn regression proves the drift resend.

Co-Authored-By: Claude Fable 5 <[email protected]>
@jalehman
jalehman force-pushed the fix/cli-bootstrap-warning-system-prompt branch from a792630 to 0407fc0 Compare August 26, 2026 21:38
@jalehman
jalehman merged commit 0b45001 into main Aug 26, 2026
196 checks passed
@jalehman
jalehman deleted the fix/cli-bootstrap-warning-system-prompt branch August 26, 2026 23:39
vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (26 commits)
  fix(plugins): preserve registry epoch on activation rollback (#129232)
  refactor(plugins): make discovery invocation-owned (#130486)
  feat(ui): save appearance preferences per user profile (#130340)
  fix: Buzz bots recover relay stalls and reject revoked senders (#130467)
  fix(code-mode): serialize catalog handles nested in final values (#130276)
  fix(webchat): CLI skill and harness-injected turns render as operator-sent messages (#130427)
  fix(agents): read the published model catalog owner from session_status (#130277)
  fix(channels): preserve long presentation text (#130368)
  fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
  refactor(plugins): unify setup registration and artifact selection (#130474)
  fix(memory): prevent forgotten session content from returning (#130451)
  refactor(outbound): consolidate transport completion (#130460)
  fix(workers): protect in-flight workspace manifests from concurrent retention (#130449)
  fix(portals): keep worker previews reachable and owned by the active environment (#130434)
  fix(config): keep core channels keys in the generated config schema (#120736)
  chore(deps): refresh dependencies after seven-day cooldown (#130296)
  fix(agents): remind exec models to quote shell metacharacters (#125485)
  fix(auth): honor shared-store ownership in temp-state exec and agent deletion (#130437)
  fix(openshell): preserve file writes during concurrent mirror commands (#130447)
  fix(workers): report full nodes as at capacity, not offline (#130445)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…ompt (openclaw#130325)

* fix(agents): route CLI bootstrap truncation notice into the system prompt

CLI-backed runs appended the detailed bootstrap truncation warning to
every turn's wire prompt, which surfaced the warning block inside user
chat bubbles on transcript-rendering surfaces. The embedded runner
already routes a compact notice through the shared system prompt
builder's bootstrapTruncationNotice slot.

Route the CLI runner through the same slot and delete the per-turn
prompt append plus its context plumbing. Detailed per-file stats still
land in the system prompt report for diagnostics.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(agents): drift first-only CLI sessions when truncation state changes

Fold bootstrap truncation-notice presence into the CLI session reuse
fingerprint, mirroring the existing bootstrapMode hashing. Without this,
a systemPromptWhen:"first" backend resuming an existing session never
receives the updated system prompt when an AGENTS.md edit crosses the
truncation threshold mid-session — a path the removed per-turn body
append used to cover. Two-turn regression proves the drift resend.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant