@@ -44,8 +44,6 @@ type ResetMessageWindow = {
4444 postBoundaryMessagePosition : number ;
4545 /** Active position of the reset row; events at or before it are pre-boundary. */
4646 boundaryActivePosition : number ;
47- /** Start of the retained span before the boundary, when firstKeptEntryId applies. */
48- keptFromActivePosition : number | undefined ;
4947} ;
5048
5149type ResetMessageWindowCacheEntry = {
@@ -171,7 +169,6 @@ function findLatestResetMessageWindow(
171169 . limit ( 1 ) ,
172170 ) ?. message_position ?? projection . state . activeMessageCount ;
173171 let keptMessagePositions : number [ ] = [ ] ;
174- let keptFromActivePosition : number | undefined ;
175172 if ( typeof reset . firstKeptEntryId === "string" ) {
176173 const firstKept = executeSqliteQueryTakeFirstSync (
177174 projection . database . db ,
@@ -187,7 +184,6 @@ function findLatestResetMessageWindow(
187184 . where ( "identity.event_id" , "=" , reset . firstKeptEntryId ) ,
188185 ) ;
189186 if ( firstKept && firstKept . active_position < resetRow . active_position ) {
190- keptFromActivePosition = firstKept . active_position ;
191187 keptMessagePositions = executeSqliteQuerySync (
192188 projection . database . db ,
193189 db
@@ -223,7 +219,6 @@ function findLatestResetMessageWindow(
223219 keptMessagePositions,
224220 postBoundaryMessagePosition,
225221 boundaryActivePosition : resetRow . active_position ,
226- keptFromActivePosition,
227222 } ;
228223}
229224
@@ -342,16 +337,18 @@ export function readVisibleTranscriptByteStats(projection: ResetWindowProjection
342337 window
343338 ? base . where ( ( eb ) => {
344339 const afterBoundary = eb ( "active.active_position" , ">" , window . boundaryActivePosition ) ;
345- const keptFrom = window . keptFromActivePosition ;
346- if ( keptFrom === undefined ) {
340+ const keptMessagePositions = window . keptMessagePositions ;
341+ if ( keptMessagePositions . length === 0 ) {
347342 return afterBoundary ;
348343 }
349- // Retained pre-boundary span stays visible, so its bytes still count.
344+ // A reset retains only the user/assistant messages named by the window, so
345+ // count those exact rows rather than the whole pre-boundary span. Including
346+ // the span would keep discarded tool results on the byte fuse after `/new`.
350347 return eb . or ( [
351348 afterBoundary ,
352349 eb . and ( [
353- eb ( "active.active_position" , ">=" , keptFrom ) ,
354350 eb ( "active.active_position" , "<" , window . boundaryActivePosition ) ,
351+ eb ( "active.message_position" , "in" , keptMessagePositions ) ,
355352 ] ) ,
356353 ] ) ;
357354 } )
0 commit comments