Skip to content

Incremental parse resumes from wrong position after file shrink/rewrite #50

Description

@httpsVishu

noticed a stale-state issue around same size transcript rewrites in src/providers/cursor/transcripts.ts file

right now tryCacheHit() treats the file as unchanged whenever sizeBytes matches the cached value, so if cursor rewrites/regenerates a transcript but the resulting file happens to have the same byte size, the parser skips reparsing entirely and just reuses the old cached parse state

const contentChanged = fileSizeBytes !== cached.sizeBytes;

if (!contentChanged) {
  return {
    result: {
      agents: resolveAgentsFromState(cached.state, sourcePath, cached.fileUpdatedAt, now),
      success: true,
      warnings: [],
    },
    updatedCache: { ...cached, mtimeMs: fileUpdatedAt },
  };
}

there is also a related assumption in resolveParseStrategy() where incremental parsing resumes from cached.lineCount whenever size/line count are at least the cached values which only seems safe for strictly append-only transcripts

in practice, if a session file gets rewritten/reset with different content but identical byte length, stale agents/task state from the previous session can persist until the file size changes again, this looked especially risky for restarted/re-generated cursor conversations

was append-only behaviour guaranteed here or could rewritten transcripts bypass cache invalidation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions