Skip to content

fix(state): share agent write admission with trajectory producers - #146563

Merged
steipete merged 4 commits into
mainfrom
codex/swarm-agent-write-admission
Sep 13, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/swarm-agent-write-admission

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Split from #130741. Prerequisite: #146491. The startup and CI inventory fixes are already on main through #146410 and #146538.

What Problem This Solves

Trajectory flushes could enter synchronous SQLite while a reclamation worker held its writer, blocking the Gateway thread needed to authorize that worker's commit. A failed append also discarded the buffered batch. Queued writes could retarget relative database or state paths if the working directory changed while they waited. Once flushing becomes queued, worker live-event handling must own that work through acknowledgment and shutdown.

User Impact

Trajectory flushes share the existing per-agent queue with session-store writes. Conflicting writes wait asynchronously, failed batches remain available to retry, and queued operations retain their selected database and state roots. Worker progress still appears immediately; acknowledgment and shutdown wait for its accepted writes to settle.

Why This Change Was Made

Move the session SQLite queue into its canonical agent owner and expose the approved withOpenClawAgentDatabaseWrite operation through the existing private SQLite facade. Exact borrowed handles are checked after waiting; callers retain their live authorization and synchronous transaction responsibilities. Native-worker callbacks cannot borrow the worker's reentrancy. Trajectory batches are selected and retired on that same queue only after successful persistence.

The existing writer API, FIFO order, native-exit reservation, integrity checks, schema and retention limits remain intact. The SDK reference documents the private operation and its caller obligations.

The live-event receiver joins each accepted prefix, including duplicate acknowledgments, and retains its window through final validation. Capacity eviction cannot remove a window during that wait, including the microtask interval after a write settles. Explicit revocation remains immediate. The existing environment lock and shutdown owner cover the operation; current worker authority is checked again before cursor and terminal-fence writes. Persistence remains nonfatal, while other callback failures preserve their original thrown value after accepted work settles.

Evidence

Controlled regressions reproduce relative-path retargeting, shared-state registry/lease retargeting, premature trajectory flushes during native reclamation, and failed-batch loss. The repaired source passes 84 focused tests when composed with the fairness queue; 35 additional queue-consumer tests also passed. The real-process path probe confirms both agent and registry/lease databases remain at their original roots.

The foundation's normal build, canonical checks, private SDK checks and independent P1 review pass. All 16 foundation source hashes remain unchanged through the follow-up repair.

CI exposed four missing-event failures from the detached flush; all four reproduced locally. Registered RPC regressions then caught early acknowledgments, shutdown settlement, revoked placement, callback failure, and both pending-write and microtask eviction races. The final 114 owner/caller and WebSocket/client tests pass, along with the complete changed gate, architecture checks and a fresh isolated P1 review. Window types and credential turnover remain in one private module; no line-limit exception was added.

Earlier CI also retained a browser target closure, a desktop resize assertion and a Windows checkout teardown failure; these were not attributed to this admission change or relabeled as fixed. Exact final-head CI and end-to-end Swarm 500 ms acceptance remain required.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 channel: telegram Channel integration: telegram app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts plugin: file-transfer size: L maintainer Maintainer-authored PR labels Sep 12, 2026
@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 Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 9:57 PM ET / September 13, 2026, 01:57 UTC (Revision 3).

ClawSweeper review

What this changes

The PR coordinates session and trajectory database writes, preserves failed recording batches and selected paths, and makes worker acknowledgments and shutdown await accepted writes.

Merge readiness

⛔ Blocked before merge - 2 items remain

This protected maintainer PR remains useful: current main and the latest release retain the failed-batch loss mechanism. No blocking introduced defect was found.

Priority: P2
Reviewed head: 46a0ed3630e3aa6530e1828c32817607d59585ae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored repair. Source and regression coverage connect queued trajectory persistence to RPC settlement and revocation checks; the separately declared integrated performance acceptance remains outstanding.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate does not apply to this maintainer-authored repair. Source and regression coverage connect queued trajectory persistence to RPC settlement and revocation checks; the separately declared integrated performance acceptance remains outstanding.
Evidence reviewed 9 items Current-main necessity: Current main clears pendingEvents and queuedBytes before calling the synchronous append; an append exception therefore loses the buffered batch.
Latest-release comparison: Inspection of v2026.9.4 at the supplied release commit shows the same clear-before-append implementation and no new agent write-admission files.
Shared admission and handle lifetime: The helper captures environment and paths before waiting, shares the canonical queue, checks an expected borrowed handle after admission, and retains it through callback settlement. Worker reservations disable inherited foreground reentrancy.
Findings None None.
Security None None.

How this fits together

Trajectory recording stores diagnostic events alongside agent sessions in SQLite. Session reclamation and worker progress reporting share these databases, so write scheduling affects Gateway responsiveness and acknowledgment timing.

