Skip to content

perf(agents): index subagent recovery ownership - #119793

Merged
vincentkoc merged 2 commits into
mainfrom
perf/subagent-recovery-owner-index
Aug 6, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/subagent-recovery-owner-index

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Resolves an operational performance problem where restart recovery sweeps repeatedly scanned the entire live subagent registry to determine ownership for each row. Large recovery sets therefore paid quadratic ownership-check cost while the registry already maintained a child-session index.

Why This Change Was Made

Base SHA: a20746e3abf7378462448c456eaa7098b85aab48

The child-session index in subagent-registry-memory.ts is the architectural owner for live generations of one child session. This change threads that existing lookup into restart recovery and durable kill reconciliation, removing five full-registry scans: one in the recovery coordinator and four in durable kill ownership/task checks.

Ownership is re-read at the existing await boundaries. Recovery currency is target-aware across source rows, accepted remaps, settlement, receipt clearing, and resume, so a stale generation cannot mutate a newer owner.

Independent best-fix review compared the owner boundary and sibling recovery paths. It confirmed that reusing the canonical child-session index is preferable to adding a recovery-local cache or downstream guards.

There are no config, schema, persistence-format, scheduling, protocol, or public API changes.

Complexity and size

  • Per swept row, K ownership checks change from O(K*N) full-registry work to O(K*G), where G is the live generation count for that child session and is normally 1.
  • Across the full sweep, ownership work changes from worst-case O(K*N^2) to O(K*N*G); the existing O(N log N) sweep ordering remains.
  • Production: +41/-42, net -1.
  • Tests: +108/-16, net +92.
  • Benchmark fixture: +10/-5, net +5.

User Impact

Operators with large retained subagent recovery sets get substantially lower restart-recovery sweep latency without changing recovery semantics, configuration, stored data, or required actions.

Evidence

Same-lease benchmark

Exact command:

node --import tsx scripts/bench-agent-concurrency.ts --runs 20 --warmup 3 --fanout 1 --sweep-rows 32,128,512 --json

Environment: Node v24.19.0, AMD EPYC, 4 CPUs. Baseline and final ran sequentially on the same Testbox lease. Both invariant sets were green and identical.

Recovery rows p50 baseline -> final p95 baseline -> final p99 baseline -> final
32 0.2557 -> 0.1868 ms (-27.0%) 0.3419 -> 0.2823 ms (-17.4%) 0.3843 -> 18.1853 ms (single scheduler outlier)
128 0.9453 -> 0.5556 ms (-41.2%) 1.2830 -> 0.7561 ms (-41.1%) 4.4494 -> 0.9361 ms (-79.0%)
512 8.5672 -> 1.8219 ms (-78.7%) 11.4056 -> 5.1632 ms (-54.7%) 13.2825 -> 11.2670 ms (-15.2%)

The 32-row final p99 is one scheduler outlier; its p50 and p95 both improved. The post-benchmark lint amendment only introduced a type alias and test deferred helper; TypeScript emitted runtime JavaScript remained byte-identical.

Race proofs

  1. A newer recovery generation wins while terminal finalization is awaited: no stale retry or second finalization occurs.
  2. Durable kill ownership changes while runtime loading is awaited: both same-run-ID replacement and a distinct newer generation avoid abort, queue clearing, completion, and retirement.
  3. A newer accepted-recovery generation wins during settlement before commit: settlement defers and preserves the abort marker and receipt.
  4. Settlement succeeds, then a newer generation wins before receipt retirement: recovery defers, retains the receipt, and does not clear or resume the stale owner.

Verification

No changelog entry: this is an internal performance and ownership repair with no new user-visible surface or operator action, and CONTRIBUTING.md leaves changelog edits to the landing maintainers.

AI-assisted implementation; the code, race behavior, benchmark methodology, and final proof were reviewed directly.

@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 6, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 6, 2026 01:06
@vincentkoc
vincentkoc force-pushed the perf/subagent-recovery-owner-index branch from 2ef3096 to 88b146c Compare August 6, 2026 01:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer reconciliation: ClawSweeper run https://github.com/openclaw/clawsweeper/actions/runs/31062375377, shard 8, completed its exact-head review of 88b146ca04e9accd4d4cfffa000ef2fd03d53b40: no findings, security cleared, confidence 0.88. Its sole Rank-up move was current-main/merge freshness. The repo-native prepare-run and merge-verify both passed with the head unchanged; hosted evidence is 80 pass / 0 fail / 0 pending, including green openclaw/ci-gate, and the changed paths have zero overlap with current main at f5125a7e56f00442ce81344b8255852dc7e729ae. This repo has no GitHub merge queue, so the strict native exact-merge/current-main validation is the satisfying path. The exact-head review remains valid.

@vincentkoc
vincentkoc merged commit c37ba84 into main Aug 6, 2026
119 checks passed
@vincentkoc
vincentkoc deleted the perf/subagent-recovery-owner-index branch August 6, 2026 02:08
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
* perf(agents): benchmark indexed recovery ownership

* perf(agents): index recovery owner lookups
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 6, 2026
…cope

* origin/main: (24 commits)
  fix(backup): skip transient gateway lock databases (openclaw#119782)
  test(agents): use canonical auth session fixtures (openclaw#119821)
  fix(memory): keep QMD file hints after stale docid misses (issue openclaw#113041) (openclaw#113515)
  test(doctor): align fast-path repair contracts (openclaw#119812)
  perf(agents): index subagent recovery ownership (openclaw#119793)
  fix(gateway): keep chat startup off catalog discovery (openclaw#119742)
  fix(test): keep TUI PTY suites in their owner lane (openclaw#119787)
  docs: correct dashboard auth precedence (openclaw#119785)
  docs: document control ui owner handoff
  fix: grant host-authorized control ui owner access
  fix(worktrees): preserve registered roots during orphan cleanup (openclaw#119709)
  fix(matrix): prevent shared client key collisions (openclaw#119667)
  fix(diagnostics-otel): propagate exported span context (openclaw#112283)
  fix(worker): isolate state observer failures (openclaw#117507)
  fix(qa): attest realized profile executions (openclaw#119761)
  fix(gateway): finish successful sessions after timestamp races (openclaw#119752)
  fix(agents): fence restart recovery lifecycle (openclaw#119776)
  fix(ui): preserve chat history and active run timing (openclaw#119729)
  improve(ollama): reduce inactive startup cost (openclaw#119745)
  improve(gateway): defer inactive plugin runtime imports (openclaw#119733)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant