Skip to content

Commit 3084acc

Browse files
committed
Explain why saveCrashState stays a separate write path
Document that this is a second terminal write path alongside finalizeRunState, kept apart because its only callers are the process-level crash and signal handlers in index.ts, which cannot afford to wait on saveState's per-session write chain during exit.
1 parent 6e1f9a0 commit 3084acc

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/session/state.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ export async function finalizeRunState(
131131
// Callers must call markCrashed() (src/session/active-run.ts) before this, so
132132
// any snapshot write still queued behind another one in the chain steps
133133
// aside instead of racing this write's rename().
134+
//
135+
// This is a second terminal write path alongside finalizeRunState, and stays
136+
// separate on purpose: its only callers are index.ts's process-level
137+
// uncaughtException/unhandledRejection and signal handlers, reached when a
138+
// crash escapes runTUI's own try/catch entirely. finalizeRunState routes
139+
// through saveState's per-session write chain so writes apply in call order;
140+
// that chain is exactly what a crash exit cannot afford to wait on, since
141+
// process.exit must happen deterministically and a stuck earlier write
142+
// (possibly the one that caused the crash) would otherwise hang it.
134143
export async function saveCrashState(
135144
cwd: string,
136145
sessionId: string,

0 commit comments

Comments
 (0)