@@ -203,6 +203,13 @@ interface CloudLogGapReconcileRequest {
203203 logUrl ?: string ;
204204}
205205
206+ interface ParsedSessionLogs {
207+ rawEntries : StoredLogEntry [ ] ;
208+ totalLineCount : number ;
209+ sessionId ?: string ;
210+ adapter ?: Adapter ;
211+ }
212+
206213interface CloudLogGapReconcileState {
207214 pendingRequest ?: CloudLogGapReconcileRequest ;
208215}
@@ -2785,7 +2792,10 @@ export class SessionService {
27852792 taskDescription ?: string ,
27862793 ) : void {
27872794 void ( async ( ) => {
2788- const { rawEntries } = await this . fetchSessionLogs ( logUrl , taskRunId ) ;
2795+ const { rawEntries, totalLineCount } = await this . fetchSessionLogs (
2796+ logUrl ,
2797+ taskRunId ,
2798+ ) ;
27892799
27902800 const session = sessionStoreSetters . getSessionByTaskId ( taskId ) ;
27912801 if ( ! session || session . taskRunId !== taskRunId ) {
@@ -2827,7 +2837,7 @@ export class SessionService {
28272837 events,
28282838 isCloud : true ,
28292839 logUrl : logUrl ?? session . logUrl ,
2830- processedLineCount : rawEntries . length ,
2840+ processedLineCount : totalLineCount ,
28312841 } ) ;
28322842 // Without this the "Galumphing…" indicator stays hidden when the hydrated
28332843 // baseline already contains an in-flight session/prompt — the live delta
@@ -3536,16 +3546,13 @@ export class SessionService {
35363546 } ;
35373547 }
35383548
3539- private parseLogContent ( content : string ) : {
3540- rawEntries : StoredLogEntry [ ] ;
3541- sessionId ?: string ;
3542- adapter ?: Adapter ;
3543- } {
3549+ private parseLogContent ( content : string ) : ParsedSessionLogs {
35443550 const rawEntries : StoredLogEntry [ ] = [ ] ;
35453551 let sessionId : string | undefined ;
35463552 let adapter : Adapter | undefined ;
3553+ const lines = content . trim ( ) . split ( "\n" ) ;
35473554
3548- for ( const line of content . trim ( ) . split ( "\n" ) ) {
3555+ for ( const line of lines ) {
35493556 try {
35503557 const stored = JSON . parse ( line ) as StoredLogEntry ;
35513558 rawEntries . push ( stored ) ;
@@ -3568,26 +3575,17 @@ export class SessionService {
35683575 }
35693576 }
35703577
3571- return { rawEntries, sessionId, adapter } ;
3578+ return { rawEntries, totalLineCount : lines . length , sessionId, adapter } ;
35723579 }
35733580
35743581 private async fetchSessionLogs (
35753582 logUrl : string | undefined ,
35763583 taskRunId ?: string ,
35773584 options : { minEntryCount ?: number } = { } ,
3578- ) : Promise < {
3579- rawEntries : StoredLogEntry [ ] ;
3580- sessionId ?: string ;
3581- adapter ?: Adapter ;
3582- } > {
3583- if ( ! logUrl && ! taskRunId ) return { rawEntries : [ ] } ;
3584- let localResult :
3585- | {
3586- rawEntries : StoredLogEntry [ ] ;
3587- sessionId ?: string ;
3588- adapter ?: Adapter ;
3589- }
3590- | undefined ;
3585+ ) : Promise < ParsedSessionLogs > {
3586+ const empty : ParsedSessionLogs = { rawEntries : [ ] , totalLineCount : 0 } ;
3587+ if ( ! logUrl && ! taskRunId ) return empty ;
3588+ let localResult : ParsedSessionLogs | undefined ;
35913589
35923590 if ( taskRunId ) {
35933591 try {
@@ -3598,7 +3596,7 @@ export class SessionService {
35983596 localResult = this . parseLogContent ( localContent ) ;
35993597 if (
36003598 ! options . minEntryCount ||
3601- localResult . rawEntries . length >= options . minEntryCount
3599+ localResult . totalLineCount >= options . minEntryCount
36023600 ) {
36033601 return localResult ;
36043602 }
@@ -3610,11 +3608,11 @@ export class SessionService {
36103608 }
36113609 }
36123610
3613- if ( ! logUrl ) return localResult ?? { rawEntries : [ ] } ;
3611+ if ( ! logUrl ) return localResult ?? empty ;
36143612
36153613 try {
36163614 const content = await trpcClient . logs . fetchS3Logs . query ( { logUrl } ) ;
3617- if ( ! content ?. trim ( ) ) return localResult ?? { rawEntries : [ ] } ;
3615+ if ( ! content ?. trim ( ) ) return localResult ?? empty ;
36183616
36193617 const result = this . parseLogContent ( content ) ;
36203618
@@ -3635,7 +3633,7 @@ export class SessionService {
36353633
36363634 return result ;
36373635 } catch {
3638- return localResult ?? { rawEntries : [ ] } ;
3636+ return localResult ?? empty ;
36393637 }
36403638 }
36413639
@@ -3705,9 +3703,11 @@ export class SessionService {
37053703 newEntries,
37063704 logUrl,
37073705 } : CloudLogGapReconcileRequest ) : Promise < void > {
3708- const { rawEntries } = await this . fetchSessionLogs ( logUrl , taskRunId , {
3709- minEntryCount : expectedCount ,
3710- } ) ;
3706+ const { rawEntries, totalLineCount } = await this . fetchSessionLogs (
3707+ logUrl ,
3708+ taskRunId ,
3709+ { minEntryCount : expectedCount } ,
3710+ ) ;
37113711 const session = sessionStoreSetters . getSessions ( ) [ taskRunId ] ;
37123712 if ( ! session || session . taskId !== taskId ) {
37133713 return ;
@@ -3718,7 +3718,7 @@ export class SessionService {
37183718 return ;
37193719 }
37203720
3721- if ( rawEntries . length >= expectedCount ) {
3721+ if ( totalLineCount >= expectedCount ) {
37223722 const events = convertStoredEntriesToEvents ( rawEntries ) ;
37233723 if ( hasSessionPromptEvent ( events ) ) {
37243724 sessionStoreSetters . clearTailOptimisticItems ( taskRunId ) ;
@@ -3727,7 +3727,7 @@ export class SessionService {
37273727 events,
37283728 isCloud : true ,
37293729 logUrl : logUrl ?? session . logUrl ,
3730- processedLineCount : rawEntries . length ,
3730+ processedLineCount : totalLineCount ,
37313731 } ) ;
37323732 this . updatePromptStateFromEvents ( taskRunId , events ) ;
37333733 return ;
0 commit comments