Add top-level unhandledRejection/uncaughtException handlers #101
Labels
No labels
bug
duplicate
enhancement
future
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/TeaLeaves#101
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: Low · Confidence: High · Effort: XS · Category: ops
Evidence
api/src/index.ts- no process-level handlers registered. Fire-and-forget promises exist (entries.ts:265,403-404; media.ts:87; reanalyzeWorker.ts:70), all currently.catch()'d.Problem
Node 24 terminates the process on an unhandled rejection. Every current fire-and-forget is guarded, but one future unguarded rejection would hard-crash the process - which also kills all in-process workers.
Impact
A single missed
.catchbecomes a full outage rather than a logged error. Low today; cheap insurance.Fix
Register top-level
unhandledRejection/uncaughtExceptionhandlers that log with context and (ideally) hook the graceful-shutdown path from F-08.Acceptance criteria
Related: F-08 (graceful shutdown).
Filed from the 2026-07-15 codebase audit. Full report:
docs/.internal/report-2026-07-15.md(gitignored).Fixed in
c1ed843(v7.2.0 wave 2).Registered in
api/src/index.ts, hooked into the #85 graceful-shutdown path as suggested:unhandledRejection→ log with the stack and keep serving. A stray rejection in a background job shouldn't take down the API and every in-process worker with it; the point is that it's diagnosable instead of a silent exit.uncaughtException→ log, then drain throughshutdown()and exit non-zero. Unlike a rejection this leaves the process in an undefined state, so restarting clean (viarestart: unless-stopped) is right.This required a small change to
shutdown(): it always calledprocess.exit(0), so routing a crash through it would have reported an abnormal termination as a clean exit — hiding crashes from the container runtime and any future alerting. It now takes an exit code (default 0 for SIGTERM/SIGINT, 1 for a crash).Acceptance criteria:
CI green (242/242).