Skip to content

fix(gateway): release leaked state after subagent launches - #170855

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-heap-growth-r94-20260919
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-heap-growth-r94-20260919

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway heap kept growing after completed subagent launches, even after their sessions were archived and deleted.

User Impact

Completed launches release their authorization state and the parent agent graph it retained. No schema, authorization policy, configuration option, or public protocol changes.

Why This Change Was Made

Typed dispatch obtained session authorization facts but consumed only the result's error, dropping the cleanup callbacks. The global session-identity listener set then retained the facts' registry witness, whose captured async context held the completed parent's tools and disposed context engine. Snapshot growth matched one resource graph per child.

Release check-only resources at the typed dispatch/wait and sessionless preparation boundary. Canonical turn admission independently authorizes its target. In-process read/mutation helpers retain their live facts through the callback and release both authority types in finally.

The synthetic rig also disables autonomous Skill Workshop reviews. They shared the agent model and consumed its ordered foreground tool fixtures after repeated session-key reuse. This preserves strict tool/reply/history assertions and all requested workload categories.

Production delta: +9 lines (plus 2 benchmark-fixture lines). The existing resource ownership contract requires the missing release calls; no new cache, owner, fallback, or alternate execution path was added.

Evidence

Isolated Linux sandbox, Node 26.8.2, 2,000 seeded sessions, 10 reconnecting clients, 440 ms RPC cadence, 5-second turn interval. Traffic includes sidebar/history polling, bounded session churn, persistent hot conversations, Code Mode, subagents, artifacts, and cron. Post-GC snapshots at minutes 5, 20, and 50.

Build 5-minute heap 20-minute heap 50-minute heap 5→50 growth 20→50 growth
Older baseline (fd80f72f) 401.70 MiB 467.40 MiB 586.77 MiB 246.75 MiB/h 238.74 MiB/h
Current baseline (14c5ff2371a0) 448.53 MiB 511.92 MiB 623.90 MiB 233.84 MiB/h 223.97 MiB/h
Patched 432.71 MiB 449.84 MiB 464.84 MiB 42.84 MiB/h 30.00 MiB/h

Heap growth falls 81.7% (5.46×), with 86.6% lower growth over the final half-hour. All final runs exercise 50 minutes of traffic; rates use the matched 45-minute post-GC snapshot interval. The current baseline completed 95 child launches, 95 cron runs, and 74,270 RPCs; the older baseline completed 96 child launches and 95 cron runs; the patch completed 95 of each plus 74,578 RPCs. The patched snapshots retain 0 context-engine resources / 0 invocation scopes at minute 5, then 1 / 2 at both minutes 20 and 50. The current baseline grows from 11 / 22 to 95 / 190, and the older baseline from 11 / 22 to 97 / 194. Snapshots use independent IDs because capture resets profiler IDs. A strong retainer path from the global session-identity listener set through captured async context identifies the leaked owner.

This removes the launch-proportional graph retention, not all heap growth. Residual growth includes compilation and workload state; this synthetic main-thread heap campaign does not establish production or worker-heap stabilization. The measured candidate contains the facade and callback cleanup changes; the additional sessionless preparation cleanup is covered by focused tests and exact-head CI and is not exercised by this rig.

An initial baseline stopped at minute 27 because autonomous Workshop reviews consumed ordered synthetic model fixtures. The corrected current baseline disables those reviews from startup; the older baseline disables them before the first review, and the patched run before its first snapshot. Strict foreground assertions remain intact.

Three focused regression cases fail against the original facade: a successful launch leaves an extra identity observer, and canceled dispatch/wait never release their prepared resources. All 66 tests passed with pnpm test src/gateway/server-plugin-in-process-dispatch.authorization.test.ts src/gateway/agent-turn/internal-facade.test.ts test/scripts/gateway-heap-rig-turns.test.ts --maxWorkers=1 (278.86 s wall; cold compilation dominated). The real authorization fixture is necessary to detect retained production observers; inference stays mocked. Exact-head PR CI passed: 70 checks, no failures; run 38371994263 completed in 682 s wall (10,128 summed job-seconds). Changed-file oxfmt, matching core/scripts lint, and git diff --check pass. The initial lint invocation attempted unrelated declaration preparation and timed out; selecting the documented matching tsconfig kept the retry scoped.

No Testbox/Crabbox lease was used; PR CI owns full gates. Independent subagent review (autoreview route unavailable): clean through P2. The helper refused the requested provider route; no operator configuration was changed.

@clawsweeper

clawsweeper Bot commented Oct 13, 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 13, 2026 08:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T08:53:19.605581Z 844cd98 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 gateway Gateway runtime scripts Repository scripts size: S labels Oct 13, 2026
@steipete
steipete merged commit e54b611 into main Oct 13, 2026
209 of 211 checks passed
@steipete
steipete deleted the steipete/perf-micro-heap-growth-r94-20260919 branch October 13, 2026 09:22
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant