Repository navigation
fix(sdk): release completed embedded request signals - #51132
Closed
opencode-agent[bot] wants to merge 1 commit into
Closed
opencode-agent[bot] wants to merge 1 commit into
opencode-agent[bot] wants to merge 1 commit into
Conversation
Contributor
|
Superseded by #53613. |
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.
Problem
OpenCode Agent memory profiles show sustained growth in
Request,Headers,AbortSignal, and array-buffer counts. A local red-capable repro using the actualOwnedFetchtransport and Effect web handler retained 120/120 completed Requests after forced GC while the embedded host stayed open. The long-lived shutdown signal held theAbortSignal.anychild; 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
origin/v2with 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).transport.test.tsfails identically on both cleanorigin/v2and this branch due an unrelated expectedSessionNotFoundErrorvs actualNotFoundErrormismatch.bun run checkreaches typecheck, then is blocked by this Host’s Node v18 (@opencode/postsrequires >=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)