@@ -767,8 +767,13 @@ describe("embedded attempt session lock lifecycle", () => {
767767
768768 await controller . releaseForPrompt ( ) ;
769769 await controller . reacquireAfterPrompt ( ) ;
770+ // Post-reacquire owned write: an owned append landing after the prompt
771+ // stream's lock reacquisition still publishes through the trust gate (the
772+ // fence stays active), so cleanup must not flag it as a takeover. Distinct
773+ // from the in-prompt publish path the trust-gate suite below covers.
774+ const beforeWrite = readSessionFileFingerprintSync ( sessionFile ) ;
770775 await fs . appendFile ( sessionFile , '{"type":"message","id":"provider-error"}\n' , "utf8" ) ;
771- controller . refreshAfterOwnedSessionWrite ( ) ;
776+ controller . publishOwnedPostMessageWrite ( beforeWrite ) ;
772777
773778 const cleanupLock = await controller . acquireForCleanup ( ) ;
774779 await cleanupLock . release ( ) ;
@@ -854,23 +859,6 @@ describe("embedded attempt session lock lifecycle", () => {
854859 expect ( release ) . toHaveBeenCalledTimes ( 3 ) ;
855860 } ) ;
856861
857- it ( "refreshes the prompt fence after an owned session manager append" , async ( ) => {
858- const sessionFile = await createTempSessionFile ( ) ;
859- const release = vi . fn ( async ( ) => { } ) ;
860- const acquireSessionWriteLockLocal3 = vi . fn ( async ( ) => ( { release } ) ) ;
861- const controller = await createEmbeddedAttemptSessionLockController ( {
862- acquireSessionWriteLock : acquireSessionWriteLockLocal3 ,
863- lockOptions : { ...lockOptions , sessionFile } ,
864- } ) ;
865-
866- await controller . releaseForPrompt ( ) ;
867- await fs . appendFile ( sessionFile , '{"type":"message","id":"owned-session-manager"}\n' , "utf8" ) ;
868- controller . refreshAfterOwnedSessionWrite ( ) ;
869-
870- await expect ( controller . withSessionWriteLock ( ( ) => "finalize" ) ) . resolves . toBe ( "finalize" ) ;
871- expect ( controller . hasSessionTakeover ( ) ) . toBe ( false ) ;
872- } ) ;
873-
874862 it ( "allows post-prompt writes after the prompt context publishes an owned transcript write" , async ( ) => {
875863 const sessionFile = await createTempSessionFile ( ) ;
876864 const releases : string [ ] = [ ] ;
0 commit comments