Skip to content

fix(state): concurrent first requests for a new agent fail with "Agent creation no longer owns its originally observed target" - #166003

Merged
steipete merged 3 commits into
mainfrom
codex/stab-agent-creation-race
Oct 6, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/stab-agent-creation-race

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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 first sessions.create calls 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 creationIdentity into the extracted AgentDatabaseFileExecutionOwner contract 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.create alternating the two agents):

Build Created Turns final Create errors
main 2983dfcfb319 2 2 13 x Agent creation no longer owns its originally observed target
main f986a7aaf15b 2 2 13 x the same
this branch, run 1 15 15 0
this branch, run 2 (new empty state) 15 15 0

Tests (TMPDIR=/private/tmp/oc-agent-creation-race, --maxWorkers=1):

src/state/openclaw-agent-execution.creation-witness.test.ts                               31 passed  26.67 s
src/config/sessions/session-logical-entry-read.worker.test.ts                             22 passed  45.93 s
incognito + sqlite-creation-worker + sqlite-entry-admission                               43 passed  35.07 s
session-entry-patch + sqlite-entry-admission                                              33 passed  32.35 s
owner restored to main, -t 'joins concurrent creators':       2 failed (14 of 15 creators fail per case)
caller repairs reverted, -t 'joins concurrent first':          2 failed

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, and git diff --check pass. 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). Commit 1f233da7c21ae adds 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 5709e38d8487 was 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 head 1f233da7c21ae completed CI run 37434385087 successfully; current integrated-head CI remains a separate gate.

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.
@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: M labels Oct 6, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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:43 AM ET / 08:43 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: 28c80ff972051241acbdbd05ca5c4435f21d2bf8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with convincing live before-and-after evidence, meaningful regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied empty-state dev Gateway evidence exercises the changed database owner through 15 concurrent sessions.create calls and reports 15 successful creations and completed turns in both branch runs, versus 13 failures on each baseline. Integrated-head regression results supplement that historical live evidence. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied empty-state dev Gateway evidence exercises the changed database owner through 15 concurrent sessions.create calls and reports 15 successful creations and completed turns in both branch runs, versus 13 failures on each baseline. Integrated-head regression results supplement that historical live evidence. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduced changes: The complete pinned base-to-head diff retains the first creation identity, counts creating borrowers, and rechecks that count after asynchronous cleanup. Matching absence observations join the existing owner rather than being rejected solely because it exists.
Queued callers use the authoritative owner: Both modified session callers remove competing absence-to-file checks while retaining execution, discovery, registry, source-admission, and final target revalidation. Failed admission releases its captured execution reference.
Physical identity and live authority remain enforced: The logical owner still checks shared-state admission, agent admission, and live creation-claim authority. Native admission checks each request's source and physical identity before granting operations; the worker checks the original creation target before opening it. Sharing the opening does not grant another request authority.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source -14, Tests +206, Docs +9. Total +201 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 26 40 -14
Tests 2 208 2 +206
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 243 42 +201

Review metrics

None.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Concurrent first requests can fail for newly used agents, with the supplied Gateway baseline losing 13 of 15 session creations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied empty-state dev Gateway evidence exercises the changed database owner through 15 concurrent sessions.create calls and reports 15 successful creations and completed turns in both branch runs, versus 13 failures on each baseline. Integrated-head regression results supplement that historical live evidence. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied empty-state dev Gateway evidence exercises the changed database owner through 15 concurrent sessions.create calls and reports 15 successful creations and completed turns in both branch runs, versus 13 failures on each baseline. Integrated-head regression results supplement that historical live evidence. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced changes: The complete pinned base-to-head diff retains the first creation identity, counts creating borrowers, and rechecks that count after asynchronous cleanup. Matching absence observations join the existing owner rather than being rejected solely because it exists. (src/state/openclaw-agent-execution.ts:103, 28c80ff97205)
  • Queued callers use the authoritative owner: Both modified session callers remove competing absence-to-file checks while retaining execution, discovery, registry, source-admission, and final target revalidation. Failed admission releases its captured execution reference. (src/config/sessions/session-accessor.sqlite-entry-admission.ts:244, 28c80ff97205)
  • Physical identity and live authority remain enforced: The logical owner still checks shared-state admission, agent admission, and live creation-claim authority. Native admission checks each request's source and physical identity before granting operations; the worker checks the original creation target before opening it. Sharing the opening does not grant another request authority. (src/state/openclaw-agent-execution-native.ts:259, 28c80ff97205)
  • Previous integration concern resolved: The current contract includes creationIdentity, while the integrated execution owner preserves creationClaim.assertCurrent() and passes creationClaim.witness to native admission. These directly address the previous review's conflict-resolution request. The supplied body reports 109 passing integration cases plus the worker-recreation creation-claim case. (src/state/openclaw-agent-execution-contract.ts:82, 28c80ff97205)
  • Meaningful regression coverage: Added cases exercise real database workers for 15 concurrent missing or schema-missing creators, shared native generations, durable transcript initialization, replaced targets, first-witness retention, and borrowing during cleanup. Separate session-boundary cases exercise both queued admission and writable reads. The body records failures when the corresponding repairs are reverted; tests were inspected but not executed during this read-only review. (src/state/openclaw-agent-execution.creation-witness.test.ts:253, 28c80ff97205)
  • Real Gateway before-and-after evidence: The supplied body snapshot, sourceRevision 0a166b0ef1b86d93718a43f7408abaf839e5d4b0b37aeaf5e8553fde6052fac2, reports an empty-state dev Gateway receiving 15 concurrent sessions.create requests across two agents: two baseline builds created only 2 sessions with 13 ownership errors; two branch runs created all 15 sessions and completed all 15 turns without create errors. This exercises the changed database owner through the production session entrypoint. These live runs precede the documented integration validation and are not claimed as fresh integrated-head executions.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • goutamadwant: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T08:03:04.849Z sha 8d472b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T08:17:36.580Z sha 1f233da :: needs changes before merge. :: none

@steipete
steipete merged commit 5592e61 into main Oct 6, 2026
122 checks passed
@steipete
steipete deleted the codex/stab-agent-creation-race branch October 6, 2026 08:47
@steipete

steipete commented Oct 6, 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
…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
RomneyDa pushed a commit that referenced this pull request Oct 7, 2026
…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.
RomneyDa added a commit that referenced this pull request Oct 8, 2026
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.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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