Repository navigation
fix(state): share agent write admission with trajectory producers - #146563
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 12, 2026, 9:57 PM ET / September 13, 2026, 01:57 UTC (Revision 3). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherTrajectory 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +194, Tests +856, Docs +59. Total +1109 across 31 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
3681e58 to
46a0ed3
Compare
|
Merged via squash.
|
…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
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
withOpenClawAgentDatabaseWriteoperation 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.