Skip to content

Commit 5ebe1e1

Browse files
t3dotggclaude
andcommitted
fix(antigravity): check upload ownership per thread, omit cut patches, and republish limits on sign-in
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b942ee9 commit 5ebe1e1

7 files changed

Lines changed: 58 additions & 15 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,14 @@ export function makeAntigravityAcpAdapterFlavor(
247247
threadId,
248248
attachments,
249249
}) {
250+
if (attachments.length === 0) return () => null;
250251
// A message may name another thread's stored upload; copy only this lineage's uploads.
251252
const owner = toSafeThreadAttachmentSegment(threadId);
253+
const ownsAll = attachments.every(
254+
(attachment) => parseThreadSegmentFromAttachmentId(attachment.id) === owner,
255+
);
252256
const inherited = new Set(
253-
options.host.readableAttachmentPaths === undefined
257+
ownsAll || options.host.readableAttachmentPaths === undefined
254258
? []
255259
: yield* options.host.readableAttachmentPaths(threadId),
256260
);

‎apps/server/src/orchestration-v2/ThreadReadableAttachments.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ it.effect("reads uploads from the history the thread's agent was given", () =>
111111
fork: {
112112
forkedFrom: fork("source", "run-3"),
113113
runs: runs("completed", "completed"),
114-
items: [message("run-1", "fork-own"), message("run-2", "fork-after-nested-fork")],
114+
// The fork names a source upload from after its fork run.
115+
items: [
116+
message("run-1", "fork-own"),
117+
message("run-2", "fork-after-nested-fork"),
118+
message("run-2", "source-after-fork"),
119+
],
115120
},
116121
nested: {
117122
forkedFrom: fork("fork", "run-1"),

‎apps/server/src/orchestration-v2/ThreadReadableAttachments.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ export const readThreadReadableAttachmentIds = Effect.fn(
3535
const own = yield* projectionStore.getThreadRecords(threadId, ["runs", "attempts", "turnItems"], {
3636
turnItemTypes: ATTACHMENT_ITEM_TYPES,
3737
});
38-
const ids = new Set(attachmentIds(visibleConversationItems(own, own.turnItems)));
38+
// Each thread contributes only uploads it owns: a message may name another thread's stored
39+
// upload, including an ancestor's upload from after the fork.
40+
const owned = (ownerId: ThreadId, items: ReadonlyArray<OrchestrationV2TurnItem>) => {
41+
const owner = toSafeThreadAttachmentSegment(ownerId);
42+
return attachmentIds(items).filter((id) => parseThreadSegmentFromAttachmentId(id) === owner);
43+
};
44+
const ids = new Set(owned(threadId, visibleConversationItems(own, own.turnItems)));
3945
const seen = new Set([threadId]);
4046
let current = own.thread;
4147
while (
@@ -57,10 +63,8 @@ export const readThreadReadableAttachmentIds = Effect.fn(
5763
...(source.thread.historyOrigin === "v1_import" ? [null] : []),
5864
],
5965
});
60-
for (const id of attachmentIds(visibleConversationItems(source, turnItems))) ids.add(id);
66+
for (const id of owned(sourceId, visibleConversationItems(source, turnItems))) ids.add(id);
6167
current = source.thread;
6268
}
63-
// A client can name another thread's stored upload; only uploads owned by this lineage count.
64-
const owners = new Set([...seen].map(toSafeThreadAttachmentSegment));
65-
return [...ids].filter((id) => owners.has(parseThreadSegmentFromAttachmentId(id)));
69+
return [...ids];
6670
});

