Skip to content

fix(sessions): Codex turns fail with "Session entry facts changed during their mutation check" when another session writes concurrently - #166010

Merged
steipete merged 1 commit into
mainfrom
codex/stab-plugin-state-race
Oct 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stab-plugin-state-race

Conversation

@steipete

@steipete steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: under concurrent use, a Codex-runtime turn could fail before replying with Failed to observe plugin state entry. | Session entry facts changed during their mutation check | invalid_state (PluginStateStoreError, no fallback). Any unrelated commit to the same agent database at the wrong moment was enough, such as another session's write or a label update.

User Impact

User impact: a turn no longer fails because an unrelated session or entry was written while its plugin state was being read. Real conflicts still fail closed: changed lineage, an active writer, or changed lifecycle facts for the entry being read.

Why This Change Was Made

Codex binding leases call store.observe, which enters plugin-state admission. The session-facts reader behind it used a revision guard that compares a database-wide revision before and after its predicate. A foreign commit between the two probes threw SessionEntryRevisionConflictError, even when the entry's facts had not changed. Revision instability now raises a typed subclass, SessionEntryRevisionChangedError. The current-entry read re-prepares its facts once inside a pinned SQLite read snapshot, where a foreign commit cannot land mid-check. The post-grant comparison still checks the re-prepared facts. Other errors, the strict mutation guard, source checks, and host authority are unchanged. There is no string-matched retry, sleep, cache, schema change, or SDK change. Built-in subagent cleanup reaches the same owner through browser cleanup claims and inherits the fix.

Evidence

Deterministic (real SQLite, foreign commits between revision probes):

TMPDIR=/private/tmp/oc-plugin-state-mutation-race pnpm test src/config/sessions/session-accessor.sqlite-entry-revalidation.test.ts --maxWorkers=1                # 48 passed, 68.1 s wall
production restored to main, -t 'admits only unchanged facts'                                                                                        # 7 failed: "Session entry facts changed during their mutation check" (including all three harmless-change cases)
revalidation + plugin-state-store.authority + binding-leases.worker + binding-authority.prepared                                                    # 71 passed, 178.6 s wall

Live (dev Gateway, OpenAI-backed agents on the built-in and Codex runtimes, bursts of 4 rounds x 15 concurrent sessions.create with a short first turn): the failure was observed twice in about 300 turns on older main builds (f986a7aaf15b: 1 in 60; a 2983dfcfb319-based build: 1 in 120). On current main 3daba29c4b12, 6 bursts (360 turns, fresh then accumulated state) produced 0 failures both with and without this change. That rules out regressions, but the race is too rare to show a live before/after, so the proof of the fix is the deterministic regression above.

Production types, scoped test types, oxlint, oxfmt, both line-limit ratchets, the madge cycle check, and git diff --check pass. Autoreview (pre-commit and final branch) was scoped-clean through P2.

Production +17/-3, tests +96/-4, docs +8/-0.

A foreign agent-database commit could fail a session-bound plugin-state
observation even when the selected session's ownership facts were unchanged,
causing native runtime turns to fail before replying.

Distinguish revision instability from predicate conflicts and reprepare only
read facts once in a short SQLite snapshot. Keep source identity, host policy,
post-grant comparison, and mutation conflict checks intact. No SDK or stored
state contracts change and no writes are replayed.

Exercise real foreign commits during initial and post-grant materialization:
unrelated writes succeed while lineage and ownership changes still refuse.
All seven cases reproduce the original broad-guard error on the pinned base;
71 owner and sibling tests pass with the repair.
@clawsweeper

clawsweeper Bot commented Oct 6, 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 size: S labels Oct 6, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 4:20 AM ET / 08:20 UTC.

ClawSweeper review

What this changes

The PR rereads session ownership facts in a short SQLite snapshot when a concurrent database commit interrupts validation, while preserving genuine conflict checks.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: pinned current main still rejects harmless concurrent commits. No actionable correctness or security defect was found in the introduced change.

Priority: P1
Reviewed head: aff46191faa8a7e4d2a5ce29d4324367fa19ab9b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful concurrency regression coverage and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-admin author is exempt from the external-contributor gate. Reported Gateway bursts exercise concurrent session turns but do not isolate the fix; deterministic real-SQLite regression results support the changed admission owner. No stored-data contract or authority-bearing capability changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-admin author is exempt from the external-contributor gate. Reported Gateway bursts exercise concurrent session turns but do not isolate the fix; deterministic real-SQLite regression results support the changed admission owner. No stored-data contract or authority-bearing capability changes.
Evidence reviewed 7 items Pinned introduction and merge result: The merge-base-to-head diff introduces only the snapshot fallback, typed revision error, regression cases, and associated documentation. The inspected test merge has the exact pinned main parent followed by the exact PR head; its result preserves the same intended four-file scope.
Still necessary on pinned main: Current main calls the revision guard directly without recovering revision instability. The source therefore retains the reported failure path when a foreign commit lands between the guard's probes; no merged fixing PR was established.
Conflict and source safeguards: Only SessionEntryRevisionChangedError enters the fallback. The existing snapshot helper closes its iterator before returning, and admission still checks physical source identity and compares session facts after the grant. Predicate conflicts and mutation guards continue to throw; no writes are replayed.
Findings None None.
Security None None.

How this fits together

Session admission checks connect agent session state to plugin-state operations. They verify the current session and database source before an operation proceeds and again after its host grant.

