Repository navigation
Conversation
MCP delivery capture no longer kills the warm Claude process after every turn. Capture-key admission is fenced by grant activate/deactivate so prompt-cache continuity can survive across messages. Co-authored-by: Cursor <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 18, 2026, 3:44 PM ET / 19:44 UTC. ClawSweeper reviewWhat this changesThe PR keeps Claude CLI child processes alive across captured turns to preserve prompt-cache state. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 7 items remain Keep open: normal captured Claude runs still restart because each outer run has a newly minted loopback token in the live-session fingerprint, so the PR does not deliver its intended warm-process cache reuse. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherClaude CLI runs receive generated MCP configuration plus a loopback grant for tool calls. The Gateway validates that grant before captured tool activity can reach delivery. flowchart LR
A[Prepared Claude run] --> B[Loopback grant]
A --> C[Generated MCP config]
C --> D[Claude child process]
B --> E[Live-session fingerprint]
D --> F[Captured tool call]
F --> G[Gateway authorization]
G --> H[Message delivery]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource -3, Tests +129. Total +126 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Restore captured-session shutdown unless MCP configuration and grant ownership move coherently to the session with a tested per-turn authorization handoff. Do we have a high-confidence way to reproduce the issue? Yes from source: two normal prepared captured runs mint different OPENCLAW_MCP_TOKEN values, and the second token changes the live-session fingerprint before reuse. Is this the best way to solve the issue? No; merely retaining the child cannot preserve reuse while the process fingerprint includes per-run credentials and those credentials are intentionally revoked after each outer run. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d1f58c4be422. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Related follow-up: #140566 (“preserve resumed CLI caches across Git changes”) is now merged. Keeping a compatible Claude process warm and preserving the request prefix when a process must resume are complementary improvements. The new fix targets the latter: it prevents Claude Code’s refreshed startup Git snapshot from rewriting the conversation prefix after workspace activity. It does not change MCP capture/grant lifetimes, process-reuse decisions, or thinking-level transitions. It should not be read as replacing the warm-session work tracked here. Existing merged/closed status is unchanged. Reference: #140566 |
Related: #124300
What Problem This Solves
Fixes an issue where users running OpenClaw through the Claude CLI live backend with MCP delivery capture (the default Gateway message-tool path, including Telegram) would lose prompt-cache continuity after every completed turn. Each message spawned a fresh
claudeprocess that resumed from disk, so the first resume of a process could rewrite the entire prompt prefix.Measured today on one Telegram Fable session (09:28–10:48 UTC, 2026-08-18): 42 API iterations, 7,237,084 cache-read tokens, and 1,174,177 one-hour cache-write tokens (billed 2x input). The final iteration read 0 cached tokens and rewrote 215,064. Gateway journals showed every completed Claude turn logging
claude live session close: ... reason=restart.This is the remaining steady-state cost after #124300 (
7f93011562d), which already restored cache reuse within a live process. Per-turn process death made that worst case the normal path.Why This Change Was Made
The capture key must ride child process environment and MCP headers (
OPENCLAW_MCP_CLI_CAPTURE_KEY,x-openclaw-cli-capture-key). Claude materializes those at spawn; there is no stdio control to rotate them without a new process. Commit0ea08076c3b5therefore killed the warm process after every captured turn so the attempt could release the key without leaving it usable for later sends (f5aba544373later moved thatfinallyblock).This change keeps that security invariant without the kill:
activeCaptureKeyis cleared.CLI_MCP_DELIVERY_DRAIN_GRACE_MS, plus 250ms admission grace), close the session withmcp-capture-rotationso the env key dies with the child.forceNewSession, fork (closeClaudeSession(..., "restart")), idle timeout, abort, and run-end live-session cleanup.Non-live one-shot CLI still gets a unique per-attempt key. Unchanged.
Accepted remaining window: a delayed HTTP packet from turn N that arrives after turn N+1 reactivates the same process-stable key would be attributed to N+1. Drain + admission grace + deactivate-between-turns is the mitigation. Fully closing that window requires killing the process (the old behavior). The one-time cold-resume prefix rewrite after a genuine process death (gateway reboot, model switch) remains an accepted cost from #124300.
User Impact
Claude CLI live sessions with MCP delivery capture keep the warm process across messages, so API-side prompt cache can stay hot instead of rewriting the prefix on every turn. Operators should see
reason=restartonly for real session identity changes, not after every captured message. Message-tool sends after a captured turn still cannot use a stale capture key.Evidence
Pre-fix reproduction (regression test captured before the production edit):
reuses a captured Claude live process and capture key across resume turnsfailed onmainwithexpected "vi.fn()" to be called once, but got 2 times— thefinallyblock killed the child, so the second resume turn spawned again.Post-fix:
reason=restart.reason=mcp-capture-rotationand fails closed (CLI message tool call remained in flight after exit).Commands (worktree, Node 25.9 via
/usr/bin/node):Autoreview:
python3 .agents/skills/autoreview/scripts/autoreview --engine claude --mode local --thinking max(claude-fable-5). Result:autoreview clean: no accepted/actionable findings reported.Production LOC (
git diff --numstat origin/main...HEAD):claude-live-session.ts+5/−10,execute-tool-tracking.ts+3/−1 comments,mcp-http.loopback-runtime.tscomment rewrite. Net production ≈ −3. Tests: newclaude-live-process-capture.test.ts(+255) after splitting off the capture lifetime cases soclaude-live-process.test.tsstays under the 1000-line cap.Live Telegram/Gateway proof was not run: this worktree must not touch the operator gateway,
~/.openclaw, or the main checkout. Owner-boundary tests inject spawn, grant activate/deactivate, and in-flight MCP drain in the original execution order.Head:
565510b98bd553e18cb40a8a8455edabeed004ac.