‎apps/server/src/provider/AntigravityProvider.test.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,16 +792,20 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => {
792792
yield* harness.provider.onSignedIn;
793793
yield* harness.provider.onSessionStarted(started);
794794
expect((yield* published)?.usageLimits).toEqual(newLimits);
795-
// Switching again replaces limits the previous account already published.
796-
const nextLimits = { ...newLimits, checkedAt: "2026-10-09T12:02:00.000Z" };
797-
yield* Ref.set(usage, Effect.succeed(nextLimits));
795+
// Switching again must not republish the previous account's limits, even if the read fails.
796+
const failed = {
797+
checkedAt: "2026-10-09T12:02:00.000Z",
798+
windows: [],
799+
unavailable: { reason: "probeFailed" },
800+
} satisfies ServerProviderUsageLimits;
801+
yield* Ref.set(usage, Effect.succeed(failed));
798802
const republished = yield* harness.nextPublish(
799-
(snapshot) => snapshot.usageLimits?.checkedAt === nextLimits.checkedAt,
803+
(snapshot) => snapshot.usageLimits?.unavailable?.reason === "probeFailed",
800804
);
801805
yield* harness.provider.onSignedIn;
802806
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
803807
yield* harness.provider.onSessionStarted(started);
804-
expect((yield* republished)?.usageLimits).toEqual(nextLimits);
808+
expect((yield* republished)?.usageLimits).toEqual(failed);
805809
}),
806810
),
807811
);

‎apps/server/src/provider/AntigravityProvider.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,22 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
506506
onSessionStarted,
507507
onConfigOptionsUpdated,
508508
onAvailableCommands,
509-
// The new sign-in may be another account, so its session start reads fresh limits.
509+
// The new sign-in may be another account. Clear and republish its limits so a failed read
510+
// cannot fall back to them; the session start then reads the new account's limits.
510511
onSignedIn: resetUsage.pipe(
511512
Effect.andThen(
512513
SubscriptionRef.update(metadata, (state) => {
513514
const { usageLimits: _previousAccount, ...draft } = state.draft;
514515
return { ...state, draft };
515516
}),
516517
),
518+
Effect.andThen(
519+
Deferred.await(republish).pipe(
520+
Effect.flatten,
521+
Effect.provideService(PublishingUsage, true),
522+
),
523+
),
524+
Effect.asVoid,
517525
),
518526
onSignedOut: clearAccountMetadata(),
519527
onAuthRequired: clearAccountMetadata(),

‎apps/server/src/provider/acp/AntigravityProtocol.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ describe("Antigravity tool results", () => {
376376
pathOnly = normalizeAntigravityToolCall(mergeToolCallState(pathOnly, completed));
377377
expect(pathOnly.data.content).toEqual([{ type: "diff", patch: { format: "omitted" } }]);
378378
expect(acpToolCallDiffPatch(pathOnly.data.content)).toBeUndefined();
379+
// A captured patch that a later update's shared text budget cut or dropped is omitted.
380+
for (const patch of [{ text: "[Earlier output truncated]\n\n@@ -80,1 +80,1 @@" }, {}]) {
381+
const kept = normalizeAntigravityToolCall({
382+
toolCallId: "edit-cut",
383+
kind: "edit",
384+
status: "completed",
385+
data: { content: [{ type: "diff", path, patch }] },
386+
});
387+
expect(kept.data.content).toEqual([{ type: "diff", path, patch: { format: "omitted" } }]);
388+
}
379389
// A patch too long to keep, or input cut to its tail, must not fall back to line-1 snippets.
380390
for (const width of [60, 120]) {
381391
const block = (value: string) =>

‎apps/server/src/provider/acp/AntigravityProtocol.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,16 @@ function withAntigravityEditPatches(
371371
return content.map((entry) => {
372372
if (!Predicate.isObject(entry) || entry.type !== "diff" || typeof entry.path !== "string")
373373
return entry;
374-
// Keep the first patch: once the edit runs, the file no longer holds the old text.
375-
if (entry.patch !== undefined) return entry;
374+
// Keep the first patch: once the edit runs, the file no longer holds the old text. A later
375+
// update's shared text budget can cut or drop it, and a cut patch would misplace the hunk.
376+
if (entry.patch !== undefined) {
377+
const patch: unknown = entry.patch;
378+
const cut =
379+
Predicate.isObject(patch) &&
380+
patch.format !== "omitted" &&
381+
(typeof patch.text !== "string" || patch.text.startsWith(TOOL_TEXT_TRUNCATED));
382+
return cut ? { ...entry, patch: { format: "omitted" } } : entry;
383+
}
376384
// Bounding keeps only the tail of long input, so a cut snippet cannot be located.
377385
if (hasTruncatedText(data.rawInput)) return { ...entry, patch: { format: "omitted" } };
378386
const text = antigravityEditPatch({

0 commit comments

Comments
 (0)