Repository navigation
fix(gateway): release leaked state after subagent launches - #170855
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
October 13, 2026 08:50
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Oct 13, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
fd80f72f)14c5ff2371a0)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-fileoxfmt, matching core/scripts lint, andgit diff --checkpass. 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.