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

Open Beginner friendly
#54 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript

Research direction

Start with apps/desktop/src/main/agent-history/index.ts around line 120, then inspect the matching pattern in usage/store.ts and session-cache.ts around line 318. Replace the spread-based maximum calculations in the named locations and verify that large file or session collections no longer trigger a RangeError.

Written by the indexing model from the issue text.

Description

performance

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.

Dominant language
TypeScript
Stars
120
Forks
13
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from unbug/tday

All issues in unbug/tday

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.