The best way to control Claude Code, Codex and more from any computer or phone
fix(server): editing a queued message deletes the attachments you removed (#29699)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 02:19 UTC
997b304dd65f8fee1e4912cbe656b459695aa8e9
11 files changed
+319
-20
apps/server/src/orchestration-v2/EffectOutbox.ts
+1
@@ -117,6 +117,7 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
117
Schema.Struct({
118
type: Schema.Literal("attachment.cleanup"),
119
attachmentIds: Schema.Array(Schema.String),
120
+ skipReferenced: Schema.optional(Schema.Boolean),
121
}),
122
Schema.Struct({
123
type: Schema.Literal("thread-title.generate"),
apps/server/src/orchestration-v2/EffectWorker.test.ts
+2
@@ -31,6 +31,7 @@ import * as CheckpointRollbackService from "./CheckpointRollbackService.ts";
31
import * as CheckpointService from "./CheckpointService.ts";
32
import * as EffectOutbox from "./EffectOutbox.ts";
33
import * as EffectWorker from "./EffectWorker.ts";
34
+import * as ProjectionStore from "./ProjectionStore.ts";
35
import * as RunFinalizationService from "./RunFinalizationService.ts";
36
import * as ProviderSessionManager from "./ProviderSessionManager.ts";
37
import * as ProviderTurnControlService from "./ProviderTurnControlService.ts";
@@ -168,6 +169,7 @@ function layerExecutorFor(input: {
169
Layer.mergeAll(
170
layerDependencies,
171
Layer.mock(ThreadManagementService.ThreadManagementService)(input.threads ?? {}),
172
+ Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
173
ServerSettings.layerTest(
174
input.continueAfterRestart === true ? { continueThreadsAfterServerUpdate: true } : {},
175
),
apps/server/src/orchestration-v2/EffectWorker.ts
+19
-2
@@ -22,6 +22,7 @@ import {
22
import * as RunFinalizationService from "./RunFinalizationService.ts";
23
import * as ResourceCleanupService from "./ResourceCleanupService.ts";
24
import * as EffectOutbox from "./EffectOutbox.ts";
25
+import * as ProjectionStore from "./ProjectionStore.ts";
26
import * as CheckpointRollbackService from "./CheckpointRollbackService.ts";
27
import * as ProviderSessionManager from "./ProviderSessionManager.ts";
28
import * as ProviderTurnControlService from "./ProviderTurnControlService.ts";
@@ -84,6 +85,7 @@ export const layerExecutor: Layer.Layer<
85
| RuntimeRequestService.RuntimeRequestServiceV2
86
| ThreadTitleRegenerationService.ThreadTitleRegenerationService
87
| ThreadManagementService.ThreadManagementService
88
+ | ProjectionStore.ProjectionStoreV2
89
| ServerSettings.ServerSettingsService
90
> = Layer.effect(
91
OrchestrationEffectExecutorV2,
@@ -98,6 +100,7 @@ export const layerExecutor: Layer.Layer<
100
const threadTitleRegeneration =
101
yield* ThreadTitleRegenerationService.ThreadTitleRegenerationService;
102
const threads = yield* ThreadManagementService.ThreadManagementService;
103
+ const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
104
const settings = yield* ServerSettings.ServerSettingsService;
105
return OrchestrationEffectExecutorV2.of({
106
execute: Effect.fn("OrchestrationEffectExecutorV2.execute")(function (effect, options) {
@@ -584,8 +587,21 @@ export const layerExecutor: Layer.Layer<
587
}),
588
),
589
);
587
- case "attachment.cleanup":
588
- return resourceCleanup.cleanupAttachments(effect.request.attachmentIds).pipe(
590
+ case "attachment.cleanup": {
591
+ const request = effect.request;
592
+ return Effect.gen(function* () {
593
+ // Another message or answer may share the file, or a stale queued edit may restore it.
594
+ const referenced = new Set(
595
+ request.skipReferenced
596
+ ? yield* projectionStore.getThreadAttachmentIds(effect.threadId, {
597
+ includeShownByLiveFork: true,
598
+ })
599
+ : [],
600
+ );
601
+ yield* resourceCleanup.cleanupAttachments(
602
+ request.attachmentIds.filter((id) => !referenced.has(id)),
603
+ );
604
+ }).pipe(
605
Effect.mapError(
606
(cause) =>
607
new OrchestrationEffectExecutionError({
@@ -595,6 +611,7 @@ export const layerExecutor: Layer.Layer<
611
}),
612
),
613
);
614
+ }
615
case "thread-title.generate":
616
return threadTitleRegeneration
617
.execute({
apps/server/src/orchestration-v2/Orchestrator.ts
+24
-1
@@ -11539,6 +11539,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11539
const dispatchQueuedRunEdit = Effect.fn("Orchestrator.dispatchQueuedRunEdit")(function* (
11540
command: Extract<OrchestrationV2Command, { readonly type: "queued-run.edit" }>,
11541
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
11542
+ effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>,
11543
) {
11544
if (command.text.trim().length === 0) {
11545
return yield* new OrchestratorDispatchError({
@@ -11632,6 +11633,28 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11633
}),
11634
});
11635
}
11636
+ // Thread deletion only cleans files the thread still references.
11637
+ const keptAttachmentIds = new Set(
11638
+ (command.attachments ?? queuedMessage.attachments).map((attachment) => attachment.id),
11639
+ );
11640
+ const droppedAttachmentIds = queuedMessage.attachments
11641
+ .map((attachment) => attachment.id)
11642
+ .filter((id) => !keptAttachmentIds.has(id));
11643
+ if (droppedAttachmentIds.length > 0) {
11644
+ yield* Ref.update(effects, (existing) => [
11645
+ ...existing,
11646
+ {
11647
+ id: `effect:${command.commandId}:attachment.cleanup`,
11648
+ commandId: command.commandId,
11649
+ threadId: command.threadId,
11650
+ request: {
11651
+ type: "attachment.cleanup",
11652
+ attachmentIds: droppedAttachmentIds,
11653
+ skipReferenced: true,
11654
+ },
11655
+ } satisfies PendingOrchestrationEffectV2,
11656
+ ]);
11657
+ }
11658
});
11659
11660
const subagentCount = (threadId: ThreadId) =>
@@ -15123,7 +15146,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
15146
yield* dispatchQueuedRunCancel(command, events);
15147
break;
15148
case "queued-run.edit":
15126
- yield* dispatchQueuedRunEdit(command, events);
15149
+ yield* dispatchQueuedRunEdit(command, events, effects);
15150
break;
15151
case "checkpoint.rollback":
15152
yield* dispatchCheckpointRollback(command, events, effects);
apps/server/src/orchestration-v2/ProjectionStore.ts
+19
-4
@@ -501,8 +501,10 @@ export interface ProjectionStoreV2Shape {
501
readonly searchThread: (
502
input: OrchestrationV2SearchThreadInput,
503
) => Effect.Effect<OrchestrationV2SearchThreadResult, ProjectionStoreV2Error>;
504
+ /** Files thread deletion may remove; `includeShownByLiveFork` adds ones a live fork shows. */
505
readonly getThreadAttachmentIds: (
506
threadId: ThreadId,
507
+ options?: { readonly includeShownByLiveFork?: boolean },
508
) => Effect.Effect<ReadonlyArray<string>, ProjectionStoreV2Error>;
509
readonly getThreadHistoryPage: (
510
threadId: ThreadId,
@@ -6255,14 +6257,27 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6257
)
6258
`;
6259
6258
- const getThreadAttachmentIds: ProjectionStoreV2Shape["getThreadAttachmentIds"] = (threadId) =>
6260
+ // Thread deletion keeps what a live fork still shows; a reference check must count it.
6261
+ const exceptShownByLiveFork = (
6262
+ threadId: ThreadId,
6263
+ runIdColumn: string,
6264
+ options: { readonly includeShownByLiveFork?: boolean } | undefined,
6265
+ ) =>
6266
+ options?.includeShownByLiveFork === true
6267
+ ? sql``
6268
+ : sql`AND NOT ${shownByLiveFork(threadId, runIdColumn)}`;
6269
+
6270
+ const getThreadAttachmentIds: ProjectionStoreV2Shape["getThreadAttachmentIds"] = (
6271
+ threadId,
6272
+ options,
6273
+ ) =>
6274
Effect.all([
6275
sql<{ id: string }>`
6276
SELECT DISTINCT json_extract(attachment.value, '$.id') AS id
6277
FROM orchestration_v2_projection_messages AS message,
6278
json_each(message.payload_json, '$.attachments') AS attachment
6279
WHERE message.thread_id = ${threadId}
6265
- AND NOT ${shownByLiveFork(threadId, "message.run_id")}
6280
+ ${exceptShownByLiveFork(threadId, "message.run_id", options)}
6281
`,
6282
sql<{ payload_json: string }>`
6283
SELECT item.payload_json
@@ -6272,7 +6287,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6287
AND (item.payload_json LIKE '%htmlRender%'
6288
OR item.payload_json LIKE ${`%${MCP_APP_OUTPUT_KEY}%`}
6289
OR item.payload_json LIKE '%preview_recording_stop%')
6275
- AND NOT ${shownByLiveFork(threadId, "item.run_id")}
6290
+ ${exceptShownByLiveFork(threadId, "item.run_id", options)}
6291
`,
6292
sql<{ id: string }>`
6293
SELECT DISTINCT json_extract(attachment.value, '$.id') AS id
@@ -6281,7 +6296,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6296
json_each(question.value) AS attachment
6297
WHERE item.thread_id = ${threadId}
6298
AND item.type = 'user_input_request'
6284
- AND NOT ${shownByLiveFork(threadId, "item.run_id")}
6299
+ ${exceptShownByLiveFork(threadId, "item.run_id", options)}
6300
`,
6301
// A guest's waiting files are pending uploads that no message row holds yet.
6302
sql<{ id: string }>`
apps/server/src/orchestration-v2/RunFinalizationQueue.test.ts
+1
@@ -97,6 +97,7 @@ it.effect.each([
97
Layer.mock(ThreadManagement.ThreadManagementService)({
98
recoverDelegatedTask: () => Effect.void,
99
}),
100
+ Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
101
ServerSettings.layerTest(),
102
Layer.mock(ProviderTurnStart.ProviderTurnStartServiceV2)({
103
start: () => Effect.sync(() => calls.push("start")).pipe(Effect.asVoid),
apps/server/src/orchestration-v2/ThreadMessageIntake.test.ts
+49
@@ -10,6 +10,7 @@ import {
10
EventId,
11
GuestMessageId,
12
MessageId,
13
+ RunId,
14
RuntimeRequestId,
15
ThreadId,
16
TurnItemId,
@@ -426,3 +427,51 @@ it.effect("sends a guest message with the guest's files, never ones the client n
427
expect(command.attachments).toEqual([guestFile]);
428
}).pipe(Effect.provide(layerIntakeTest)),
429
);
430
+
431
+it.effect("refuses a queued edit that keeps a file another edit already deleted", () =>
432
+ Effect.gen(function* () {
433
+ const config = yield* ServerConfig.ServerConfig;
434
+ const storedFile = (name: string) => ({
435
+ type: "image" as const,
436
+ id: ChatAttachmentId.make(createAttachmentId("thread-queued-edit")!),
437
+ name,
438
+ mimeType: "image/png",
439
+ sizeBytes: 3,
440
+ });
441
+ const kept = storedFile("kept.png");
442
+ const deleted = storedFile("deleted.png");
443
+ NodeFS.writeFileSync(
444
+ NodePath.join(config.attachmentsDir, `${kept.id}.png`),
445
+ new Uint8Array([1, 2, 3]),
446
+ );
447
+ const captured: OrchestrationV2ServerCommand[] = [];
448
+ const edit = (attachments: ReadonlyArray<typeof kept>) =>
449
+ dispatchCommand({
450
+ type: "queued-run.edit",
451
+ commandId: CommandId.make(`queued-edit-${attachments.length}`),
452
+ threadId: ThreadId.make("thread-queued-edit"),
453
+ runId: RunId.make("run-queued-edit"),
454
+ text: "Edited from a stale view.",
455
+ attachments,
456
+ }).pipe(
457
+ Effect.provide(
458
+ Layer.mock(ThreadManagementService.ThreadManagementService)({
459
+ dispatch: layerFailingDispatchHandler(captured),
460
+ hasReceipt: (commandId) =>
461
+ Effect.succeed(captured.some((command) => command.commandId === commandId)),
462
+ }),
463
+ ),
464
+ Effect.result,
465
+ );
466
+
467
+ yield* edit([kept]);
468
+ expect(captured).toHaveLength(1);
469
+ const result = yield* edit([kept, deleted]);
470
+ expect(result._tag).toBe("Failure");
471
+ expect(captured).toHaveLength(1);
472
+ // A retry of the accepted edit replays its receipt even after a later cleanup removed its file.
473
+ NodeFS.rmSync(NodePath.join(config.attachmentsDir, `${kept.id}.png`));
474
+ yield* edit([kept]);
475
+ expect(captured).toHaveLength(2);
476
+ }).pipe(Effect.provide(layerIntakeTest)),
477
+);
apps/server/src/orchestration-v2/ThreadMessageIntake.ts
+19
@@ -2,6 +2,7 @@ import { remapComposerContextAttachments } from "@t3tools/shared/composerContext
2
import { appendUserInputAttachmentPaths } from "../provider/userInputAttachments.ts";
3
import type { ChatAttachment, OrchestrationV2Command } from "@t3tools/contracts";
4
import * as Effect from "effect/Effect";
5
+import * as FileSystem from "effect/FileSystem";
6
import * as Schema from "effect/Schema";
7
import { resolveAttachmentPath } from "../attachmentStore.ts";
8
import * as ServerConfig from "../config.ts";
@@ -159,6 +160,24 @@ export const dispatchCommand = Effect.fn("ThreadMessageIntake.dispatchCommand")(
160
(command.type !== "queued-run.edit" || command.attachments === undefined)
161
)
162
return yield* threads.dispatch(command);
163
+ // An accepted edit's retry replays its receipt even if a later cleanup removed its files.
164
+ if (command.type === "queued-run.edit" && !(yield* threads.hasReceipt(command.commandId))) {
165
+ const config = yield* ServerConfig.ServerConfig;
166
+ const fileSystem = yield* FileSystem.FileSystem;
167
+ // A stale view can keep a file that another client's edit dropped and deleted.
168
+ for (const attachment of command.attachments ?? []) {
169
+ if (AttachmentClaims.attachmentIsPendingUpload(attachment)) continue;
170
+ const path = resolveAttachmentPath({ attachmentsDir: config.attachmentsDir, attachment });
171
+ if (
172
+ path !== null &&
173
+ !(yield* fileSystem.exists(path).pipe(Effect.orElseSucceed(() => false)))
174
+ ) {
175
+ return yield* new AttachmentClaims.AttachmentClaimError({
176
+ message: `Attachment '${attachment.name}' cannot be sent: attachment not found.`,
177
+ });
178
+ }
179
+ }
180
+ }
181
const claimed = yield* AttachmentClaims.claimPendingAttachments({
182
threadId: command.threadId,
183
attachments: command.attachments ?? [],
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+183
-13
@@ -491,7 +491,8 @@ const layerProjectDeletionTest = Layer.mergeAll(
491
Layer.provide(McpProviderSessions.layer),
492
Layer.provide(SqlitePersistence.layerMemory),
493
Layer.provide(layerCheckpointStoreTest),
494
- Layer.provide(layerServerConfig),
494
+ // Exposed so tests can reach the attachments directory that resource cleanup removes from.
495
+ Layer.provideMerge(layerServerConfig),
496
Layer.provide(ServerSettings.layerTest()),
497
Layer.provide(layerTestProviderInstanceRegistry),
498
Layer.provide(layerGitWorkflowTest),
@@ -680,6 +681,147 @@ it.layer(layerProjectDeletionTest)("project deletion during thread commands", (i
681
}),
682
);
683
684
+ it.effect.each(["no fork", "a live fork"] as const)(
685
+ "a queued edit's cleanup keeps a file earlier history still shows, with %s",
686
+ (fork) =>
687
+ Effect.gen(function* () {
688
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
689
+ const eventSink = yield* EventSink.EventSinkV2;
690
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
691
+ const config = yield* ServerConfig.ServerConfig;
692
+ const fileSystem = yield* FileSystem.FileSystem;
693
+ const path = yield* Path.Path;
694
+ const key = `queued-edit-shared-file-${fork.replaceAll(" ", "-")}`;
695
+ const threadId = ThreadId.make(key);
696
+ const storedFile = (name: string) =>
697
+ ({
698
+ type: "image",
699
+ id: createAttachmentId(threadId)!,
700
+ name: `${name}.png`,
701
+ mimeType: "image/png",
702
+ sizeBytes: 5,
703
+ }) as const;
704
+ const shared = storedFile("shared");
705
+ const dropped = storedFile("dropped");
706
+ const filePath = (file: typeof shared) =>
707
+ path.join(config.attachmentsDir, `${file.id}.png`);
708
+ yield* fileSystem.writeFileString(filePath(shared), "bytes");
709
+ yield* fileSystem.writeFileString(filePath(dropped), "bytes");
710
+ yield* orchestrator.dispatch({
711
+ type: "thread.create",
712
+ commandId: CommandId.make(`${key}:create`),
713
+ createdBy: "user",
714
+ creationSource: "web",
715
+ threadId,
716
+ projectId: ProjectId.make("queued-edit-shared-file-project"),
717
+ title: "Shared file",
718
+ modelSelection,
719
+ runtimeMode: "full-access",
720
+ interactionMode: "default",
721
+ branch: null,
722
+ worktreePath: null,
723
+ });
724
+ const writeRun = Effect.fn("test.writeQueuedEditRun")(function* (input: {
725
+ readonly name: string;
726
+ readonly ordinal: number;
727
+ readonly status: "completed" | "queued";
728
+ readonly attachments: ReadonlyArray<typeof shared>;
729
+ }) {
730
+ const now = yield* DateTime.now;
731
+ const runId = RunId.make(`${key}:${input.name}`);
732
+ const messageId = MessageId.make(`${key}:${input.name}`);
733
+ const completed = input.status === "completed";
734
+ yield* eventSink.write({
735
+ events: [
736
+ {
737
+ id: EventId.make(`${key}:${input.name}:run`),
738
+ type: "run.created",
739
+ threadId,
740
+ runId,
741
+ occurredAt: now,
742
+ payload: {
743
+ id: runId,
744
+ threadId,
745
+ ordinal: input.ordinal,
746
+ providerInstanceId: modelSelection.instanceId,
747
+ modelSelection,
748
+ providerThreadId: null,
749
+ userMessageId: messageId,
750
+ rootNodeId: null,
751
+ activeAttemptId: null,
752
+ status: input.status,
753
+ requestedAt: now,
754
+ startedAt: completed ? now : null,
755
+ completedAt: completed ? now : null,
756
+ checkpointId: null,
757
+ contextHandoffId: null,
758
+ },
759
+ },
760
+ {
761
+ id: EventId.make(`${key}:${input.name}:message`),
762
+ type: "message.updated",
763
+ threadId,
764
+ runId,
765
+ occurredAt: now,
766
+ payload: {
767
+ id: messageId,
768
+ threadId,
769
+ runId,
770
+ nodeId: null,
771
+ role: "user",
772
+ text: `Send ${input.name} work`,
773
+ attachments: input.attachments,
774
+ streaming: false,
775
+ createdBy: "user",
776
+ creationSource: "web",
777
+ createdAt: now,
778
+ updatedAt: now,
779
+ },
780
+ },
781
+ ],
782
+ });
783
+ return runId;
784
+ });
785
+
786
+ const sourceRunId = yield* writeRun({
787
+ name: "source",
788
+ ordinal: 1,
789
+ status: "completed",
790
+ attachments: [shared],
791
+ });
792
+ if (fork !== "no fork") {
793
+ const forkThreadId = ThreadId.make(`${key}:fork`);
794
+ yield* orchestrator.dispatch({
795
+ type: "thread.fork",
796
+ commandId: CommandId.make(`${key}:fork`),
797
+ sourceThreadId: threadId,
798
+ targetThreadId: forkThreadId,
799
+ sourcePoint: { type: "run", runId: sourceRunId },
800
+ createdBy: "user",
801
+ creationSource: "web",
802
+ });
803
+ }
804
+ const queuedRunId = yield* writeRun({
805
+ name: "queued",
806
+ ordinal: 2,
807
+ status: "queued",
808
+ attachments: [shared, dropped],
809
+ });
810
+ yield* orchestrator.dispatch({
811
+ type: "queued-run.edit",
812
+ commandId: CommandId.make(`${key}:edit`),
813
+ threadId,
814
+ runId: queuedRunId,
815
+ text: "Send queued work without files",
816
+ attachments: [],
817
+ });
818
+ yield* worker.drain();
819
+
820
+ assert.isFalse(yield* fileSystem.exists(filePath(dropped)));
821
+ assert.equal(yield* fileSystem.readFileString(filePath(shared)), "bytes");
822
+ }).pipe(Effect.provide(NodeServices.layer)),
823
+ );
824
+
825
it.effect("waits for an in-flight thread update before planning deletion", () =>
826
Effect.gen(function* () {
827
const projects = yield* ProjectService.ProjectService;
@@ -9352,7 +9494,23 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
9494
it.effect("edits and removes queued runs", () =>
9495
Effect.gen(function* () {
9496
const orchestrator = yield* Orchestrator.OrchestratorV2;
9497
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
9498
const threadId = ThreadId.make("runtime-layer-queued-edit-thread");
9499
+ const attachment = (name: string) =>
9500
+ ({
9501
+ type: "image",
9502
+ id: `runtime-layer-queued-edit-${name}`,
9503
+ name: `${name}.png`,
9504
+ mimeType: "image/png",
9505
+ sizeBytes: 128,
9506
+ }) as const;
9507
+ const kept = attachment("kept");
9508
+ const shared = attachment("shared");
9509
+ const dropped = attachment("dropped");
9510
+ const effectRequests = (commandId: string) =>
9511
+ Effect.map(outbox.listByCommandId(CommandId.make(commandId)), (effects) =>
9512
+ effects.map((effect) => effect.request),
9513
+ );
9514
9515
yield* orchestrator.dispatch({
9516
type: "thread.create",
@@ -9376,7 +9534,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
9534
threadId,
9535
messageId: MessageId.make("runtime-layer-queued-edit-active-message"),
9536
text: "Keep the provider occupied.",
9379
- attachments: [],
9537
+ attachments: [shared],
9538
modelSelection,
9539
dispatchMode: { type: "start_immediately" },
9540
});
@@ -9421,22 +9579,33 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
9579
threadId,
9580
runId: queuedRun.id,
9581
text: "Updated queued text with an attachment.",
9424
- attachments: [
9425
- {
9426
- type: "image",
9427
- id: "runtime-layer-queued-edit-attachment",
9428
- name: "screenshot.png",
9429
- mimeType: "image/png",
9430
- sizeBytes: 128,
9431
- },
9432
- ],
9582
+ attachments: [kept, shared, dropped],
9583
+ });
9584
+ yield* orchestrator.dispatch({
9585
+ type: "queued-run.edit",
9586
+ commandId: CommandId.make("runtime-layer-queued-edit-drop-attachments"),
9587
+ threadId,
9588
+ runId: queuedRun.id,
9589
+ text: "Updated queued text with an attachment.",
9590
+ attachments: [kept],
9591
});
9592
const afterAttachmentEdit = yield* orchestrator.getThreadProjection(threadId);
9593
assert.deepEqual(
9594
afterAttachmentEdit.messages
9595
.find((message) => message.id === queuedRun.userMessageId)
9596
?.attachments.map((attachment) => attachment.id),
9439
- ["runtime-layer-queued-edit-attachment"],
9597
+ [kept.id],
9598
+ );
9599
+ assert.deepEqual(
9600
+ yield* effectRequests("runtime-layer-queued-edit-drop-attachments"),
9601
+ [
9602
+ {
9603
+ type: "attachment.cleanup",
9604
+ attachmentIds: [shared.id, dropped.id],
9605
+ skipReferenced: true,
9606
+ },
9607
+ ],
9608
+ "dropped files are queued for a cleanup that skips files the thread still references",
9609
);
9610
9611
yield* orchestrator.dispatch({
@@ -9451,9 +9620,10 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
9620
afterTextOnlyEdit.messages
9621
.find((message) => message.id === queuedRun.userMessageId)
9622
?.attachments.map((attachment) => attachment.id),
9454
- ["runtime-layer-queued-edit-attachment"],
9623
+ [kept.id],
9624
"an edit without attachments must leave the stored attachments untouched",
9625
);
9626
+ assert.deepEqual(yield* effectRequests("runtime-layer-queued-edit-text-only"), []);
9627
9628
const emptyEditError = yield* orchestrator
9629
.dispatch({
apps/server/src/orchestration-v2/runtimeLayer.ts
+1
@@ -343,6 +343,7 @@ const layerEffectExecutorProvided = EffectWorker.layerExecutor.pipe(
343
layerRuntimeRequestServiceProvided,
344
layerThreadTitleRegenerationProvided,
345
layerThreadManagementProvided,
346
+ ProjectionStore.layer,
347
),
348
),
349
);
apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
+1
@@ -552,6 +552,7 @@ export function layerWithRegistry<Error>(
552
layerThreadTitleRegenerationTest,
553
layerServerSettings,
554
layerThreadManagementProvided,
555
+ layerStores,
556
),
557
),
558
);