Repository navigation
fix(agents): avoid blocking Gateway during spawn preparation - #159135
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: needs maintainer review before merge. Reviewed September 26, 2026, 4:10 PM ET / 20:10 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch moves persisted-session lookup for native, visible, and ACP subagent spawning into database read workers and updates child-session handling, tests, and worker-access documentation. Merge readiness✅ Ready for maintainer review Keep this PR open. Current main still reads the requester session synchronously during spawn preparation, and the branch addresses that path without a definite introduced defect found in this review. Priority: P2 Review scores
Verification
How this fits togetherSubagent spawn preparation reads the requesting session and its saved settings before admitting a child. The selected session identity and store then feed child creation, context forking, and completion routing. flowchart LR
A[Spawn request] --> B[Session key and configuration]
B --> C[Read worker discovery]
C --> D[Selected requester session]
D --> E[Caller check and child admission]
E --> F[Child session and completion]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +178, Tests +315, Docs +9. Total +502 across 21 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep requester selection with the existing read-worker owner, preserve the selected physical store through child writes, and retain live caller checks at admission and commit. Do we have a high-confidence way to reproduce the issue? Yes. Current main's native spawn path synchronously resolves and loads the requester session, and the PR supplies a production-entrypoint benchmark for that boundary; this read-only review did not execute it. Is this the best way to solve the issue? Yes. The patch uses the established database read workers and keeps selection, physical-store custody, and caller checks with their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c0e6951d6f02. 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 (1 earlier review cycle)
|
6c2bcea to
a947ae5
Compare
Resolve persisted spawn session targets through the existing read workers while preserving ordered lookup and canonical validation. Recheck caller authority after preparation and bind child creation and fork writes to the selected physical store. Preserve contributor inheritance, requester identity, and incognito ownership.
a947ae5 to
38f9ce6
Compare
|
Merged via squash.
|
…w#159135) Resolve persisted spawn session targets through the existing read workers while preserving ordered lookup and canonical validation. Recheck caller authority after preparation and bind child creation and fork writes to the selected physical store. Preserve contributor inheritance, requester identity, and incognito ownership.
What Problem This Solves
Spawning a subagent can stall the Gateway by loading and validating the complete session store just to locate its requester.
User Impact
Persisted-session lookup for native, visible, and ACP spawning runs in the existing database workers. Requester identity, preference inheritance, contributor inheritance, cancellation, and transcript forking retain their existing contracts. There is no schema, configuration, retention, or update change, and no migration is required. Cold worker startup increases the first request's elapsed time in the synthetic measurement below.
Why This Change Was Made
The candidate-only lookup option previously narrowed the returned rows after complete store hydration. One asynchronous adapter now carries the existing ordered lookup through worker-owned discovery and selected-key listing, retaining canonical-key and pending-sibling validation while its physical readers are current.
Callers recheck authority before child admission and effects. Contributor inheritance joins participant recording before reading the selected full parent entry. Child creation and forking bind their writes to the selected physical database, so a configured path changing during an await cannot redirect them. Incognito databases retain their process-local owner; the existing live skill-selection commit guard remains in place.
Evidence
The real spawn regression fails on the original implementation. With 4,096 unrelated synthetic sessions, main-thread session-store SQL calls fall from 27 to zero and unrelated-session JSON parses fall from 4,096 to zero. These counts exclude the existing lifecycle-control database. Main-thread CPU was 48.116 ms before and 14.846 ms afterward; cold elapsed time was 49.729 ms before and 837.380 ms afterward, including candidate worker startup. A warmed candidate used 4.327 ms of main-thread CPU and 41.150 ms elapsed. There is no comparable warmed baseline and no deployed-latency claim.
The initial six-file proof passed 150 cases. The final integration group passed 116 cases covering ACP orchestration and authority, native preparation authority, and visible admission. Three selected-path/participant cases passed; the creation and fork cases first reproduced writes to the wrong database and now preserve the original database and transcript. An obsolete ACP fixture mock was corrected before its 85 orchestration cases passed; that initial failure occurred before product assertions.
The full changed check passed production types, all 25 test type graphs, core/script lint, unused-code checks, and guards. After the two physical-path bindings and fixture changes, production types, the owning agents-other test graph, targeted typed lint, ratchets, formatting, and diff checks passed. Fresh isolated review found no actionable P0–P2 findings. A test-selector expansion was stopped before repeating all 25 graphs; it was not a type failure.
pnpm buildpassed in 8m50.228s, including runtime imports, Doctor closures, plugin SDK declarations, and the UI build. Standalone changed-test costs below used the repository'snode scripts/run-vitest.mjs <file> --maxWorkers=1entry point; paths are undersrc/agents/subagents/spawn/.subagent-spawn-session-patch.test.tsacp-spawn.test.tssubagent-spawn.test.tssubagent-spawn.requester-incarnation.test.tsOPENCLAW_DB_WORKER_BENCH=1The first hosted run failed because three newly added fixtures on main omitted the required Cron scheduler dependency. Its two type-check failures and seven history-test failures are repaired by the existing main fix; the other 115 jobs were cancelled by the failed gate. The next run exposed an updater-script fixture missing reporting dependencies, already repaired in #159127; its other 106 cancellations were consequences of that single wrapper failure. This PR now includes both repairs, and
git range-diffconfirms the performance patch is unchanged after each rebase. Fresh CI passed on the final head: 152 jobs succeeded and 20 were skipped. The newer session/config refactor on main was also checked with the unchanged patch applied tof72bb2cca2d: all 11 requester and selected-database cases passed in 45.249s, retaining zero main-thread session-store calls and unrelated parses. The isolated integration checkout initially lacked workspace dependency links and failed before tests; a frozen-lock install repaired that setup before the passing run.Hosted verbose logs report summed test-case durations of 5.917s for eight requester cases, 1.977s for 85 ACP cases, 2.139s for the three session-patch cases, and 16.180s for 84 native-spawn cases. These are test-case duration sums, not standalone file wall times. The table above records measured local file wall times.