Skip to content

fix(agents): prevent registry stalls during large fan-outs - #116286

Merged
vincentkoc merged 2 commits into
mainfrom
perf/agent-concurrency-stress
Jul 30, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/agent-concurrency-stress

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Closes #116227

What Problem This Solves

Fixes an issue where large agent and subagent fan-outs repeatedly rewrote and deep-cloned every retained registry run for each lifecycle mutation, blocking the Gateway event loop and creating substantial transient memory churn.

Why This Change Was Made

Hot registry mutations now name the exact changed or removed run IDs. The SQLite owner upserts those rows and deletes exact absent IDs in one transaction, while the in-process read cache updates the same entries incrementally.

Explicit restore and test-reset boundaries retain complete-snapshot replacement and pruning. The schema, serialized record shape, rollback behavior, and persistence notifications are unchanged.

User Impact

Large concurrent fan-outs spend substantially less synchronous time persisting registrations, terminal transitions, cleanup, steering, and idle bookkeeping. Unrelated retained runs no longer multiply the work for each transition.

Evidence

Stress matrix

A throwaway production-module harness exercised:

  • 10, 25, 50, and 100 concurrent runs
  • wide active descendant queries
  • nested idle parents with active descendants
  • growing active registration waves
  • terminal and idle lifecycle waves with 32 KiB completion results
  • 10 to 100 embedded active runs with waiters and teardown

The embedded registry returned to zero active runs and settled every waiter at 100-way concurrency. The dominant defect was durable subagent registry persistence.

Same-process before/after measurements on 100-run waves:

                                      full snapshot   exact rows
growing active registry wall time       17,710 ms      1,360 ms
growing active registry RSS after GC      +52.7 MiB      +3.5 MiB
terminal/idle registry wall time         13,693 ms      3,487 ms
terminal/idle registry RSS after GC        +31.6 MiB      -2.2 MiB

The wall-clock improvement was 13.0x for the growing wave and 3.9x for the terminal wave in that run. An earlier baseline run produced the same superlinear shape with lower absolute times, confirming normal host variance rather than a one-off ordering artifact.

Narrow regressions

  • SQLite triggers prove an incremental mutation updates one named row, deletes one named row, and does not touch an unrelated retained row.
  • Read-cache coverage proves incremental updates preserve unrelated entries.
  • Best-effort failure coverage proves an exact deletion remains authoritative in-process and cannot resurrect from stale SQLite state.
  • Registration coverage proves queued and running paths select exact-row persistence.

Validation

node scripts/run-vitest.mjs \
  src/agents/subagent-registry.test.ts \
  src/agents/subagent-registry-state.test.ts \
  src/agents/subagent-registry.store.sqlite.test.ts \
  src/agents/subagent-registry-lifecycle.test.ts \
  src/agents/subagent-registry-requester-yield.test.ts
  5 files passed, 275 tests passed

exact rebased-head regression selection
  6 files passed, 10 tests passed, 294 skipped

node scripts/run-tsgo.mjs -p tsconfig.core.json ...
  passed

direct targeted oxlint, oxfmt, git diff --check
  passed

Blacksmith Testbox:

Autoreview:

autoreview clean: no accepted/actionable findings reported
overall: patch is correct (0.9)

Not tested

  • No live provider or channel traffic was needed; the defect is isolated to the production registry persistence and cache modules.
  • The exploratory 10/25/50/100 stress harness remains uncommitted. Only the exact behavioral regressions are permanent.

@vincentkoc vincentkoc self-assigned this Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 30, 2026 07:28
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 30, 2026, 3:37 AM ET / 07:37 UTC.

ClawSweeper review

What this changes

This PR changes the subagent-run registry so hot lifecycle mutations persist and cache only the named changed or removed runs instead of repeatedly rewriting the full retained registry.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open for maintainer review. The incremental persistence design targets the reported large-fan-out stall and has focused regression coverage plus stress evidence, but the branch still adds a normal-PR entry to release-owned CHANGELOG.md and changes durable subagent lifecycle state across many call paths.

Priority: P2
Reviewed head: c4fd934b522c32a131fd05bfd6291696acb874dc
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a focused persistence boundary and targeted regression coverage, with one small release-process correction remaining.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes redacted terminal stress and focused regression evidence.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes redacted terminal stress and focused regression evidence.
Evidence reviewed 5 items Incremental persistence boundary: The proposed registry wrapper passes nonempty changed run IDs to the persistence dependency and reserves zero IDs for explicit full-snapshot restore or reset boundaries.
SQLite mutation contract: The proposed SQLite store upserts supplied rows and deletes only supplied absent IDs for incremental writes, while retaining complete-snapshot pruning for explicit replacement.
State-cache regression coverage: The branch adds coverage that an incremental mutation updates the named cache entry without changing an unrelated retained entry.
Findings 1 actionable finding [P3] Remove the release-owned changelog entry
Security None None.

How this fits together

The subagent registry tracks active and retained agent runs while lifecycle code registers, completes, cleans up, and resumes them. Its SQLite persistence bridge and in-process read cache feed later gateway and agent lifecycle decisions.

flowchart LR
  A[Agent and subagent lifecycle events] --> B[Subagent run registry]
  B --> C[Changed or removed run IDs]
  C --> D[SQLite exact-row persistence]
  C --> E[In-process read cache]
  D --> F[Durable subagent state]
  E --> G[Gateway lifecycle readers]
Loading

Decision needed

Question Recommendation
After removal of the release-owned changelog entry, should maintainers accept the exact-row persistence contract for all changed subagent lifecycle paths? Remove changelog entry and review: Keep the incremental persistence implementation, remove the normal-PR CHANGELOG.md entry, and complete focused maintainer review of changed lifecycle persistence paths.

Why: The patch changes the durability boundary for agent lifecycle state; focused tests are present, but acceptance requires maintainer judgment over the complete lifecycle ownership surface.

Before merge

  • Remove the release-owned changelog entry (P3) - Normal OpenClaw PRs must not edit the release-owned CHANGELOG.md; keep this user-visible summary in the PR body and let the release process select the release-note entry instead.
  • Resolve merge risk (P1) - This changes the durable and cached representation of lifecycle mutations; any caller that omits a changed or removed run ID could leave persisted registry state stale until a later full snapshot, so maintainer review should sample the changed lifecycle fan-out paths before merge.
  • Complete next step (P2) - This member-authored, maintainer-labeled durable-state change needs explicit maintainer review; the only mechanical correction currently identified is removal of the release-owned changelog entry.

Findings

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:59
Agent review details

Security

None.

PR surface

Source +114, Tests +103, Docs +1. Total +218 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 19 224 110 +114
Tests 3 105 2 +103
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 330 112 +218

Review metrics

Metric Value Why it matters
Persistence mode 1 hot-path durability change Hot lifecycle writes move from full-registry replacement to exact-row upsert/delete behavior, so lifecycle-state review matters even though the schema and serialized record shape are unchanged.

Stored data model

Persistent data-model change detected: persistent cache schema: src/agents/subagent-registry-state.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Remove release-owned changelog entry (recommended)
    Delete the normal-PR changelog line, keep the user-impact description in the PR body, and then finish the lifecycle-state review before merge.
  2. Pause for broader lifecycle audit
    Pause this PR if maintainers cannot confirm that every changed mutation path supplies the authoritative changed or removed run IDs.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove the normal-PR CHANGELOG.md entry; retain the PR-body user-impact summary and focused registry persistence validation.

Technical review

Best possible solution:

Keep exact-row persistence for hot mutations, preserve full-snapshot replacement only at restore and reset boundaries, remove the release-owned changelog entry, and complete a maintainer audit of the lifecycle callers that now supply run IDs.

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

Yes, at source level: the linked report specifies a production persistence-harness path that grows and terminalizes retained registry runs, and the PR body supplies before/after stress measurements. I did not independently execute that harness in this read-only review.

Is this the best way to solve the issue?

Yes, provisionally: exact-row persistence is the narrow owner-boundary fix because full replacement remains available for explicit restore and reset boundaries. The remaining review need is confirmation that every changed lifecycle path provides authoritative run IDs.

Full review comments:

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:59
    Normal OpenClaw PRs must not edit the release-owned CHANGELOG.md; keep this user-visible summary in the PR body and let the release process select the release-note entry instead.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.83

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Large concurrent agent fan-outs can stall gateway work, but the reported impact is limited to high-concurrency registry lifecycle operations rather than an unusable core runtime.
  • merge-risk: 🚨 session-state: The PR changes how subagent lifecycle state is persisted and cached, so an incomplete changed-ID handoff could leave durable run state stale or mis-associated.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes redacted terminal stress and focused regression evidence.

Evidence

What I checked:

  • Incremental persistence boundary: The proposed registry wrapper passes nonempty changed run IDs to the persistence dependency and reserves zero IDs for explicit full-snapshot restore or reset boundaries. (src/agents/subagent-registry.ts:80, c4fd934b522c)
  • SQLite mutation contract: The proposed SQLite store upserts supplied rows and deletes only supplied absent IDs for incremental writes, while retaining complete-snapshot pruning for explicit replacement. (src/agents/subagent-registry.store.sqlite.ts:384, c4fd934b522c)
  • State-cache regression coverage: The branch adds coverage that an incremental mutation updates the named cache entry without changing an unrelated retained entry. (src/agents/subagent-registry-state.test.ts:98, c4fd934b522c)
  • Prior review continuity: The latest completed ClawSweeper review at the same head identified removal of the release-owned changelog entry as its only finding; the current diff still contains that added entry. (CHANGELOG.md:59, c4fd934b522c)
  • Related bug ownership: The PR body explicitly links the open fan-out persistence report, whose reproduction describes full-map SQLite writes and cloning on every lifecycle mutation. (src/agents/subagent-registry-state.ts:128, c4fd934b522c)

