fix: guard run completion boundary

This commit is contained in:
ZacharyZhang-NY committed 2026-04-23 20:34:31 -04:00
1 parent 245586a9aa
commit d21edb244f
6 files changed
+268 -8

No files matched your search

+9 -2
View File
@@ -90,11 +90,14 @@ async function startRun(job: RunJob) {
await runner.run(job);
} finally {
cancelledRuns.delete(job.runId);
active.delete(job.runId);
tickQueue();
}
}
function acknowledgeRunCompletion(runId: string) {
const released = active.delete(runId);
if (released) tickQueue();
}
function cancelRun(runId: string) {
const queuedIndex = queue.findIndex((entry) => entry.runId === runId);
if (queuedIndex >= 0) {
@@ -129,6 +132,10 @@ parentPort.on("message", (event) => {
cancelRun(message.runId);
return;
}
if (message.type === "run-completion-ack") {
acknowledgeRunCompletion(message.runId);
return;
}
if (message.type === "steer-run") {
const accepted = runner.steer(message.runId, message.message);
post({
+9 -1
View File
@@ -3,8 +3,10 @@ import type { workerMessageSchema } from "./types";
import { handleRunLog } from "../handlers/run-log-handler";
import { handleRunStatus } from "../handlers/run-status-handler";
import { handleRunFinished } from "../handlers/run-finished-handler";
import { releaseCompletedRunWorkspaceLock } from "../handlers/run-finished-helpers";
import { handleContextCompaction } from "../handlers/context-compaction-handler";
import type { HandlerContext, HandlerDeps } from "../handlers/handler-context";
import type { RunFinishedContext } from "../handlers/run-finished-helpers";
export async function handleWorkerMessage(
message: unknown,
@@ -47,11 +49,17 @@ export async function handleWorkerMessage(
handleRunStatus(event, deps, context);
return;
case "run-finished": {
let completion: RunFinishedContext | null = null;
try {
handleRunFinished(event, deps, context);
completion = handleRunFinished(event, deps, context);
} finally {
deps.getRuntimeBridge?.()?.releaseRunResources(event.runId);
}
releaseCompletedRunWorkspaceLock(completion, deps);
if (!worker) {
throw new Error(`run-completion-ack worker missing for run ${event.runId}`);
}
worker.postMessage({ type: "run-completion-ack", runId: event.runId });
return;
}
case "agent-event": {