flowchart TD
  A[Plugin-state operation] --> B[Read session facts]
  C[Concurrent database commit] --> B
  B --> D{Revision changed?}
  D -->|Yes| E[Reprepare in read snapshot]
  D -->|No| F[Host admission]
  E --> F
  F --> G[Recheck source and ownership]
  G --> H[Proceed or reject conflict]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +14, Tests +92, Docs +8. Total +114 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 17 3 +14
Tests 1 96 4 +92
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 121 7 +114

Review metrics

None.

Technical review

Best possible solution:

Keep recovery confined to session-fact reads, using the existing snapshot owner while retaining source identity, host authority, and post-grant ownership checks.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a foreign commit between the current-main revision probes throws even when selected session facts are unchanged. The contributor reports a failing baseline regression; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. A typed, single snapshot reprepare at the existing read owner is a narrow repair that preserves genuine conflicts and avoids replaying writes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0fdc8ac2734c.

Labels

Label changes:

  • add P1: The reported concurrency race aborts real agent turns before they reply.
  • 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 repository-admin author is exempt from the external-contributor gate. Reported Gateway bursts exercise concurrent session turns but do not isolate the fix; deterministic real-SQLite regression results support the changed admission owner. No stored-data contract or authority-bearing capability changes.

Label justifications:

  • P1: The reported concurrency race aborts real agent turns before they reply.
  • 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 repository-admin author is exempt from the external-contributor gate. Reported Gateway bursts exercise concurrent session turns but do not isolate the fix; deterministic real-SQLite regression results support the changed admission owner. No stored-data contract or authority-bearing capability changes.

Evidence

What I checked:

  • Pinned introduction and merge result: The merge-base-to-head diff introduces only the snapshot fallback, typed revision error, regression cases, and associated documentation. The inspected test merge has the exact pinned main parent followed by the exact PR head; its result preserves the same intended four-file scope. (src/config/sessions/session-entry-current-admission.worker.ts:103, aff46191faa8)
  • Still necessary on pinned main: Current main calls the revision guard directly without recovering revision instability. The source therefore retains the reported failure path when a foreign commit lands between the guard's probes; no merged fixing PR was established. (src/config/sessions/session-entry-current-admission.worker.ts:99, 0fdc8ac2734c)
  • Conflict and source safeguards: Only SessionEntryRevisionChangedError enters the fallback. The existing snapshot helper closes its iterator before returning, and admission still checks physical source identity and compares session facts after the grant. Predicate conflicts and mutation guards continue to throw; no writes are replayed. (src/config/sessions/session-entry-current-admission.worker.ts:106, aff46191faa8)
  • Regression coverage: Seven table cases inject real foreign SQLite commits around fact materialization: three harmless changes are admitted and four ownership changes are rejected. Existing coverage also protects strict mutation guards, rollback invalidation, and replaced database sources. The supplied body reports seven failures with production restored to the base and 71 passing owner/sibling tests after the repair; this reviewer did not execute tests. (src/config/sessions/session-accessor.sqlite-entry-revalidation.test.ts:348, aff46191faa8)
  • Production boundary and dependency scope: OpenClaw's plugin-state worker calls session-current admission at transaction and commit boundaries around observe and mutation operations. The repair depends on OpenClaw's SQLite revision and snapshot owners, with no changed dependency on the external Codex harness or protocol; the Codex consumer example does not establish such a dependency. (src/plugin-state/plugin-state.worker.ts:169, aff46191faa8)
  • Runtime evidence and trusted-author status: The captured body, source revision cbb58e0b476a44ac017fac9b3a2af4138e13c0dfd632d77957fba75bd4de1296, reports dev-Gateway concurrent session turns and acknowledges that current-main runs produced zero failures both with and without the patch. Those runs support smoke coverage rather than causal live proof. GitHub independently reports steipete's repository permission as admin, so the external-contributor proof gate does not apply. (aff46191faa8)

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 enabled auto-merge (squash) October 6, 2026 08:28
@steipete
steipete merged commit 3556559 into main Oct 6, 2026
122 checks passed
@steipete
steipete deleted the codex/stab-plugin-state-race branch October 6, 2026 08:29
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

steipete added a commit that referenced this pull request Oct 7, 2026
)

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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…nclaw#166010)

A foreign agent-database commit could fail a session-bound plugin-state
observation even when the selected session's ownership facts were unchanged,
causing native runtime turns to fail before replying.

Distinguish revision instability from predicate conflicts and reprepare only
read facts once in a short SQLite snapshot. Keep source identity, host policy,
post-grant comparison, and mutation conflict checks intact. No SDK or stored
state contracts change and no writes are replayed.

Exercise real foreign commits during initial and post-grant materialization:
unrelated writes succeed while lineage and ownership changes still refuse.
All seven cases reproduce the original broad-guard error on the pinned base;
71 owner and sibling tests pass with the repair.
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.
Kimiyu-186 added a commit that referenced this pull request Oct 14, 2026
…6010) (#171716)

A foreign agent-database commit could fail a session-bound plugin-state
observation even when the selected session's ownership facts were unchanged,
causing native runtime turns to fail before replying.

Distinguish revision instability from predicate conflicts and reprepare only
read facts once in a short SQLite snapshot. Keep source identity, host policy,
post-grant comparison, and mutation conflict checks intact. No SDK or stored
state contracts change and no writes are replayed.

Exercise real foreign commits during initial and post-grant materialization:
unrelated writes succeed while lineage and ownership changes still refuse.
All seven cases reproduce the original broad-guard error on the pinned base;
71 owner and sibling tests pass with the repair.

Co-authored-by: Peter Steinberger <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. 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

Development

Successfully merging this pull request may close these issues.

1 participant