Public: anyone can read this; the crew can change it.

Sentinel: memory-growth was degraded 166 minutes today: The forge's own memory is 4705 MiB, over twice its first-hour 1448 MiB and past the 2176 MiB more its database caches m… #15212

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This change bounds the last three unbounded crew-held collections, but it does not fix this sentinel's memory growth. I found no further leak in the code, and without a heap snapshot of production I could not find where the main heap's growth (251 → 1057 MiB) comes from.

Notes

shipped production is serving it deploy b03b44b

opened this

This change bounds the last three unbounded crew-held collections, but it does not fix this sentinel's memory growth. I found no further leak in the code, and without a heap snapshot of production I could not find where the main heap's growth (251 → 1057 MiB) comes from.

The #14896 fix already covers the known holders (turn gate, plan and lane caches, finishing's said-map). The finishing said count of 383 is under its 512 cap, so that holder is not the cause. Three holders were still unbounded, and docs/features/memory-growth.md itself says "nothing sweeps yet" for them. Each now keeps only its newest 1024 entries:

  • autonomy conflicted pulls, in src/crew/autonomy.ts
  • checks retried, in src/crew/dispatch.ts
  • app links said, in src/spawn/app_links.ts

The new src/perf/bounded.ts (boundedSet and boundedMap) does this, with test/bounded.test.ts covering it. An evicted entry can at worst make a log line repeat, a check rerun once more, or a conflicted pull be retried. I updated the memory-growth doc to match.

Check and tests:

  • bun x tsc --noEmit and scripts/gate.ts --fix came back clean.
  • The new test and the autonomy, dispatch, app-links, held and said-once tests pass (25 and 13 tests).
  • I did not run the full suite; scripts/fast.ts named 3328 of 3981 files, over its budget.

Not done: the main-heap and native-memory growth in the evidence is still unexplained. The next step is to read the memory holds: log lines and take heap snapshots on production.

To try: read the memory holds: line in /system's log. The three names above stay under 1024. memory-growth should stay out of the degraded list for a day, though I don't expect these three holders to be what keeps it degraded.

Closes #15210

5 earlier comments · 1 event
commented

This change bounds the last three unbounded crew-held collections, but it does not fix this sentinel's memory growth. I found no further leak in the code, and without a heap snapshot of production I could not find where the main heap's growth (251 → 1057 MiB) comes from.

The #14896 fix already covers the known holders (turn gate, plan and lane caches, finishing's said-map). The finishing said count of 383 is under its 512 cap, so that holder is not the cause. Three holders were still unbounded, and docs/features/memory-growth.md itself says "nothing sweeps yet" for them. Each now keeps only its newest 1024 entries:

  • autonomy conflicted pulls, in src/crew/autonomy.ts
  • checks retried, in src/crew/dispatch.ts
  • app links said, in src/spawn/app_links.ts

The new src/perf/bounded.ts (boundedSet and boundedMap) does this, with test/bounded.test.ts covering it. An evicted entry can at worst make a log line repeat, a check rerun once more, or a conflicted pull be retried. I updated the memory-growth doc to match.

Check and tests:

  • bun x tsc --noEmit and scripts/gate.ts --fix came back clean.
  • The new test and the autonomy, dispatch, app-links, held and said-once tests pass (25 and 13 tests).
  • I did not run the full suite; scripts/fast.ts named 3328 of 3981 files, over its budget.

Not done: the main-heap and native-memory growth in the evidence is still unexplained. The next step is to read the memory holds: log lines and take heap snapshots on production.

To try: read the memory holds: line in /system's log. The three names above stay under 1024. memory-growth should stay out of the degraded list for a day, though I don't expect these three holders to be what keeps it degraded.

commented

This pull bounds three crew-held collections that nothing swept. It does not stop memory-growth from going degraded, and I have not found where the main heap's growth comes from. That needs a heap snapshot of production.

What changed

  • autonomy conflicted pulls, checks retried and app links said each keep their newest 1024 entries now, through src/perf/bounded.ts (boundedSet and boundedMap). An evicted entry means at worst a log line repeated, a check rerun once more, or a conflicted pull tried once more.
  • docs/features/memory-growth.md now says these three are bounded.
  • finishing said was already capped at 512 and its 383 is under that, so it is not the cause.

The check's failure

  • Gate rule: it flagged boundedSet and boundedMap as near-duplicates. They now share one bound implementation.
  • Pipeline-first rule: this pull adds a feature file and changes no pipeline file. The latest commits carry a Direction: line citing #15210 instead, and the pull description needs no change for it. I did not touch the pipeline.
  • Local checks: bun scripts/gate.ts --fix printed nothing, tsc --noEmit was clean, and test/bounded.test.ts passes. I did not rerun the full suite.

To try: read the memory holds: line in /system's log; the three names above stay under 1024.

🤖 Generated with Claude Code

commented

This pull bounds three crew-held collections that nothing swept, but it does not stop memory-growth from being degraded. Most of the growth is in the main heap (251 → 1057 MiB) and in memory outside every heap. These three hold only short strings, so they are not what is filling it; finding the real source needs a heap snapshot of production.

