@@ -197,6 +197,33 @@ test("sessions.patch rejects a mismatched reclaimed identity without archiving",
197197 expect ( loadSessionEntry ( { storePath, sessionKey } ) ?. archivedAt ) . toBeUndefined ( ) ;
198198} ) ;
199199
200+ test ( "sessions.patch rejects a reclaimed return when its authoritative placement stayed active" , async ( ) => {
201+ const { storePath } = await createSessionStoreDir ( ) ;
202+ const sessionKey = "agent:main:archive-cloud-stale-reclaim" ;
203+ const sessionId = "session-archive-cloud-stale-reclaim" ;
204+ await writeSessionStore ( { entries : { [ sessionKey ] : sessionStoreEntry ( sessionId ) } } ) ;
205+ const placement = workerPlacement ( { sessionId, sessionKey, state : "active" } ) ;
206+ const reclaim = vi . fn ( async ( ) => workerPlacement ( { sessionId, sessionKey, state : "reclaimed" } ) ) ;
207+
208+ const archived = await directSessionReq (
209+ "sessions.patch" ,
210+ { key : sessionKey , archived : true , expectedSessionId : sessionId } ,
211+ {
212+ context : {
213+ workerSessionPlacementService : placementReader ( ( ) => placement ) ,
214+ workerPlacementDispatchService : { dispatch : vi . fn ( ) , reclaim } ,
215+ } ,
216+ } ,
217+ ) ;
218+
219+ expect ( archived ) . toMatchObject ( {
220+ ok : false ,
221+ error : { code : "UNAVAILABLE" , retryable : true } ,
222+ } ) ;
223+ expect ( reclaim ) . toHaveBeenCalledOnce ( ) ;
224+ expect ( loadSessionEntry ( { storePath, sessionKey } ) ?. archivedAt ) . toBeUndefined ( ) ;
225+ } ) ;
226+
200227test ( "sessions.patch rejects a placement identity changed during the runtime drain" , async ( ) => {
201228 const { storePath } = await createSessionStoreDir ( ) ;
202229 const sessionKey = "agent:main:archive-cloud-fresh-placement" ;
0 commit comments