Repository navigation
fix(state): concurrent first requests for a new agent fail with "Agent creation no longer owns its originally observed target" - #166003
Conversation
Keep creation identity with the existing execution owner so concurrent sessions.create requests join one native generation. Count creating borrowers, retain the first witness even on an ordinary owner, and recheck the reservation after asynchronous cleanup. Delegate queued session admission and writable-read identity validation to that owner. Preserve physical replacement, agent/shared-state, incognito, registry, and source-authority checks without retries or new caches. Cover concurrent missing and schema-missing creation, completed adoption, queued callers, replacement targets, and release/reborrow races. Schemas, public contracts, stored data, and update behavior are unchanged.
|
🦞👀 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:43 AM ET / 08:43 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR lets concurrent first requests share one agent database creation and updates session admission and writable reads to validate through that shared owner. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main, and the integrated head resolves the previous ownership-refactor concern. No actionable correctness or security defect was found. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw stores session data in a SQLite database for each agent. The database execution owner coordinates opening, worker access, request authorization, and cleanup before session operations proceed. flowchart TD
A[Concurrent session requests] --> B[Session target selection]
B --> C[Shared database execution owner]
C --> D[Identity and authority checks]
D --> E[Native database worker]
D --> F[Refuse invalid request]
E --> G[Agent SQLite and session results]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -14, Tests +206, Docs +9. Total +201 across 7 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use one execution owner for concurrent first-use creation while retaining physical-identity fencing and per-request live-authority checks. Do we have a high-confidence way to reproduce the issue? Yes: current main explicitly rejects a second creator carrying the same absent-path observation, and the supplied live Gateway baseline demonstrates the corresponding concurrent sessions.create failure. This review did not execute the reproduction. Is this the best way to solve the issue? Yes: extending the existing execution owner's reservation and removing competing caller checks repairs the invariant without adding retries, another owner, configuration, or a stored-data migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d3c121c23788. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…t creation no longer owns its originally observed target" (openclaw#166003) * fix(state): share concurrent first agent database creation Keep creation identity with the existing execution owner so concurrent sessions.create requests join one native generation. Count creating borrowers, retain the first witness even on an ordinary owner, and recheck the reservation after asynchronous cleanup. Delegate queued session admission and writable-read identity validation to that owner. Preserve physical replacement, agent/shared-state, incognito, registry, and source-authority checks without retries or new caches. Cover concurrent missing and schema-missing creation, completed adoption, queued callers, replacement targets, and release/reborrow races. Schemas, public contracts, stored data, and update behavior are unchanged. * test(state): narrow concurrent creation witnesses before use
…t creation no longer owns its originally observed target" (#166003) * fix(state): share concurrent first agent database creation Keep creation identity with the existing execution owner so concurrent sessions.create requests join one native generation. Count creating borrowers, retain the first witness even on an ordinary owner, and recheck the reservation after asynchronous cleanup. Delegate queued session admission and writable-read identity validation to that owner. Preserve physical replacement, agent/shared-state, incognito, registry, and source-authority checks without retries or new caches. Cover concurrent missing and schema-missing creation, completed adoption, queued callers, replacement targets, and release/reborrow races. Schemas, public contracts, stored data, and update behavior are unchanged. * test(state): narrow concurrent creation witnesses before use (cherry picked from commit 5592e61) Adapted to release/2026.10.2: the file owner type is still local to openclaw-agent-execution.ts, and the creation-claim witness from #143991 is absent on this branch.
Backport the existing creation-owner repair with its queued-read and public RPC regressions. Restore matching runnerless-ghost evidence coverage. Release provenance: 5592e61 -> #166003; dd5a40a -> #166175 Original creation repair by Peter Steinberger. Adapted to the October admission owner without schema or permission changes. Proof: 168 focused tests passed; fresh P0/P1 review clean; branch-native check-changed passed.
What Problem This Solves
Fixes: the first concurrent requests for an agent whose database does not exist yet failed with
Agent creation no longer owns its originally observed target(UNAVAILABLE). On a fresh Gateway, 15 concurrent firstsessions.createcalls across two agents produced 2 sessions; the other 13 failed. This hits a fresh install or newly added agent receiving several requests at once: channel messages, cron runs, or UI tabs.User Impact
User impact: concurrent first requests for a new agent all succeed and share one database creation. Genuinely different targets still fail as before: a replaced file, a different agent or shared-state database, incognito ownership, or revoked authority.
Why This Change Was Made
Each request independently observed the database path as absent and carried that observation as a creation witness. The execution owner rejected every request after the first, even though it already held a shared native-opening promise for the same target. The owner now keeps the first creation witness and counts creating borrowers, including borrowers that join during cleanup, so matching requests share one native generation. Two sibling callers rejected the same valid absence-to-file transition on their own: queued session-entry admission and writable session-entry reads. They now defer to the owner's checks.
Main's admission refactor landed during review. The conflict resolution moves
creationIdentityinto the extractedAgentDatabaseFileExecutionOwnercontract and preserves main's creation-claim witness beside this fix's native-generation creation identity. The merged refactor's claim-authority checks remain intact.Evidence
Live (dev Gateway, OpenAI-backed agents on the built-in and Codex runtimes; an empty state directory, then immediately 15 concurrent
sessions.createalternating the two agents):2983dfcfb319Agent creation no longer owns its originally observed targetf986a7aaf15bTests (
TMPDIR=/private/tmp/oc-agent-creation-race,--maxWorkers=1):Two further races found in review are covered by passing regressions: losing a reborrowed reservation during cleanup, and an ordinary owner not keeping the first creator's witness.
pnpm tsgo:core, oxlint, oxfmt, the madge cycle check (0), the docs MDX and link audits, the line-cap and max-lines ratchets, andgit diff --checkpass. Autoreview of the branch was scoped-clean through P2.Production +26/-40, tests +208/-2, docs +9/-0.
Landing validation
CI run 37432998361, attempt 1, caught unchecked array-index types in the new creation-witness regression (
TS2345/TS2532). Commit1f233da7c21aeadds explicit assertions that the first observation and generation claim exist before use; production behavior is unchanged. The affected state/logging test type graph now passes. The corrected creation-witness suite passes all 31 tests (17.68 s Vitest; 24.13 s including wrapper preparation), formatting and diff checks pass, and independent review found no actionable defects through P2. The preceding exact-head focused run also passed all 53 creation-witness and queued session-entry tests (39.51 s Vitest; 62.86 s including worker prerequisites).Current main
5709e38d8487was merged solely to resolve the reported ownership-refactor conflict; the branch was not rebased. The integrated candidate passes the state/logging test type graph, 109 tests across the creation-witness, logical-entry, SQLite creation/admission, incognito, and agent-admission suites (two Vitest shards, 131.89 s including prerequisites), plus the focused worker-recreation creation-claim test (1 passed, 17 unselected; 30.97 s including prerequisites). Formatting and diff checks pass, and independent review of the complete integrated delta found no actionable defects through P2. The preceding head1f233da7c21aecompleted CI run 37434385087 successfully; current integrated-head CI remains a separate gate.