Skip to content

Install crash handlers so a detached throw terminates the process - #341

Merged
TheGreatAxios merged 1 commit into
release/tui-bugfixesfrom
cl-5565-crash-handlers
Aug 7, 2026
Merged

Install crash handlers so a detached throw terminates the process#341
TheGreatAxios merged 1 commit into
release/tui-bugfixesfrom
cl-5565-crash-handlers

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Register process.on("uncaughtException") and process.on("unhandledRejection") in src/index.ts at startup
  • Each writes a best-effort crash report to ~/.corbits/projects/<project-key>/errors/<timestamp>.txt, keyed the same way projectSessionsRoot keys a session's own directory, then calls process.exit(1)
  • primeCrashReporting resolves and caches that directory once at startup, right after config load; the handler itself never calls projectSessionsRoot (which shells out to git with no timeout), so a hung or corrupted git can never block the exit this change exists to force

Verification

  • bun run typecheck, bun run build, and bun test all pass, rebased onto origin/release/tui-bugfixes (4372 pass, 0 fail)
  • src/crash/report.test.ts covers: report contents; the fail-open null-return path (a real mkdir failure, not a mock); that the crash directory matches projectSessionsRoot exactly; and the git-hang path specifically — a resolver that throws is called exactly once at priming time and never again from crashReportDir/writeCrashReport, proving the handler cannot re-trigger a hung git call
  • Verified termination directly: a script registering a log-only uncaughtException listener (mirroring @opentui/core's Renderer.handleError, confirmed in node_modules/.bun/@opentui+core*/.../chunk-node-0yw3x5m7.js) before and after our handler both terminate the process with exit code 1 in each ordering. No automated test exercises handleFatal or the registered handlers directly — the terminates-the-process property is verified only by that manual script, not by bun test
  • Not solved by this PR, tracked separately rather than left as a caveat: a crash still leaves run.json un-finalized (status: "running", no finishedAt), since persistRunSnapshot is a closure inside runTUI capturing local session state not reachable from the process-level handler

Closes CL-5565

@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

CL-5565

@TheGreatAxios
TheGreatAxios changed the base branch from main to release/tui-bugfixes August 7, 2026 04:20
@TheGreatAxios
TheGreatAxios force-pushed the cl-5565-crash-handlers branch 2 times, most recently from c01e6ae to f7c76ef Compare August 7, 2026 05:14
Register uncaughtException and unhandledRejection handlers that write
a best-effort crash report and exit non-zero, closing the gap between
what the implementation notes described and what the code actually
did. OpenTUI installs its own log-only handler for the same events,
but Node calls every registered listener, so ours still runs and
exits the process afterward.

The crash directory is keyed the same way a session's own directory
is, so a report lands next to that session's run state and
transcript. That key resolution shells out to git with no timeout, so
it is never done from the handler itself: the directory is resolved
and cached once at startup, well before any crash, and the handler
only ever reads the cached value with no further git calls.
@TheGreatAxios
TheGreatAxios force-pushed the cl-5565-crash-handlers branch from f7c76ef to f19aa46 Compare August 7, 2026 05:28
@TheGreatAxios
TheGreatAxios merged commit 6e219a4 into release/tui-bugfixes Aug 7, 2026
2 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-5565-crash-handlers branch August 7, 2026 06:36
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.

1 participant