Repository navigation
fix(agents): pass admitted sessionEntry to clearCliSessionInStore during CLI recovery - #208637
zsicheng0214 wants to merge 1 commit into
Conversation
|
🦞👀 ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: passed. What this changesThis PR passes the admitted session entry to the existing guarded CLI binding clear before fresh-session recovery. Example: native-sess-1 expires while the cached writer differs from the admitted writer.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a concrete recovery failure still present on current main, with no introduced correctness defect found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe command agent adapter connects admitted turns to CLI backends; the session-store owner guards binding updates, and the CLI runner performs eligible fresh retries. flowchart TD
A[Gateway agent request] --> B[Admitted CLI candidate]
B --> C[CLI subprocess]
C --> D[Expired session recovery]
D --> E[Guarded binding clear]
E --> F[Fresh history seeded attempt]
F --> G[Persist replacement binding]
Technical reviewBest possible solution: Use the admitted working entry for the existing guarded clear while preserving writer, lifecycle, native-binding, and media-replay checks. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the stale-writer mismatch and suppressed retry; the contributor supplies a failing baseline regression, but this read-only review executed no target code. Is this the best way to solve the issue? Passing the already-admitted mutable entry fixes the incorrect expected-writer input through the existing owner without another database read or weaker write guards. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d31aefeac1a1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +66. Total +66 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ 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 (1 earlier review cycle)
Reviewed November 29, 2026, 7:09 PM ET / November 30, 2026, 00:09 UTC (Revision 2). |
|
Added redacted isolated Gateway end-to-end logs and 3-turn CLI subprocess invocation trace on
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Fixes #208264
What Problem This Solves
When a CLI backend reports
session_expiredand triggers fresh-session recovery (onBeforeFreshCliSessionRetry),clearCliBindinginsrc/agents/command/attempt-execution.tscalledclearCliSessionInStorewithout passingactiveSessionEntry: params.sessionEntry. As a result,clearCliSessionInStorefell back toparams.sessionStore[sessionKey]— the stale entry cached before turn admission, which still held an olderactiveWriterRunId.patchCliSessionBindingInStorethen rejected the patch becausesameCliSessionWriterrequiressessionId,lifecycleRevision, andactiveWriterRunIdto match the admitted store row, causing fresh-session retry to be skipped permanently until/reset.User Impact
CLI backends using
freshSessionRecovery: "invalidated-only"now clear their invalidated native CLI session binding and execute the fresh-session retry when the durable store holds the current admitted writer, while still refusing to clear if a concurrent replacement writer or/resetsupersedes the session after admission. No configuration changes or migrations are required.Why This Change Was Made
In
src/agents/command/attempt-execution.ts:withAdmittedCliCandidatealready reads the latest admitted session row (turn.sessionEntry, assigned toparams.sessionEntry), which carries the current admittedactiveWriterRunIdandlifecycleRevision(and receives writer updates during history preparation).activeSessionEntry: params.sessionEntrytoclearCliSessionInStoreinsideclearCliBindingmatches the sibling auto-reply candidate (src/auto-reply/reply/agent-runner-cli-candidate.ts) andpersistStoppedFirstSession/settleResultin the same file, avoids an extra database read, and preserves all threesameCliSessionWriterguards (sessionId,lifecycleRevision,activeWriterRunId) as well asexpectedCliSessionId.Evidence
1. Live Isolated Gateway End-to-End Proof (Reviewed Head
61c1054e9, Nodev24.22.3, Real Spawned CLI Subprocess — NorunCliAgentMock)Started an isolated OpenClaw Gateway (
startGatewayWithClient) configured with a real spawned local CLI backend (freshSessionRecovery: "invalidated-only",reseedFromRawTranscriptWhenUncompacted: true,sessionMode: "existing") and sent 3 sequential WebSocketagentRPC turns onagent:main:main:"Remember the secret code: ALPHA-7."-> spawns fresh native sessionnative-sess-1.native-sess-1from the backend's active session store so--resume native-sess-1fails withsession_expired."What was the secret code?"-> attempt 1 fails withsession_expired; Gateway clears the expired binding using the admitted session entry, retries once on freshnative-sess-2with saved history (ALPHA-7), and returns the recovered answer."Confirm resumed session."-> resumesnative-sess-2directly on the first attempt without retrying.Redacted Gateway logs (
OPENCLAW_LOG_LEVEL=warn)Turn payloads & CLI subprocess invocation trace
{ "turn1Payloads": [ { "text": "Recovered with saved history (ALPHA-7) on native-sess-1.", "mediaUrl": null } ], "turn2Payloads": [ { "text": "Recovered with saved history (ALPHA-7) on native-sess-2.", "mediaUrl": null } ], "turn3Payloads": [ { "text": "Resumed native-sess-2 ok.", "mediaUrl": null } ], "cliInvocations": [ { "resumeId": null, "promptHasAlpha7": true, "outcome": "fresh", "sessionId": "native-sess-1", "hasHistory": true }, { "resumeId": "native-sess-1", "promptHasAlpha7": false, "outcome": "session_expired" }, { "resumeId": null, "promptHasAlpha7": true, "outcome": "fresh", "sessionId": "native-sess-2", "hasHistory": true }, { "resumeId": "native-sess-2", "promptHasAlpha7": false, "outcome": "resumed", "sessionId": "native-sess-2" } ] }2. Base-Red / Head-Green Unit & SQLite Session Store Verification (
61c1054e9)Base (
origin/main) fails the new stale-cached-writer regression test:Fix (
61c1054e9) passes all 89 tests insrc/agents/command/attempt-execution.cli.test.ts:Lint & format:
oxlint src/agents/command/attempt-execution.ts src/agents/command/attempt-execution.cli.test.ts—Found 0 warnings and 0 errors.(keptattempt-execution.tswithin the 700-line limit).oxfmt --check src/agents/command/attempt-execution.ts src/agents/command/attempt-execution.cli.test.ts—All matched files use the correct format.