Skip to content

perf(session-cache): collectFiles() called again after dirty check, duplicating stat syscalls #69

@github-actions

Description

@github-actions

Problem

apps/desktop/src/main/usage/session-cache.ts L211–218 and L317–319

isAgentDirty already calls watcher.collectFiles() to obtain the file list, but after re-scanning in the dirty branch it calls it again to update the watermark:

// L211-218 - first call
function isAgentDirty(watcher, index) {
  const files = watcher.collectFiles(); // stat all files
  ...
}

// L317-319 - second call (same files)
const files = watcher.collectFiles(); // ← duplicate stat
const { fileCount, maxMtime } = statFiles(files);

For agents with hundreds of session files (e.g. codex), every refresh stat-walks the same file set twice.

Suggested fix

Change isAgentDirty to return { dirty: boolean; files: FileWithMtime[] } and reuse the already-stat'd file list directly in the dirty branch.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions