Skip to content

fix(opencode): handle empty session list for attach --dir to prevent segfault#28594

Open
lexlian wants to merge 3 commits into
anomalyco:devfrom
lexlian:fix/attach-dir-empty-session-crash
Open

fix(opencode): handle empty session list for attach --dir to prevent segfault#28594
lexlian wants to merge 3 commits into
anomalyco:devfrom
lexlian:fix/attach-dir-empty-session-crash

Conversation

@lexlian
Copy link
Copy Markdown

@lexlian lexlian commented May 21, 2026

Issue for this PR

Closes #28214

Type of change

  • Bug fix

What does this PR do?

opencode attach <url> --dir <PATH> crashes with a Bun segmentation fault when no existing session on the server has a working directory matching <PATH>.

Root cause: validateSession() in validate-session.ts only validates when --session is provided. When --dir is provided without --session, validation is skipped entirely. The TUI then starts with an empty session list filtered by the directory, causing an unhandled rejection that triggers Bun's microtask queue to panic.

Fix (two parts):

  1. validate-session.ts: Added directory validation — when --dir is provided without --session, fetch the session list and throw a clear error if empty.
  2. app.tsx: Added graceful handling in the --continue effect — when no sessions are found for the directory, navigate to home instead of staying on the dummy session route.

How did you verify your code works?

  • Created 5 unit tests in test/cli/validate-session.test.ts — all pass
  • Both modified files compile cleanly with bun build
  • The fix catches the error early with a clear message instead of segfaulting

Screenshots / recordings

N/A — CLI fix, not a UI change.

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 May 21, 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 attach segfaults (Bun panic in drainMicrotasks) when --dir has no matching session

1 participant