Skip to content

fix(tui): surface worker defects instead of swallowing them - #532

Merged
agenteinstinct1-max merged 4 commits into
dev-vibecodedfrom
fix/396-worker-defects
Oct 22, 2026
Merged

agenteinstinct1-max merged 4 commits into
dev-vibecodedfrom
fix/396-worker-defects

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #396

Type of change

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

What does this PR do?

packages/opencode/src/cli/tui/worker.ts registered no-op handlers for unhandledRejection and uncaughtException, so any defect in an RPC handler, a GlobalBus projection or a background job never reached logging, never settled the pending RPC call, and never engaged the worker-process crash-restart (isCrash only sees signal/exit code, and a swallowed defect produces neither). The main thread saw an RPC hang and the TUI footer froze with no toast.

Changes:

  • Both defect classes are now logged to stderr and emitted to the main thread as a worker.error RPC event carrying message, stack and a fatal flag. The handler construction is a pure exported factory (createDefectHandlers) so the contract is unit-testable, matching the resolveIsTuiWorker precedent.
  • The main thread (createEventSource in packages/opencode/src/cli/cmd/tui.ts) subscribes to worker.error and translates it into the existing tui.toast.show event, so the defect appears as an error toast ("Backend worker error" / "Backend worker crashed") instead of a silent freeze.
  • An uncaughtException in the subprocess additionally exits with code 134 after a short flush delay. 134 is the exit-code counterpart of SIGABRT and isCrash classifies it as a crash on every platform, so the existing crash-restart engages. A thread worker shares the UI process and only reports; it must not exit.
  • An unhandledRejection reports but keeps the worker alive: rejections from fire-and-forget listeners are frequently recoverable and killing the backend for one would be worse than the toast.

How did you verify your code works?

New suite packages/opencode/test/cli/tui-worker-defects.test.ts (4/4 pass): rejection reported non-fatal with no exit; non-Error rejection stringified; subprocess uncaughtException reported fatal and exits 134; thread worker reports fatal but never exits the shared process. Existing tui-bootstrap and worker-process suites still pass (15/15). Repo-wide typecheck is left to CI (the sandbox cannot hold it in memory).

Screenshots / recordings

No visual change: the toast uses the existing tui.toast.show path.

Checklist

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

@github-actions

Copy link
Copy Markdown

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.

@kilo-code-bot

kilo-code-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/opencode/src/cli/tui/worker.ts
  • packages/opencode/src/util/rpc.ts
  • packages/opencode/test/cli/tui-worker-defects.test.ts
Previous Review Summaries (4 snapshots, latest commit 49cd9c9)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 49cd9c9)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • packages/opencode/src/cli/tui/worker-error-toast.ts - 1 changed line, type narrowing fix

Previous review (commit d330354)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • packages/opencode/src/cli/cmd/tui.ts
  • packages/opencode/src/cli/tui/worker-error-toast.ts
  • packages/opencode/src/cli/tui/worker.ts
  • packages/opencode/src/util/rpc.ts
  • packages/opencode/test/cli/tui-worker-defects.test.ts

Previous review (commit e8c880d)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/tui/src/component/bg-pulse-render.ts
  • packages/tui/test/component/bg-pulse-render.test.ts

Previous review (commit 4096ec9)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • packages/opencode/src/cli/cmd/tui.ts
  • packages/opencode/src/cli/tui/worker.ts
  • packages/opencode/test/cli/tui-worker-defects.test.ts
  • packages/tui/src/component/bg-pulse-render.ts
  • packages/tui/test/component/bg-pulse-render.test.ts

Reviewed by free · Input: 19.5K · Output: 967 · Cached: 107.3K

Unhandled rejections and uncaught exceptions in the TUI worker were
dropped by no-op handlers, so a defect in an RPC handler, bus listener or
background job never logged, never settled the pending RPC and never
engaged the subprocess crash-restart - the TUI footer just froze.

- both defect classes are now logged and emitted to the main thread as a
  "worker.error" RPC event
- the main thread translates that event into an error toast via the
  existing tui.toast.show event path
- an uncaughtException in the subprocess exits 134 (the SIGABRT exit-code
  counterpart that isCrash classifies as a crash on every platform) so
  the crash-restart engages; a thread worker shares the UI process and
  only reports

Fixes #396
@agenteinstinct1-max
agenteinstinct1-max merged commit e7d5a5e into dev-vibecoded Oct 22, 2026
6 checks passed
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.

1 participant