Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/server/src/orchestration-v2/ProviderTurnStartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,16 @@ const NATIVE_SESSION_LOAD_METHODS: ReadonlySet<unknown> = new Set([

const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);

// A lost connection names no method; startTurn fails before the prompt, so the reload never finished.
const ACP_CONNECTION_LOST_TAGS = [
"AcpTransportError",
"AcpProcessExitedError",
"AcpInputStreamEndedError",
] as const;

const nativeSessionLoadFailed = (error: unknown): boolean =>
(isAcpRequestError(error) && NATIVE_SESSION_LOAD_METHODS.has(error.method)) ||
ACP_CONNECTION_LOST_TAGS.some((tag) => Predicate.isTagged(error, tag)) ||
(Predicate.hasProperty(error, "cause") && nativeSessionLoadFailed(error.cause));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function makeTestAdapter(input: {
readonly failStartOnce?: Ref.Ref<boolean>;
/** Like an ACP agent restarted under a loaded thread whose native session is gone. */
readonly loseNativeSessionOnce?: Ref.Ref<boolean>;
readonly lostNativeSessionCause?: unknown;
readonly refuseStarts?: Ref.Ref<number>;
readonly refusalCause?: unknown;
readonly failInjectionOnce?: Ref.Ref<boolean>;
Expand Down Expand Up @@ -318,13 +319,15 @@ function makeTestAdapter(input: {
threadId: turnInput.threadId,
providerThreadId: turnInput.providerThread.id,
runId: turnInput.runId,
cause: EffectAcpErrors.AcpRequestError.fromProtocolError(
{
code: -32603,
message: `Session not found: ${turnInput.providerThread.nativeThreadRef?.nativeId}`,
},
{ method: "session/load" },
),
cause:
input.lostNativeSessionCause ??
EffectAcpErrors.AcpRequestError.fromProtocolError(
{
code: -32603,
message: `Session not found: ${turnInput.providerThread.nativeThreadRef?.nativeId}`,
},
{ method: "session/load" },
),
});
if (
input.refuseStarts !== undefined &&
Expand Down Expand Up @@ -2324,6 +2327,56 @@ describe("orchestration v2 provider switching", () => {
}),
);

// regression: #46045 the agent's stdout broke during session/load at turn start.
it.live(
"recovers in a fresh native session when session/load at turn start fails in transport",
() =>
Effect.gen(function* () {
const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
const loseNativeSessionOnce = yield* Ref.make(false);
yield* unverifiedReplacementHarness(
"lost-native-session-transport",
[
makeTestAdapter({
instanceId: GROK_MODEL_SELECTION.instanceId,
driver: GROK_DRIVER,
capabilities: AcpProviderCapabilitiesV2,
modelSelection: GROK_MODEL_SELECTION,
responseByRunOrdinal: {},
capturedTurns,
loseNativeSessionOnce,
lostNativeSessionCause: new EffectAcpErrors.AcpTransportError({
detail: "Antigravity sent a protocol line that is too large.",
cause: new Error("protocol line too large"),
}),
nativeThreadGeneration: yield* Ref.make(0),
}),
],
({ orchestrator, dispatchRequest, awaitSettled }) =>
Effect.gen(function* () {
yield* dispatchRequest(1, GROK_MODEL_SELECTION);
yield* awaitSettled(1);
yield* Ref.set(loseNativeSessionOnce, true);
yield* dispatchRequest(2, GROK_MODEL_SELECTION);
yield* awaitSettled(2);

const projection = yield* orchestrator.getThreadProjection(threadId);
const run2 = projection.runs.at(-1)!;
const failure = projection.turnItems.findLast((item) => item.type === "error");
assert.equal(
run2.status,
"completed",
`turn 2 failed: ${failure?.type === "error" ? failure.failure.message : "no error item"}`,
);
const turns = yield* Ref.get(capturedTurns);
assert.equal(turns.length, 2);
assert.notEqual(turns[1]!.nativeThreadId, turns[0]!.nativeThreadId);
assert.isNotEmpty(replacementRecordsFor(projection, run2.id));
}),
);
}),
);

// regression: #44152 a retry after the replacement failed to open prompted the lost session.
it.live("keeps recovering after the replacement session fails to open", () =>
Effect.gen(function* () {
Expand Down
Loading