Repository navigation
fix(sessions): Codex turns fail with "Session entry facts changed during their mutation check" when another session writes concurrently - #166010
Conversation
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.
|
🦞👀 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, 4:20 AM ET / 08:20 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherSession 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +14, Tests +92, Docs +8. Total +114 across 4 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. 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 auto-merge.
|
) 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.
…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.
…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.
…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]>
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 threwSessionEntryRevisionConflictError, 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):
Live (dev Gateway, OpenAI-backed agents on the built-in and Codex runtimes, bursts of 4 rounds x 15 concurrent
sessions.createwith a short first turn): the failure was observed twice in about 300 turns on older main builds (f986a7aaf15b: 1 in 60; a2983dfcfb319-based build: 1 in 120). On current main3daba29c4b12, 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 --checkpass. Autoreview (pre-commit and final branch) was scoped-clean through P2.Production +17/-3, tests +96/-4, docs +8/-0.