flowchart TD
  A[Session writes] --> D[Per-agent write queue]
  B[Trajectory event batches] --> D
  C[Reclamation worker] --> D
  D --> E[SQLite database]
  B --> F[Worker event settlement]
  E --> F
  F --> G[Recheck current worker authority]
  G --> H[Acknowledgment and terminal fence]
Loading

Before merge

  • Resolve merge risk (P1) - The declared integrated 500 ms Swarm responsiveness target remains unverified; focused correctness coverage does not establish that performance result.
  • Complete next step (P2) - Land the declared prerequisite fix: keep I/O responsive during queued session writes #146491 and satisfy the PR's stated integrated 500 ms Swarm acceptance gate before landing.
Agent review details

Security

None.

PR surface

Source +194, Tests +856, Docs +59. Total +1109 across 31 files.

View PR surface stats
Area Files Added Removed Net
Source 12 378 184 +194
Tests 18 1077 221 +856
Docs 1 59 0 +59
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 31 1514 405 +1109

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +194 net lines; tests/support +856 net lines Production growth has a stated purpose: centralizing admission and completing worker-event settlement, with most growth devoted to regression coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one per-agent FIFO write owner, retain batches until successful persistence, and settle accepted worker work before acknowledging under freshly checked authority.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one per-agent FIFO write owner, retain batches until successful persistence, and settle accepted worker work before acknowledging under freshly checked authority.

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

Yes, from source: an append exception on current main discards the already-cleared trajectory batch. The branch includes targeted failure and contention regressions; this review did not execute them.

Is this the best way to solve the issue?

Yes. Extending the existing queue and lifecycle owners addresses the failure without adding a competing store, schema, or configuration mode.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded storage and worker-lifecycle reliability repair, without evidence of an urgent widespread outage.
  • 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 ordinary contributor-proof gate does not apply to this maintainer-authored repair. Source and regression coverage connect queued trajectory persistence to RPC settlement and revocation checks; the separately declared integrated performance acceptance remains outstanding.

Evidence

What I checked:

  • Current-main necessity: Current main clears pendingEvents and queuedBytes before calling the synchronous append; an append exception therefore loses the buffered batch. (src/trajectory/runtime.ts:380, b4b790b8692f)
  • Latest-release comparison: Inspection of v2026.9.4 at the supplied release commit shows the same clear-before-append implementation and no new agent write-admission files. (src/trajectory/runtime.ts, 3a9d69db306c)
  • Shared admission and handle lifetime: The helper captures environment and paths before waiting, shares the canonical queue, checks an expected borrowed handle after admission, and retains it through callback settlement. Worker reservations disable inherited foreground reentrancy. (src/state/openclaw-agent-db-write.ts:17, 46a0ed3630e3)
  • Acknowledgment and authority ordering: The receiver joins accepted trajectory promises and retains its window through final validation. The RPC owner awaits that operation under its existing environment lock and revalidates placement, credentials, and shutdown state before updating acknowledgment cursors or terminal fences. (src/gateway/worker-environments/worker-turn-rpc.ts:530, 46a0ed3630e3)
  • Focused regression coverage: Read the registered-dispatch tests for persisted, failed, revoked, and stopped outcomes, including no early response or durable cursor update; additional tests cover failed-batch retry, captured paths, callback failure, duplicate acknowledgment, and eviction during settlement. Tests were inspected, not executed in this read-only review. (src/gateway/worker-environments/live-events-settlement.test.ts:23, 46a0ed3630e3)
  • Private facade and storage contract: The documentation explicitly limits the additive operation to the existing private SQLite facade and preserves caller-owned transactions and authorization. The introduced delta changes no schema, retention limit, configuration default, dependency, or public typed SDK contract. Public docs: docs/plugins/sdk-runtime/state-and-system.md. (docs/plugins/sdk-runtime/state-and-system.md:193, 46a0ed3630e3)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the outcome of the already-declared integrated 500 ms Swarm acceptance gate.

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-09-12T23:36:51.287Z sha 3681e586ae4d89e2b4ac410002d411b6324f07c8 :: needs changes before merge. :: none
  • reviewed 2026-09-12T23:45:04.393Z sha 3681e586ae4d89e2b4ac410002d411b6324f07c8 :: needs changes before merge. :: none

@steipete
steipete force-pushed the codex/swarm-agent-write-admission branch from 3681e58 to 46a0ed3 Compare September 13, 2026 01:47
@steipete
steipete merged commit ee679bb into main Sep 13, 2026
190 of 192 checks passed
@steipete
steipete deleted the codex/swarm-agent-write-admission branch September 13, 2026 03:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…enclaw#146563)

* fix: keep I/O responsive during queued session writes

* test(telegram): await debounced dispatch completion

* fix(state): share agent write admission with trajectory producers

* fix(gateway): join worker event writes before acknowledgment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui channel: telegram Channel integration: telegram docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. plugin: file-transfer rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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