Skip to content

A mind's result bodies stay in RAM until the one memory owner sheds them (MemoryReporter 'mind_results'; no RESULTS_RESIDENT_CHARS) - #5595

Merged
joelteply merged 4 commits into
canaryfrom
fable/results-memory-reporter
Oct 29, 2026
Merged

joelteply merged 4 commits into
canaryfrom
fable/results-memory-reporter

Conversation

@joelteply

@joelteply joelteply commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Serves the residents (#5591 Fault 3 step 3): result storage is a tier of one state, sized by the host's measured memory through the one owner, never a constant (Joel: no hand-rigged numbers). Stacked on #5573 (cormac/focus-results 54be7a5).

  • Deletes RESULTS_RESIDENT_CHARS = 1 << 20 and every eviction at receipt, restore and settlement.
  • One MemoryReporter mind_results on the MemoryPressureMonitor for every resident mind: report() = resident body bytes (bytes, a working memory reached twice counted once); budget() min = never-evictable bytes (each mind's newest result, unsaved results, last copies), preferred = max = everything resident; priority Interactive (her working state); shed_load moves the oldest bodies across minds to their handles until under the host's RAM overrun past the monitor's own gate (inputs are the monitor's numbers). A body moves only once its saved copy is proven (at shed time, outside the mind's lock, through spill::reproduces, the same read her view's load renders) to load back to exactly that body; proofs are cached, so budget() does no filesystem access and counts an unproven body as pinned.
  • Last copy: a body whose saved output does not resolve is never moved (typed LastCopy, probe wm.results.last_copy_kept); every handle a record points at stays live (no POINTER_INDEX cutoff); prune drops only records with neither a resident body nor a handle.
  • No filesystem stat under a mind's actions lock: candidates collected under it, checked outside, evicted under it only if unchanged.
  • Known cost (measure live): records are kept for every saved result, so the checkpoint grows over a mind's life; bound = consolidation moving old records' text down a tier (Fault 3: a mind's memory is one state with one allocator; capacity only from grants #5591).

Measured

Not full governor coverage: the shed target is the host's RAM overrun past the Interactive gate (over_gate). Swap-only pressure, with RAM use under the gate, makes over_gate return 0 and sheds nothing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply

Copy link
Copy Markdown
Contributor Author

Review (Cormac) at exact 52859c0: CHANGES REQUESTED, two blocking findings. I read the delta against #5573 (54be7a5).

Verified: "no filesystem stat under a mind's actions lock". residency() takes candidates from memory.resident_results(), which releases her lock, then calls saved(...) outside it. shed_to evicts only when the record still names the vouched handle (vouched.get(&seq) == handle).

Blocking 1 (Codex's finding, confirmed): saved_output vouches with path.is_file() only. A file that exists but is truncated, corrupt or unreadable vouches, the body leaves RAM, and her next load silently renders a pointer. That loses the last good copy. The check is cheap where it matters: at shed time, outside her lock, read the saved output and compare it with the resident body you're about to drop (both trimmed, as the record keeps it). Vouch only on equality; anything else is LastCopy::Mismatch and stays resident, with the wm.results.last_copy_kept probe. Please add a fixture with a real file whose bytes differ from the body (a truncated write), and assert the body stays.

Blocking 2: MindResultsReporter::budget() calls saved_output (a filesystem stat) for every resident record of every mind. The monitor's budget_snapshot() calls reporter.budget() synchronously while holding self.reporters.read() (memory_pressure_monitor.rs:98-106). So each snapshot does N filesystem calls across all minds' rings inside the monitor, under its reporters lock. That's the shape CONCURRENCY-STYLE-GUIDE forbids, and it grows with the fleet. A vouch is immutable for a handle once verified (spill output is content-addressed), so verify once at shed time per Blocking 1, cache it on the record (or a per-mind set of verified handles), and have budget() read only that cache. Unverified then counts as pinned in min_bytes, which is the conservative direction.

Non-blocking:

  • over_gate takes the host's used bytes over the Interactive gate, and the PR states that a swap-only warning sheds nothing. That's fine; keep it named in the PR, as you did.
  • The checkpoint now keeps a record for every saved result, so volatile.json grows over a mind's life. You flagged it with Fault 3: a mind's memory is one state with one allocator; capacity only from grants #5591 as the bound; please card it with an owner so the growth read has somewhere to land.

joelteply added a commit that referenced this pull request Oct 29, 2026
…o it

Codex on #5595: vouching with `path.is_file()` counted an existing but unreadable or corrupt
file as a safe copy, so the body left RAM and her view's later load rendered a pointer: the
last copy was lost.

- The spill owner gains the one read of a saved result (`spill::saved_whole`, the text her
  view's `load` renders, which now reads through it) and its digest (`WholeDigest`,
  `saved_digest`).
- The shed plans from memory only, then reads and digests each planned candidate's copy
  outside the mind's lock; under the lock a body moves only if its record still names that
  handle and its digest matches. An unreadable copy or a mismatch keeps the body resident
  with the typed `LastCopy` probe (reason unreadable / mismatch). No filesystem access under
  the lock; `budget()` reads memory only.
- The reporter's doc states plainly: swap-only pressure sheds nothing (`over_gate` returns
  0), so this is not full governor coverage.

Tests use real spill files: a copy with wrong content and a deleted copy keep their bodies
resident while a good one moves and loads back to exactly what she read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Oct 29, 2026
…touches the filesystem

Cormac on #5595: budget() stat'ed every resident record of every mind, and the monitor calls
it under its reporters lock on every snapshot.

- Proof at shed time only: each candidate's body is copied out (her lock held only for the
  copy) and compared with what its saved copy loads back to (`spill::reproduces`, through the
  one read her view's `load` uses). A proven (persona, handle) is cached in the reporter; the
  output is content-addressed and live-protected while a record names it. The cache is pruned
  at each shed to the handles still resident.
- budget() reads only that cache: an unproven body counts as pinned in min_bytes.
- Only proven bodies are planned and moved; the eviction re-checks (seq, handle) under the
  lock. Drops the digest from the previous commit (no hashing under the lock).

Tests (real spill files): a truncated write and wrong content prove LastCopy::Mismatch (the
probe's reason "mismatch"), a missing file LastCopy::Unreadable, and all three keep their
bodies through a shed; with the spill dir deleted after a shed, budget() answers from the
cache (min = only the newest pinned).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Re-review (Cormac) at exact 0aaccb2: both of my blocking findings are resolved in source. The PASS waits on CI at this head (one check has run so far) and on your serving-down test run; I'll confirm once both are green.

  • Blocking 1, fixed. prove(...) calls spill::reproduces(persona, handle, body), which is saved_whole(...) == body. saved_whole is the same trimmed read her view's load renders, so the proof is exactly "the saved copy loads back to what she'd see". A mismatch or an I/O error keeps the body resident as LastCopy::{Mismatch, Unreadable}, with the probe.
  • Blocking 2, fixed. budget() is budget_of(...) and reads only the ProvenCopies cache. Proofs happen in prove_candidates at shed time, are cached per (persona, handle), and are pruned to still-resident handles. Since every handle a record names stays live, a cached proof can't outlive its file.

Non-blocking: prove_candidates runs inside shed_load, which the monitor calls from its poll. A first proof reads the whole saved file there, synchronously on the monitor's task. That's rare and only under pressure, but a large output read stalls the monitor exactly when it's busiest. Consider spawn_blocking for the proving pass (CONCURRENCY-STYLE-GUIDE), or proving eagerly when a result is saved, since the body is in hand then and costs no read.

joelteply and others added 4 commits October 29, 2026 16:38
…: RESULTS_RESIDENT_CHARS is gone

RAM decides, not a number (Joel, 2026-10-29: no hand-rigged constants). The 1 << 20-char cap
per mind evicted at receipt, settlement and restore; now nothing evicts there.

- One MemoryReporter, `mind_results` (persona_workspace/mind_results_reporter.rs), accounts every
  resident mind's result bodies in BYTES (live cycles and private mind cycles; a memory reached
  twice counts once). Priority Background (a cache: every shed body is saved to its handle).
  min = what no shed may move; preferred = max = what it holds.
- shed_load sheds the host's overrun past the monitor's own gate for that priority
  (used - pressure_gate * total, from the published PressureSnapshot), oldest received first
  across minds (new `received_ms` on each record), down to that allocation exactly.
- Never moved: a mind's newest result, an unsaved one, or one whose saved output does not
  resolve or is missing (typed `LastCopy`, probed `wm.results.last_copy_kept`).
- `evict_resident_results_over(bytes, saved)` (working_memory/residency.rs) is the one eviction
  verb; only the reporter calls it in production. No hysteresis: the owner decides when.
- Registered once at boot beside the persona registry (persona_registry_modules.rs).

Tests: never evicted at receipt however large the ring; restore keeps every body; the shed takes
the oldest across two minds to the allocation and keeps newest, unsaved and unreloadable bodies,
with stored_chars + handle kept; report sums bytes across minds; the shed target is the overrun
past the monitor's gate. Tests that only asserted the constant's bursts were replaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ve, and no stat under a mind's lock

- Priority Interactive: her results are working state for her current task, not an idle
  cache, so a shed gives up only the host's overrun past 0.80 instead of every movable body
  at the first Warning. The swap-only limit is noted in the reporter's doc.
- Last copy: every record naming a handle keeps it live (`receipt_keys`) and stays in the log
  (`prune` drops only records with neither a body nor a handle, past the ledger's share).
  The newest 12 pointers (`POINTER_INDEX`) are now a rendering count only.
- No filesystem access under a mind's lock: `resident_results()` reads candidates under it,
  the reporter checks each saved output after it drops, and the eviction moves only
  `(seq, handle)` pairs it vouched for, re-checked under the lock.

Tests: a moved body's handle stays live behind 60 newer pointers and its record stays
priced; a shed moves only records still naming the vouched handle; the target test reads
the Interactive gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…o it

Codex on #5595: vouching with `path.is_file()` counted an existing but unreadable or corrupt
file as a safe copy, so the body left RAM and her view's later load rendered a pointer: the
last copy was lost.

- The spill owner gains the one read of a saved result (`spill::saved_whole`, the text her
  view's `load` renders, which now reads through it) and its digest (`WholeDigest`,
  `saved_digest`).
- The shed plans from memory only, then reads and digests each planned candidate's copy
  outside the mind's lock; under the lock a body moves only if its record still names that
  handle and its digest matches. An unreadable copy or a mismatch keeps the body resident
  with the typed `LastCopy` probe (reason unreadable / mismatch). No filesystem access under
  the lock; `budget()` reads memory only.
- The reporter's doc states plainly: swap-only pressure sheds nothing (`over_gate` returns
  0), so this is not full governor coverage.

Tests use real spill files: a copy with wrong content and a deleted copy keep their bodies
resident while a good one moves and loads back to exactly what she read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…touches the filesystem

Cormac on #5595: budget() stat'ed every resident record of every mind, and the monitor calls
it under its reporters lock on every snapshot.

- Proof at shed time only: each candidate's body is copied out (her lock held only for the
  copy) and compared with what its saved copy loads back to (`spill::reproduces`, through the
  one read her view's `load` uses). A proven (persona, handle) is cached in the reporter; the
  output is content-addressed and live-protected while a record names it. The cache is pruned
  at each shed to the handles still resident.
- budget() reads only that cache: an unproven body counts as pinned in min_bytes.
- Only proven bodies are planned and moved; the eviction re-checks (seq, handle) under the
  lock. Drops the digest from the previous commit (no hashing under the lock).

Tests (real spill files): a truncated write and wrong content prove LastCopy::Mismatch (the
probe's reason "mismatch"), a missing file LastCopy::Unreadable, and all three keep their
bodies through a shed; with the spill dir deleted after a shed, budget() answers from the
cache (min = only the newest pinned).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the fable/results-memory-reporter branch from 0aaccb2 to 1609faf Compare October 29, 2026 21:38
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS (Cormac) at exact 1609faf. CI is green at this head (14 pass, 0 fail). git range-diff 52859c051..0aaccb2f5 6e7c6e5b1~1..1609fafa5 shows the two fix commits identical after the rebase, so my re-review of 0aaccb2 holds here: both blockers are resolved (prove = saved_whole == body through the view's one read; budget() reads only the ProvenCopies cache). The spawn_blocking / prove-at-save note stays non-blocking.

@joelteply
joelteply merged commit 5bcb03d into canary Oct 29, 2026
17 checks passed
@joelteply
joelteply deleted the fable/results-memory-reporter branch October 29, 2026 21:58
joelteply added a commit that referenced this pull request Oct 29, 2026
…no longer grows with every act (Level::Folded) (#5600)

* Her view's floor is one fold block, not the sum of every pointer she ever held

On the M5 (2026-10-29 22:00Z), after #5595 kept a record for every saved
result, Aris's view held 97 results with 2 whole: ~95 pointers x ~190 chars
(~4.5k tokens) of floor before anything whole fit, growing with every act.

The one codec (continuum-context) gains a level below the pointer:
- Source::fold (default None): one block standing for the contiguous oldest
  run, O(1) in the run. A source without it floors at its pointers as before.
- view/allot.rs owns the levels and the floor: floor(k) = the oldest k items
  at their least (the fold block when cheaper than their pointers, else the
  pointers). Spent newest first with the existing monotone ceiling; raising
  item i to size s is affordable when s + floor(i) <= spare + floor(i+1), so
  without a fold it is the old arithmetic, and with one the block is repriced
  as the run shrinks and refunded when the last folded item rises.
- The block renders once where the oldest folded item stood, fixed for the
  epoch; folded items never arrive mid-epoch; start_would_restore counts only
  a rise to summary or whole (a pointer the block covers is no turnover).
- Claim.pointer_chars -> floor_chars; the cognition prompt's view_claims
  prices its floor through view::floor (one owner) instead of re-summing.
- The actions source folds as "[actions #a-#b: n earlier acts, folded at this
  start]".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* A folded act reopens by its number: tool/output takes act, and the fold says so

Folding her oldest acts into "#a-#b" hid each act's handle, and tool/output
took only an outputId, so a folded act could not be reopened (goal 7: the full
result stays reachable).

- tool/output takes exactly one of outputId or act. act resolves through the
  CALLING persona's working memory (PersonaWorkspaceRegistry::act_output_handle,
  her public cycle) via WorkingMemory::saved_handle, now the one act -> handle
  resolution, returning a typed ActOutputRefusal (Unknown / Unsaved /
  NoResident) that names the act; never another output. Help, schema doc and the
  generated ToolOutputParams.ts say so. Open views follow a page read by act
  through the result's echoed outputId.
- The actions fold reads "[actions #a-#b: n earlier acts folded; reopen one
  with tool/output act=<n>]", fixed per epoch, O(1) in the run.
- Source::fold reads only the run's ends (the actions impl skips at most the
  leading banner), so a start asking once per raised item is O(n), not O(n^2).
- Fold-or-pointers is decided once, in chars (view::allot fold_of); view::floor
  prices that decision in the caller's unit, so view_claims (tokens) and the
  view never disagree about which rendering is the floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* The view never folds a standing head: her [actions] banner stays at the front, so a turnover keeps the settled prefix; the fold run is the oldest acts after it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant