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.
Problem
apps/desktop/src/main/usage/session-cache.tsL211–218 and L317–319isAgentDirtyalready callswatcher.collectFiles()to obtain the file list, but after re-scanning in the dirty branch it calls it again to update the watermark:For agents with hundreds of session files (e.g. codex), every refresh stat-walks the same file set twice.
Suggested fix
Change
isAgentDirtyto return{ dirty: boolean; files: FileWithMtime[] }and reuse the already-stat'd file list directly in the dirty branch.