@@ -1293,7 +1293,13 @@ function testMemoryTaskAdmissionV2Contract() {
12931293 actualInstructionEnvelope : envelope ,
12941294 workItemSet,
12951295 workflowRouteDecision : route ,
1296- stickyProject : projectTargetLease
1296+ stickyProject : projectTargetLease ,
1297+ contextAcquisition : {
1298+ contextEpoch : envelope . contextEpoch ,
1299+ hostSessionId : 'mcp-admission-session' ,
1300+ activeRoot,
1301+ project
1302+ }
12971303 }
12981304 fs . writeFileSync ( lifecycleStatePath , JSON . stringify ( lifecycleState , null , 2 ) + '\n' )
12991305 const args = {
@@ -1421,6 +1427,20 @@ function testMemoryTaskAdmissionV2Contract() {
14211427 assert . strictEqual ( admitted . structuredContent . ownerAcquisition . cp1Confirmed , false )
14221428 assert . strictEqual ( admitted . structuredContent . continuationLease . status , 'consumed' )
14231429 assert . strictEqual ( admitted . structuredContent . ownerAcquisition . finalized , true )
1430+ // The next Hook reads canonical task state, not the pre-admission projection.
1431+ // Automatic owner acquisition must carry the verified ingress across that
1432+ // boundary, just as an explicit owner renewal does.
1433+ const admittedState = readTaskRecoveryState ( {
1434+ metaDir : resolveTaskRecoveryMetaDir ( { activeRoot, project } ) ,
1435+ identity : { activeRoot, project, taskId : admitted . structuredContent . taskId , taskStatus : 'active' }
1436+ } )
1437+ assert . strictEqual ( admittedState . status , 'fresh' )
1438+ assert . deepStrictEqual ( admittedState . state . actualInstructionEnvelope , envelope )
1439+ assert . deepStrictEqual ( admittedState . state . workflowRouteDecision , route )
1440+ assert . deepStrictEqual ( admittedState . state . workItemSet , workItemSet )
1441+ assert . deepStrictEqual ( admittedState . state . stickyProject , projectTargetLease )
1442+ assert . strictEqual ( admittedState . state . contextAcquisition . contextEpoch , envelope . contextEpoch )
1443+ assert . strictEqual ( admittedState . state . contextAcquisition . hostSessionId , 'mcp-admission-session' )
14241444 const replay = resultById ( responses , 3 )
14251445 assert . strictEqual ( replay . isError , false )
14261446 assert . strictEqual ( replay . structuredContent . admissionId , admitted . structuredContent . admissionId )
@@ -1459,6 +1479,29 @@ function testMemoryTaskAdmissionV2Contract() {
14591479 } ) ] , TEMP_ROOT )
14601480 assert . notStrictEqual ( resultById ( firstCp , 9 ) . isError , true , resultById ( firstCp , 9 ) . content ?. [ 0 ] ?. text )
14611481 assert . doesNotMatch ( fs . readFileSync ( path . join ( taskRoot , '.memory' , 'sessions.md' ) , 'utf8' ) , / \| C P 1 \| ⏳ \| / u)
1482+ for ( const [ label , drift ] of [
1483+ [ 'other-session' , { hostSessionId : 'another-host-session' } ] ,
1484+ [ 'other-root' , { activeRoot : path . join ( TEMP_ROOT , 'another-active-root' ) } ]
1485+ ] ) {
1486+ setupLegacyWorkspace ( )
1487+ fs . mkdirSync ( path . dirname ( lifecycleStatePath ) , { recursive : true } )
1488+ fs . writeFileSync ( lifecycleStatePath , JSON . stringify ( { ...lifecycleState ,
1489+ contextAcquisition : { ...lifecycleState . contextAcquisition , ...drift }
1490+ } ) + '\n' )
1491+ const observed = resultById ( runServer ( 'mcp/memory-server.js' , [ rpcRequest ( 10 , 'tools/call' , {
1492+ name : 'memory_task_admit_v2' , arguments : { ...args ,
1493+ task : { ...args . task , displayName : `MCP-context-${ label } ` , aliases : [ ] }
1494+ }
1495+ } ) ] , TEMP_ROOT ) , 10 )
1496+ assert . notStrictEqual ( observed . isError , true , observed . content ?. [ 0 ] ?. text )
1497+ const isolated = readTaskRecoveryState ( {
1498+ metaDir : resolveTaskRecoveryMetaDir ( { activeRoot, project } ) ,
1499+ identity : { activeRoot, project, taskId : observed . structuredContent . taskId , taskStatus : 'active' }
1500+ } )
1501+ assert . strictEqual ( isolated . status , 'fresh' )
1502+ assert . deepStrictEqual ( isolated . state . actualInstructionEnvelope , envelope )
1503+ assert ( ! isolated . state . contextAcquisition ?. hostSessionId , `${ label } context must not be inherited` )
1504+ }
14621505}
14631506
14641507function testMemoryFinalizedFreshResumeV3Contract ( ) {
0 commit comments