Skip to content

Commit e1c5c89

Browse files
committed
test(server): Antigravity recovers when its native failure follows end_turn
stderr and stdout are separate pipes, so the native failure record can reach T3 after the successful prompt response. Cover that order: the first turn completes, the runtime is still retired, and the next message resumes the saved session in a fresh process. Assert the session ID on the session/resume request itself.
1 parent 7c6e5d4 commit e1c5c89

2 files changed

Lines changed: 52 additions & 12 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,9 @@ const program = Effect.gen(function* () {
962962
const requestedSessionId = String(request.sessionId ?? sessionId);
963963
beginAcpMockPrompt(cancelledSessions, requestedSessionId);
964964
promptCount += 1;
965-
if (process.env.T3_ACP_ANTIGRAVITY_HARNESS_FAILURE === "1") {
966-
yield* Effect.promise(
965+
const harnessFailure = process.env.T3_ACP_ANTIGRAVITY_HARNESS_FAILURE;
966+
if (harnessFailure === "1" || harnessFailure === "after-end-turn") {
967+
const writeHarnessFailure = Effect.promise(
967968
() =>
968969
new Promise<void>((resolve) => {
969970
process.stderr.write(
@@ -972,7 +973,17 @@ const program = Effect.gen(function* () {
972973
);
973974
}),
974975
);
975-
// The native ACP parent can report success after its local harness has failed.
976+
// The native ACP parent can report success after its local harness has
977+
// failed. Its stderr and stdout are separate pipes, so the failure record
978+
// can reach the client before or after the successful response.
979+
if (harnessFailure === "after-end-turn") {
980+
yield* Effect.sleep("200 millis").pipe(
981+
Effect.andThen(writeHarnessFailure),
982+
Effect.forkDetach,
983+
);
984+
return yield* finishPrompt(requestedSessionId, "end_turn");
985+
}
986+
yield* writeHarnessFailure;
976987
return yield* finishPrompt(requestedSessionId, "end_turn");
977988
}
978989
if (

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
1414
import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
1515
import * as Crypto from "effect/Crypto";
1616
import * as DateTime from "effect/DateTime";
17+
import * as Deferred from "effect/Deferred";
1718
import * as Effect from "effect/Effect";
1819
import * as Exit from "effect/Exit";
1920
import * as FileSystem from "effect/FileSystem";
@@ -125,7 +126,10 @@ const layerSession = Layer.mergeAll(
125126
);
126127

127128
describe("AntigravityAdapterV2 harness recovery", () => {
128-
it.effect("fails despite end_turn and resumes the saved session in a fresh process", () =>
129+
const recoverHarnessFailure = (
130+
harnessFailure: "1" | "after-end-turn",
131+
firstTurnStatus: "failed" | "completed",
132+
) =>
129133
Effect.gen(function* () {
130134
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
131135
const fileSystem = yield* FileSystem.FileSystem;
@@ -137,15 +141,25 @@ describe("AntigravityAdapterV2 harness recovery", () => {
137141
const workspace = yield* fileSystem.makeTempDirectoryScoped();
138142
const requestLogPath = path.join(workspace, "requests.jsonl");
139143
let processCount = 0;
144+
const firstRuntimeTerminated = yield* Deferred.make<void>();
140145
const instanceId = ProviderInstanceId.make("antigravity-recovery-test");
141146
const adapter = yield* makeAntigravityAdapterV2({
142147
instanceId,
143148
selfInvocation: yield* resolveSelfInvocation(),
144149
makeRuntime: (input) =>
145150
Effect.suspend(() => {
146151
processCount += 1;
152+
const processNumber = processCount;
147153
return makeAntigravityAcpRuntime({
148154
...input,
155+
onTermination: (error) =>
156+
(input.onTermination?.(error) ?? Effect.void).pipe(
157+
Effect.andThen(
158+
processNumber === 1
159+
? Deferred.succeed(firstRuntimeTerminated, undefined)
160+
: Effect.void,
161+
),
162+
),
149163
childProcessSpawner,
150164
spawn: {
151165
command: process.execPath,
@@ -154,7 +168,9 @@ describe("AntigravityAdapterV2 harness recovery", () => {
154168
env: {
155169
T3_ACP_ANTIGRAVITY: "1",
156170
T3_ACP_REQUEST_LOG_PATH: requestLogPath,
157-
...(processCount === 1 ? { T3_ACP_ANTIGRAVITY_HARNESS_FAILURE: "1" } : {}),
171+
...(processNumber === 1
172+
? { T3_ACP_ANTIGRAVITY_HARNESS_FAILURE: harnessFailure }
173+
: {}),
158174
},
159175
},
160176
}).pipe(Effect.provideService(Crypto.Crypto, crypto));
@@ -193,9 +209,11 @@ describe("AntigravityAdapterV2 harness recovery", () => {
193209
yield* session.startTurn(
194210
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, modelSelection, now }),
195211
);
196-
const failed = yield* terminal;
197-
assert.equal(failed._tag, "Some");
198-
if (failed._tag === "Some") assert.equal(failed.value.status, "failed");
212+
const first = yield* terminal;
213+
assert.equal(first._tag, "Some");
214+
if (first._tag === "Some") assert.equal(first.value.status, firstTurnStatus);
215+
// The adapter must retire the first process even when end_turn won the race.
216+
yield* Deferred.await(firstRuntimeTerminated);
199217
yield* session.startTurn(
200218
makeTurnInput({
201219
threadId,
@@ -211,10 +229,21 @@ describe("AntigravityAdapterV2 harness recovery", () => {
211229
assert.equal(completed._tag, "Some");
212230
if (completed._tag === "Some") assert.equal(completed.value.status, "completed");
213231
assert.equal(processCount, 2);
214-
const requests = yield* fileSystem.readFileString(requestLogPath);
215-
assert.include(requests, "session/resume");
216-
assert.include(requests, "mock-session-1");
217-
}).pipe(Effect.provide(layerSession), Effect.scoped),
232+
const requests = (yield* fileSystem.readFileString(requestLogPath))
233+
.trim()
234+
.split("\n")
235+
.map((line) => JSON.parse(line) as { method?: string; params?: { sessionId?: string } });
236+
const resumeRequests = requests.filter((request) => request.method === "session/resume");
237+
assert.equal(resumeRequests.length, 1);
238+
assert.equal(resumeRequests[0]?.params?.sessionId, "mock-session-1");
239+
}).pipe(Effect.provide(layerSession), Effect.scoped);
240+
241+
it.live("fails despite end_turn and resumes the saved session in a fresh process", () =>
242+
recoverHarnessFailure("1", "failed"),
243+
);
244+
245+
it.live("resumes in a fresh process when the native failure arrives after end_turn", () =>
246+
recoverHarnessFailure("after-end-turn", "completed"),
218247
);
219248
});
220249

0 commit comments

Comments
 (0)