Keep unexpected provider loss failed while retaining input fallback

This commit is contained in:
Dotta committed 2026-10-05 17:07:08 -05:00
1 parent 1998fd7ae9
commit bb7ab1cbfa
5 files changed
+65 -15

No files matched your search

@@ -851,7 +851,7 @@ describe("HarnessDriverBackend", () => {
expect(events.map((event) => event.eventType)).toEqual([
"runtime_request.created",
"runtime_request.expired",
"turn.interrupted",
"turn.failed",
]);
}
await session.close({ reason: "fixture complete" });
@@ -898,7 +898,7 @@ describe("HarnessDriverBackend", () => {
await session.close({ reason: "fixture complete" });
});
it("emits one non-replayable input expiration and terminal wait after provider loss", async () => {
it("expires pending input without converting provider loss into a successful wait", async () => {
const questionSet = {
schema: "paperclip.question_set.v1" as const,
questions: [{ id: "target", prompt: "Which target?", required: true, answerMode: "text" as const }],
@@ -940,11 +940,14 @@ describe("HarnessDriverBackend", () => {
},
} });
await expect(iterator.next()).resolves.toMatchObject({ value: {
eventType: "turn.interrupted",
eventType: "turn.failed",
sourceSeq: 3,
payload: { reason: "provider_process_lost" },
} });
await expect(iterator.next()).resolves.toMatchObject({ done: true });
await expect(session.snapshot()).resolves.toMatchObject({ terminal: {
turnTerminalState: "failed", runTerminalState: "failed",
} });
});
it("does not synthesize a fallback after the input was already resolved", async () => {
@@ -507,7 +507,7 @@ class HarnessNativeSession implements NativeSession {
let sourceInstanceId: string | null = null;
let lastSourceSequence = 0;
let sawTerminal = false;
let synthesizedDurableWait = false;
let synthesizedProviderFailure = false;
let streamFailure: unknown = null;
const observedPendingInputs = new Map<string, Record<string, unknown>>();
try {
@@ -627,7 +627,7 @@ class HarnessNativeSession implements NativeSession {
this.#rethrowProtocolIntegrity(error);
return null;
});
let governedWaitTurnId: string | undefined;
let providerLossTurnId: string | undefined;
for (const request of observedPendingInputs.values()) {
const sourceSeq =
Math.max(lastSourceSequence, snapshot?.lastSourceSequence ?? 0) + 1;
@@ -635,7 +635,7 @@ class HarnessNativeSession implements NativeSession {
const requestId = String(request.requestId);
const turnId =
typeof request.turnId === "string" ? request.turnId : undefined;
governedWaitTurnId ??= turnId;
providerLossTurnId ??= turnId;
const itemId =
typeof request.itemId === "string" ? request.itemId : requestId;
yield {
@@ -667,16 +667,18 @@ class HarnessNativeSession implements NativeSession {
},
};
}
if (governedWaitTurnId) {
if (providerLossTurnId) {
// Expiring input preserves its durable human fallback. The unexpected
// transport loss remains a failed provider execution, never a yield.
const sourceSeq =
Math.max(lastSourceSequence, snapshot?.lastSourceSequence ?? 0) + 1;
lastSourceSequence = sourceSeq;
synthesizedDurableWait = true;
synthesizedProviderFailure = true;
sawTerminal = true;
this.#terminal = {
schema: "paperclip.prp.terminal.v1",
turnTerminalState: "interrupted",
runTerminalState: "cancelled",
turnTerminalState: "failed",
runTerminalState: "failed",
reportedWorkDisposition: "yielded",
};
yield {
@@ -687,16 +689,16 @@ class HarnessNativeSession implements NativeSession {
sourceKind: "runner",
runId: this.#input.identity.runId,
normalizedSessionId: this.#input.identity.sessionId,
turnId: governedWaitTurnId,
eventType: "turn.interrupted",
turnId: providerLossTurnId,
eventType: "turn.failed",
schemaVersion: 1,
priority: 0,
emittedAt: new Date().toISOString(),
payload: { status: "interrupted", reason: "provider_process_lost" },
payload: { status: "failed", reason: "provider_process_lost" },
};
}
}
if (streamFailure && !synthesizedDurableWait) throw streamFailure;
if (streamFailure && !synthesizedProviderFailure) throw streamFailure;
}
async startTurn(input: Parameters<HarnessSession["startTurn"]>[0]) {