finalizeInterruptedMessages
constfinalizeInterruptedMessages: (staleMs) =>Promise<number> =sqliteRepo.finalizeInterruptedMessages
Defined in: lib/repositories/chat-history.ts:35
Finalize assistant turns left in-flight (done=0) by a worker/sidepanel
death mid-stream. Marks each done and flags metrics.interrupted so the UI
can surface the partial answer as interrupted and offer a retry.
Ownership is enforced inside the query, so there is no separate liveness check to race:
- Staleness: a row is finalized only if it has not been written within
staleMs. Streaming partial-content writes bumpupdatedAt~every second, so a turn actively streaming in ANY window is never selected. ANULLupdatedAt(rows predating the column) is treated as stale. - Tool-loop ownership: a turn awaiting tool approval can legitimately go
minutes without a message write while its durable
tool_loop_runscheckpoint is live. Excluding sessions that have any checkpoint row keeps those live waits from being finalized (rows are deleted on completion and pruned when abandoned).
Returns the count fixed.
Parameters
Section titled “Parameters”staleMs?
Section titled “staleMs?”number = 20_000
Returns
Section titled “Returns”Promise<number>