Repository navigation
refactor(agents): move workspace state operations off the Gateway thread - #163496
Conversation
Keep canonical snapshots, conditional alias registration, first-writer setup merges, and exact vanished-workspace expiry off the Gateway thread. Preserve live filesystem and caller grants at transaction and commit, recent/future protection, and acknowledged cache retirement through native settlement.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 2, 2026, 7:24 PM ET / 23:24 UTC (Revision 10). ClawSweeper reviewWhat this changesMoves workspace snapshots, alias registration, setup updates, and expiry cleanup into existing database workers while preserving creation safeguards and released plugin callbacks. Merge readiness⛔ Blocked before merge - 1 item remains The refactor remains useful and has no actionable findings. Earlier callback and recovery-hold defects are resolved; the previous generic migration-proof blocker is inapplicable because stored contracts are unchanged. Priority: P2 Review scores
Verification
How this fits togetherWorkspace preparation supplies agent creation and reply execution with bootstrap files and durable setup facts. The Gateway retains filesystem and caller checks while existing shared-state workers perform SQLite operations. flowchart TD
A[Agent creation and reply preparation] --> B[Workspace preparation]
B --> C[Host authority and filesystem checks]
C --> D[Shared-state worker]
D --> E[Recovery hold and commit checks]
E --> F[Existing SQLite workspace state]
F --> G[Settled results and cache retirement]
G --> B
Before merge
Agent review detailsSecurityNone. PR surfaceSource +543, Tests +528, Docs +42, Other +3. Total +1116 across 45 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one shared-state worker owner for workspace SQL, with current host authority, transaction-local recovery checks, and the documented SDK compatibility window. Do we have a high-confidence way to reproduce the issue? Not applicable as a discrete bug report; current-main source directly establishes the remaining host-thread SQL, and the supplied boundary runs exercise its worker replacement. Is this the best way to solve the issue? Yes. Reusing the existing broker and connection-bound kernels preserves ownership, while the compatibility adapter avoids breaking released plugins. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9ed025c44dde. 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
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
Split workspace guards into SQL-free host authority and a transaction-local recovery predicate. Preserve the recovery reader and typed refusal across worker transport, and prove creation grants avoid host SQL and snapshot children. Route bootstrap and Bun Talk fixtures through the host broker, join Windows worker teardown, and keep the assertion baseline shrink-only.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Keep the Talk worker fixture in canonical order so CI planning and CLI ownership select the same files.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ead (openclaw#163496) * perf(agents): move workspace state operations into shared workers Keep canonical snapshots, conditional alias registration, first-writer setup merges, and exact vanished-workspace expiry off the Gateway thread. Preserve live filesystem and caller grants at transaction and commit, recent/future protection, and acknowledged cache retirement through native settlement. * fix(agents): evaluate workspace recovery holds in worker transactions Split workspace guards into SQL-free host authority and a transaction-local recovery predicate. Preserve the recovery reader and typed refusal across worker transport, and prove creation grants avoid host SQL and snapshot children. Route bootstrap and Bun Talk fixtures through the host broker, join Windows worker teardown, and keep the assertion baseline shrink-only. * fix(test): preserve sorted Gateway worker ownership Keep the Talk worker fixture in canonical order so CI planning and CLI ownership select the same files. * fix: preserve workspace mutation guards across worker admission Keep the released plugin callback compatible and deprecated, with actionable synchronous database access refusal inside worker grants. Recheck recovery holds before host filesystem effects and preserve callback refusals through auxiliary attestation. * fix: allow legacy workspace guards before worker dispatch Preserve synchronous database access in released plugin callbacks with one deprecation warning. Keep typed guards at commit admission and recovery checks before filesystem effects. Extract persisted state-owner record admission without changing ownership policy. * fix(agents): avoid snapshots in workspace recovery guards Keep current host recovery checks native outside worker grants while preserving private snapshots for artifact-preserving and schema-admission reads. Prove that real workspace preparation during creation spawns no synchronous snapshots, retaining the grant SQL boundary and late-hold regressions. * fix: declare the ownership guard callback as a function Use a function-valued callback contract and avoid shadowing the workspace test namespace. Both corrections preserve runtime behavior and pass focused type-aware lint and independent P2 review. * fix(test): route Talk workers and settle cleanup fixtures
What Problem This Solves
Workspace initialization and ordinary reply preparation awaited async facades that still ran snapshots, alias registration, setup merges, and exact expired-state cleanup on the Gateway thread. This moves that SQL into the existing shared-state workers while preserving current authority, recovery holds, and filesystem safety.
User Impact
Workspace preparation retains first-writer timestamps, alias safety, vanished-workspace protection, FIFO settlement, and cache retirement. A serialized recovery-hold predicate runs on the worker's transaction connection immediately before commit, using the same connection-bound SQL kernel as the remaining host callers. A new hold rolls back the transaction and preserves the existing
DuplicateAgentErrorand remediation message.Host filesystem mutations still recheck current recovery holds immediately before each effect, including IDENTITY.md after awaited preparation. Those existing host checks explicitly select native current reads outside worker grants. Without this selection, removing the cached host writer made each file guard spawn a synchronous snapshot subprocess. Artifact-preserving scopes and schema-admission reads retain private snapshots; current guards never reuse stale discovery bytes. The worker's host grant checks remain SQL-free.
Decided by Peter: warn and allow. Released plugins can continue passing
beforePersistentApply, including callbacks that synchronously read OpenClaw databases. Each callback runs synchronously once immediately before worker dispatch, outside admission grants; throwing stops dispatch. A once-per-process deprecation warning names the typedguard.assertHostreplacement. The documented timing nuance is that legacy checks run before dispatch, while typed guards revalidate live authority inside the commit grant. The compatibility record and SDK migration guide preserve this released surface through the next Plugin SDK major.No schema, configuration, permission, retention, durability, or update-contract change.
src/plugins/compat/workspace-mutation-guard.tsis SDK deprecation metadata, not a database migration/backfill/repair. Existing tables and stored encodings are unchanged; recovery reads reuse the existing connection-bound query. The released-plugin regression and compatibility-registry cases cover the public upgrade contract. This does not claim that the entire creation or config-preflight flow is free of host SQLite.Implementation Notes
Confirmed expiry receipts retire the stored workspace's file cache within the existing FIFO interval, including lost ordinary replies. Accepted writes settle before database close. Read-only snapshots, explicit deletion, and Doctor relocation retain their existing owners.
The gateway ownership extraction moves persisted-record parsing and classification into a cohesive module, leaving live custody and schema authority with the original owner. The compiled-wrapper inventory includes all extracted modules. Bootstrap/Talk fixtures use the existing host-broker fork pools, and Windows teardown joins worker close before removing temporary files.
The assertion baseline is an exact shrink-only ratchet-down: one obsolete unchecked-decode allowance removed, with no allowance added or loosened. Against integrated main
db24ac34b6ab0337ba37b8f57432ea601fbc621a, the authored change is +1,116 net lines, below the approved cap.Evidence
status:nulland a 120 s timeout; its exact child signal was not captured. The passing replay is not claimed as an inherited-CI qualification. A queued Testbox attempt was stopped without test results.After the CI repair, the full selected changed-check pipeline completed successfully, including all 27 test typecheck graphs, unused-export scans, and core/script lint. Its 3,078.68 s wall time includes waiting behind the full build. Post-main focused proof then passed 396 Node tests in 330.33 s wall, including the fixed real UI validators, routing, workspace worker/creation guards, plugin compatibility, and all four new lineage cases. Those four lineage cases also passed under Bun in 68.64 s wall. Fresh post-integration production types pass, Madge reports 0 cycles (63.41 s), and the runtime import graph reports 0 cycles. After the later main conflict repair, all 20 cleanup cases plus the PR wrapper inventory check passed in 108.47 s wall; P2 review is clean again. Unchanged proof is retained for the disjoint main advance.
The earlier full changed-check invocation passed its first 24 checks and found two local lint issues: a shadowed test namespace and a method-shaped callback declaration. Both are corrected and pass focused type-aware lint (63.79 s); every remaining check from the same plan also passed, completing the full changed-check coverage. Both Madge and the runtime import-cycle guard report zero cycles. Final exact-head CI run 37075599338 completed successfully at
adef036d5fb21beb31bd1ee5cb70d9c58b381d69. No CI rerun or inherited-failure bypass was needed for this head. Local wall times include substantial preparation overhead on the shared host.CI History and Limits
Run 37062757944 at
88d4a106completed with 80 successful jobs and four root failures. Three affected jobs exposed two repairable causes: real Talk consumers omitted from the host-broker pools, and cleanup fixtures capturing protected database bytes before asynchronous worker shutdown/checkpoint had settled. The Talk repair routes those three files through existing pools. The initial fixture repair awaited canonical closure at both byte-baseline sites; main subsequently fixed all four closure sites inee51203de7ba2(#163805). Merge commitadef036d5fb21beb31bd1ee5cb70d9c58b381d69resolves the resulting conflict by adopting main’s fixture byte-for-byte, removing our duplicate fixture diff. Main integration introduced one additional real consumer,agent-consult-runtime.lineage.test.ts: all four cases reproduced the missing-host-broker error through workspace preparation (90.33 s wall), so that file is routed through the same existing pool too.The fourth failure was
test/scripts/ui.test.ts > scripts/ui > checks the selected staged directory with both real validators: its fixture omits the now-requiredasset-manifest.json. The identical failure is independently present on main run 37061184155, Windows job111018447113, and the fixture/validators/manifest owner are unchanged by this PR. Main subsequently fixed this fixture in2d1011a9a4161ae3931acfe1dea25800e344e5eb; merge commit354edf97d4e90933de45925c3d60a6cab86382c5integrates that fix without rebasing. An inherited-red exception is not being requested for a failure whose fix is now integrated.The original CI exposed PR-caused bootstrap routing, Bun Talk routing, Windows teardown, and cold setup/creation failures. These were repaired and cleared on a later exact-head run. Main's wrapper-inventory and missed async claim-recovery caller fixes are integrated, along with the environment-name budget repair. Main was merged without rebasing.
A later local run exposed creation timeouts from the newly uncached host recovery-read path; the native fallback and workspace-scoped subprocess regression address that cause. A separate warm-turn fixture hit its first turn's 35-second deadline before workspace dispatch. The same case reproduced on pinned main
ed754faa, before workspace tasks, SessionManager opening, or legacy append. Its exact delay within early preparation remains unresolved. This local control is not, by itself, an exact-head hosted CI bypass.Earlier matched synthetic workspace comparison (main / PR): cold setup 10.66 / 13.70 s; 200 warm preparations 2.66 / 2.28 s; process wall 22.11 / 23.31 s; peak RSS 518,438,912 / 583,270,400 bytes. This describes the scoped workload on a shared host, not a live Gateway latency benchmark.
ClawSweeper revision 9 completed for this exact head at 2026-10-02 23:08 UTC, with no actionable or security findings. Its analysis explicitly confirms that the earlier generic migration-proof concern is resolved because stored contracts are unchanged. The generated checklist still classifies the static SDK compatibility record as a migration; that checklist item is inapplicable, as the same review explains.