Likely related people:

  • vincentkoc: The available review context ties this member to the concrete reproduction, the linked registry-scaling report, and the current incremental-persistence implementation. (role: recent area contributor; confidence: medium; commits: c4fd934b522c; files: src/agents/subagent-registry.ts, src/agents/subagent-registry-state.ts, src/agents/subagent-registry.store.sqlite.ts)

Rank-up moves

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

  • Remove the release-owned CHANGELOG.md entry before merge.

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-07-30T07:32:44.255Z sha c4fd934b522c32a131fd05bfd6291696acb874dc :: found issues before merge. :: [P3] Remove the release-owned changelog entry

@vincentkoc
vincentkoc force-pushed the perf/agent-concurrency-stress branch from c4fd934 to 0ffe66b Compare July 30, 2026 07:39
@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper follow-up:

  • Removed the release-owned CHANGELOG.md entry in 0ffe66b454a.
  • As the agents/state owner for this change, I reviewed the changed-ID coverage and accept the persistence boundary. Hot registration, lifecycle, delivery, listener, sweeper, cleanup, wake, and deletion paths pass the exact affected run IDs. Restore/reset remains the explicit zero-ID full-snapshot path, so restart recovery still reconstructs from the canonical complete registry state.
  • Exact rebased-head proof: 5 focused registry files, 275 tests passed; git diff --check passed. The earlier Testbox changed-files gate covered the same source/test diff and passed all selected typecheck, lint, boundary, guard, and schema checks.

The remaining risk is a future mutation caller omitting its run ID; the centralized boundary and exact-row/cache regressions make that contract visible and testable.

@vincentkoc
vincentkoc merged commit d30d22d into main Jul 30, 2026
12 checks passed
@vincentkoc
vincentkoc deleted the perf/agent-concurrency-stress branch July 30, 2026 07:40
vincentkoc added a commit that referenced this pull request Jul 30, 2026
…n-dedupe

* origin/main: (25 commits)
  fix(qqbot): use Gateway timezone for reminders (#116294)
  test(openai): cover out-of-order named mark acks
  docs(openai): clarify cumulative playback marks
  test(openai): cover sustained unnamed mark acknowledgements
  fix(openai): preserve playback acknowledgement order
  test(openai): verify bounded playback acknowledgements
  fix(openai): bound realtime playback marks
  test(agents): mock incremental registry persistence (#116307)
  fix(memory-core): MEMORY.md compaction deletes user notes written under a promotion-style heading (#116180)
  feat(reply): annotate recent history images (#100866)
  chore(ios): refresh native i18n inventory
  fix(ios): isolate capability router handlers
  docs(ios): cut 2026.7.22 release notes
  docs(hooks): document validation responses
  test(qa): assert hook account rejection reasons
  fix(gateway): validate hook delivery accounts
  perf(gateway): bound prepared runtime startup work (#116261)
  fix(agents): prevent registry stalls during large fan-outs (#116286)
  fix(sqlite): preserve replaced snapshot targets on Windows (#116284)
  fix(ci): load frozen shard runner without repository fetch (#116273)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
…116286)

* fix(agents): persist subagent registry mutations incrementally

* chore(agents): leave release notes to release process
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
…n-dedupe

* origin/main: (25 commits)
  fix(qqbot): use Gateway timezone for reminders (openclaw#116294)
  test(openai): cover out-of-order named mark acks
  docs(openai): clarify cumulative playback marks
  test(openai): cover sustained unnamed mark acknowledgements
  fix(openai): preserve playback acknowledgement order
  test(openai): verify bounded playback acknowledgements
  fix(openai): bound realtime playback marks
  test(agents): mock incremental registry persistence (openclaw#116307)
  fix(memory-core): MEMORY.md compaction deletes user notes written under a promotion-style heading (openclaw#116180)
  feat(reply): annotate recent history images (openclaw#100866)
  chore(ios): refresh native i18n inventory
  fix(ios): isolate capability router handlers
  docs(ios): cut 2026.7.22 release notes
  docs(hooks): document validation responses
  test(qa): assert hook account rejection reasons
  fix(gateway): validate hook delivery accounts
  perf(gateway): bound prepared runtime startup work (openclaw#116261)
  fix(agents): prevent registry stalls during large fan-outs (openclaw#116286)
  fix(sqlite): preserve replaced snapshot targets on Windows (openclaw#116284)
  fix(ci): load frozen shard runner without repository fetch (openclaw#116273)
  ...
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 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: subagent registry persistence scales superlinearly with concurrent runs

1 participant