@@ -2272,6 +2272,54 @@ describe("compaction-safeguard recent-turn preservation", () => {
22722272 expect ( result . compaction ?. summary ) . not . toContain ( "Old duplicated section" ) ;
22732273 } ) ;
22742274
2275+ it ( "preserves the prior summary when staged summarization returns a generic fallback" , async ( ) => {
2276+ mockSummarizeInStages . mockReset ( ) ;
2277+ mockSummarizeInStages . mockResolvedValue ( {
2278+ kind : "generic-fallback" ,
2279+ text : "Context contained 4 messages. Summary unavailable due to size limits." ,
2280+ } ) ;
2281+
2282+ const sessionManager = stubSessionManager ( ) ;
2283+ const model = createAnthropicModelFixture ( ) ;
2284+ setCompactionSafeguardRuntime ( sessionManager , {
2285+ model,
2286+ recentTurnsPreserve : 0 ,
2287+ } ) ;
2288+
2289+ const compactionHandler = createCompactionHandler ( ) ;
2290+ const mockContext = createCompactionContext ( {
2291+ sessionManager,
2292+ getApiKeyMock : vi . fn ( ) . mockResolvedValue ( "test-key" ) ,
2293+ } ) ;
2294+ const event = {
2295+ preparation : {
2296+ messagesToSummarize : [ { role : "user" , content : "latest ask status" , timestamp : 1 } ] ,
2297+ turnPrefixMessages : [ ] ,
2298+ firstKeptEntryId : "entry-1" ,
2299+ tokensBefore : 1_500 ,
2300+ fileOps : {
2301+ read : [ ] ,
2302+ edited : [ ] ,
2303+ written : [ ] ,
2304+ } ,
2305+ settings : { reserveTokens : 4_000 } ,
2306+ previousSummary : "## Goal\nKnown context that must survive the outage." ,
2307+ isSplitTurn : false ,
2308+ } ,
2309+ customInstructions : "" ,
2310+ signal : new AbortController ( ) . signal ,
2311+ } ;
2312+
2313+ const result = ( await compactionHandler ( event , mockContext ) ) as {
2314+ cancel ?: boolean ;
2315+ compaction ?: { summary ?: string } ;
2316+ } ;
2317+
2318+ expect ( result . cancel ) . not . toBe ( true ) ;
2319+ expect ( result . compaction ?. summary ) . toContain ( "Known context that must survive the outage." ) ;
2320+ expect ( result . compaction ?. summary ) . toContain ( "Summary unavailable due to size limits." ) ;
2321+ } ) ;
2322+
22752323 it ( "falls back to LLM when provider throws a provider-side AbortError with signal not aborted" , async ( ) => {
22762324 // Reproduce the undici AbortError("This operation was aborted") shape that
22772325 // arrives when the compaction provider's HTTP connection drops mid-stream while
0 commit comments