Skip to content

fix(agents): avoid blocking Gateway during spawn preparation - #159135

Merged
steipete merged 1 commit into
mainfrom
codex/subagent-requester-worker-20260926
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/subagent-requester-worker-20260926

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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 build passed in 8m50.228s, including runtime imports, Doctor closures, plugin SDK declarations, and the UI build. Standalone changed-test costs below used the repository's node scripts/run-vitest.mjs <file> --maxWorkers=1 entry point; paths are under src/agents/subagents/spawn/.

Test file Result Measured wall time
subagent-spawn-session-patch.test.ts 3 passed 39.657s shell wall
acp-spawn.test.ts 85 passed 23.353s shell wall
subagent-spawn.test.ts 84 passed 28.922s shell wall
subagent-spawn.requester-incarnation.test.ts Passed with OPENCLAW_DB_WORKER_BENCH=1 41.39s wrapper wall

The 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-diff confirms 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 to f72bb2cca2d: 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.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 gateway Gateway runtime agents Agent runtime and tooling size: L labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 19:48
@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 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 4:10 PM ET / 20:10 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: a947ae50275a16ad17530592b71cb2516d68c4b3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the existing worker boundary and has focused source and benchmark evidence, with the cold-start cost stated plainly.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The Repository State identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its reported synthetic SQLite run reaches production requester lookup and measures the after-change thread result, but stops before child admission; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The Repository State identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its reported synthetic SQLite run reaches production requester lookup and measures the after-change thread result, but stops before child admission; no stored-data contract changes.
Evidence reviewed 6 items Current main still uses synchronous requester reads: Native spawn resolves the store target synchronously and then loads the requester entry before child admission.
Introduced worker boundary: The new adapter discovers durable stores and selects exact requester rows while its discovery and physical readers are current.
Physical write target and caller check: Child creation uses the selected physical read source for its write and checks caller activity at the write guard.
Findings None None.
Security None None.

How this fits together

Subagent 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +178, Tests +315, Docs +9. Total +502 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 13 300 122 +178
Tests 7 343 28 +315
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 652 150 +502

Review metrics

Metric Value Why it matters
Production and test growth production net +190 lines; tests net +303 lines The production growth adds the worker adapter and caller cutover; the tests cover the thread boundary and selected-store behavior.
Reported spawn lookup timing main-thread CPU 48.116 → 14.846 ms; cold elapsed 49.729 → 837.380 ms The synthetic benchmark makes the responsiveness gain and first-request latency cost visible.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway responsiveness improvement with targeted regression coverage and no demonstrated emergency impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 Repository State identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its reported synthetic SQLite run reaches production requester lookup and measures the after-change thread result, but stops before child admission; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

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

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 (1 earlier review cycle)
  • reviewed 2026-09-26T19:56:37.744Z sha 6c2bcea813a60b554c916c63d79cc3615f32ca13 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/subagent-requester-worker-20260926 branch from 6c2bcea to a947ae5 Compare September 26, 2026 20:03
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.
@steipete
steipete force-pushed the codex/subagent-requester-worker-20260926 branch from a947ae5 to 38f9ce6 Compare September 26, 2026 20:20
@steipete
steipete merged commit b2265de into main Sep 26, 2026
241 checks passed
@steipete
steipete deleted the codex/subagent-requester-worker-20260926 branch September 26, 2026 20:43
@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 27, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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