Skip to content

Commit 7698786

Browse files
t3dotggclaude
andcommitted
fix(antigravity): keep main's shared attachment folder
Copying each thread's uploads into a private folder added a new way to fail: a failed copy blocked the whole turn, even for images sent as bytes. The isolation was also weak, because the agent's shell can read the shared folder anyway. Drop the copies and pass stored upload paths, as main does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 386202d commit 7698786

23 files changed

Lines changed: 30 additions & 1045 deletions

‎apps/server/src/guest/GuestShareService.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const layerCleanup = Layer.effect(
9898
cleanupScheduledTasks: () => Effect.void,
9999
cleanupTerminals: () => Effect.void,
100100
cleanupPreviews: () => Effect.void,
101-
cleanupProviderUploads: () => Effect.void,
102101
cleanupAttachments: (attachmentIds) =>
103102
Effect.forEach(
104103
attachmentIds,

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

Lines changed: 7 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
makeAntigravityAcpAdapterFlavor,
4040
makeAntigravityAdapterV2,
4141
} from "./AntigravityAdapterV2.ts";
42-
import { antigravityThreadUploadsRoot } from "../../provider/acp/AntigravityThreadUploads.ts";
4342

4443
const flavor = makeAntigravityAcpAdapterFlavor({
4544
instanceId: ProviderInstanceId.make("antigravity-test"),
@@ -140,9 +139,7 @@ const layerSession = Layer.mergeAll(
140139
NodeServices.layer,
141140
IdAllocator.layer,
142141
McpProviderSessions.layer,
143-
TestProviderHost.layer({
144-
readableAttachments: { "thread-antigravity-containment": ["pasted.txt"] },
145-
}).pipe(Layer.provide(NodeServices.layer)),
142+
TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer)),
146143
);
147144

148145
describe("AntigravityAdapterV2 compaction", () => {
@@ -245,55 +242,6 @@ describe("AntigravityAdapterV2 session open", () => {
245242
);
246243
});
247244

248-
describe("AntigravityAdapterV2 thread uploads", () => {
249-
it.effect("copies only uploads this thread owns or inherited, not another thread's by ID", () =>
250-
Effect.gen(function* () {
251-
const fileSystem = yield* FileSystem.FileSystem;
252-
const path = yield* Path.Path;
253-
const host = yield* ProviderHost.ProviderHost;
254-
const threadId = ThreadId.make("thread-antigravity-containment");
255-
const upload = (id: string) => {
256-
const attachment = {
257-
type: "file",
258-
id,
259-
name: `${id}.txt`,
260-
mimeType: "text/plain",
261-
sizeBytes: 4,
262-
} as const;
263-
return fileSystem
264-
.writeFileString(path.join(host.paths.attachmentsDir, id), "data")
265-
.pipe(Effect.as(attachment));
266-
};
267-
const own = yield* upload(
268-
"thread-antigravity-containment-00000000-0000-4000-8000-000000000001",
269-
);
270-
const foreign = yield* upload("thread-other-00000000-0000-4000-8000-000000000002");
271-
const inherited = yield* upload("pasted.txt");
272-
const uploadsFlavor = makeAntigravityAcpAdapterFlavor({
273-
instanceId: ProviderInstanceId.make("antigravity-uploads-test"),
274-
crypto: yield* Crypto.Crypto,
275-
fileSystem,
276-
path,
277-
host,
278-
selfInvocation: yield* resolveSelfInvocation(),
279-
makeRuntime: () => Effect.die("not spawned in this test"),
280-
withProcess: (_stop, task) => task,
281-
// @effect-diagnostics-next-line effectSucceedWithVoid:off - This optional result requires undefined, not the wider void type.
282-
defaultModel: Effect.succeed(undefined),
283-
});
284-
const resolve = yield* uploadsFlavor.prepareAttachments!({
285-
threadId,
286-
attachments: [own, foreign, inherited],
287-
});
288-
assert.isString(resolve(own));
289-
assert.isString(resolve(inherited));
290-
assert.isNull(resolve(foreign));
291-
const root = antigravityThreadUploadsRoot(host.paths.stateDir, threadId);
292-
assert.isFalse(yield* fileSystem.exists(path.join(root, foreign.id)));
293-
}).pipe(Effect.provide(layerSession), Effect.scoped),
294-
);
295-
});
296-
297245
describe("AntigravityAdapterV2 client file system", () => {
298246
it.effect("serves confined reads and leaves edits to the agent's diff tools", () =>
299247
Effect.gen(function* () {
@@ -393,27 +341,11 @@ describe("AntigravityAdapterV2 client file system", () => {
393341
const insidePath = path.join(workspace, "src", "inside.ts");
394342
yield* fileSystem.makeDirectory(path.dirname(insidePath), { recursive: true });
395343
yield* fileSystem.writeFileString(insidePath, "inside");
396-
// The agent gets only this thread's copies; the shared store stays out of reach.
397-
// The copies live under the canonical root (macOS temp paths resolve through /private).
398-
const threadUploads = yield* fileSystem.realPath(
399-
antigravityThreadUploadsRoot(host.paths.stateDir, threadId),
400-
);
401-
const sessionNew = (yield* fileSystem.readFileString(requestLog))
402-
.trim()
403-
.split("\n")
404-
.map((line) => JSON.parse(line) as { method?: string; params?: unknown })
405-
.find((request) => request.method === "session/new");
406-
assert.deepNestedPropertyVal(sessionNew, "params.additionalDirectories", [threadUploads]);
407344
const pasted = yield* readTextFile(
408-
{ sessionId: "mock-session-1", path: path.join(threadUploads, "pasted.txt") },
345+
{ sessionId: "mock-session-1", path: attachment },
409346
context("fs/read_text_file"),
410347
);
411348
assert.equal(pasted.content, "pasted");
412-
const shared = yield* readTextFile(
413-
{ sessionId: "mock-session-1", path: attachment },
414-
context("fs/read_text_file"),
415-
).pipe(Effect.exit);
416-
assert.isTrue(Exit.isFailure(shared), "the shared attachment store is not a read root");
417349
yield* fileSystem.writeFileString(insidePath, "\uFEFFfirst\né中🙂\nlast");
418350
const sliced = yield* readTextFile(
419351
{ sessionId: "mock-session-1", path: insidePath, line: 2, limit: 1 },
@@ -472,19 +404,13 @@ describe("AntigravityAdapterV2 workspace changes", () => {
472404
const host = yield* ProviderHost.ProviderHost;
473405
const document = ChatFileAttachment.make({
474406
type: "file",
475-
id: "thread-antigravity-workspace-change-00000000-0000-4000-8000-000000000003",
407+
id: "native-pdf",
476408
name: "diagram.pdf",
477409
mimeType: "application/pdf",
478410
sizeBytes: 9,
479411
});
480-
yield* fileSystem.writeFileString(host.resolveAttachmentPath(document)!, "%PDF-1.7");
481-
const documentPath = path.join(
482-
antigravityThreadUploadsRoot(
483-
host.paths.stateDir,
484-
ThreadId.make("thread-antigravity-workspace-change"),
485-
),
486-
"thread-antigravity-workspace-change-00000000-0000-4000-8000-000000000003",
487-
);
412+
const documentPath = host.resolveAttachmentPath(document)!;
413+
yield* fileSystem.writeFileString(documentPath, "%PDF-1.7");
488414
let readTextFile: Parameters<RuntimeService["handleReadTextFile"]>[0] | undefined;
489415
const instanceId = ProviderInstanceId.make("antigravity-workspace-change-test");
490416
const adapter = yield* makeAntigravityAdapterV2({
@@ -603,26 +529,19 @@ describe("AntigravityAdapterV2 workspace changes", () => {
603529
Stream.runHead,
604530
);
605531
const sent = yield* Deferred.await(promptReceived);
606-
// Staged copies live under the canonical root (macOS temp paths resolve through /private).
607-
const stagedDocument = yield* fileSystem.realPath(documentPath);
608532
assert.deepEqual(
609533
sent.prompt.filter((block) => block.type === "resource_link"),
610534
[
611535
{
612536
type: "resource_link",
613-
uri: (yield* path.toFileUrl(stagedDocument)).href,
537+
uri: (yield* path.toFileUrl(documentPath)).href,
614538
name: "diagram.pdf",
615539
mimeType: "application/pdf",
616540
size: 8,
617541
},
618542
],
619543
);
620-
// The prompt names this thread's private copy, never the shared store.
621-
assert.include(JSON.stringify(sent.prompt), stagedDocument);
622-
assert.notInclude(
623-
JSON.stringify(sent.prompt),
624-
yield* fileSystem.realPath(host.paths.attachmentsDir),
625-
);
544+
assert.include(JSON.stringify(sent.prompt), documentPath);
626545
if (readTextFile === undefined) {
627546
return yield* Effect.die("Antigravity sessions must serve client file requests");
628547
}

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

Lines changed: 13 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
ANTIGRAVITY_DEFAULT_MODEL,
3-
type ChatAttachment,
43
ProviderDriverKind,
54
ProviderInstanceId,
6-
type ThreadId,
75
type OrchestrationV2ProviderCapabilities,
86
type ProviderSetupError,
97
} from "@t3tools/contracts";
@@ -23,30 +21,18 @@ import type { AntigravityAuth } from "../../provider/AntigravityAuth.ts";
2321
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
2422
import {
2523
antigravityAppendsSystemPrompt,
26-
antigravityMovedUploadsNotice,
2724
antigravityPermissionMode,
2825
antigravityRuntimeModeForSessionMode,
2926
applyAntigravityAcpModelSelection,
3027
buildAntigravityPrompt,
3128
type AntigravityAcpRuntimeInput,
3229
} from "../../provider/acp/AntigravityAcpSupport.ts";
33-
import {
34-
parseThreadSegmentFromAttachmentId,
35-
toSafeThreadAttachmentSegment,
36-
} from "../../attachmentStore.ts";
3730
import {
3831
antigravitySubagentLaunches,
3932
describeAntigravitySubagentLaunches,
4033
} from "../../provider/acp/AntigravityChildWork.ts";
4134
import { readAntigravityClientTextFile } from "../../provider/acp/AntigravityClientFiles.ts";
4235
import { watchAntigravityPromptOutcome } from "../../provider/acp/AntigravityTurnOutcome.ts";
43-
import {
44-
antigravityThreadUploadPath,
45-
antigravityThreadUploadsRoot,
46-
markAntigravityMovedUploads,
47-
syncAntigravityThreadUploads,
48-
takeAntigravityMovedUploads,
49-
} from "../../provider/acp/AntigravityThreadUploads.ts";
5036
import {
5137
antigravityApprovalOptions,
5238
antigravitySubagentOutput,
@@ -147,29 +133,10 @@ export function makeAntigravityAcpAdapterFlavor(
147133
options: AntigravityAdapterV2Options & AntigravityFlavorServices,
148134
): AcpAdapterV2Flavor {
149135
const { profileDirectory } = options;
150-
const uploadsRoot = (threadId: ThreadId) =>
151-
antigravityThreadUploadsRoot(options.host.paths.stateDir, threadId);
136+
const antigravityClientFileRoots = (cwd: string | null) =>
137+
cwd === null ? [options.host.paths.attachmentsDir] : [cwd, options.host.paths.attachmentsDir];
152138
const makeRuntime = Effect.fn("AntigravityAdapterV2.makeRuntime")(
153139
function* (input: AcpAdapterV2RuntimeInput) {
154-
const storedPaths =
155-
options.host.readableAttachmentPaths === undefined
156-
? []
157-
: yield* options.host.readableAttachmentPaths(input.threadId);
158-
// Every start, load and resume rebuilds the copies, so a cold resume can read older uploads.
159-
const synced = yield* syncAntigravityThreadUploads({
160-
stateDir: options.host.paths.stateDir,
161-
threadId: input.threadId,
162-
attachmentsDir: options.host.paths.attachmentsDir,
163-
storedPaths,
164-
prune: true,
165-
}).pipe(
166-
Effect.mapError(
167-
(cause) => new EffectAcpErrors.AcpTransportError({ detail: cause.detail, cause }),
168-
),
169-
);
170-
if (synced.created && input.resumeSessionId !== undefined && storedPaths.length > 0) {
171-
yield* markAntigravityMovedUploads(synced.root, storedPaths);
172-
}
173140
const scope = yield* Scope.fork(yield* Effect.scope);
174141
const runtime = yield* options
175142
.withProcess(
@@ -178,7 +145,7 @@ export function makeAntigravityAcpAdapterFlavor(
178145
...input,
179146
clientFileReads: true,
180147
sessionSystemPromptAppend: PULL_REQUEST_LINKING_INSTRUCTIONS,
181-
additionalDirectories: [synced.root],
148+
additionalDirectories: [options.host.paths.attachmentsDir],
182149
}),
183150
)
184151
.pipe(Effect.provideService(Scope.Scope, scope));
@@ -244,62 +211,22 @@ export function makeAntigravityAcpAdapterFlavor(
244211
mcpOverHttp: true,
245212
sessionCarriesPullRequestLinking: antigravityAppendsSystemPrompt,
246213
makeRuntime,
247-
prepareAttachments: Effect.fn("AntigravityAdapterV2.prepareAttachments")(function* ({
248-
threadId,
249-
attachments,
250-
}) {
251-
if (attachments.length === 0) return () => null;
252-
// A message may name another thread's stored upload; copy only this lineage's uploads.
253-
const owner = toSafeThreadAttachmentSegment(threadId);
254-
const ownsAll = attachments.every(
255-
(attachment) => parseThreadSegmentFromAttachmentId(attachment.id) === owner,
256-
);
257-
const inherited = new Set(
258-
ownsAll || options.host.readableAttachmentPaths === undefined
259-
? []
260-
: yield* options.host.readableAttachmentPaths(threadId),
261-
);
262-
const readable = (attachment: ChatAttachment) => {
263-
const stored = options.host.resolveAttachmentPath(attachment);
264-
return stored !== null &&
265-
(parseThreadSegmentFromAttachmentId(attachment.id) === owner || inherited.has(stored))
266-
? stored
267-
: null;
268-
};
269-
const { root } = yield* syncAntigravityThreadUploads({
270-
stateDir: options.host.paths.stateDir,
271-
threadId,
272-
attachmentsDir: options.host.paths.attachmentsDir,
273-
storedPaths: attachments.flatMap((attachment) => readable(attachment) ?? []),
274-
prune: false,
275-
}).pipe(
276-
Effect.mapError((cause) => EffectAcpErrors.AcpRequestError.internalError(cause.detail)),
277-
);
278-
return (attachment: ChatAttachment) => {
279-
const stored = readable(attachment);
280-
return stored === null ? null : antigravityThreadUploadPath(root, stored);
281-
};
282-
}),
283214
buildPrompt: ({
284-
threadId,
285215
text,
286216
attachments,
287217
resolveAttachmentPath,
288218
promptCapabilities,
289219
agentVersion,
290220
currentModel,
291221
}) =>
292-
takeAntigravityMovedUploads(uploadsRoot(threadId)).pipe(
293-
Effect.flatMap((moved) =>
294-
buildAntigravityPrompt({
295-
input: moved === undefined ? text : antigravityMovedUploadsNotice(text, moved),
296-
attachments,
297-
resolveAttachmentPath,
298-
promptCapabilities,
299-
agentVersion,
300-
currentModel,
301-
}),
302-
),
222+
buildAntigravityPrompt({
223+
input: text,
224+
attachments,
225+
resolveAttachmentPath,
226+
promptCapabilities,
227+
agentVersion,
228+
currentModel,
229+
}).pipe(
303230
Effect.provideService(FileSystem.FileSystem, options.fileSystem),
304231
Effect.provideService(Path.Path, options.path),
305232
),
@@ -322,11 +249,11 @@ export function makeAntigravityAcpAdapterFlavor(
322249
sessionModeForPolicy: (policy) => antigravityPermissionMode(policy.runtimeMode),
323250
runtimeModeForSessionMode: antigravityRuntimeModeForSessionMode,
324251
clientFileSystem: {
325-
readTextFile: (request, cwd, threadId) =>
252+
readTextFile: (request, cwd) =>
326253
readAntigravityClientTextFile({
327254
fileSystem: options.fileSystem,
328255
path: options.path,
329-
allowedRoots: cwd === null ? [uploadsRoot(threadId)] : [cwd, uploadsRoot(threadId)],
256+
allowedRoots: antigravityClientFileRoots(cwd),
330257
request,
331258
}),
332259
},

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
104104
Schema.Struct({
105105
type: Schema.Literal("preview.cleanup"),
106106
}),
107-
Schema.Struct({
108-
type: Schema.Literal("provider-uploads.cleanup"),
109-
}),
110107
Schema.Struct({
111108
type: Schema.Literal("attachment.cleanup"),
112109
attachmentIds: Schema.Array(Schema.String),
@@ -133,7 +130,6 @@ export const REPLAY_SAFE_EFFECT_TYPES_AFTER_PROCESS_LOSS = [
133130
"scheduled-tasks.cleanup",
134131
"terminal.cleanup",
135132
"preview.cleanup",
136-
"provider-uploads.cleanup",
137133
"attachment.cleanup",
138134
"thread-title.generate",
139135
"delegated-tasks.stop",

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,6 @@ export const layerExecutor: Layer.Layer<
526526
}),
527527
),
528528
);
529-
case "provider-uploads.cleanup":
530-
return resourceCleanup.cleanupProviderUploads(effect.threadId).pipe(
531-
Effect.mapError(
532-
(cause) =>
533-
new OrchestrationEffectExecutionError({
534-
effectId: effect.id,
535-
effectType: effect.request.type,
536-
cause,
537-
}),
538-
),
539-
);
540529
case "attachment.cleanup":
541530
return resourceCleanup.cleanupAttachments(effect.request.attachmentIds).pipe(
542531
Effect.mapError(

0 commit comments

Comments
 (0)