Skip to content

fix(life16): free walking routes no walk can read again [LIFE16-Routes-075] - #95

Merged
NeoLorenzo merged 2 commits into
mainfrom
fix/life16-cache-leak
Nov 2, 2026
Merged

NeoLorenzo merged 2 commits into
mainfrom
fix/life16-cache-leak

Conversation

@NeoLorenzo

Copy link
Copy Markdown
Owner

What

Fixes a memory leak on long Life runs. The state kept every walking route ever planned (state.routes, indexed by route id), about 45,000 route segments a day, so the heap grew about 12 MB a day and a year's run ran out of memory, in Node and in the page's worker alike.

Each step now begins by freeing every route below the lowest one still being walked (releaseRoutes in engine.ts). Route ids keep counting, so wake-up order (which breaks ties by route id) and every trajectory are unchanged.

Why it is safe

  • A route is read only while its walk lasts; within a step the checker and replay also read routes of walks under way when the step began, and of walks started and ended in it. All of these are at or above the lowest route still walked when the step begins.
  • The checker already reports "Missing recorded route" if a route still in use were freed.
  • Fingerprints are unchanged.

Measured

Canonical forty, seed 20260813, in 12-hour in-place steps as the worker runs, days 1 to 120:

ms per day (days 21–120) routes held at day 120
Before 124–147 55,675
After 130–141 93

The heap now grows about 0.3 MB a day instead of 12 MB: 421 MB at day 25, 508 MB at day 350.

Tests

  • New unit test: routes below the lowest still walked are freed and ids keep counting.
  • The tests comparing a batched day with minute-by-minute stepping free routes in both before comparing, since single steps free them sooner.
  • npm run agent:check passes.

Update [LIFE16-Routes-075]; 074 is Life 17 (#94).

@NeoLorenzo
NeoLorenzo merged commit 323f604 into main Nov 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant