The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(server): guests of a forked thread can open files on the messages it inherited (#29794)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 19:23 UTC
a9468dab74df255ce7f1a601ca1a73ef743d51e9
3 files changed
+106
-1
apps/server/src/guest/GuestShareService.test.ts
+76
@@ -965,6 +965,82 @@ it.effect("serves the shared thread's files to its guest, never another thread's
965
}).pipe(Effect.scoped, Effect.provide(layerTest)),
966
);
967
968
+it.effect("gives a fork's guest the files on messages the fork shows from its source", () =>
969
+ Effect.gen(function* () {
970
+ const { orchestrator } = yield* shareThread;
971
+ const guestShares = yield* GuestShareService.GuestShareService;
972
+ const { attachmentsDir } = yield* ServerConfig.ServerConfig;
973
+ const fileSystem = yield* FileSystem.FileSystem;
974
+ const ownerImage = Effect.fn(function* (name: string) {
975
+ const image = {
976
+ type: "image" as const,
977
+ id: ChatAttachmentId.make(createAttachmentId(threadId)!),
978
+ name,
979
+ mimeType: "image/png",
980
+ sizeBytes: PNG.length,
981
+ };
982
+ yield* fileSystem.writeFile(
983
+ resolveAttachmentPath({ attachmentsDir, attachment: image })!,
984
+ PNG,
985
+ );
986
+ yield* orchestrator.dispatch({
987
+ type: "message.dispatch",
988
+ commandId: CommandId.make(`owner:${name}`),
989
+ threadId,
990
+ messageId: MessageId.make(`message:${name}`),
991
+ text: name,
992
+ attachments: [image],
993
+ dispatchMode: { type: "defer_start" },
994
+ createdBy: "user",
995
+ creationSource: "web",
996
+ });
997
+ return image;
998
+ });
999
+ const inherited = yield* ownerImage("before.png");
1000
+ const run = (yield* orchestrator.getThreadRecords(threadId, ["runs"])).runs[0]!;
1001
+ const now = yield* DateTime.now;
1002
+ yield* (yield* EventSink.EventSinkV2).write({
1003
+ events: [
1004
+ {
1005
+ id: EventId.make("event:run-done"),
1006
+ type: "run.updated",
1007
+ threadId,
1008
+ runId: run.id,
1009
+ providerInstanceId: instanceId,
1010
+ occurredAt: now,
1011
+ payload: { ...run, status: "completed", completedAt: now },
1012
+ },
1013
+ ],
1014
+ });
1015
+ const forkId = ThreadId.make("thread:guest-share-fork");
1016
+ yield* orchestrator.dispatch({
1017
+ type: "thread.fork",
1018
+ commandId: CommandId.make("fork"),
1019
+ sourceThreadId: threadId,
1020
+ targetThreadId: forkId,
1021
+ sourcePoint: { type: "run", runId: run.id },
1022
+ createdBy: "user",
1023
+ creationSource: "web",
1024
+ });
1025
+ const later = yield* ownerImage("after.png");
1026
+ const { url } = yield* guestShares.create({ threadId: forkId });
1027
+ const { token: session } = yield* guestShares.redeem({
1028
+ credential: url.slice(url.indexOf("#") + 1),
1029
+ name: "Sam",
1030
+ });
1031
+
1032
+ assert.equal(
1033
+ (yield* guestShares.attachment(session, inherited.id)).attachment.id,
1034
+ inherited.id,
1035
+ );
1036
+ // The source's messages after the fork point are not part of the fork.
1037
+ assert.equal(
1038
+ (yield* Effect.flip(guestShares.attachment(session, later.id))).reason,
1039
+ "unavailable",
1040
+ );
1041
+ }).pipe(Effect.provide(layerTest)),
1042
+);
1043
+
1044
it.effect("serves an image on the host only when an agent reply the guest sees shows it", () =>
1045
Effect.gen(function* () {
1046
const { orchestrator, guestShares } = yield* shareThread;
apps/server/src/guest/GuestShareService.ts
+12
-1
@@ -715,7 +715,18 @@ const make = Effect.gen(function* () {
715
.find((candidate) => candidate.id === attachmentId),
716
),
717
Effect.mapError(() => unavailable),
718
- ));
718
+ )) ??
719
+ // A fork shows its source's earlier messages, which stay in the source thread.
720
+ (thread.forkedFrom === null
721
+ ? undefined
722
+ : yield* orchestrator.getTimelinePage(thread.id, { attachmentId, limit: 1 }).pipe(
723
+ Effect.map(({ items }) =>
724
+ items
725
+ .flatMap(({ item }) => (item.type === "user_message" ? item.attachments : []))
726
+ .find((candidate) => candidate.id === attachmentId),
727
+ ),
728
+ Effect.mapError(() => unavailable),
729
+ ));
730
const path =
731
found === undefined ? null : resolveAttachmentPath({ attachmentsDir, attachment: found });
732
if (found === undefined || path === null) return yield* unavailable;
apps/server/src/orchestration-v2/ProjectionStore.ts
+18
@@ -394,6 +394,7 @@ export type ProjectionRecords<K extends ProjectionRecordField> = Pick<
394
export interface ProjectionTimelinePageOptions {
395
readonly afterPosition?: number;
396
readonly itemId?: TurnItemId;
397
+ readonly attachmentId?: string;
398
readonly view?: "messages" | "activity";
399
readonly limit: number;
400
}
@@ -5835,6 +5836,20 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5836
.withTransaction(
5837
Effect.gen(function* () {
5838
const index = yield* readTimelineIndex(threadId, new Set());
5839
+ const attachmentOwners =
5840
+ options.attachmentId === undefined
5841
+ ? undefined
5842
+ : new Set(
5843
+ (yield* sql<{ thread_id: string; turn_item_id: string }>`
5844
+ SELECT item.thread_id, item.turn_item_id
5845
+ FROM orchestration_v2_projection_turn_items AS item,
5846
+ json_each(item.payload_json, '$.attachments') AS attachment
5847
+ WHERE item.thread_id IN ${sql.in([...new Set(index.visible.map((row) => row.sourceThreadId))])}
5848
+ AND item.type = 'user_message'
5849
+ AND json_extract(attachment.value, '$.id') = ${options.attachmentId}`).map(
5850
+ (row) => `${row.thread_id}:${row.turn_item_id}`,
5851
+ ),
5852
+ );
5853
const matching = index.visible
5854
.map((row, position) => ({ ...row, position }))
5855
.filter((row) =>
@@ -5845,6 +5860,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5860
row.item.type,
5861
))
5862
: row.sourceItemId === options.itemId,
5863
+ )
5864
+ .filter(
5865
+ (row) => attachmentOwners?.has(`${row.sourceThreadId}:${row.sourceItemId}`) ?? true,
5866
);
5867
const page = matching.slice(0, options.limit);
5868
const sources = yield* encodeTimelineSources(