Skip to content

P5 O2: a memory-reducing collection at each entry into idle (Decision Log 124, owed (2)) - #324

Merged
SSFSKIM merged 8 commits into
masterfrom
p5-o2-idle-gc
Oct 29, 2026
Merged

SSFSKIM merged 8 commits into
masterfrom
p5-o2-idle-gc

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

P5 O2: a memory-reducing collection at each entry into idle (P5 Decision Log 124, owed (2))

MAWS's three long-lived Node processes are mawsd, the engine host and the pty host. Each now runs one synchronous V8 last-resort collection at every entry into idle, the first right after its start. This is production behaviour, not a test aid, so the daemon-idle bound measures what a user's machine does (the architect's ruling, 587).

Why

Each process grows V8's young generation to 16 MiB during its start. When V8 later shrinks it, it keeps those pages for a run-dependent share of runs, and no later collection returns them. Locally, plain:

  • mawsd read 29,169 to 40,929 KiB, and the engine host 65,537 to 88,577, with their heaps the same 16 to 17 MiB.
  • A collection after the active phase changed nothing (37,441 to 42,193 and 71,249 to 90,689).
  • Collected at the first idle entry after start, while those pages are still the heap's, the daemon scene held 27,793 to 29,793 (mawsd) and 64,897 to 67,057 (engine host).
  • Alone, they fell from 46.3 to 25.6–26.4 MB (mawsd), from 85.0–85.4 to 49.9–50.0 MB (engine host) and from 36.6–36.7 to 24.4–24.7 MB (pty host).

What counts as idle, per process

Each process's quiet is told to the collector at every reading. The collector asks it again synchronously at the moment it collects, on the loop's next turn (setImmediate). A late busy signal can therefore only delay a collection, never let one run during work.

  • mawsd (DaemonClocks.quiet, src/mawsd/clocks.ts): serving and not stopped; no client on any socket; no app between (an app's hello waiting for a parked host to wake, or a departing app's drain still forwarding, Relay.between); an empty interest union, with no remote viewer either; and no hold.
  • The engine host (Supervision.quiet, src/engine-host/supervision.ts):
    • serving, its startup gate settled, and not leaving or stopping;
    • the plugin runner not busy, counted from a read's entry;
    • no client interest, and no launch preparing (counted from the launch's entry);
    • every live row idle by E10's rule, read from each row's live status().
      A live row that ends while quiet (an idle release, a stop, an engine's exit) is a dropped holding and collects past the guard.
  • The pty host (PtyTable.quiet, src/pty-host/table.ts): no live pty and no shutdown begun. It is entered once after its start, behind the login-shell capture, and each time its last terminal exits. Its shutdown stops the collector.

An entry whose heap grew by less than 1 MiB, in both used size and pages, since the last collection collects nothing, unless a dropped holding forces it. The gc extension is made in one fresh context with --expose-gc on only for that moment, so no global gc exists. Each collection logs its duration and the heap before and after: idle: collected in 22 ms, heap 58.1 to 31.4 MiB (used 37.1 to 30.5). That way real use on the owner's machine shows any long pause without a bench.

The busy-source table tests pin the class, not the instance (the architect, 588). Every busy source each predicate reads is set pending at the moment a queued collection runs, and the row asserts the collection is vetoed: 17 rows on the engine host, 4 on mawsd and 2 on the pty host. A missed signal shows up as a missing row.

The pause at a large heap

Measured on the MacBook (M1 Max, 1-minute load 5.3–9.2) at 3487028, in the daemon shape over C3's replay. The app was connected with no interest and idleExitMinutes was null. 23 runs, all passed (data: the desk track's scratch/idle-gc-pause/). Each cell below is the engine host's collection time, the range over runs. The measured line was idle: collected in N ms from host.log.

Scene Runs Heap before, MiB physical (used) Used after, MiB Collection, ms
One long session (3 turns × 200 tool calls, 26,569 events, ring full), idle after each turn 3 71–73 (53–61) 48–52 26–35
the same, the session stopped 3 55 (53) 44 26–33
One long session with 64 KiB outputs, idle after each turn 3 162–193 (124–155) 105–134 31–40
the same, stopped 3 112–113 (106) 79 29–34
20 medium sessions, all idle / all stopped at once 3 147–159 (82–94) / 76–78 (70–71) 68 / 48 35–37 / 32–36
10 long sessions, all idle / all stopped at once 3 221–253 (147–190) / 118–129 (112–122) 111 / 59 53–58 / 44–48
20 long sessions, all idle / all stopped at once 3 303–383 (198–287) / 198–219 (188–200) 185 / 82 88–102 / 72–74
30 long sessions, all idle / all stopped at once 2 397–459 (289–362) / 177–281 (160–261) 259 / 104 116–123 / 94–99
An idle entry between launches while sessions open (slowest per run) 11 up to 201 (189) up to 178 31–119
  • What drives the time. It is the number of live small objects, not bytes. 64 KiB outputs held 105–134 MiB live and collected in 31–40 ms. Ten long sessions at 111 MiB live of small objects took 53–58 ms. The fit is a floor of about 25 ms plus about 0.4 ms per MiB of object-dense live heap, which reaches 100 ms near 200 MiB.
  • The fixture factor (estimated, not measured). Each replayed session also holds its whole parsed fixture, about 4.8 MiB, for its life. A real session doesn't hold that in the host. So these scenes carry about twice the live heap real sessions would. On that estimate, 20 to 30 real heavy sessions sit near 90–115 MiB live, where the measured pauses were 40–80 ms.
  • The outlier (unexplained). One launch's collection at about 96 MiB used took 104–108 ms in 3 of the 5 runs that passed that point, about twice its neighbours. It falls at the same heap size each time. Its cause was not found.
  • mawsd collected only at its start (14–17 ms, 33 MiB heap before), because the connected app kept it from going quiet again.
  • The ruling. The architect ruled no design change and no heap-size guard (589). The collection runs only at an idle entry, so its cost is a one-time delay to the next arriving request. A guard would bound a pause only in scenes past real use, and it would take the reclaim from the heaviest users. No tracker row is opened for the outlier unless real-use logs show a pause past 100 ms.

The proof on the mini

The bound is P5 Decision Log 128's: 99,145 KiB and 1.12 s. The architect's landing rule (632, 641):

  • Every e2e:daemon-idle run on this PR's head, ad09678, is judged by Rule B. Rule B was approved at 03:25Z, before any of these runs.
  • The verdict is never judged by hand. It comes from the shipped invalidReasons and loadPair in test/support/daemon-idle.ts, at a2fc850 on the load-rule branch p5-o2-load-rule, run on each run's recorded samples.
  • Every Rule B-valid run counts. Each must be at most 94,188 KiB, 5% under the bound, and mawsd must stay within 1 MiB across all of them.
  • Rule B only exempts: it never voids a run the peak rule admits.

A run valid under the peak rule uploads no artifact. Such a run is replayed from its line's peak, which is under 5, so it is valid by the rule's guard.

Every run was on the mini, inside CI-opt's measured hold on 2026-10-29.

The landing set, on ad09678 (the merged head):

Run Peak rule Rule B (pair) Total KiB Margin mawsd Engine host CPU s Note
40814726160 valid (4.1) valid 92,579 6,566 (6.62%) 28,817 63,761 0.11 Screen Sharing was connected at the window's end (the owner, 04:02–04:04Z)
40820891730 void (7.5) valid (3.20) 92,083 7,062 (7.12%) 28,641 63,441 0.13 one silent thread wake, 05:38:55Z
40820904200 void (8.1) valid (2.83) 91,891 7,254 (7.32%) 28,625 63,265 0.12 two silent thread wakes, 05:14:09 and 05:15:06Z
40822960789 valid (3.1) valid 91,395 7,750 (7.82%) 28,193 63,201 0.12
  • Every counted run is at most 94,188. The smallest margin is 6,566 KiB, 6.62% of the bound. Tracker row 457 closes at 5%.
  • mawsd spans 28,193 to 28,817, 624 KiB, across the counted runs, within 1 MiB.
  • CPU is at most 0.13 s against 1.12 s.
  • CI-opt's 5 s sampler saw no process at real CPU in any of the thread wakes. The busiest was mDNSResponder at 8–10%, and the process count stayed flat. The two measured processes' own records show no work at the wakes:
    • mawsd's CPU over the window was 0.00 s.
    • The engine host's was the same in void and valid windows.
    • Its footprint steps fall at other samples.

The A-B-A on ad09678 (40816219223), recorded as data. It is void under both rules: A' reached 6.5 with a pair of 5.43, from macOS's XProtect Remediator scans, sustained for about two minutes.

  • A (detached): 63,649 KiB.
  • B (daemon): 92,419 KiB (mawsd 28,865, engine host 63,553).
  • A': 63,457 KiB.
  • Ratio x1.454. Before the lever it was 1.452 (P5 Decision Log 128's record); 781b88c's in-job ratio was x1.454.

The enrolled run on ad09678 (40826529043) is valid under Rule B. The architect ruled that one rule covers every measured idle window (645).

  • Unenrolled window: valid under both rules (peak 3.7). 90,643 KiB, mawsd 28,529.
  • Enrolled window: void under the peak rule (5.5 at one sample), valid under Rule B (pair 3.67). 96,099 KiB, mawsd 34,433.
  • The increment is +5,456 KiB and +0.04 s, within P5 Decision Log 114's 8,192 KiB budget: mawsd +5,904, engine host -448. The link was up.
  • It is the first valid enrolled reading on a tree with the collection, and it closes the enrolled-budget question.

The lever on its own tree, 781b88c (before master's merge; replayed the same way):

Run Peak rule Rule B (pair) Total KiB mawsd Engine host
40804364622 valid (2.7) valid 90,867 28,465 62,401
40805962574 void (7.6) valid (2.62) 91,363 28,513 62,849
40807583597 valid (3.7) valid 90,211 27,937 62,273
40809164967 void (6.4) valid (2.67) 91,331 28,561 62,769
A-B-A 40810725580 B void (10.7) B void (7.74) B 91,379 28,561 A 62,321, A' 63,377; x1.454

What the series shows.

  • The lever lowers the engine host in both shapes, the detached supervisor's and the daemon's. The margin therefore comes from the engine host, and the in-job ratio is unchanged.
  • Master's additions since 781b88c are a measured shift of about +0.8 MiB in the engine host (+813 KiB in the mean, +912 in the median). The readings are every Rule B-valid window's engine host, in both shapes:
    • ad09678: 63,201 to 63,761 over six windows (the four runs, and the A-B-A's A and B), mean 63,478.
    • 781b88c: 62,273 to 63,377 over six windows (the four runs, and the A-B-A's A and A'), mean 62,665.
      The ranges overlap only where 781b88c's A', 63,377, sits above ad09678's two lowest, 63,201 and 63,265.
  • A bundle comparison names the additions exactly. It builds the plain e2e variant in both trees, normalizes chunk hashes and $N identifiers, and diffs out/main. The additions are:
    • the host chunks gain lane A's ipc tables, the people-sidebar layout schema and OrgMemberSchema;
    • mawsd's index chunk is re-split: the websocket-server chunk is gone and an identity chunk is added;
    • src/endpoint/by-effect.ts grows by 4 lines.
  • O2 landed on a series in which 40634705341, at 103,683 KiB, sat over the then-bound 101,113. It was a burst void under the peak rule and is valid under Rule B, so it is a valid miss under the new rule. This PR is what puts master inside 99,145. Nothing is restated retroactively.

Rejected

  • A 1 MiB semi-space cap. It gives the same footprint (28,465 to 28,737 and 65,105 to 65,553), but it needs a flag at every spawn: --js-flags in utility processes and the LaunchAgent's argv. It stays the fallback only if the mini's mawsd spread holds at 1 MiB or more. The architect rules on it then.
  • --semi-space-growth-factor=1 set in-process. It works only because V8 checks it at heap setup.

Commits

Gates

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

…nce at each entry into idle (P5 Decision Log 124, owed (2))

Each long-lived Node process runs one V8 last-resort collection when it goes idle by its own facts, after its start
and on each later return, never on a timer (@shared/host/idle-collect.ts). The gc extension is made in one fresh
context with --expose-gc on only for that moment, so no global gc exists and nothing else can call it; an entry that
finds the heap within 1 MiB of what the last collection left collects nothing, so a client that comes and goes costs
one collection at most.

- mawsd (clocks.ts): quiet from its start's end on, with no client on any socket, an empty interest union and no hold.
- The engine host (supervision.ts): quiet once it serves, with no client interest, every live row idle by E10's
  isIdleRow and the plugin runner idle; the process table now tells interest changes.
- The pty host (register.ts): quiet with no live pty, after its start's login-shell capture.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…holding collects, and nothing collects through an exit

- The collector (@shared/host/idle-collect.ts): an entry collects when the heap's use or its pages grew by GROWTH_BYTES
  since the last collection, so work inside the pages V8 kept is seen; `dropped()` collects while idle past the guard,
  for garbage neither size shows; `stop()` ends every later collection, a queued one included.
- The engine host (supervision.ts): quiet waits for the startup gate (designSystems.ready) to settle; the plugin runner
  tells each time it becomes busy (runner.ts `onBusy`) and Supervision refreshes on it; a live row that ends with the
  host quiet (an idle release, an engine's exit) is told as a dropped holding; a stop-all, in either mode, and a leave
  tell quiet false for good; engine.shutdown's body stops the collector, so every exit path is covered (index.ts).
- mawsd: its exit stops the collector beside the clocks, so an entry the last evaluation queued does not run.
- The pty host: the table tells its shutdown before it ends any pty (`onShutdown`), and the register stops the
  collector there, so the shutdown's last exit is not an entry.
- mawsd-scene.ts: the `collect` stand-in's type is written out (tsc's TS2742 on the inferred one).

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…finds the process busy

A dropped() queued while idle kept its guard bypass only until the next deferred turn, so work that made the process
busy before that turn lost it, and the next entry, finding neither heap size grown, collected nothing. The bypass now
stays owed until a collection runs while idle (a failed one included) or the collector stops.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…t from its CLI's spawn

A read (plugins.list, marketplaces.list, plugins.available) has no Operation, so the runner counted it only once its
CLI's group existed; its preparation (the binary probe, the directory's stat, the environment capture, which may be a
login shell's) ran with busy() false and no onBusy, and a collection queued at a quiet transition could land on it
(round 3 review, finding 2). The runner now counts a read from its entry to its end or failure: busy() is true and
onBusy fires at once, and onIdle when the read settles. The supervisor's idle exit and exit-when-idle, which read the
same busy(), now wait for a read's preparation too.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…t again, over its live state

A source can begin work before it tells it: EngineSession.send() marks its use (a status still at rest) and then makes
its queue busy, which it tells only once linked-read preparation and the queue's save settle; with saveQueue() held, a
collection ran while session.status().busy was true (round 3 review, finding 1). Three earlier rounds each fixed one
missed signal; this fixes the class.

- The collector (@shared/host/idle-collect.ts) takes the process's own quiet predicate (`quiet`, required) and asks it
  at the moment of collecting. A process it finds busy is not idle: nothing collects, a dropped holding stays owed, and
  the next reading that finds it quiet is an entry. Callers now tell every reading, not only a change, so that entry
  comes at the next refresh even when the busy spell is never told.
- The engine host: Supervision.quiet() reads the rows' live status (budget.ts isIdleRow), interest, a launch preparing,
  the runner's busy(), the startup gate, a stop-all and an exit; index.ts hands it to the collector.
- A launch's preparation (the binary probe, relay check and environment capture before its row exists) is held in the
  process table from its entry (ProcessTable.preparing / launching, told through onHoldChanged, which replaces
  onInterestChanged and carries interest too).
- mawsd: DaemonClocks.quiet() is the collector's predicate. An app between a relay's socket and the client count (a
  hello waiting on its admission, a departure until its drain ends the app's side) holds the quiet (Relay.between(),
  told through the new `between` option), so the departure's entry comes once the drain is done; the exit clock still
  counts welcomed clients only.
- The pty host: the table's quiet() (no live pty, no shutdown begun) is the collector's predicate.
- Tests: per process, a table with one row per source the collection-time quiet reads, each made pending as a queued
  collection runs (on the engine host told to no one), asserting it is held off; the reviewer's reproduction over the
  real ProcessTable and EngineSession with saveQueue() held, and over the real runner with its binary check held; the
  relay's between() over its admission and its drain.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T02:07:40.238044Z 781b88c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…c lever

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@SSFSKIM

SSFSKIM commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

The proof on the mini is in, and the description's proof section is filled in.

On ad09678, four e2e:daemon-idle runs count under the architect's landing rule. Each verdict comes from the shipped Rule B invalidReasons at a2fc850, run on the run's recorded samples:

Run Total KiB Margin under 99,145
40814726160 92,579 6.62%
40820891730 92,083 7.12%
40820904200 91,891 7.32%
40822960789 91,395 7.82%
  • Every run is at most 94,188 KiB.
  • mawsd spans 28,193 to 28,817, 624 KiB, within 1 MiB.
  • CPU is at most 0.13 s against 1.12 s.

The A-B-A on this head, 40816219223, is void under both rules. That was XProtect's scan, in A'. Its ratio was x1.454.

Master's additions since 781b88c add about +0.8 MiB to the engine host (+813 KiB in the mean).

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

@SSFSKIM
SSFSKIM merged commit ce9d875 into master Oct 29, 2026
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
… shape 6.6 to 7.8% under acceptance 14's bound; O2's over-bound reading recorded as it was; the headroom row closed, a row for the burst-tolerant load rule

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…for the measured series

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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