Skip to content

fix(run): await loop() before instance disposal — state leak on every CLI run - #17821

Closed
jnorthrup wants to merge 1 commit into
anomalyco:devfrom
jnorthrup:fix/run-await-loop
Closed

jnorthrup wants to merge 1 commit into
anomalyco:devfrom
jnorthrup:fix/run-await-loop

Conversation

@jnorthrup

@jnorthrup jnorthrup commented Mar 16, 2026 •

Copy link
Copy Markdown

Issue for this PR

Fixes #9157
Fixes #10913
Fixes #13230
Fixes #17047
Closes https://github.com/anomalyco/opencode/security/advisories/GHSA-xv3r-6x54-766h
See also #17547 and oven-sh/bun#28138

Type of change

  • Bug fix

What does this PR do?

In run.ts execute(), loop() was fire-and-forget. execute() returned right after enqueuing the prompt, so bootstrap()'s finally block called Instance.dispose() while the session was still running. The loop re-created directory-keyed state after disposal — those objects were never freed. On aarch64 macOS where bun already reserves ~485GB VSZ per process (oven-sh/bun#28138), this tips machines into OOM within minutes of active use. Fix: capture and await the promise so disposal only happens once the session reaches idle.

How did you verify your code works?

Traced State.dispose / Instance.dispose lifecycle in project/state.ts and confirmed the loop re-enters State.create after premature disposal.

Screenshots / recordings

https://github.com/anomalyco/opencode/security/advisories/GHSA-xv3r-6x54-766h

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one PR that appears related to this issue:

Potential Related PR:

However, the current PR (#17821) appears to be addressing a specific security advisory (GHSA-xv3r-6x54-766h) with a targeted one-line fix to the loop() await issue in run.ts, and I did not find any other open PRs that are directly attempting to fix the same issue.

No duplicate PRs found

@jnorthrup jnorthrup changed the title fix(run): await loop() before instance disposal fix(run): await loop() before instance disposal fix: #16730 Mar 16, 2026
@jnorthrup
jnorthrup marked this pull request as draft March 16, 2026 16:10
@jnorthrup jnorthrup changed the title fix(run): await loop() before instance disposal fix: #16730 fix(run): await loop() before instance disposal — state leak on every CLI run Mar 16, 2026
@jnorthrup jnorthrup closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant