Repository navigation
fix(sessions): avoid first-turn refusals from retired Usage executors - #170572
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR acquires existing-store Usage executors at writer admission while preserving the originally observed file identity. Example: Usage prepares the main agent's store, then its executor retires before acquisition.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a distinct first-turn failure still present on fetched main, with no actionable correctness findings. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Usage cache writer sits between background transcript aggregation and the shared agent-database execution owner; it accepts rollup or prune requests and commits derived cache data through the existing writer queue. flowchart TD
A[Usage refresh] --> B[Capture original file identity]
B --> C[Existing writer queue]
C --> D[Check refresh authority]
D --> E[Acquire current executor]
E --> F[Agent database worker]
F --> G[Session SQLite store]
Technical reviewBest possible solution: Acquire the current executor inside the existing writer reservation while retaining original-file constraints, creation witnesses, and live authority checks. Do we have a high-confidence way to reproduce the issue? The source and added deterministic retirement regression establish a concrete reproduction path; the author reports the exact baseline failure, but no target code was executed during this read-only review. Is this the best way to solve the issue? The patch repairs capture timing at the existing owner rather than retrying failed writes, and preserves foreground ordering, cold-store preparation, physical identity, cancellation, and revocation checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2c7872bdad12. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +18, Tests +76. Total +94 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 Reviewed October 12, 2026, 11:27 PM ET / October 13, 2026, 03:27 UTC. |
|
Merged via squash.
|
What Problem This Solves
Fixes a new session's first turn being refused with
Agent database execution admission is closedwhen Usage writer preparation retains an executor that retires before consumption.User Impact
An existing store's Usage refresh acquires its current executor at writer admission. Session replacement and the first turn can proceed against the original physical store. A replacement file, revoked refresh authority, or cancellation still refuses the write. No operator action or migration is required.
Why This Change Was Made
The cache retained an execution reference before awaited work. Capture of an existing-store executor now happens inside the existing writer reservation, after checking the refresh authority, with the originally observed physical identity pinned. Missing stores still retain their creation witness before yielding; existing writers are still prepared before the scan, preserving the cold scan/prune fix in #170308. Incognito and maintenance paths are unchanged. There are no retries or changes to timeouts, schema, durability, retention, FIFO ordering, or authority.
Source attribution: the early cache-writer capture originated in #163287 (
4a66195396d4) and survived the process-local reservation change in #169974 and existing-store preparation in #170308. The native failure also reproduced on #170464's warmed parent, so reverting #170464 does not repair it. This is source attribution plus a current-main deterministic negative control, not a claimed historical first-red bisect.Evidence
The new regression forces retirement before Usage acquisition, then verifies session replacement and independently reads the committed session and rollup. It fails on unpatched main
f9af58c66f79with the exact admission-closed error (333 ms case; 50.89 s wrapper). Companion cases retain refusal and unchanged file bytes after physical replacement or authority revocation.pnpm test src/infra/session-cost-usage-cache.admission.test.ts src/infra/session-cost-usage-cache.worker.test.ts src/state/openclaw-agent-execution.idle.test.ts src/state/openclaw-agent-execution.close-wedge.test.ts src/gateway/server.sessions.create.auth-policy.test.ts --maxWorkers=1: 51/51 passed, 194.75 s wrapper. Includes the original Gateway initial-turn case and cancellation, pending-open, FIFO, missing-store creation, drainage, idle retention, and native-close recovery contracts. The three new cases took 1.178, 1.544, and 1.056 s.CI seconds are not available at PR creation. The first implementation used a creation constraint for an existing file and failed three pending-open assertions; using the existing file constraint restored them without changing those tests. The new replacement control initially expected the wrong refusal text and now asserts the owner's exact existing-only identity error. No failing run is relabeled green.