Files
AgentCompany/src/main/worker/handlers/run-finished-handler.ts
T
ZacharyZhang-NY cc02b45864 refactor(worker): split god-handler into per-message type files
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.
2026-04-16 22:04:37 -04:00

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);
}