Extract handleWorkerMessage (380 lines, 12 positional args) into dispatcher + focused handler modules. Dispatcher now routes by message.type to run-log / run-status / run-finished handlers, each receiving (event, deps, context) triple. run-finished is further decomposed into 5 steps: finalizeRun, accumulateAndRotateSession, emitAndNotifyCompletion, runPostCompletionAutomation, triggerSelfWake. No behavior change: all branches, notifications, lease renewals, circuit breaker, and escalation semantics preserved. Schema validation stays at dispatcher top level.
23 lines
740 B
TypeScript
23 lines
740 B
TypeScript
import {
|
|
accumulateAndRotateSession,
|
|
emitAndNotifyCompletion,
|
|
finalizeRun,
|
|
runPostCompletionAutomation,
|
|
triggerSelfWake,
|
|
} from "./run-finished-helpers";
|
|
import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context";
|
|
|
|
export function handleRunFinished(
|
|
event: Extract<WorkerMessageEvent, { type: "run-finished" }>,
|
|
deps: HandlerDeps,
|
|
context: HandlerContext,
|
|
): void {
|
|
const rfCtx = finalizeRun(event, deps, context);
|
|
if (!rfCtx) return;
|
|
|
|
accumulateAndRotateSession(event, deps, rfCtx);
|
|
emitAndNotifyCompletion(event, deps, rfCtx);
|
|
const { hadDeferredWakes } = runPostCompletionAutomation(event, deps, context, rfCtx);
|
|
triggerSelfWake(event, deps, context, rfCtx, hadDeferredWakes);
|
|
}
|