@@ -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} ) ;
0 commit comments