@@ -2059,6 +2059,32 @@ describe("SessionRunnerLLM", () => {
20592059 yield * s . runPrompt ( "Fourth" )
20602060
20612061 expect ( s . requests . at ( - 1 ) ?. system . map ( ( part ) => part . text ) ) . toEqual ( [ defaultSystem , fakeIdentity , "Latest context" ] )
2062+ // The surviving "Changed context" update predates the fresh baseline and would contradict it.
2063+ expect ( messageRoles ( s . requests . at ( - 1 ) ) ) . toEqual ( [ "user" , "user" ] )
2064+ expect ( ( yield * s . context ) . some ( ( message ) => message . type === "system" ) ) . toBe ( false )
2065+ } )
2066+
2067+ scenario ( "hides an update a revert left behind once the source is removed" , function * ( s ) {
2068+ s . systemRemoved = true
2069+ yield * s . runPrompt ( "First" )
2070+ s . systemRemoved = false
2071+ s . systemBaseline = "Entered mode"
2072+ const second = yield * s . runPrompt ( "Second" )
2073+ s . systemRemoved = true
2074+ yield * s . runPrompt ( "Third" )
2075+
2076+ // The removal is delivered with "Third"; the "Entered mode" update survives before "Second".
2077+ yield * s . bus . publish ( SessionEvent . RevertEvent . Committed , { sessionID, to : second . id } )
2078+ yield * s . runPrompt ( "Fourth" )
2079+
2080+ const last = s . requests . at ( - 1 ) !
2081+ expect ( systemTexts ( last ) ) . toEqual ( [ ] )
2082+ expect ( userTexts ( last ) ) . toEqual ( [ "First" , "Fourth" ] )
2083+ expect ( last . system . map ( ( part ) => part . text ) . join ( "\n" ) ) . not . toContain ( "Entered mode" )
2084+ // Clients still see every message; only the model context hides the stale update.
2085+ expect ( ( yield * s . messages ) . filter ( ( message ) => message . type === "system" ) ) . toMatchObject ( [
2086+ { text : "Entered mode" } ,
2087+ ] )
20622088 } )
20632089
20642090 scenario ( "uses the selected model family prompt when the agent does not override it" , function * ( s ) {
0 commit comments