Skip to content

perf(subagents): avoid rechecking settled runs on idle sweeps - #181560

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-subagent-sweep-authority-rederive-20260919
Oct 23, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-subagent-sweep-authority-rederive-20260919

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Idle registry sweeps re-derived child identity up to three times per retained run, resolved an unchanged runtime owner just to read its retirement tombstone, and allocated async yield checks for non-yielded rows. Even settled history with no due cleanup took that path.

User Impact

Reduces idle subagent-registry allocation and sweep time while preserving completion, recovery, cancellation, and retention behavior. No configuration, schema, or public-contract changes.

Why This Change Was Made

The registry prepares recorded child authority alongside its immutable row projection. Its publication owner maintains unfinished-work and retention-deadline candidates; replacement, deletion, and reset update those indexes. Settled rows join the sweep only when cleanup is due. Empty sweeps skip read-scope preparation, and only yielded rows allocate a yield-settlement operation. Completion retirement reads the existing runtime-owner tombstone directly.

Live custody and current Gateway/row checks after awaits remain at the effect boundary. The original cleanup-identity capture and session-deletion compare-and-swap are preserved. Normal cadence remains 60 seconds; explicit scheduling defaults to 5 seconds, with recovery retries between 1 and 60 seconds.

Production delta: 164 additions / 51 deletions, net +113 lines. The additional in-memory index preserves existing future archive and strict five-minute session-retention deadlines while excluding settled history. It also preserves unfinished recovery, delivery, and cancellation obligations; there is no second persistent owner.

Evidence

Paired measurements

The committed scripts/perf/subagent-sweep-measure.ts exercises the real production sweeper and canonical immutable registry. settled is retained completed history; mixed is 70% history, 10% live claimed runs, 10% pending delivery, and 10% future archive. Every run asserts exact record identity/digests and fails on unexpected effects.

Each process executes 12,000 measured sweeps after 100 warmups, with 1 ms pacing and allocation sampling including collected objects. Linux, Node 26.12.1, identical dependency lockfiles, isolated synthetic state, concurrent baseline/candidate under one exclusive quiet lock. Preparation uses CPUs 0–63; measurement uses 64,66,…,94 versus 65,67,…,95, swapped for pair two. The shared production guard runs before/during each pair, with 8 GiB per-process memory limits. No guard-interrupted pair is included.

Acceptance was recorded before measurement: v5.2/v5.3, >=20% adverse mean or >=10% adverse in both pairs; opposite signs or >5× baseline differences require absolute deltas and a third pair for gating metrics. p95/p99 need 200/1,000 samples per side. Major GC is context below 50 collections. GC pause-tail shifts below 1 ms are context, as are higher tails with >=20% fewer collections and no total-GC increase. The maximum-pause gate remains max(50 ms, 2 × baseline maximum).

Baseline registry code is 7a1d72c44102; the candidate uses the final changed-source bytes. The publication rebase incorporated unrelated main changes without changing those registry bytes. Results are source-owner measurements, not whole-Gateway/model latency or post-deployment evidence. Allocation/minute is the same value as allocation/sweep at the normal one-minute idle cadence; earlier requested sweeps add proportionally.

Values below are paired means. The 50-row settled case includes a third pair to resolve opposite-sign GC/event-loop deltas; the other cases use the two swapped pairs.

Workload Allocation KiB/sweep, before → after Paired delta Mean sweep ms, before → after Paired delta Total GC/work delta Promotion/work delta
Settled, 50 219.58 → 3.53 -98.39% 0.163628 → 0.002556 -98.44% +0.93% -26.59%
Settled, 500 1994.47 → 3.50 -99.82% 1.281623 → 0.002145 -99.83% -74.67% -33.97%
Mixed, 50 222.72 → 24.60 -88.96% 0.167578 → 0.027103 -83.83% -74.24% -25.51%
Mixed, 500 2037.42 → 60.54 -97.03% 1.521262 → 0.064087 -95.79% -94.19% -17.16%

The 50-row settled third-pair decision uses absolute mean deltas: total GC +0.000036 ms/sweep (0.003902 → 0.003938), event-loop p99 -0.174421 ms (1.584810 → 1.410388). No gating metric is adversely beyond the acceptance thresholds. Per-pair total-GC deltas were +1.920 ms (+3.99%), −10.362 ms (−21.23%), and +9.747 ms (+22.41%) per 12,000 sweeps; the absolute mean is +0.435 ms (+0.93%). Event-loop p99 deltas were +0.021504 ms (+1.05%), −0.295936 ms (−21.28%), and −0.248832 ms (−18.81%), giving −0.174421 ms (−11.01%) from the absolute means.

Per-pair GC, promotion, and tail evidence
Case/pair GC total ms, before → after Promotion bytes/sweep, before → after Maximum pause ms, before → after Minor GC p95/p99 ms (count), before → after Major collections, before → after Event-loop p99 ms (samples), before → after
Settled, 50, 1 48.174 → 50.094 34.619 → 25.467 1.514 → 31.911 0.891/1.514 (n=99) → 1.155/1.155 (n=11) 0 → 2 2.040831 (n=11999) → 2.062335 (n=11999)
Settled, 50, 2 48.808 → 38.446 34.601 → 25.475 1.286 → 22.561 0.678/1.286 (n=99) → 0.764/0.764 (n=10) 0 → 2 1.390591 (n=11999) → 1.094655 (n=11999)
Settled, 50, 3 43.485 → 53.231 34.601 → 25.269 1.207 → 33.761 0.605/1.207 (n=99) → 0.835/0.835 (n=10) 0 → 2 1.323007 (n=11999) → 1.074175 (n=11999)
Settled, 500, 1 209.288 → 49.841 38.421 → 25.039 1.292 → 32.461 0.314/0.534 (n=857) → 0.827/0.827 (n=10) 0 → 2 2.672639 (n=11999) → 1.070079 (n=11999)
Settled, 500, 2 181.649 → 48.773 38.421 → 25.700 0.975 → 32.154 0.335/0.444 (n=857) → 0.736/0.736 (n=11) 0 → 2 2.643967 (n=11999) → 1.077247 (n=11999)
Mixed, 50, 1 22.973 → 6.653 34.588 → 25.785 1.107 → 1.221 0.344/0.502 (n=101) → 1.221/1.221 (n=11) 0 → 0 1.461247 (n=11999) → 1.110015 (n=11999)
Mixed, 50, 2 24.763 → 5.589 34.380 → 25.587 1.018 → 0.989 0.393/0.461 (n=101) → 0.989/0.989 (n=11) 0 → 0 1.466367 (n=11999) → 1.147903 (n=11999)
Mixed, 500, 1 208.747 → 12.418 38.421 → 31.797 1.071 → 0.926 0.376/0.464 (n=923) → 0.579/0.926 (n=27) 0 → 0 2.930687 (n=11999) → 1.674239 (n=11999)
Mixed, 500, 2 228.346 → 12.932 38.619 → 32.023 1.198 → 1.002 0.466/0.537 (n=923) → 0.554/1.002 (n=27) 0 → 0 2.924543 (n=11999) → 1.149951 (n=11999)

Every candidate minor-GC tail has fewer than 200 samples; these pause tails are context. Major GC remains below 50 collections per side. The largest candidate pause is 33.761 ms, below the 50 ms max-pause floor. Total GC/work and promotion remain the gating GC metrics.

Workload Sweep p95 ms, before → after (12,000 samples/side/pair) Sweep p99 ms, before → after (12,000 samples/side/pair)
Settled, 50 0.223185 → 0.006780 0.290463 → 0.013818
Settled, 500 1.301131 → 0.004176 1.368473 → 0.008332
Mixed, 50 0.180732 → 0.032363 0.207231 → 0.039153
Mixed, 500 1.554447 → 0.072544 1.631142 → 0.091678