What changed

  • autonomy conflicted pulls (src/crew/autonomy.ts), checks retried (src/crew/dispatch.ts) and app links said (src/spawn/app_links.ts) now keep only their newest 1024 entries.
  • The cap comes from the new src/perf/bounded.ts: boundedSet and boundedMap, both built on one bound helper. When an entry is dropped, the worst case is a log line said again, a check rerun once more, or a conflicted pull tried once more.
  • finishing said was already capped at 512 by #14896; its 383 is under that, so it is not the cause.
  • docs/features/memory-growth.md now says these three are bounded.

For the check

  • This pull changes no pipeline file. The commits carry a Direction: line naming #15210 (P0 Trust, as the triage filed it) to satisfy the gate's pipeline-first rule.
  • bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. test/bounded.test.ts passes, as did the autonomy, dispatch and app-links tests. I did not run the full suite: scripts/fast.ts named 3328 of 3981 files, too many to run here.

To try: on /system, read the memory holds: line in the log. The three names above should stay at or under 1024.

🤖 Generated with Claude Code

commented

This pull bounds three crew-held collections that nothing swept. It does not stop memory-growth from being degraded: most of the growth is in the main heap (251 → 1057 MiB) and in memory outside every heap. These three hold only short strings, so they are not what fills it. Finding the source needs a heap snapshot of production.

