@@ -521,7 +521,7 @@ export async function compactConversation(
521521 }
522522
523523 // Store the current file state before clearing
524- const preCompactReadFileState = cacheToObject ( context . readFileState )
524+ let preCompactReadFileState = cacheToObject ( context . readFileState )
525525
526526 // Clear the cache
527527 context . readFileState . clear ( )
@@ -543,6 +543,9 @@ export async function compactConversation(
543543 ) ,
544544 createAsyncAgentAttachmentsIfNeeded ( context ) ,
545545 ] )
546+ // Release the readFileState snapshot — it can hold 25+ MB of file content
547+ preCompactReadFileState =
548+ undefined as unknown as typeof preCompactReadFileState
546549
547550 const postCompactFileAttachments : AttachmentMessage [ ] = [
548551 ...fileAttachments ,
@@ -649,6 +652,8 @@ export async function compactConversation(
649652
650653 // Extract compaction API usage metrics
651654 const compactionUsage = getTokenUsage ( summaryResponse )
655+ // Release the full API response — it holds content blocks + usage metadata
656+ summaryResponse = undefined as unknown as typeof summaryResponse
652657
653658 const querySourceForEvent =
654659 recompactionInfo ?. querySource ?? context . options . querySource ?? 'unknown'
@@ -922,7 +927,7 @@ export async function partialCompactConversation(
922927 }
923928
924929 // Store the current file state before clearing
925- const preCompactReadFileState = cacheToObject ( context . readFileState )
930+ let preCompactReadFileState = cacheToObject ( context . readFileState )
926931 context . readFileState . clear ( )
927932 context . loadedNestedMemoryPaths ?. clear ( )
928933 // Intentionally NOT resetting sentSkillNames — see compactConversation()
@@ -937,6 +942,9 @@ export async function partialCompactConversation(
937942 ) ,
938943 createAsyncAgentAttachmentsIfNeeded ( context ) ,
939944 ] )
945+ // Release the readFileState snapshot — it can hold 25+ MB of file content
946+ preCompactReadFileState =
947+ undefined as unknown as typeof preCompactReadFileState
940948
941949 const postCompactFileAttachments : AttachmentMessage [ ] = [
942950 ...fileAttachments ,
@@ -992,6 +1000,8 @@ export async function partialCompactConversation(
9921000 summaryResponse ,
9931001 ] )
9941002 const compactionUsage = getTokenUsage ( summaryResponse )
1003+ // Release the full API response — it holds content blocks + usage metadata
1004+ summaryResponse = undefined as unknown as typeof summaryResponse
9951005
9961006 logEvent ( 'tengu_partial_compact' , {
9971007 preCompactTokenCount,
0 commit comments