Repository navigation
fix(workers): keep workspace recovery running during unrelated writes - #166375
Conversation
Share the existing pinned-snapshot session-facts reprepare in the revision owner. Worker recovery and current-entry admission opt into read checks while strict mutation checks and real ownership conflicts still fail closed. Sibling of #166010; repro from #165994 by @Oldrich333. Deterministic two-connection negative control fails all seven placement cases on the baseline; 61 owner and sibling tests pass with the repair.
|
🦞👀 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. Reviewed October 6, 2026, 9:20 PM ET / October 7, 2026, 01:20 UTC. ClawSweeper reviewWhat this changesWorkspace recovery and session admission share a bounded SQLite snapshot retry so unrelated writes do not cause false ownership conflicts. Merge readiness✅ Ready for maintainer review This PR remains useful: the merged admission fix leaves workspace recovery exposed to unrelated concurrent writes. The introduced changes preserve ownership checks, and no blocking correctness finding was identified. Priority: P2 Review scores
Verification
How this fits togetherWorker workspace recovery restores a session's local or repository workspace after worker execution. Session database facts and live placement authority determine whether recovery and its subsequent effects may proceed. flowchart TD
A[Recovery request] --> B[Resolve session and workspace]
B --> C[Check live owner and database source]
C --> D[Validate session ownership]
D --> E{Concurrent revision change?}
E -->|Yes| F[Recheck in short SQLite snapshot]
E -->|No| G[Guarded recovery callback]
F -->|Ownership unchanged| G
F -->|Ownership changed| H[Reject recovery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +108, Docs +1. Total +109 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep snapshot reevaluation in the revision owner while recovery retains exact session ownership and live source assertions through every effect. Do we have a high-confidence way to reproduce the issue? Yes, from source: a foreign commit between the strict guard's revision probes makes current-main workspace recovery reject unchanged ownership. The submitted two-connection regression supplies a deterministic path; this review did not execute it. Is this the best way to solve the issue? Yes. Moving the existing admission retry into its revision owner and opting recovery into read mode avoids duplicate policy while preserving strict mutation checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ed4974479682. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…claw#166375) Share the existing pinned-snapshot session-facts reprepare in the revision owner. Worker recovery and current-entry admission opt into read checks while strict mutation checks and real ownership conflicts still fail closed. Sibling of openclaw#166010; repro from openclaw#165994 by @Oldrich333. Deterministic two-connection negative control fails all seven placement cases on the baseline; 61 owner and sibling tests pass with the repair.
What Problem This Solves
Fixes: worker workspace recovery can fail with
invalid_statewhen another session writes to the same agent database during its ownership check.Fixes #165994
Sibling of #166010; repro from #165994 by @Oldrich333.
User Impact
Recovery tolerates unrelated concurrent writes while still rejecting changed session IDs, lifecycle revisions, active writers, database sources, and revoked authority. No configuration, public SDK, schema, migration, or update behavior changes.
Why This Change Was Made
The admission worker already re-prepared session facts once in a pinned SQLite read snapshot after a database-wide revision change. Move that mechanism into the existing revision-guard owner and opt both admission and workspace recovery into its internal read mode. Default mutation checks remain strict, active transactions do not retry, and neither writes nor recovery callbacks are replayed.
Two behavior-preserving cleanups in those owners remove a redundant missing-entry branch and combine identical target-rejection branches.
Evidence
7880834c1961, all seven final regression cases fail in 65.09 s. All three harmless-write cases reject withSession entry facts changed during their mutation check; the conflict cases encounter that broad revision error instead of rechecking the changed owner.node scripts/run-vitest.mjs src/gateway/server-worker-placement-session-target.test.ts src/config/sessions/session-accessor.sqlite-entry-revalidation.test.ts --maxWorkers=1.pnpm tsgo:coreand the changed-pathpnpm tsgo:core:testgateway-server lane pass, as do scoped oxlint, oxfmt, both line-limit ratchets, assertion safety, the SQLite-worker ratchet, import-cycle checking, andgit diff --check.Autoreview: scoped-clean through P2, no accepted or actionable findings.
LOC against the pinned main merge base: production +43/-43 (net 0), tests +109/-1 (net +108), docs +8/-7 (net +1).
Test cost (
--maxWorkers=1): the changed placement file has 13 passing tests and 93.15 s Vitest wall time; the unchanged 48-test admission sibling takes 79.54 s. These include worker compilation/setup on a shared host. Existing managed-worktree lifecycle probes dominate the placement fixture cost; the added cases use the direct recovery boundary with real SQLite, no Gateway boots, sleeps, or polling. Exact-head CI is attached: preflight passed in 69 s; test jobs were queued at handoff, so final CI test seconds are pending.Validation scope is deterministic local SQLite and recovery/admission boundaries; no live cloud worker or provider run was needed.