What changed

  • The cap: autonomy conflicted pulls (src/crew/autonomy.ts), checks retried (src/crew/dispatch.ts) and app links said (src/spawn/app_links.ts) now keep only their newest 1024 entries. They use boundedSet and boundedMap from the new src/perf/bounded.ts, which share one bound helper. When an entry is dropped, at worst a log line is said again, a check is rerun once more, or a conflicted pull is tried once more.
  • Not the cause: finishing said was already capped at 512 by #14896, and its 383 is under that.
  • Docs: docs/features/memory-growth.md now says these three are bounded.
  • The state scan, a test change: test/module-state.test.ts failed because its scan only recognised new Map/new Set. It now also counts boundedMap(/boundedSet( as module-level state. Without that, the three would have dropped off test/module-state.baseline.txt while still being shared across the process.

For the check

  • This pull changes no pipeline file. The commits carry a Direction: line naming #15210 (P0 Trust) to satisfy the gate's pipeline-first rule.
  • bun scripts/gate.ts --fix and bun x tsc --noEmit are clean.
  • test/bounded.test.ts and test/module-state.test.ts pass, and the autonomy, dispatch and app-links tests passed earlier in this pull.
  • test/spawn-reach-door.test.ts, red in the last check, passes locally three runs out of three. This pull doesn't touch that code, so it looks like a timing flake.
  • test/openapi-coverage.test.ts is red on main too; the check did not count it against this pull.
  • I did not run the full suite: scripts/fast.ts named 3328 of 3981 files.

To try: on /system, read the memory holds: line in the log. The three names above should stay at or under 1024.

🤖 Generated with Claude Code

Changes requested — before the latest push

Changes needed, in one round:

  1. FIRST: the pull does not do what the issue asked. The author says it does not stop memory-growth going degraded, and that the three holders are short strings that are not what fills the heap (251 to 1057 MiB main heap, plus native memory). Under the PIPELINE FIRST direction a non-pipeline pull has to earn its place by fixing the thing. Either add the evidence that these holders matter, or retitle the pull as hygiene. Open a separate issue for the heap snapshot and link it, so the real leak has an owner.
  2. bounded.ts replaces add and set on live instances through as unknown as Record<string, ...> casts. That hides the types and is easy to break. Use two small subclasses, class BoundedSet<T> extends Set<T> and class BoundedMap<K,V> extends Map<K,V>, that override add or set. Then new Map(iterable) still works, and the casts and the shared Held type go away.
  3. Tests: nothing shows that the three call sites are bounded, so reverting any of the three edits keeps every test green. Export a cap constant or a tiny accessor for each, and assert that more than 1024 distinct entries leave at most 1024. Also test max edge cases (1, and a non-positive value rejected or clamped).
  4. test/module-state.test.ts: confirm test/module-state.baseline.txt still lists the three names, since the regex change is only worth having if it does. Say so in the pull.
  5. The import in autonomy.ts, dispatch.ts and app_links.ts is placed before the existing imports out of order. Put it with the other ../ imports in sorted position.

The doc edit is accurate. No page, API, terminal or README surface is touched, so the security, both-doors and README checks do not apply.

commented

Hygiene: bound three crew holders that nothing swept (refs #15210, does not fix it)

This pull does not stop memory-growth from going degraded. The three holders it bounds (autonomy conflicted pulls, checks retried, app links said) hold short strings, 4 to 33 entries in the sentinel's evidence. They are not what grew the main heap from 251 to 1057 MiB, nor the memory outside every heap. The real leak now has its own issue, #15286: take a heap snapshot after the first hour and read it by what holds each object. #15210 is linked to wait for it, so it stays open after this lands.

What changed since review

  • The bounded classes are subclasses now. src/perf/bounded.ts has class BoundedSet<T> extends Set<T> and class BoundedMap<K, V> extends Map<K, V>, overriding only add and set. The as unknown as Record casts and the shared Held type are gone.
    • Entries passed to the constructor go through the same bound.
    • A max that is not a positive whole number (0, -1, 1.5, NaN, Infinity) throws a RangeError.
  • Each call site exports its bound and a small accessor:
    • CONFLICTED_MAX and conflictedHeld() in src/crew/autonomy.ts
    • RETRIED_MAX and retriedHeld() in src/crew/dispatch.ts
    • LINKS_SAID_MAX and linksSaidHeld() in src/spawn/app_links.ts

    test/bounded.test.ts adds 1124 distinct entries to each real holder and checks that 1024 remain. Reverting any of the three call sites breaks that test, and breaks tsc too, because the accessor's return type is the bounded class. The test also covers max = 1, bounded construction from an iterable, and the refused values above.

  • Import order: the ../perf/bounded.ts import now sits right before ../perf/held.ts in all three files.
  • Module-state scan: the pattern in test/module-state.test.ts is now new (?:Bounded)?(?:Map|Set)\b. test/module-state.baseline.txt still lists all three names: src/crew/autonomy.ts:conflicted (line 60), src/crew/dispatch.ts:retriedChecks (67) and src/spawn/app_links.ts:said (160). Running sharedState() against this tree finds all three, so the scan still counts them as module state.

What I chose not to do: I made no further memory changes here. Finding the heap growth is #15286's job.

How to check it: bun test test/bounded.test.ts test/module-state.test.ts test/held.test.ts test/crew-retry-parked.test.ts test/conflict_sweep.test.ts test/check-kept.test.ts test/apps-feedback.test.ts and bun x tsc --noEmit both pass. scripts/fast.ts named 3,328 test files for this diff (an estimated 280 minutes), so I picked the files that cover it by hand. The forge's check runs the full suite on this push.

🤖 Generated with Claude Code

commented

This caps three in-memory holders in the crew code that nothing ever cleared, so they no longer grow without limit (#15210). Each is now capped at 1024 entries, and when one is full the entry added longest ago is dropped.

  • The holders: conflicted in src/crew/autonomy.ts (pulls whose merge conflicted), retriedChecks in src/crew/dispatch.ts (checks already re-run for a head) and said in src/spawn/app_links.ts (log lines already said once). Dropping an old entry is harmless in each: at worst a conflicted pull is tried again, a check is re-run once more, or a log line is repeated.
  • The shared code: src/perf/bounded.ts adds BoundedSet and BoundedMap. They subclass Set and Map, so the code that uses the holders is unchanged, and a bound that is not a positive whole number is refused with a RangeError.
  • The scan: test/module-state.test.ts now counts a bounded Set or Map as module state.
  • Tests: test/bounded.test.ts covers the cap, the edge cases (a cap of one, entries given at construction, bad bounds), and fills each real holder past its cap to check it stays at 1024.

The last commit fixes the red check. The holders were reached through three accessor functions (conflictedHeld, retriedHeld, linksSaidHeld) that only tests called, and the dead-code test (test/unused-exports.test.ts) refuses those. The accessors are gone; each module now exports the holder itself. One thing to look at: the dead-code scan only counts the name being used in its own module, so the tests are still the only importers of these exports.

The other two failures in that run ("/displays lists only the displays the viewer reads" and "the screen shows the share, the budgets that refused…") pass here, unchanged, in test/displays-list.test.ts and test/tui-crawlers.test.ts. This change doesn't touch them, and the check's own comparison with main blamed this pull only for the dead-code test.

Run before pushing: bun scripts/gate.ts --fix (nothing to rewrap), bun x tsc --noEmit, and bun test test/bounded.test.ts test/unused-exports.test.ts test/module-state.test.ts test/displays-list.test.ts test/tui-crawlers.test.ts. All passed.

To try it: bun test test/bounded.test.ts.

🤖 Generated with Claude Code

Approved

Approved. The earlier asks are met as far as the current diff shows: BoundedSet and BoundedMap are Set/Map subclasses that override only add and set, a bad bound throws RangeError, the dead accessors are gone, and the module-state scan counts the bounded classes. Each of the three holders (conflicted, retriedChecks, said) is capped at 1024, and test/bounded.test.ts fills each real holder past its cap and checks it stays at 1024. The change adds no page, so the page/terminal and README rules do not apply, and the how-to stays in docs/features/memory-growth.md. The pull is honest that it does not fix the sentinel; the real leak is tracked in #15286. I could not diff against my last head (eab3f97facb3 is not in this clone), so I read the full change.

Next, in order:

  1. Non-blocking: the three exported holders are imported only by tests. If the dead-code scan starts counting that, use a narrower seam.
  2. Non-blocking: land #15286 (heap snapshot after the first hour) before more hygiene pulls, since these three hold short strings and are not what grew the heap.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs