@@ -517,11 +517,28 @@ interface ParsedLogSegment {
517517/**
518518 * Resilient parse of `turns.jsonl` alone (extras merged by the caller), so a
519519 * torn or poisoned base cannot block the healing write.
520+ *
521+ * `baseListed` is the directory listing `turnSegmentStats` already paid for.
522+ * A missing base is empty history (the same answer `pathExists` gave). A
523+ * listed base is read directly: `access` only repeated that listing, and a
524+ * changed base fingerprint was doing it once per appended turn. ENOENT
525+ * between the listing and the read is still empty history, not a throw.
520526 */
521- async function readBaseLogFromDisk ( dir : string ) : Promise < ParsedLogSegment > {
527+ async function readBaseLogFromDisk (
528+ dir : string ,
529+ baseListed : boolean ,
530+ ) : Promise < ParsedLogSegment > {
531+ if ( ! baseListed ) return { turns : [ ] , approvals : [ ] } ;
522532 const basePath = path . join ( dir , TURNS_FILE ) ;
523- if ( ! ( await pathExists ( basePath ) ) ) return { turns : [ ] , approvals : [ ] } ;
524- const text = await fs . promises . readFile ( basePath , "utf-8" ) ;
533+ let text : string ;
534+ try {
535+ text = await fs . promises . readFile ( basePath , "utf-8" ) ;
536+ } catch ( cause ) {
537+ if ( cause instanceof Error && "code" in cause && cause . code === "ENOENT" ) {
538+ return { turns : [ ] , approvals : [ ] } ;
539+ }
540+ throw cause ;
541+ }
525542 const approvals : PendingOperation [ ] = [ ] ;
526543 const turns = parseSegmentTurns ( text , true , TURNS_FILE , true , approvals ) ;
527544 return { turns, approvals } ;
@@ -1618,11 +1635,14 @@ export async function createSessionStores(
16181635 // Otherwise parse turns.jsonl here rather than through the isogit base's
16191636 // load(): that also validates metadata.json against the vendor shape,
16201637 // which this store no longer writes (tokenUsage lives on the sidecar).
1621- // Metadata is read separately by readSessionMetadata.
1638+ // Metadata is read separately by readSessionMetadata. The segment list
1639+ // already says whether the base file is present, so the parse does not
1640+ // probe it again.
1641+ const baseListed = segments . at ( 0 ) ?. name === TURNS_FILE ;
16221642 const baseLog =
16231643 reused >= 1 && turnsCache !== null
16241644 ? turnsCache . base
1625- : await readBaseLogFromDisk ( dir ) ;
1645+ : await readBaseLogFromDisk ( dir , baseListed ) ;
16261646 const parsedExtras : ParsedLogSegment [ ] = [ ] ;
16271647 for ( let index = 1 ; index < segments . length ; index ++ ) {
16281648 const cached =
0 commit comments