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.
Problem
apps/desktop/src/main/agent-history/index.tsL120Same 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), aRangeErroris thrown.Suggested fix
This also eliminates the intermediate
maparray. The same pattern exists insession-cache.tsL318 and should be fixed there too.