Skip to content

perf(subagents): avoid rebuilding list indexes for internal run updates - #158792

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-subagent-index-rebuild-per-publication-20260919
Sep 26, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-subagent-index-rebuild-per-publication-20260919

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session-list preparation rebuilt the complete subagent read index after every registry publication, including internal bookkeeping that did not change any list facts. Large retained registries paid repeated main-thread CPU and allocation costs during active subagent work.

User Impact

Subagent activity causes substantially less session-list indexing work while preserving status, descendant counts, parent links, swarm membership, and live ownership. Configuration, stored data, and update behavior are unchanged.

Why This Change Was Made

Carry exact changed run IDs through the existing publication owner. A projection-owned index compares the canonical compact facts and live-owner identity, patches affected memberships, and advances its list revision only when those facts change. Full-record readers retain the existing publication revision fence. Registry replacement/reload rebuilds the index; projection disposal releases its subscription. Full construction and keyed updates share the same topology implementation; construction never writes through its borrowed input map. Prepared memory winners remain plain, cloneable Set data, maintained with the affected child memberships.

The complete cutover adds 284 net production lines. The additional bookkeeping preserves old child/controller/requester/swarm memberships, retained generations, raw queued-owner identity, and source/disposal lifecycles; it replaces the old construction loop and adds no configuration or persistence surface.

Evidence

Synthetic workload: 5,000 retained runs (4,990 completed and ten initially running), with nine internal requesterSettleWake.progressOperationId publications per active run followed by one completion. At an assumed six-second progress interval this models 100 registry publications/minute. Each publication goes through the live registry publication owner and the real session projection context. Ordinary streaming progress/heartbeat events do not all publish registry rows, so this is a fixture rate, not a measured production publication rate. Registry task/label, result payloads, and retry bookkeeping are absent from the compact list facts; session labels remain owned by session entries. Execution, topology, duration, cleanup/delivery status, and collector facts remain visible.

Per 100 publications / modeled minute Before After
Full index rebuilds after initial preparation 100 0
List revision changes / keyed patches 100 10
Thread CPU 572.081 ms Below counter resolution (reported 0 ms)
Wall time 588.287 ms 1.697 ms
Sampled allocated bytes 1,267,721,288 1,027,552
RSS growth during measurement 434,610,176 bytes 217,088 bytes

Allocation was sampled with the Node heap sampler at 16 KiB, including objects collected by minor/major GC. CPU and wall values cover that same profiled interval and include instrumentation overhead. These are microbenchmark measurements, not a live Gateway heap or latency claim. The final CPU interval is shorter than the host counter can resolve; the wall measurement is reported separately rather than treating zero as exact CPU cost. The benchmark harness was temporary; the permanent regression enforces zero list-revision growth and no full rebuild for 100 progress-only publications, followed by completion and retirement.

All heavy validation used provider blacksmith-testbox, profile openclaw-check:

  • Lease tbx_01m3ed6zbx411vsy1hyajbf3yp (run): initial benchmark command found missing dependencies; pnpm install --frozen-lockfile passed. Baseline benchmark passed. node scripts/run-vitest.mjs on the benchmark, projection-context, subagent-index, and registry-queries files passed 51 tests in 50.57 s. The 2,048-session drain built one index while applying a completion and unrelated session writes. Two subsequent sync attempts timed out before executing tests; the lease was stopped and replaced.

  • Lease tbx_01m3ee3dn5rvntyj73g8tys9t7 (run): one dependency install passed. The original production files at 6c7544adc982 failed the new regression as intended (100 list revisions versus 0); candidate restoration passed all 36 comparison/query tests. Paired captures confirmed the reduction. The initial changed-file gate found the query file's line cap, fixed by extracting the shared topology owner; test typechecking then caught the progress fixture field at the wrong nesting level, corrected to the actual requester-wake receipt. Its default remote base also included unrelated source changes; the final gate pins the actual task base. A further full-sync timeout prevented execution, so this lease was stopped and replaced.

  • Lease tbx_01m3ef8hbgse97ktvd12p2f1rj (run): one dependency install passed. A single synchronized invocation repeated the corrected original-code negative control, candidate benchmark/regression, changed-file gate, and per-file timings. Its paired measurement is the table above.

  • Full implementation gate: node scripts/check-changed.mjs --base 6c7544adc982 — passed, including core plus all 25 test typecheck graphs, lint, dead exports, and guards.

  • Final per-file cost runs: /usr/bin/time -p pnpm test <file> --maxWorkers=1 — all 52 tests passed: projection-context 22.02 s (5 tests), registry-queries 9.97 s (30), identity benchmark 8.91 s (1), subagent-index 31.38 s (16). Wrapper/compiler startup is included; the context file spent 16.2 s preparing compiler outputs. The existing subagent-index integration fixture spent about 17 s in database/recovery/drain tests; only its build-count expectation changed. The full final invocation took 29m16s. All leases were stopped.

  • Read-only construction follow-up on lease tbx_01m3ehcc34xfvcv0x6vnzq7g1a (run): the extended existing test failed on the earlier candidate with four writes through the input map, then all 54 query/memory/projection tests passed in 53.61 s. node scripts/run-tsgo.mjs -p tsconfig.core.json, the agents-other test graph, and targeted node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json passed. This guard removes construction-time writes; the measured keyed publication behavior remains covered by the final regressions. The invocation passed in 3m43s and the lease was stopped.

  • Hosted CI repair on lease tbx_01m3ejyff8akybwa0pk93tq93e (run): CI run 36234016711 found that the function-valued iterator wrapper was dropped by structuredClone in the existing materialization immutability test. Replaying its 40-file Node selection reproduced that exact failure; with the Set-backed facts, all 562 tests passed (118.31 s), without changing the wire goldens or materialization expectations. The 30 query tests passed (10.26 s pnpm wall), and 21 focused projection tests passed (35.53 s wrapper wall). Core and affected test-graph typechecks plus targeted lint passed; independent review was clean through P2. This invocation passed in 6m20s and the lease was stopped.

  • Independent Codex autoreview: clean through P2 for the main implementation and both follow-ups. git diff --check passed.

  • Final hosted CI: run 36235445956 passed on 6b6d7c67fb1c6b42d0782b0b398408d516fe30a9, including openclaw/ci-gate. Hosted run elapsed approximately 14m25s; the repaired checks-node-changed-compact-large-11 job took 298 s, including setup and its grouped tests.

No live Gateway was modified or restarted. Production heap-burst/stall reduction remains to be verified after deployment.

Carry keyed registry publications into the resident session-list index. Skip unchanged compact facts, preserve full-read revision fences, and patch affected topology while retaining live-owner and source replacement semantics.
@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 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 09:38
@steipete
steipete marked this pull request as draft September 26, 2026 09:40
@steipete
steipete marked this pull request as ready for review September 26, 2026 09:51
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 6:25 AM ET / 10:25 UTC (Revision 2).

ClawSweeper review

What this changes

The branch updates the Gateway’s session-list projection to patch affected subagent run indexes and skip full rebuilds for progress-only registry updates.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Current main still rebuilds the subagent list index, so this performance work remains useful. The prior review’s source-replacement finding remains unresolved at the current head and blocks merge.

Priority: P2
Reviewed head: 6b6d7c67fb1c6b42d0782b0b398408d516fe30a9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Relevant paired production-path measurements support the optimization, while the unresolved parent-link defect limits patch readiness.
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 Testbox before/after workload exercises the production registry publication and session projection and observes fewer rebuilds, but it does not cover removed-child replacement or prove production Gateway heap impact. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

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 Testbox before/after workload exercises the production registry publication and session projection and observes fewer rebuilds, but it does not cover removed-child replacement or prove production Gateway heap impact. No stored-data contract changes.
Evidence reviewed 8 items Current main still rebuilds: The current-main projection rebuilds its subagent index when the registry revision changes; the PR’s keyed index is absent.
Introduced parent-refresh trigger: On a broad refresh, the introduced branch visits only child keys in the rebuilt index.
Replacement retains old keys: The replacement path records child keys from both the old and new indexes, including children removed from the new snapshot.
Findings 1 actionable finding [P2] Refresh old-only children after source replacement
Security None None.

