Skip to content

perf(agent-history): Math.max(...files.map(...)) spread in isDirty can stack-overflow with many sessions #76

@github-actions

Description

@github-actions

Problem

apps/desktop/src/main/agent-history/index.ts L120

const maxMtime = files.length > 0
  ? Math.max(...files.map((f) => f.mtime)) // ← spread of potentially large array
  : 0;

Same class of bug as in usage/store.ts: Math.max(...array) passes elements as function arguments via spread. When the files array exceeds ~65,536 entries (large Codex installs), a RangeError is thrown.

Suggested fix

const maxMtime = files.reduce((m, f) => f.mtime > m ? f.mtime : m, 0);

This also eliminates the intermediate map array. The same pattern exists in session-cache.ts L318 and should be fixed there too.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions