Repository navigation
improve: reduce Gateway blocking during image delivery - #159348
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 27, 2026, 12:49 AM ET / 04:49 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch moves managed-image metadata writes into OpenClaw’s shared-state worker and waits for accepted media work before publishing affected transcript messages. Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open. Current main and the latest release still perform managed-image metadata writes on the Gateway thread. The prior upgrade concern is resolved by the unchanged stored-row representation, and this review found no introduced blocking defect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives media from agent replies, saves original files and metadata in shared state, then publishes transcript messages. Clients use those messages to request the attachments. flowchart LR
A[Agent media reply] --> B[Gateway media preparation]
B --> C[Original file custody]
B --> D[Shared-state worker]
D --> E[Committed metadata]
C --> F[Transcript publication]
E --> F
F --> G[Client attachment download]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +457, Tests +781, Docs +10. Total +1248 across 65 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep shared SQLite as the single metadata owner and require settled promotion before clients can observe a managed attachment. Do we have a high-confidence way to reproduce the issue? Yes. Current main visibly executes managed-image writes synchronously, and the PR reports a real image-create observer run measuring that boundary; this read-only review did not execute it. Is this the best way to solve the issue? Yes. The patch uses the existing shared-state worker and transcript completion owner while preserving the stored record format, which is a maintainable boundary for this work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4c3181e2386c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
2f38b8c to
1e5e654
Compare
|
Merged via squash.
|
* perf(gateway): move managed media writes off the event loop * test(media): await worker cleanup in Windows fixture * refactor(media): keep worker kernel details private * test(media): use native custody for outgoing chat fixtures
What Problem This Solves
Image delivery still performs metadata writes on the Gateway event loop even though its metadata reads already use a worker.
User Impact
Creating, promoting, and cleaning up managed images no longer performs database work on the Gateway thread. Chat publication waits for its accepted media work, preserving attachment availability and cleanup ordering. No schema, migration, retention, configuration, or operator change is required; existing update behavior remains unchanged.
Why This Change Was Made
Move insertion, message-commit promotion, cleanup claims, and claimed deletion into the existing shared-state worker and transaction owner. Promotion reserves its records before yielding so cleanup cannot overtake accepted work. Both transcript owners join completion before publication or release, and chat, injected messages, internal replies, cron, heartbeat, and restart delivery move onto that contract together. The old synchronous and later-attachment paths are removed.
The asynchronous boundary needs explicit custody: the original descriptor and metadata row settle together, native commit receipts reconcile lost ordinary replies, and uncertain or retired-store outcomes retain bytes without accepting a stale result. The existing admission record supplies a stable coordination key for ordering, never authorization. The added production code carries these custody and settlement guarantees through the existing storage owner.
Stored-data compatibility
The stored image-record types, selected columns, row serializer, row decoder, and equality behavior are unchanged from the base revision. Worker commands and completion callbacks change only execution and publication ordering; they do not change database columns, schema version, transcript bytes, or retention. The existing real record-store suite passes all eight cases, including every-field round-trip and close/reopen persistence. No new migration or Doctor action is needed. This resolves the review renderer’s path-based compatibility item; the review itself also confirms that the stored-data representation is unchanged.
Evidence
Fourteen added cases took 13.905 s combined case-body time in focused
--maxWorkers=1runs. Individual body times are 0.687/3.163 s for record ordering and receipts; 2.366/0.768/0.848/0.763/1.541/1.428 s for custody outcomes; 0.050/0.048/0.051 s for transcript completion; 0.959/0.611 s for injected-message publication; and 0.622 s for restart publication. The new custody file occupied 74.49 s including cold transform/setup in its Vitest cell. Multi-file wrapper walls are not represented as standalone per-file costs. The successful final hosted Gateway-methods job passed 1,335 tests across 68 files (one skipped) in 153.68 s; its repaired directive fixture passed all 225 cases with 8.028 s summed case-body time. Those are group/body costs, not standalone file wall times, and that job does not contain the 14 new cases. These tests use actual worker settlement because an in-process helper test cannot prove the commit/cleanup boundary.The first public-flow attempt reached its unchanged 600 s external budget without a test-body result while an owned thread was observed waiting on Btrfs allocation. Its namespace/resource claim and receipt remain retained. After completed task-cache cleanup and a healthy filesystem preflight, one recovery run passed with unchanged assertions and timeout. An internal-source suite also reported a fork-termination warning after all eleven cases passed; its supervisor joined every descendant, but the warning's cause is not claimed fixed. Earlier fixture/type corrections and their original failures remain recorded in the task evidence.
The first hosted run failed in
src/media/local-media-path.windows.test.ts: image ingestion passed its assertions, but the fixture tried to removeopenclaw.sqliteafter only synchronous handle close and Windows returnedEBUSY. The fixture now awaits the existing scoped session-state cleanup owner before deleting its directory; the redundant global synchronous teardown is removed. Nine existing cleanup and real worker-custody cases pass in 65.232 s wrapper wall. Native Windows CI on commit765f5bf6then passed the ingestion and awaited cleanup case in 741 ms, and its media group passed 9/9 cases in 13.80 s. The job was later cancelled during another group after an independent dependency-check failure; this is case/group evidence, not a whole-job pass. The owningcore-test-infratype graph, one-file typed lint, formatting, and diff checks pass. No test assertions, retries, or production behavior changed in this repair.The dependency check then found two kernel exports whose production callers were removed by this cutover. Those details are now private; the two synchronous publication observers use the existing typed command dispatcher. All 26 existing cases in the affected files pass in 96.608 s supervised wall. Both exact
pnpm deadcode:fullscans, production types, both owning test type graphs, typed lint, formatting and diff checks pass. Fresh independent review found no actionable P0–P2 issue in the three-file repair. No new tests, runtime behavior, stored representation, dependency or schema changes were introduced. The repaired source is included in the successful final CI run below.The next hosted run exposed 18 outgoing-image assertions in
chat.directive-tags.test.ts: its cannedsaveMediaBufferreturned a pathname without production's descriptor custody, so delivery correctly rejected the fake resource. The original binding-owned reply case reproduced the failure locally in 38.138 s supervised wall. The six-line fixture repair forwards every argument to the real save function for outgoing originals and keeps the existing inbound fixtures and assertions. All 225 existing cases then passed in 43.001 s supervised wall (40.05 s Vitest), including the 18 hosted failures. The owning Gateway-methods type graph passes in 42.640 s; typed lint, formatting, and diff checks also pass. A fresh independent P0–P2 review of the fixture and seven complete storage/custody owners found no actionable issue. No production change or new test was needed. The repaired fixture is included in the successful final CI run below.CI on
2f38b8c4then encountered an inherited UI lint regression inindex.tree-snapshots.test.ts, introduced by main commit8cea9e99. PR #159394 fixed that exact map/spread violation; its owning lint, UI shards, and CI gate passed. This branch is refreshed ontoaad795bfcontaining that fix, with the complete reviewed patch byte-identical and no overlapping main changes in its 65 paths. Fresh CI on head1e5e6540passed: run 36295083109, with 155 successful jobs, 19 skips, and no failures. The earlier failed run remains a distinct result. The current-head ClawSweeper review is published and has no correctness or security findings.