How this fits together

The subagent registry publishes run changes to the Gateway’s resident session-list projection. That projection turns run facts into session status, activity, and parent links shown to clients.

flowchart LR
  A[Subagent run changes] --> B[Registry publication]
  B --> C[Resident run index]
  C --> D{List facts changed?}
  D -->|Yes| E[Refresh affected sessions]
  D -->|No| F[Reuse session facts]
Loading

Before merge

  • Refresh old-only children after source replacement (P2) - When a replacement snapshot removes a child’s last run, the new index records the old child key, but this broad branch visits only keys still in the rebuilt index. The retained session row is never reprojected, so its derived parent and parent index remain stale. Include the old-only keys and cover that replacement case.
  • Resolve merge risk (P1) - Replacing a registry source after a child’s last run disappears can leave that session’s derived parent link and parent index stale.
  • Complete next step (P2) - Refresh old-only child rows on registry source replacement and verify that their derived parent links clear before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P2] Refresh old-only children after source replacement — src/gateway/session-row-projection-context.ts:157-159
Agent review details

Security

None.

PR surface

Source +284, Tests +109. Total +393 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 9 391 107 +284
Tests 4 115 6 +109
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 506 113 +393

Review metrics

Metric Value Why it matters
Production versus test growth production +284 net lines; tests +109 net lines The PR body explains the production growth as keyed membership and lifecycle bookkeeping.

Stored data model

Persistent data-model change detected: serialized state: src/agents/subagents/registry/subagent-registry-state.ts, unknown-data-model-change: src/agents/subagents/registry/subagent-registry-state.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair replacement refresh (recommended)
    Refresh old-only child rows after a registry source replacement and prove their obsolete derived parent links clear.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Include old-only child keys when refreshing parent links after a resident subagent index source replacement; add a regression that removes a child's last run and verifies the stored row loses its derived parent.

Technical review

Best possible solution:

Keep the keyed publication index and make source replacement refresh both formerly and newly indexed children, with a row-level regression for removed ancestry.

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

Yes. Current-main source shows the repeated rebuild path, and the PR reports a baseline negative control; source inspection also gives a direct replacement scenario for the stale-parent defect. This review did not execute either scenario.

Is this the best way to solve the issue?

Yes, once the parent refresh is corrected. Keyed updates use the existing registry publication and projection owners, but source replacement must invalidate children that disappear.

Full review comments:

  • [P2] Refresh old-only children after source replacement — src/gateway/session-row-projection-context.ts:157-159
    When a replacement snapshot removes a child’s last run, the new index records the old child key, but this broad branch visits only keys still in the rebuilt index. The retained session row is never reprojected, so its derived parent and parent index remain stale. Include the old-only keys and cover that replacement case.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cc75881752cf.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The performance improvement is bounded, and the remaining stale-lineage defect has a focused repair.
  • merge-risk: 🚨 session-state: A source replacement can retain obsolete parent relationships in resident session state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository state identifies a member-authored PR, so the external-contributor proof gate does not apply. Its reported Testbox before/after workload exercises the production registry publication and session projection and observes fewer rebuilds, but it does not cover removed-child replacement or prove production Gateway heap impact. No stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/session-row-projection-context.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/session-row-projection.subagent-index.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --base 6c7544a.
  • [P1] git diff --check.

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)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prove that replacing a snapshot and removing a child’s last run clears its derived parent link.

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-26T09:57:05.133Z sha 5bf0926 :: blocked before merge. :: [P2] Refresh children removed by a registry source replacement

@steipete
steipete merged commit 44c9551 into main Sep 26, 2026
204 of 205 checks passed
@steipete
steipete deleted the steipete/perf-micro-subagent-index-rebuild-per-publication-20260919 branch September 26, 2026 10:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…es (openclaw#158792)

* perf(subagents): patch list indexes on registry publication

Carry keyed registry publications into the resident session-list index. Skip unchanged compact facts, preserve full-read revision fences, and patch affected topology while retaining live-owner and source replacement semantics.

* fix(subagents): keep read index construction read-only

* fix(subagents): retain cloneable prepared run facts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant