Skip to content

fix(cli): dispose all instances on command exit - #42177

Open
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:session-dir-dispose
Open

fix(cli): dispose all instances on command exit#42177
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:session-dir-dispose

Conversation

@vladislav-miroshnikov

@vladislav-miroshnikov vladislav-miroshnikov commented Aug 12, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #41841

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

opencode run --session <id> --dir <path> can load a second InstanceContext via server middleware when the session's original directory differs from --dir. The CLI's finally block was calling store.dispose(ctx), which only disposes the primary instance — the middleware-loaded instance is left running with its IPC server alive, so the process never exits.

Changed store.dispose(ctx) to store.disposeAll() with a logWarning on failure (matching the pattern in global-lifecycle.ts). This ensures all instances loaded during the command are cleaned up. The JSDoc comment is updated to reflect the new behavior.

serve and web commands are unaffected — they use instance: false and return before reaching the finally block. The TUI has its own disposal path.

How did you verify your code works?

Typecheck clean. Existing tests for disposeAll semantics in instance.test.ts (dedup, re-arm) remain green. The source-string assertion in effect-cmd-instance-als.test.ts still passes.

Screenshots / recordings

N/A

Checklist

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

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode run --session <id> --dir <different-dir> hangs indefinitely after the turn completes

1 participant