Skip to content

perf(subagents): skip terminal child reads during restart - #169034

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-gateway-restart-time-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-gateway-restart-time-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway restart recovery serially reopens child sessions for retained terminal subagents. Thousands of historical runs add tens of seconds to the post-ready recovery tail, and an unavailable completed child store can prevent activation from reaching unfinished runs.

User Impact

Completed subagents restore without the unnecessary startup child-session read. Existing delivery, cancellation, and interruption owners retain their checks. This shortens recovery completion; the measurements show no material readiness, first-chat, or memory improvement. No schema, config, or update migration changes are required.

Why This Change Was Made

Terminal records skip the startup read and continue through the existing current-row, restart-recovery, cancellation, and delivery checks. Unfinished executions and queued collectors retain their current-session reconciliation. The patch uses the simplified restoration owner on current main; it adds no cache or competing delivery path.

Production LOC is +4 (9 added, 5 removed). The current-session identity and queued-collector rollback contracts require retaining the existing read for unfinished runs. The condition removes a database read per terminal run while preserving those contracts. Related tests move into the existing test-support module so the oversized test file shrinks.

Evidence

Paired isolated Linux benchmark on AWS Crabbox cbx_5e6599185151 (c7a.8xlarge, Node 24.19.0), exact baseline 48a348028fb0f9e60f57832e8b03b35264ccdf54 and candidate 17641f82f85a8f15d85248972db729f2479a8561. Each variant used the same stopped synthetic snapshot, one warmup, and three measured restarts: 3,000 completed subagents (50.7 MB retained payload), 3,000 child sessions, and 12,000 transcript messages.

Median Before After
Subagent recovery 29.875 s 1.738 s
Recovery complete since launch 43.523 s 15.559 s
Stop → readyz 200 13.356 s 13.398 s
Stop → completed first chat 19.621 s 19.304 s
Peak Gateway RSS 2,900.1 MiB 2,911.8 MiB

Recovery is 17.2× faster, saving 28.14 seconds. Readiness, first-chat latency, and memory show no material improvement in this sample. First chat ends at a successful agent.wait terminal response from a loopback mock provider. Only documented pre-dispatch session-admission refusals are retried; candidate sample 0 required eight retries and the other five measured samples required none. Their time is included. No live state or external model calls were used.

Startup phase medians (milliseconds)
Phase Before After
process.bootstrap (cumulative since process start) 5,538.4 5,609.3
cli.main.gateway-run-bootstrap 2,731.3 2,770.9
cli.command.config-ready 2,728.7 2,769.0
cli.bootstrap.admission.state-snapshot 2,336.2 2,369.6
cli.bootstrap.gateway-lock 687.1 687.6
sidecars.main-session-recovery 607.5 618.2
sidecars.worker-environments 56.0 42.5
sidecars.plugin-services 15.2 15.4
post-ready.startup-maintenance 1,289.4 1,372.7
startup.maintenance.session-transcripts 1,264.4 1,430.3
post-ready.gateway-data.session-history-worker 631.2 688.8
sidecars.subagent-recovery 29,874.7 1,737.8

The transcript-maintenance median has three baseline spans and two candidate spans; the third candidate completed its parent maintenance span without a matching transcript child span. This synthetic setup does not reproduce production plugin-service or import costs.

Validation:

  • On untouched baseline 48a34802, the new regression fails because the completed child store is unavailable. The patched path restores the active run without reading that completed child.
  • Blacksmith Testbox tbx_01m4n61c091ream79dj7v9ghcb: 190 tests passed across the registry, cancellation, queued recovery, and restart recovery suites; export-name collision guard and both eager-import/source-closure files passed (20 tests). The new regression took 6 ms. The four-file test run took 57.85 s in Vitest; the owning infra pair took 35.84 s with one worker.
  • The full local changed-file gate found an unrelated existing max-lines suppression/baseline mismatch in src/web-search/runtime.test.ts. The same guard fails on a clean, untouched 48a34802 worktree. Neither that file nor its baseline is changed here.
  • Exact-head CI passed, including all required checks, types, lint, guards, docs, UI checks, and selected Node shards. The Node jobs took 104–315 seconds including setup and existing sibling tests. Independent review is clean. No inherited-CI exception is required.
  • Both full benchmark builds and the paired AWS command passed. The initial Testbox benchmark lost its Gateway during warmup and contributed no timing samples. All leases are stopped.

@clawsweeper

clawsweeper Bot commented Oct 11, 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: S labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 09:27
@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 Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR skips startup child-session reads for completed subagents while preserving reconciliation for unfinished runs.

Example: Restart a Gateway retaining 3,000 completed subagents and their child sessions.

  • Before: The recorded baseline median subagent recovery takes 29.70 seconds.
  • After: The earlier candidate’s recorded median takes 2.40 seconds; this is historical benchmark evidence, without a readiness or first-chat improvement claim.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, worthwhile optimization with shipped-entry-point performance evidence, meaningful regression coverage, preserved ownership boundaries, and successful current-head CI gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded paired Linux runs exercise the completed-child optimization through the built CLI’s real Gateway using identical retained-state snapshots; the revised patch preserves the same terminal predicate, while the reported 12.4× improvement remains earlier-candidate evidence rather than a measurement of this head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Historical completed subagents prolong post-ready recovery, and an unavailable completed child store can prevent unfinished runs from activating.
Reason: The substantial recorded recovery improvement justifies the small production change, and the established feature owner’s direction preserves existing recovery and effect boundaries.

Merge readiness

✅ Ready for maintainer review

This PR provides a worthwhile recovery optimization that current main still lacks; no introduced defect was found, the previous conflict is resolved, and current-head CI gates are successful.

Priority: P2
Reviewed head: 17641f82f85a8f15d85248972db729f2479a8561

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway startup hydrates persisted subagent registry rows, restores requester ownership, and passes unfinished execution or terminal settlement to the existing recovery, delivery, and cleanup owners.

flowchart TD
A[Gateway startup] --> B[Registry hydration]
B --> C[Current run and recovery guards]
C --> D[Completed run settlement]
C --> E[Unfinished child reconciliation]
E --> D
D --> F[Guarded delivery and cleanup]
Loading

Technical review

Best possible solution:

Restore completed runs from registry facts while unfinished execution and final effects retain their existing session and lifecycle owners.

Do we have a high-confidence way to reproduce the issue?

Current main serially reads completed child sessions before advancing activation, so a failed completed-child read can block later runs; the PR reports a baseline-failing regression and real Gateway measurements, which this read-only review did not rerun.

Is this the best way to solve the issue?

The focused shortcut removes unnecessary I/O at the restoration owner without adding a cache or competing delivery path, while downstream cleanup retains its session-identity and authority checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6e06137f85ef.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit d00524c adds src/agents/subagents/registry/subagent-registry-restore.ts:295 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: d00524c29577; files: src/agents/subagents/registry/subagent-registry-restore.ts)

PR surface

Source +4, Tests +50, Docs +3. Total +57 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 5 +4
Tests 2 78 28 +50
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 90 33 +57

Review metrics

Metric Value Why it matters
Production versus test LOC Production +9/−5; tests and support +78/−28 Four net production lines remove a redundant read; test growth adds one activation-progress regression and relocates existing routing coverage.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Retained completed children add substantial post-ready recovery work and can prevent activation from reaching unfinished runs, without a demonstrated readiness regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-11T09:32:34.631Z sha 3aca714 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-11T09:51:55.266Z sha 3aca714 :: needs changes before merge. :: none

Reviewed October 11, 2026, 6:19 AM ET / 10:19 UTC (Revision 3).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Oct 11, 2026
@steipete
steipete force-pushed the steipete/perf-micro-gateway-restart-time-20260919 branch from 3aca714 to 17641f8 Compare October 11, 2026 10:01
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@steipete
steipete merged commit 13826f2 into main Oct 11, 2026
136 checks passed
@steipete
steipete deleted the steipete/perf-micro-gateway-restart-time-20260919 branch October 11, 2026 10:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 19, 2026
First-parent upstream 069a5b8..75df19c (17 commits, including
openclaw#169043 entry lifecycle queries, openclaw#169034, openclaw#169058 memory index facts,
openclaw#168950, openclaw#169019 telegram queued history replies, openclaw#168790/openclaw#168756/
openclaw#168759/openclaw#168739 Solid UI ports, openclaw#168813 codex metadata/startup
lifecycles, openclaw#168981, openclaw#168992 agent preparation SQLite work).

Only conflict: worker-access inventory, regenerated (631 files, 2436
calls). Auto-merged files carrying our overlay, reviewed: snapshot.ts
(upstream's block-reply reconcile reads through index-1; our per-part
continuation-marker strip in extractAssistantStreamSnapshot unchanged),
codex side-question.ts (upstream's request-scoped client lease; our
disableContinuationTools and the extracted dynamic-tool-call helper
unaffected), subagent-registry-restore.ts, session-sharing-store.native.ts.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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