Skip to content

fix(workers): keep workspace recovery running during unrelated writes - #166375

Merged
steipete merged 1 commit into
mainfrom
fix/placement-session-revision-guard
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/placement-session-revision-guard

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: worker workspace recovery can fail with invalid_state when 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

  • Real-entry-point regression: seven two-connection SQLite cases invoke the recovery preparer and its retained assertion. Three harmless-write cases succeed; session ID, lifecycle, and writer conflicts reject before further recovery work.
  • Negative control: with only the three production files reverted to baseline 7880834c1961, all seven final regression cases fail in 65.09 s. All three harmless-write cases reject with Session entry facts changed during their mutation check; the conflict cases encounter that broad revision error instead of rechecking the changed owner.
  • Final owner and sibling proof: 61 tests pass, 179.85 s wall, using 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:core and the changed-path pnpm tsgo:core:test gateway-server lane pass, as do scoped oxlint, oxfmt, both line-limit ratchets, assertion safety, the SQLite-worker ratchet, import-cycle checking, and git 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 7, 2026
@steipete
steipete marked this pull request as ready for review October 7, 2026 01:12
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 9:20 PM ET / October 7, 2026, 01:20 UTC.

ClawSweeper review

What this changes

Workspace 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
Reviewed head: efdc62661b1445c5f5b22d487900b6d93303bd0e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful real-SQLite regressions and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported two-connection SQLite runs exercise the production recovery preparer and retained assertion, with harmless writes accepted and ownership changes rejected; these remain inspected regression evidence, not an independently observed live recovery run. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported two-connection SQLite runs exercise the production recovery preparer and retained assertion, with harmless writes accepted and ownership changes rejected; these remain inspected regression evidence, not an independently observed live recovery run. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduction and merge result: The introduced delta is 7880834..efdc626. Raw test-merge records confirm the pinned base followed by the exact head; comparison against that base preserves the same guard and recovery changes.
Remaining current-main defect: Fetched main still invokes the strict revision guard from workspace recovery without snapshot retry. The merged #166010 added retry only to current-entry admission; it does not supersede this recovery repair.
Bounded retry and strict mutation default: Read mode retries only the typed revision-change error, only outside an active transaction, and only once through the existing pinned snapshot helper. Predicate conflicts and source failures propagate; mutation mode retains the original guard.
Findings None None.
Security None None.

How this fits together

Worker 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +108, Docs +1. Total +109 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 43 43 0
Tests 1 109 1 +108
Docs 1 8 7 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 160 51 +109

Review metrics

Metric Value Why it matters
Recovery race coverage 3 harmless-write cases and 4 ownership-conflict cases The added matrix distinguishes recovery availability from rejection of stale session ownership.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #165994
Summary: This PR repairs the workspace-recovery remainder of the reported revision-guard false conflict; the merged sibling repaired admission reads.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs a concrete concurrency failure in workspace recovery with a limited worker-specific blast radius.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported two-connection SQLite runs exercise the production recovery preparer and retained assertion, with harmless writes accepted and ownership changes rejected; these remain inspected regression evidence, not an independently observed live recovery run. No stored-data contract changes.

Label justifications:

  • P2: This repairs a concrete concurrency failure in workspace recovery with a limited worker-specific blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported two-connection SQLite runs exercise the production recovery preparer and retained assertion, with harmless writes accepted and ownership changes rejected; these remain inspected regression evidence, not an independently observed live recovery run. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 76c9e8c into main Oct 7, 2026
202 of 203 checks passed
@steipete
steipete deleted the fix/placement-session-revision-guard branch October 7, 2026 01:29
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant