Skip to content

Commit a0b0571

Browse files
committed
Restore the dispose-host clear on the normal run-end path
Deleted along with the standalone active-run clear when that call site was folded into finalizeRunState's write, but the dispose host has no on-disk write to piggyback on, so it never got a replacement. Every normal run was leaving the dispose host pointing at a torn-down closure that a later signal could still invoke. Restored to mirror finalizeOnCrash, matching active-host.ts's stated contract of clearing on either path.
1 parent 61b509d commit a0b0571

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/tui/runner.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,11 @@ export async function runTUI(initialConfig: Config): Promise<number> {
557557
// handler isn't the only reader of the handle: index.ts installs its own
558558
// uncaughtException/unhandledRejection listeners that call getActiveRun()
559559
// directly and, if it's still set, write a competing "crashed" record via
560-
// saveCrashState. An escaped throw during flushPartialOnCrash or the
561-
// finalizeRunState await below would otherwise reach that listener while
562-
// the handle still reads as live, racing its write against the "failed"
563-
// write in progress here. finalizeRunState (state.ts) also clears the
564-
// handle, but only after its own saveState resolves — too late to close
565-
// that window, so the clear is duplicated here. finalizeRunState is left
566-
// unchanged: its other callers (normal completion, session rotation) rely
567-
// on it being the one that clears the handle.
560+
// saveCrashState. finalizeRunState (state.ts) also clears the handle
561+
// before its own saveState await, but only once it's called below — an
562+
// escaped throw during the flushPartialOnCrash await just above would
563+
// still reach that listener with the handle live, so it's cleared here
564+
// too to close that earlier window.
568565
clearActiveRun();
569566
clearActiveDisposeHost();
570567
await flushPartialOnCrash().catch((flushErr: unknown) => {
@@ -2340,6 +2337,11 @@ export async function runTUI(initialConfig: Config): Promise<number> {
23402337
// The run itself is over here, so this write clears the active-run handle
23412338
// (via finalizeRunState in state.ts) in the same call, rather than pairing
23422339
// the on-disk write with a separate in-memory statement at this call site.
2340+
// The dispose host has no on-disk counterpart to piggyback on, so it still
2341+
// needs its own clear here, mirroring finalizeOnCrash — otherwise a signal
2342+
// arriving after this normal exit would find a handle pointing at a
2343+
// torn-down closure.
2344+
clearActiveDisposeHost();
23432345
await writeRunSnapshot(
23442346
persistedStatus,
23452347
{

0 commit comments

Comments
 (0)