Skip to content

fix(sdk): release completed embedded request signals - #51132

Closed
opencode-agent[bot] wants to merge 1 commit into
v2from
sdk-request-release
Closed

opencode-agent[bot] wants to merge 1 commit into
v2from
sdk-request-release

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Problem

OpenCode Agent memory profiles show sustained growth in Request, Headers, AbortSignal, and array-buffer counts. A local red-capable repro using the actual OwnedFetch transport and Effect web handler retained 120/120 completed Requests after forced GC while the embedded host stayed open. The long-lived shutdown signal held the AbortSignal.any child; Effect’s abort listener on that child kept each handler Request reachable. The prior SDK signal-listener change in draft #51012 did not sever this parent edge.

Fix

Use a per-request controller with explicit source/shutdown abort forwarding. Remove both forwarding listeners when the response finishes or the handler rejects. This preserves caller cancellation, host-close cancellation, and streaming body cancellation while releasing completed requests.

Verification

  • Regression test failed on origin/v2 with 120/120 Requests retained; after fix, no more than 3/120 survived GC in three consecutive runs (last async frames may remain live). Failure-path retention and caller/host/stream cancellation tests also pass (5 focused tests total).
  • SDK typecheck, targeted Prettier, targeted oxlint, and diff whitespace checks pass.
  • Existing transport.test.ts fails identically on both clean origin/v2 and this branch due an unrelated expected SessionNotFoundError vs actual NotFoundError mismatch.
  • Full repo bun run check reaches typecheck, then is blocked by this Host’s Node v18 (@opencode/posts requires >=22.12); an earlier unconstrained run also hit the Host process/thread limit. Repo-wide lint passed. Neither limitation changes the scoped SDK checks.

This is a measured local retention fix, not a claim that production RSS has already fallen. No merge, deployment, or service restart was performed. Related: anomalyco/anomaly#260 and anomalyco/anomaly#623.

Requested by: @jlongster (James via Slack)

@kitlangton

Copy link
Copy Markdown
Contributor

Superseded by #53613.

@kitlangton kitlangton closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants