@@ -1225,10 +1225,6 @@ const layer = Layer.effect(
12251225 throw new Error ( "Impossible" )
12261226 } )
12271227
1228- /**
1229- * A wake enters an existing turn rather than creating one, so there is no new user message to
1230- * own. Claim the latest one instead, which is what the scope's turn evidence is keyed against.
1231- */
12321228 const ownLatestUser = Effect . fn ( "SessionPrompt.ownLatestUser" ) ( function * (
12331229 attachment : AttachmentCoordinator . Scope | undefined ,
12341230 sessionID : SessionID ,
@@ -1325,6 +1321,7 @@ const layer = Layer.effect(
13251321 auto : task . auto ,
13261322 overflow : task . overflow ,
13271323 } )
1324+ yield * ownLatestUser ( turnAttachment , sessionID )
13281325 if ( result === "stop" ) break
13291326 continue
13301327 }
@@ -1335,6 +1332,7 @@ const layer = Layer.effect(
13351332 ( yield * compaction . isOverflow ( { tokens : lastFinished . tokens , model } ) )
13361333 ) {
13371334 yield * compaction . create ( { sessionID, agent : lastUser . agent , model : lastUser . model , auto : true } )
1335+ yield * ownLatestUser ( turnAttachment , sessionID )
13381336 continue
13391337 }
13401338
@@ -1536,6 +1534,7 @@ const layer = Layer.effect(
15361534 auto : true ,
15371535 overflow : ! handle . message . finish ,
15381536 } )
1537+ yield * ownLatestUser ( turnAttachment , sessionID )
15391538 }
15401539 return "continue" as const
15411540 } ) . pipe (
@@ -1550,14 +1549,21 @@ const layer = Layer.effect(
15501549 return yield * lastAssistant ( sessionID )
15511550 } )
15521551
1552+ // Attachment carriage is an invocation-private Task seam, not part of the generic SessionPrompt
1553+ // service. Validate the handed capability before Runner arbitration so even a joined Runner cannot
1554+ // let a wrong-Session scope reach Task execution or observer state. This observes no registry and
1555+ // confers no authority over unrelated ingress.
15531556 const loopWithAttachment : (
15541557 input : LoopInput ,
15551558 attachment ?: AttachmentCoordinator . Scope ,
15561559 ) => Effect . Effect < SessionV1 . WithParts , AdmissionError > = Effect . fn ( "SessionPrompt.loopWithAttachment" ) ( function * (
15571560 input : LoopInput ,
15581561 attachment ?: AttachmentCoordinator . Scope ,
15591562 ) {
1560- yield * ownLatestUser ( attachment , input . sessionID )
1563+ if ( attachment && attachment . sessionID !== input . sessionID ) {
1564+ yield * attachment . degrade ( )
1565+ return yield * Effect . die ( new Error ( `Attachment scope does not belong to session ${ input . sessionID } ` ) )
1566+ }
15611567 return yield * state . ensureRunning (
15621568 input . sessionID ,
15631569 lastAssistant ( input . sessionID ) ,
0 commit comments