Repository navigation
fix: keep completed CLI pre-tool text after session replacement - #164293
Oldrich333 wants to merge 3 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe PR saves completed Claude CLI pre-tool commentary in conversation history and pairs it with native records so it remains visible once after session replacement. Review scores
Merge readiness✅ Ready for maintainer review The PR remains useful: current main still drops diverted commentary from canonical history. The earlier findings are addressed, the supplied runtime evidence covers the intended behavior, and no remaining actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw’s CLI runner converts local model output into live commentary and final replies. Its canonical transcript and native-history importer feed the conversation history shown by the Gateway. flowchart TD
A[Claude CLI output] --> B[Streaming parser]
B --> C[Live commentary]
B --> D[Canonical transcript writer]
B --> E[Final reply]
F[Native session history] --> G[History identity matching]
D --> G
G --> H[Conversation history]
Technical reviewBest possible solution: Keep completed visible commentary in the canonical transcript through the existing writer, while leaving the broader timestamp and missing-window claims separately tracked. Do we have a high-confidence way to reproduce the issue? Yes: current main diverts pre-tool text into commentary without persisting it, and the supplied real Claude CLI before/after trace exercises binding replacement and restart. This review established the current-main mechanism from source without executing it. Is this the best way to solve the issue? Yes: persisting the exact diverted blocks through the existing transcript writer and pairing native records by identity is a focused repair that preserves final-reply behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b48245c41428. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +129, Tests +328. Total +457 across 11 files. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 4, 2026, 6:25 PM ET / 22:25 UTC (Revision 5). |
b43f1e6 to
d4e9755
Compare
|
Fixed the Ran locally: all 75 non-e2e/live files in |
Related: #135244
What Problem This Solves
Fixes: with commentary enabled (block streaming / progress drafts), completed pre-tool Claude CLI text is diverted to commentary and lives only in the native Claude session. After the native CLI binding is replaced (
/reset soft, auth/account change),chat.historyno longer shows it; only the final reply survives.User Impact
Pre-tool text the user already saw stays readable in the conversation after a later CLI reset, each text once, with one final answer. No user action or migration. Out of scope: the issue's separate missing-record-window, timestamp-reassignment and old-session-list claims; interrupted (non-completed) turns.
Why This Change Was Made
The parser already decides which text becomes commentary (
flushPendingClaudeCommentaryText). This change persists exactly that text, at that point, through the existing canonical transcript writer (persistCliAssistantTranscript: same hooks, room-event guard, session/lifecycle/writer fences), as one assistant row per diverted block with idempotency keycli-assistant:<runId>:seg:<nativeMessageId>:<ordinal>. Backend output replacements are applied before persistence, the same transform live commentary gets. The final reply write is unchanged. The segment also records Claude's own record id for that text block (the stream-jsonassistantsnapshotuuid, which equals the native JSONL rowuuid) as__openclaw.cliNativeRef; the history index uses it as the local row's external identity, so while the binding is live the native import pairs with the canonical segment by identity even when display transforms changed the text. After binding replacement the canonical segment remains.Changes vs the previous head (ClawSweeper rev 3 findings):
OldName→NewName).<thinking>…</thinking>) is routed by the existing partition before text reaches the commentary buffer; only visible text is persisted.--include-partial-messages(custom args only) no id is captured and matching falls back to the existing text comparison.Rebased on current main (conflicts resolved; merges cleanly with
d65e8ec89).Evidence
Real behavior: installed Claude Code 2.1.287 (subscription login),
claude-cli/claude-sonnet-5-5, two disposable gateways with isolated state,agents.defaults.blockStreamingDefault: "on"in both base (2d3ac4a35, unpatched main) and head (this branch). Same script per build: twochat.sendturns, each asking the model to write a marker sentence, callRead, then answer → stop gateway → drop the session'scliSessionIds/cliSessionBindings(the state effect of/reset soft→clearAllCliSessions) → start gateway →chat.history.Base (unpatched), bound — pre-tool text visible only via the native import:
Base after binding replacement + restart — pre-tool text gone:
Head (
d4e97554e), bound — each text once (canonical segment paired with its native row by id; canonicalcliNativeRef.externalId8fdfcdce-…= native JSONLuuid8fdfcdce-…of thePRE-TOOL-MARKERtext block):Head after binding replacement + restart — both pre-tool texts retained, once each:
On the previous head (
5ca101fcf, same script) a third turn on the new native session also merged once (segment + final). The binding was dropped in the stopped store because the CLI operator client was not authorized to run/reset softas a chat command.Tests:
src/agents/cli-output-stream.test.ts,src/agents/cli-runner/cli-run-transcript.test.ts, newsrc/agents/cli-runner/execute.commentary-history.test.ts, newsrc/gateway/cli-session-history.segments.test.ts: 4 files, 48 tests pass; vitest 32–37 s locally; new tests under 40 ms each. Negative controls: removing the replacement step fails the adapter test; reverting the index change fails both identity-pairing tests.src/gateway/cli-session-history.test.ts: 54/54.tsgocore + agents/gateway test shards clean; oxfmt/oxlint clean.src/gatewayhistory-boundary + cli-session-history suites: 91/91.pnpm check:changed: all stages pass except a type error inui/…/mcp-app-bridge.cursor.test.ts, reproduced identically on plain2d3ac4a35(untouched by this PR).5ca101fcf; second found the identity-pairing case above, then re-reviewedd4e97554eclean (including a replay of the real Claude Code stream).