Validation

  • Regression: unchanged base performs 12 recorded-authority derivations across two sweeps; the fix performs zero.
  • Five focused registry/authority files pass: 190 tests. Final sweep/index/cadence rerun: 84 tests. The recovery file takes 12.3 seconds wall time and exercises real worker/session ownership boundaries; the new work-count test itself takes milliseconds.
  • Import-closure guards: 22 tests pass; export-name collision check passes.
  • Focused oxfmt/oxlint and the one permitted core typecheck (pnpm tsgo:core, native checker) pass. No broad local suite or Testbox allocation.
  • Independent Codex autoreview is clean through P2, including the final empty-sweep change; GitHub code review also reported no findings.
  • PR CI is the broad proof. Run 39937949361 has one attributed inherited failure in checks-node-changed-compact-large-16: the progress-card external-silence assertion expects retirement despite a still-required public reply. The same full file fails on unchanged main 7a1d72c44102 and this head (25 passed, 1 failed each); the exact pre-PR parent 93a5a35ecf7f also reproduces the named assertion. fix(agents): settle consumed yield cohorts without retry #181260 changed the required-reply policy and added the opposite expectation in its delivery test, leaving this older worker assertion stale. The failing test and reply-policy sources are identical at CI base c4b9005153d9. All other jobs in the completed CI run pass or are intentionally skipped; security checks pass. The aggregate CI gate is red solely because of this attributed inherited failure. Landing uses the authorized inherited-failure exception. No CI rerun or deployment was performed.

Reproduction (each side uses its own new state/log/result paths and a shared future start epoch):

node --expose-gc --trace-gc-nvp --import ./scripts/tsx.mjs \
  scripts/perf/subagent-sweep-measure.ts \
  --runs 500 --workload mixed --operations 12000 --yield-ms 1 \
  --state-dir /path/to/new-state --start-at <epoch-ms> \
  --gc-log /path/to/capture.log --output /path/to/result.json \
  > /path/to/capture.log 2>&1

Prepare recorded child authority with immutable registry rows and index unfinished work plus retained cleanup deadlines. Keep runtime custody, recovery, and session-deletion checks at their effect boundaries. Avoid empty-sweep read scopes and non-yielded settlement promises.
@clawsweeper

clawsweeper Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 23, 2026 10:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T10:19:42.042319Z 53131d5 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 23, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

CI attribution for head 53131d55c12589cb9a37230bdc10d1b1add41964, run 39937949361: checks-node-changed-compact-large-16 fails only subagent-control.worker.test.ts > subagent progress drafts > settles the progress card according to intentional external silence (retire expected once, observed zero).

The same full file fails identically on the unchanged main baseline 7a1d72c44102a24843c602c6559aa72fec3f49a5 in an isolated Linux sandbox and on this PR head locally: 25 passed, 1 failed in each run. Command: node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-control.worker.test.ts --maxWorkers=1. Both use the repository-pinned Bun test runtime. The exact pre-PR parent 93a5a35ecf7ff46462001b5ccd1f669f8765e31c also fails the isolated named case with the same assertion. The CI merge base c4b9005153d99913a33a4c30ce172f9589a4febb differs from that parent only in four channel-stop/documentation files; the failing test and subagent reply-policy sources are identical.

The mismatch predates this PR: #181260 (535989c92996) changed subagent_settle receipt classification to preserve the owner's required-reply obligation. A yielded public cohort with undelivered findings requires a visible result, so NO_REPLY keeps the requester wake pending and the progress card alive. That change added the explicit required public silence → visible_reply_missing regression in subagent-announce-delivery.yielded-settle.test.ts, but retained this older worker-test expectation. The reply-policy/receipt-classification code and failing assertion are untouched here.

The six other files in this CI shard pass (173 passing tests overall). Focused sweep, authority, recovery, retention, import-closure, lint, and core typecheck proof is recorded in the PR body; independent review is clean. This failure is retained and attributed, not rerun away or reported as green.

@steipete
steipete merged commit 619555b into main Oct 23, 2026
229 of 234 checks passed
@steipete
steipete deleted the steipete/perf-micro-subagent-sweep-authority-rederive-20260919 branch October 23, 2026 10:29
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
Prepare recorded child authority with immutable registry rows and index unfinished work plus retained cleanup deadlines. Keep runtime custody, recovery, and session-deletion checks at their effect boundaries. Avoid empty-sweep read scopes and non-yielded settlement promises.
RomneyDa added a commit that referenced this pull request Oct 28, 2026
Prepare recorded child authority with immutable registry rows and index unfinished work plus retained cleanup deadlines. Keep runtime custody, recovery, and session-deletion checks at their effect boundaries. Avoid empty-sweep read scopes and non-yielded settlement promises.

Source-commit: 619555b
Co-authored-by: RomneyDa <[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 scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant