fix: make artifact projection durable
This commit is contained in:
1 parent
84c00e0011
commit
88c905c381
15 files changed
+654
-76
No files matched your search
@@ -7,6 +7,7 @@ import { releaseCompletedRunWorkspaceLock } from "../handlers/run-finished-helpe
|
||||
import { handleContextCompaction } from "../handlers/context-compaction-handler";
|
||||
import type { HandlerContext, HandlerDeps } from "../handlers/handler-context";
|
||||
import type { RunFinishedContext } from "../handlers/run-finished-helpers";
|
||||
import type { RunResourceReleaseResult } from "../../agent-runtime/runtime-artifact-reconciler";
|
||||
|
||||
export async function handleWorkerMessage(
|
||||
message: unknown,
|
||||
@@ -50,10 +51,21 @@ export async function handleWorkerMessage(
|
||||
return;
|
||||
case "run-finished": {
|
||||
let completion: RunFinishedContext | null = null;
|
||||
let runtimeResourcesReleased = false;
|
||||
let runtimeReleaseResult: RunResourceReleaseResult = { ok: true };
|
||||
const releaseRuntimeResources = (): RunResourceReleaseResult => {
|
||||
if (runtimeResourcesReleased) return runtimeReleaseResult;
|
||||
runtimeResourcesReleased = true;
|
||||
runtimeReleaseResult =
|
||||
deps.getRuntimeBridge?.()?.releaseRunResources(event.runId) ?? { ok: true };
|
||||
return runtimeReleaseResult;
|
||||
};
|
||||
try {
|
||||
completion = handleRunFinished(event, deps, context);
|
||||
completion = handleRunFinished(event, deps, context, {
|
||||
beforePostCompletionAutomation: releaseRuntimeResources,
|
||||
});
|
||||
} finally {
|
||||
deps.getRuntimeBridge?.()?.releaseRunResources(event.runId);
|
||||
releaseRuntimeResources();
|
||||
}
|
||||
releaseCompletedRunWorkspaceLock(completion, deps);
|
||||
if (!worker) {
|
||||
|
||||
@@ -8,17 +8,39 @@ import {
|
||||
import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context";
|
||||
import type { RunFinishedContext } from "./run-finished-helpers";
|
||||
|
||||
export interface RunFinishedHooks {
|
||||
beforePostCompletionAutomation?: (context: RunFinishedContext) =>
|
||||
| void
|
||||
| { ok: true }
|
||||
| { ok: false; errorMessage: string };
|
||||
}
|
||||
|
||||
export function handleRunFinished(
|
||||
event: Extract<WorkerMessageEvent, { type: "run-finished" }>,
|
||||
deps: HandlerDeps,
|
||||
context: HandlerContext,
|
||||
hooks: RunFinishedHooks = {},
|
||||
): RunFinishedContext | null {
|
||||
const rfCtx = finalizeRun(event, deps, context);
|
||||
if (!rfCtx) return null;
|
||||
|
||||
accumulateAndRotateSession(event, deps, rfCtx);
|
||||
emitAndNotifyCompletion(event, deps, rfCtx);
|
||||
const { hadDeferredWakes } = runPostCompletionAutomation(event, deps, context, rfCtx);
|
||||
triggerSelfWake(event, deps, context, rfCtx, hadDeferredWakes);
|
||||
const boundaryResult = hooks.beforePostCompletionAutomation?.(rfCtx);
|
||||
const effectiveEvent =
|
||||
boundaryResult && !boundaryResult.ok
|
||||
? {
|
||||
...event,
|
||||
status: "failed" as const,
|
||||
summary: null,
|
||||
errorMessage: boundaryResult.errorMessage,
|
||||
usageStatus: "error_stop" as const,
|
||||
}
|
||||
: event;
|
||||
if (boundaryResult && !boundaryResult.ok) {
|
||||
deps.db.core.runs.markRunCompletionFailure(event.runId, boundaryResult.errorMessage);
|
||||
}
|
||||
emitAndNotifyCompletion(effectiveEvent, deps, rfCtx);
|
||||
const { hadDeferredWakes } = runPostCompletionAutomation(effectiveEvent, deps, context, rfCtx);
|
||||
triggerSelfWake(effectiveEvent, deps, context, rfCtx, hadDeferredWakes);
|
||||
return rfCtx;
|
||||
}
|
||||
Reference in new issue
Block a user