The best way to control Claude Code, Codex and more from any computer or phone
fix(antigravity): file reads no longer show unrelated errors (#26910)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 29, 2026 at 04:06 UTC
c1876b57c9258cc9a5b1a429d76e3f169bfcd9a5
4 files changed
+359
-1
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
+199
@@ -707,3 +707,202 @@ describe("AntigravityAdapterV2 html_render pages", () => {
707
}).pipe(Effect.provide(layerSession), Effect.scoped),
708
);
709
});
710
+
711
+describe("AntigravityAdapterV2 subagent reads", () => {
712
+ it.effect("completes a read T3 served when the agent later fails it with a step error", () =>
713
+ Effect.gen(function* () {
714
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
715
+ const fileSystem = yield* FileSystem.FileSystem;
716
+ const path = yield* Path.Path;
717
+ const crypto = yield* Crypto.Crypto;
718
+ const mockAgentPath = yield* path.fromFileUrl(
719
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
720
+ );
721
+ const workspace = yield* fileSystem.makeTempDirectoryScoped({
722
+ prefix: "t3-antigravity-reads-",
723
+ });
724
+ const outside = yield* fileSystem.makeTempDirectoryScoped({
725
+ prefix: "t3-antigravity-reads-outside-",
726
+ });
727
+ const served = path.join(workspace, "served.ts");
728
+ yield* fileSystem.writeFileString(served, "export {};");
729
+ const denied = path.join(outside, "secret.txt");
730
+ yield* fileSystem.writeFileString(denied, "secret");
731
+ const unseen = path.join(workspace, "unseen.ts");
732
+ const retried = path.join(workspace, "retried.ts");
733
+ const stepError = 'Model produced invalid output. ("model output error")';
734
+ type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
735
+ let sessionUpdate: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
736
+ let readTextFile: Parameters<RuntimeService["handleReadTextFile"]>[0] | undefined;
737
+ const instanceId = ProviderInstanceId.make("antigravity-subagent-reads-test");
738
+ const threadId = ThreadId.make("thread-antigravity-subagent-reads");
739
+ const adapter = yield* makeAntigravityAdapterV2({
740
+ instanceId,
741
+ selfInvocation: yield* resolveSelfInvocation(),
742
+ makeRuntime: (input) =>
743
+ makeAntigravityAcpRuntime({
744
+ ...input,
745
+ childProcessSpawner,
746
+ spawn: {
747
+ command: process.execPath,
748
+ args: [mockAgentPath],
749
+ cwd: input.cwd,
750
+ env: { T3_ACP_ANTIGRAVITY: "1" },
751
+ },
752
+ }).pipe(
753
+ Effect.provideService(Crypto.Crypto, crypto),
754
+ Effect.map((runtime): RuntimeService => ({
755
+ ...runtime,
756
+ handleSessionUpdate: (handler) =>
757
+ Effect.sync(() => {
758
+ sessionUpdate = handler;
759
+ }).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
760
+ handleReadTextFile: (handler) =>
761
+ Effect.sync(() => {
762
+ readTextFile = handler;
763
+ }).pipe(Effect.andThen(runtime.handleReadTextFile(handler))),
764
+ // agy_acp_server announces a subagent's client_view_file on the parent session,
765
+ // never completes it, then fails every open call with the next step error.
766
+ prompt: () =>
767
+ Effect.gen(function* () {
768
+ if (sessionUpdate === undefined || readTextFile === undefined) {
769
+ return yield* Effect.die("the adapter must handle updates and reads");
770
+ }
771
+ const send = sessionUpdate;
772
+ const handleRead = readTextFile;
773
+ const update = (update: EffectAcpSchema.SessionUpdate) =>
774
+ send(
775
+ normalizeAntigravitySessionUpdate({ sessionId: "mock-session-1", update }),
776
+ );
777
+ // The agent's own view_file never reaches T3, so it must not take a served read.
778
+ const reads = [
779
+ ["call_native", served, "Running view_file"],
780
+ ["call_served", served, "Running client_view_file"],
781
+ ["call_missing", retried, "Running client_view_file"],
782
+ ["call_retried", retried, "Running client_view_file"],
783
+ ["call_denied", denied, "Running client_view_file"],
784
+ ["call_unseen", unseen, "Running client_view_file"],
785
+ ] as const;
786
+ for (const [toolCallId, target, title] of reads) {
787
+ yield* update({
788
+ sessionUpdate: "tool_call",
789
+ toolCallId,
790
+ title,
791
+ kind: "read",
792
+ status: "in_progress",
793
+ rawInput: { absolute_path: target },
794
+ locations: [{ path: target }],
795
+ });
796
+ }
797
+ const serve = (target: string) =>
798
+ handleRead(
799
+ { sessionId: "subagent-conversation", path: target },
800
+ { requestId: `read-${target}`, method: "fs/read_text_file" },
801
+ ).pipe(Effect.exit);
802
+ yield* serve(served);
803
+ yield* serve(retried);
804
+ yield* fileSystem.writeFileString(retried, "export {};").pipe(Effect.orDie);
805
+ yield* serve(retried);
806
+ yield* serve(denied);
807
+ for (const [toolCallId] of reads) {
808
+ yield* update({
809
+ sessionUpdate: "tool_call_update",
810
+ toolCallId,
811
+ status: "failed",
812
+ rawOutput: stepError,
813
+ });
814
+ }
815
+ return { stopReason: "end_turn" as const };
816
+ }),
817
+ })),
818
+ ),
819
+ withProcess: (_stop, task) => task,
820
+ // @effect-diagnostics-next-line effectSucceedWithVoid:off - This optional result requires undefined, not the wider void type.
821
+ defaultModel: Effect.succeed(undefined),
822
+ });
823
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
824
+ runtimeMode: "full-access",
825
+ interactionMode: "default",
826
+ cwd: workspace,
827
+ });
828
+ const modelSelection = { instanceId, model: "gemini-test-low" } as const;
829
+ const session = yield* adapter.openSession({
830
+ threadId,
831
+ providerSessionId: ProviderSessionId.make("provider-session-antigravity-subagent-reads"),
832
+ modelSelection,
833
+ runtimePolicy,
834
+ });
835
+ const providerThread = yield* session.ensureThread({
836
+ threadId,
837
+ modelSelection,
838
+ runtimePolicy,
839
+ });
840
+ const now = yield* DateTime.now;
841
+ yield* session.startTurn({
842
+ appThread: {
843
+ createdBy: "user",
844
+ creationSource: "web",
845
+ id: threadId,
846
+ projectId: ProjectId.make("project-antigravity-subagent-reads"),
847
+ title: "Antigravity subagent reads",
848
+ providerInstanceId: instanceId,
849
+ modelSelection,
850
+ runtimeMode: "full-access",
851
+ interactionMode: "default",
852
+ branch: null,
853
+ worktreePath: workspace,
854
+ activeProviderThreadId: providerThread.id,
855
+ lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
856
+ forkedFrom: null,
857
+ createdAt: now,
858
+ updatedAt: now,
859
+ archivedAt: null,
860
+ settledOverride: null,
861
+ settledAt: null,
862
+ lastVisitedAt: null,
863
+ deletedAt: null,
864
+ },
865
+ threadId,
866
+ runId: RunId.make("run-antigravity-subagent-reads"),
867
+ runOrdinal: 1,
868
+ providerTurnOrdinal: 1,
869
+ attemptId: RunAttemptId.make("attempt-antigravity-subagent-reads"),
870
+ rootNodeId: NodeId.make("node-antigravity-subagent-reads"),
871
+ providerThread,
872
+ message: {
873
+ createdBy: "user",
874
+ creationSource: "web",
875
+ messageId: MessageId.make("message-antigravity-subagent-reads"),
876
+ text: "review the codebase",
877
+ attachments: [],
878
+ },
879
+ modelSelection,
880
+ runtimePolicy,
881
+ });
882
+ const events = Array.from(
883
+ yield* session.events.pipe(
884
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
885
+ Stream.runCollect,
886
+ ),
887
+ );
888
+ const read = (nativeId: string) => {
889
+ const event = events.findLast(
890
+ (event) =>
891
+ event.type === "turn_item.updated" &&
892
+ event.turnItem.nativeItemRef?.nativeId === nativeId,
893
+ );
894
+ return event?.type === "turn_item.updated" && event.turnItem.type === "dynamic_tool"
895
+ ? { status: event.turnItem.status, output: event.turnItem.output }
896
+ : undefined;
897
+ };
898
+
899
+ const failed = { status: "failed" as const, output: stepError };
900
+ assert.deepEqual(read("call_served"), { status: "completed", output: undefined });
901
+ assert.deepEqual(read("call_retried"), { status: "completed", output: undefined });
902
+ assert.deepEqual(read("call_native"), failed);
903
+ assert.deepEqual(read("call_missing"), failed);
904
+ assert.deepEqual(read("call_denied"), failed);
905
+ assert.deepEqual(read("call_unseen"), failed);
906
+ }).pipe(Effect.provide(layerSession), Effect.scoped),
907
+ );
908
+});
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
+16
-1
@@ -29,6 +29,7 @@ import {
29
antigravitySubagentOutput,
30
classifyAntigravitySubagentToolCall,
31
extractAntigravityUserInputQuestion,
32
+ makeAntigravityReadRepair,
33
makeAntigravityUserInputResponse,
34
normalizeAntigravityToolCall,
35
} from "../../provider/acp/AntigravityProtocol.ts";
@@ -128,8 +129,22 @@ export function makeAntigravityAcpAdapterFlavor(
129
}),
130
)
131
.pipe(Effect.provideService(Scope.Scope, scope));
132
+ // Repair keeps state across updates, so each runtime must have one session-update handler.
133
+ const reads = makeAntigravityReadRepair();
134
return {
135
...runtime,
136
+ handleReadTextFile: (handler) =>
137
+ runtime.handleReadTextFile((request, context) =>
138
+ handler(request, context).pipe(
139
+ Effect.onExit((exit) =>
140
+ Effect.sync(() => reads.attempted(request.path, Exit.isSuccess(exit))),
141
+ ),
142
+ ),
143
+ ),
144
+ prompt: (payload, promptOptions) =>
145
+ Effect.sync(reads.reset).pipe(Effect.andThen(runtime.prompt(payload, promptOptions))),
146
+ handleSessionUpdate: (handler) =>
147
+ runtime.handleSessionUpdate((notification) => handler(reads.repair(notification))),
148
start: () =>
149
runtime
150
.start()
@@ -138,7 +153,7 @@ export function makeAntigravityAcpAdapterFlavor(
153
(started) => options.onSessionStarted?.(started, input.cwd) ?? Effect.void,
154
),
155
),
141
- };
156
+ } satisfies typeof runtime;
157
},
158
Effect.provideService(Crypto.Crypto, options.crypto),
159
Effect.mapError((cause): EffectAcpErrors.AcpError =>
apps/server/src/provider/acp/AntigravityProtocol.test.ts
+79
@@ -13,6 +13,7 @@ import {
13
normalizeAntigravitySessionUpdate,
14
normalizeAntigravityToolCall,
15
sanitizeAntigravityToolPayload,
16
+ makeAntigravityReadRepair,
17
} from "./AntigravityProtocol.ts";
18
import {
19
mergeToolCallState,
@@ -413,3 +414,81 @@ describe("Antigravity tool results", () => {
414
expect(serialized).not.toContain("inline-data-url");
415
});
416
});
417
+
418
+describe("Antigravity served reads", () => {
419
+ const flush = (reads: ReturnType<typeof makeAntigravityReadRepair>, toolCallId: string) =>
420
+ reads.repair({
421
+ sessionId: "session-1",
422
+ update: {
423
+ sessionUpdate: "tool_call_update",
424
+ toolCallId,
425
+ status: "failed",
426
+ rawOutput: "Tool execution failed",
427
+ },
428
+ }).update;
429
+
430
+ it("credits a read T3 served before the agent announced it", () => {
431
+ const reads = makeAntigravityReadRepair();
432
+ reads.attempted("/repo/a.ts", true);
433
+ reads.repair({
434
+ sessionId: "session-1",
435
+ update: {
436
+ sessionUpdate: "tool_call",
437
+ toolCallId: "call_late",
438
+ title: "Running client_view_file",
439
+ kind: "read",
440
+ status: "in_progress",
441
+ locations: [{ path: "/repo/a.ts" }],
442
+ },
443
+ });
444
+ expect(flush(reads, "call_late")).toEqual({
445
+ sessionUpdate: "tool_call_update",
446
+ toolCallId: "call_late",
447
+ status: "completed",
448
+ });
449
+ });
450
+
451
+ it("forgets an earlier turn's unannounced served read", () => {
452
+ const reads = makeAntigravityReadRepair();
453
+ reads.attempted("/repo/a.ts", true);
454
+ reads.reset();
455
+ reads.repair({
456
+ sessionId: "session-1",
457
+ update: {
458
+ sessionUpdate: "tool_call",
459
+ toolCallId: "call_refused",
460
+ title: "Running client_view_file",
461
+ kind: "read",
462
+ status: "in_progress",
463
+ locations: [{ path: "/repo/a.ts" }],
464
+ },
465
+ });
466
+ reads.attempted("/repo/a.ts", false);
467
+ expect(flush(reads, "call_refused")).toMatchObject({ status: "failed" });
468
+ });
469
+
470
+ it("drops an earlier turn's unanswered read so a new turn's served read gets the credit", () => {
471
+ const reads = makeAntigravityReadRepair();
472
+ const announce = (toolCallId: string) =>
473
+ reads.repair({
474
+ sessionId: "session-1",
475
+ update: {
476
+ sessionUpdate: "tool_call",
477
+ toolCallId,
478
+ title: "Running client_view_file",
479
+ kind: "read",
480
+ status: "in_progress",
481
+ locations: [{ path: "/repo/a.ts" }],
482
+ },
483
+ });
484
+ announce("call_abandoned");
485
+ reads.reset();
486
+ announce("call_current");
487
+ reads.attempted("/repo/a.ts", true);
488
+ expect(flush(reads, "call_current")).toEqual({
489
+ sessionUpdate: "tool_call_update",
490
+ toolCallId: "call_current",
491
+ status: "completed",
492
+ });
493
+ });
494
+});
apps/server/src/provider/acp/AntigravityProtocol.ts
+65
@@ -216,6 +216,71 @@ export function sanitizeAntigravityToolPayload(payload: unknown): unknown {
216
}
217
const isJsonRecord = Schema.is(Schema.Record(Schema.String, Schema.Json));
218
219
+const ANTIGRAVITY_CLIENT_READ_TITLES = new Set([
220
+ "Running client_view_file",
221
+ "Run client_view_file?",
222
+]);
223
+
224
+function antigravityClientReadPath(update: {
225
+ readonly title?: string | null;
226
+ readonly locations?: ReadonlyArray<{ readonly path: string }> | null;
227
+ readonly rawInput?: unknown;
228
+}): string | undefined {
229
+ if (!update.title || !ANTIGRAVITY_CLIENT_READ_TITLES.has(update.title)) return undefined;
230
+ const target =
231
+ update.locations?.[0]?.path ??
232
+ (Predicate.isObject(update.rawInput) ? update.rawInput.absolute_path : undefined);
233
+ return typeof target === "string" && target ? target : undefined;
234
+}
235
+
236
+/**
237
+ * The agent never completes a subagent's `client_view_file` call, then fails every open call
238
+ * with the next unrelated step error. Report reads T3 served as completed instead.
239
+ */
240
+export function makeAntigravityReadRepair() {
241
+ type Outcome = "served" | "refused";
242
+ const openReads = new Map<string, { readonly path: string; outcome?: Outcome }>();
243
+ // The agent runs a client tool in a background task, so its request can precede the announcement.
244
+ const earlyOutcomes: Array<{ readonly path: string; readonly outcome: Outcome }> = [];
245
+ return {
246
+ /** Earlier turns' rows are already settled, and their unanswered reads must not take credit. */
247
+ reset: () => {
248
+ openReads.clear();
249
+ earlyOutcomes.length = 0;
250
+ },
251
+ /** Each `fs/read_text_file` request answers the oldest open read of its path, in order. */
252
+ attempted: (path: string, served: boolean) => {
253
+ const outcome = served ? "served" : "refused";
254
+ for (const read of openReads.values()) {
255
+ if (read.path !== path || read.outcome !== undefined) continue;
256
+ read.outcome = outcome;
257
+ return;
258
+ }
259
+ earlyOutcomes.push({ path, outcome });
260
+ },
261
+ repair: (
262
+ notification: EffectAcpSchema.SessionNotification,
263
+ ): EffectAcpSchema.SessionNotification => {
264
+ const update = notification.update;
265
+ if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") {
266
+ return notification;
267
+ }
268
+ const path = antigravityClientReadPath(update);
269
+ if (path !== undefined && !openReads.has(update.toolCallId)) {
270
+ const early = earlyOutcomes.findIndex((entry) => entry.path === path);
271
+ const outcome = early === -1 ? undefined : earlyOutcomes.splice(early, 1)[0]?.outcome;
272
+ openReads.set(update.toolCallId, outcome === undefined ? { path } : { path, outcome });
273
+ }
274
+ if (update.status !== "completed" && update.status !== "failed") return notification;
275
+ const read = openReads.get(update.toolCallId);
276
+ openReads.delete(update.toolCallId);
277
+ if (update.status === "completed" || read?.outcome !== "served") return notification;
278
+ const { rawOutput: _stepError, ...rest } = update;
279
+ return { ...notification, update: { ...rest, status: "completed" } };
280
+ },
281
+ };
282
+}
283
+
284
export function normalizeAntigravitySessionUpdate(
285
notification: EffectAcpSchema.SessionNotification,
286
): EffectAcpSchema.SessionNotification {