Skip to content

server: a mind switch is a sequence move in milliseconds, through the pool and flash (never serialized, dropped or truncated) - #139

Open
joelteply wants to merge 21 commits into
codex/s4-per-mind-integrationfrom
fable/mind-switch-s4
Open

joelteply wants to merge 21 commits into
codex/s4-per-mind-integrationfrom
fable/mind-switch-s4

Conversation

@joelteply

Copy link
Copy Markdown

Joel, 2026-11-16: "This is the entire difference between a multi mind system and a POS. There is almost zero cost to context switch."

Why

On the M5 today, a mind leaving a lane was serialized into the size-capped prompt cache: up to 2.35 GB per switch, with 224 cache evictions in 3 hours. When she didn't fit, she was dropped: 10 times, 8.7 GB of finished work. The arriving mind resumed from an older checkpoint and re-prefilled; one switch discarded 102k tokens and redid 59k.

What

A request names its mind with "page": the core's PageKey::Mind, 128 bits, parsed once at the JSON edge. Every named mind has exactly one home:

  • Lane: decoding.
  • Parked: a sequence of the unified KV pool. Moving in or out is seq_cp + seq_rm for target and draft: attention cells are re-tagged and the recurrent state moves by id, so nothing is serialized.
  • Flash: her sequence is copied out of the pool (a memcpy inside unified memory), her cells are freed at once, and the file is written by the page-IO worker off the decode thread. She comes back by mapping the file and inserting it.

How the pieces behave:

  • A switch parks the lane's mind and moves the arriving mind in from wherever she is. When the pool is out of room, the coldest parked mind goes to flash first.
  • A failed insert never loses a mind. Her file and record stay; she is still on flash.
  • "No free space in the KV cache" now sends the coldest parked mind to flash, replacing the old try_clear_idle_slots purge, which truncated a mind.
  • Unknown content (a core page restore, or scratch) is adopted by the arriving mind, never cleared.
  • --minds N (the core's resident count) sets the context's sequence capacity to lanes plus N. The parked ids are what the context reports. It requires --kv-unified and --slot-save-path; without them the server refuses to start, with a typed error.

Measured (qwen35-0.8b hybrid, M5; three minds of about 3.3k tokens rotating through one lane, 3 rounds)

Pool Switch out Switch in Each return
Holds all three 0.16–0.20 ms 0.16–0.18 ms (parked) cache_n 3300 of 3304
Holds two 0.16 ms, plus the coldest to flash: 58.1 MiB copied out in 1.7–2.9 ms 5.9–8.0 ms from flash; whole switch 6.7–8.8 ms cache_n 3300 of 3304; nothing purged, lost or truncated

0 warnings.

Next

  • Prefetch: the core names the next mind, and she is loaded from flash into a free parked sequence while others decode, so her switch is the 0.2 ms move.
  • The core's half (Codex): send "page" with each request; launch with --minds; drop its page save/restore around switches once the engine reports the mind parked.

Measured after deploy

Owner: Fable, on the M5 with the real residents. Switch time per act, prefill tokens per act, decode tok/s and swap, against today's baseline.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 2 commits November 16, 2026 13:58
…ery slot's checkpoints (CONTINUUM-ENGINE 4.7.6 step 1)

The M5, 2026-11-16 19:53Z: the engine (up 2h58m, 4 residents, --cache-ram 9494, --ctx-checkpoints 32,
--parallel 5) held 16.1 GB SWAPPED (vmmap: resident 33.2G, swapped 16.1G; system swap 15.0 of 15.4 GB) and decode
ran at a median 1.3 tok/s over its last 80 acts (par ~56): two holders sized apart, nothing bounding their sum
(the log: 89-103 MiB checkpoints, stores full; cache entries up to 2.35 GB, 224 cache evictions in 3h).

- --cache-ram N (MiB, > 0) bounds the prompt cache AND every slot's checkpoints together.
- Checkpoints are charged first (they serve the minds in the slots): a checkpoint is quoted before it is copied
  (llama_state_seq_get_size_ext, target + draft parts), and the slot holding the most checkpoint bytes gives up
  its least valuable one (checkpoint_to_evict keeps her head) until it fits; one larger than the whole budget is
  not made.
- The prompt cache holds the rest: its limit is the budget less the checkpoint bytes, applied after every
  checkpoint and before every cache save (the cache then evicts down to it).
- -1 (no limit) and 0 (disabled) behave as before.

Step 1 of 4.7.6: the accounting bound, no new flag (the core's existing --cache-ram figure is the grant until
the one-pool ABI replaces both sizers with Codex's core change). The arena (4.7.6 revision) follows.

Receipt (qwen35-0.8b, M5, --cache-ram 150 --ctx-checkpoints 32 --parallel 4, 4 slots x 3 rounds of growing
prompts): "host budget (prompt cache + checkpoints, all slots): 150 MiB"; 8 budget evictions of 19.3 MiB
checkpoints; 0 warnings. The real-persona read is the M5 deploy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…e pool and flash; never a serialization, a drop or a truncation (Joel: "almost zero cost to context switch")

The M5, 2026-11-16: a mind leaving a lane was serialized into the size-capped prompt cache (up to 2.35 GB per
switch, 224 evictions in 3h) and DROPPED when it did not fit (10 "exceeds cache size limit, skipping", 8.7 GB);
the arriving mind resumed from an older checkpoint and re-prefilled (one switch: 102k tokens discarded, 59k redone).

Every mind the request names ("page": the core's PageKey::Mind, 128 bits, parsed once at the JSON edge) has one
home: a lane (decoding); PARKED, a sequence of the unified KV pool (seq_cp + seq_rm: attention cells re-tagged, the
recurrent state moved by id, target and draft); or FLASH (her sequence copied out of the pool, a memcpy inside
unified memory, her cells freed at once, the file written by the page-IO worker off the decode thread).
- A named request on a lane holding another mind parks her (or, the pool out of parked ids, sends the coldest
  parked mind to flash first, or her straight from the lane) and moves the arriving mind in from where she is:
  parked (a move) or flash (her file mapped and inserted; the pool full, the coldest parked mind goes down first,
  then the insert is tried again; she is never dropped: on failure her file and record stay).
- The decode's "no free space in the KV cache" sends the coldest parked mind to flash (was: purge an idle slot,
  i.e. truncate a mind); an idle lane's named mind goes to flash whole, never purged.
- Content no named mind owns (a core page restore, scratch) is adopted by the arriving mind, never cleared: the
  prompt's prefix match keeps what is hers. Erase and page restore reset the lane's mind.
- --minds N (the core's resident count): the context's sequence capacity is lanes + N; the parked ids are what the
  context reports (llama_n_seq_max), never assumed; output rows cover every sequence. --minds needs --kv-unified
  and --slot-save-path (typed refusal to start otherwise).
- The prompt cache is off the switch path for named requests.

Receipts (qwen35-0.8b hybrid, M5, --parallel 2 --kv-unified --minds 3, three minds of ~3.3k tokens rotating
through one lane, 3 rounds):
- pool holds all three (-c 16384): switch out 0.16-0.20 ms, in (parked) 0.16-0.18 ms; every return cache_n
  3300 of 3304 (4 tokens prefilled).
- pool holds two (-c 8192): coldest to flash 58.1 MiB copied out in 1.7-2.9 ms; back from flash inserted in
  5.9-8.0 ms; whole switch 6.7-8.8 ms; every return cache_n 3300 of 3304; nothing purged, nothing lost.
Next: prefetch the next mind from flash into a free parked sequence while others decode (the core names who is
next), so her switch is the 0.2 ms move.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…decode (POST /minds/prefetch), so her switch is the 0.16 ms move

Like a streaming engine loading what the camera needs next: the core names who is next; the engine inserts her
flash page into a free parked sequence now (the coldest parked mind going down to flash to make room), between
the current mind's decode steps. When her request arrives, the switch is a sequence move.

POST /minds/prefetch {"page": "<mind>"} -> {success, message: lane | parked | new | flash, no parked id free |
flash, pool full (ms)}; a task on the engine thread (SERVER_TASK_TYPE_MIND_PREFETCH), the only owner of the KV.

Receipt (qwen35-0.8b hybrid, M5, --parallel 2 --kv-unified --minds 3 -c 8192: the pool holds two of three
~3.3k-token minds; each request's next mind prefetched 150 ms into its decode): prefetch 6.9-10.1 ms each (flash
insert 6.1-8.6 ms, the coldest out in 1.8-2.9 ms), all landing during the previous mind's decode; every switch
out 0.166-0.177 ms, in (parked) 0.155-0.163 ms; every return cache_n 3300 of 3304, she holds 3327 tokens.
Without prefetch the same rotation switched in 6.7-8.8 ms (from flash at the switch). 0 warnings.

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

Copy link
Copy Markdown
Author

Source review at a8388c4: blocking custody and scheduling defects in server-context-minds.inc.

flash_out removes both sequences and relinquishes their ids before the asynchronous file write succeeds. The only byte buffer is owned by the worker lambda; after a failed fopen/fwrite/fclose it is destroyed, and flash_insert explicitly starts cold. Preserve the charged buffer under the existing completion owner until durable success or a recoverable terminal outcome; failed writes must not destroy the last state. Replay disk-full, short write, close failure and retry, with unchanged restored token/state evidence.

flash_insert spins with std::this_thread::yield while the worker writes. Since it runs on the engine task thread, a slow disk blocks all decode. Keep the arrival pending under the completion owner and resume after completion; do not busy-wait the engine thread. Verify concurrent resident progress during a delayed write.

Core save/restore deletion remains blocked on these fixes and the agreed incarnation/page/generation custody receipt. Small-model happy-path timing does not cover either failure.

joelteply and others added 2 commits November 16, 2026 14:30
…waits on the disk; a failed write keeps her in RAM (Codex's review of #139)

- flash_out: the record holds her bytes (ram) beside the page-IO worker's write; the worker never owns the last
  copy. minds_reap (each loop, never waiting) releases the RAM copy once the file landed; a failed write keeps it
  (she lives in RAM) without retrying every step against a failing disk: her next trip out of a lane writes again.
- flash_insert: from RAM while the write is in flight or failed (no spin on the engine thread), else her file
  mapped; the file is removed on the page-IO worker, ordered after its own write.

Receipts (qwen35-0.8b hybrid, M5, --parallel 2 --kv-unified --minds 3 -c 8192, three ~3.3k-token minds x 3
rounds): normal: back from flash 5.0-7.5 ms, every return cache_n 3300/3304. Pages dir read-only (every write
fails): every return still cache_n 3300 (back from RAM 3.7-5.6 ms), 7 failed-write lines (one per write, no storm),
nothing lost. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…came from, switch ms, generation), so the core deletes its own page moves only on the engine's word (Codex on #139)

timings.mind = {page, from: lane | parked | flash | ram | new | adopted | flash_pool_full, switch_ms, generation};
typed in the slot's stats (enum mind_from, the page as two integers), text only at the JSON edge. Her
generation advances each time her state moves (out of a lane, back into one), carried with her record.

Receipt (qwen35-0.8b, M5, three minds through a two-mind pool): turn 1 {from new, generation 1}; turn 2
{from flash, switch 5.7-7.8 ms, generation 3, cache_n 3300}. 0 warnings.

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

Copy link
Copy Markdown
Author

Follow-up source review at 5111d28: the record-held RAM buffer and non-waiting insert resolve the two original mechanisms. The caller also checks page equality after an outgoing-copy failure, so that branch does not admit the wrong mind.

Remaining blocker: when flash_insert fails, mind_switch keeps the old record but clears the lane, assigns the requested page, and admits cold execution (flash_pool_full). That creates a new live version while the previous version remains eligible for later restoration. Refuse/defer admission with a typed outcome, preserving one authoritative version. Replay insert failure and a later retry with exact generation and token-state assertions. Do not continue cold or use a completion receipt to retroactively authorize a pre-dispatch custody decision.

RAM staging also needs a charge in the single pool: failed writes must create backpressure when the grant is exhausted, rather than accumulating unbounded retained buffers.

joelteply and others added 12 commits November 16, 2026 14:40
…cut, reloaded or re-served); a failed switch defers the request, never runs cold

The M5, 2026-11-16: 26 of 30 page restores put the same mind back into the same slot ~16 s after it was saved out,
around a learning step: /learn ran ON her sequence and cut it back to the learned turn (keep_first(n0)), or served the
past example on her slot first (cutting her newer context to the example's prompt), so the core saved and restored
her around every learning step.

- POST /learn {"side_sequence": true, messages...}: never served on her slot. From the longest prefix her slot
  shares with the served prompt, back to the latest checkpoint at or before it: her cells [0, from) re-tagged onto a
  free side sequence (a parked id; nothing copied), that checkpoint's recurrent state loaded there, the served
  prompt's own tokens [from, n0) decoded on it, then llama_opt_learn on the side sequence (its restore one token).
  The side sequence is removed after. Typed refusals: no side sequence free (launch with --minds), no checkpoint at
  or before the shared prefix; never a fallback onto her slot.
- learn_pin on a completion pins the checkpoint at its prompt's end - 1; checkpoint_to_evict and
  erase_superseded_checkpoints skip pinned ones; a side learn releases it.
- mind_switch returns false when the leaving mind cannot leave intact or the arriving mind cannot be inserted; the
  request then waits for a lane (Codex on #139: never a cold run beside a stored version of her).

Receipt (qwen35-0.8b hybrid, M5, --parallel 2 --kv-unified --minds 2 --train-dir): she is served a turn (537-token
prompt, learn_pin), acts again (564 tokens; the template renders that turn's generation suffix differently in
history, so her slot differs from the served prompt at token 535), then the past turn is learned side_sequence:
success, 9 labels from position 536, loss 5.70, 531.7 ms; her next act reuses 563 of 564 tokens (nothing cut,
re-served or paged). Before this commit the same learn was refused ("no longer holds this turn's prompt"). 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…d_ids}: the core reads before dispatch that the engine owns mind switches (Codex on #139: a completion receipt cannot authorize skipping the save that precedes the same request)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…he optimizer result; the pin is released only when the learn committed; the reply says learned_on and live_sequence_preserved, typed (Codex's review of #139)

Receipt (qwen35-0.8b, M5, -b 256 -ub 256): past turn learned side_sequence, 9 labels, 407.8 ms,
learned_on=side_sequence, live_sequence_preserved=true; her next act cache_n 563 of 564. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…r bytes, released from RAM) and come back with her; her prompt moves into her record before she leaves, back onto her lane if she cannot

The record kept every checkpoint of a flashed mind in host RAM (~100 MB each on a 35B hybrid), so going to flash did
not free what she held. Her bytes are now [target state][draft state][checkpoints: count, then per checkpoint its
positions, pin and three blobs], validated on the way back (sizes checked before any copy).

Receipt (qwen35-0.8b hybrid, M5, three minds through a two-mind pool, 3 rounds): her flash bytes 96.6 MiB (58.1 state
+ 2 checkpoints of 19.3 MiB), copied out in 2.4 ms, inserted back in 7.8-8.1 ms; whole switch 9.0-11.1 ms (from flash or
RAM); every return cache_n 3300; she comes back holding her 2 checkpoints (2788 and 3300 tokens). 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…nd flashed minds' RAM copies count against --cache-ram; to make room, the coldest parked mind goes down to flash first (her checkpoints with her), before any lane gives one up

The make-room decision counts only what stays resident (a RAM copy is freed within ms of its write landing), so
sending one mind down is seen to free her checkpoints and the loop stops there.

Receipt (qwen35-0.8b hybrid, M5, --cache-ram 60 with three ~38 MiB-of-checkpoints minds through a two-mind pool, 3
rounds): 7 minds sent to flash under the budget before 4 lane-checkpoint evictions; 3 of 6 returns re-prefilled
(cache_n 0) because the lane's checkpoint at their resume point was among those evicted: the budget's trade-off at
an intentionally tight grant (unbounded, every return was cache_n 3300). Choosing which checkpoint goes by value
per byte (keep the one her next resume needs) is 4.7.6's pool policy, next. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… newest checkpoint (her resume point) goes last

The lane-eviction loop counted minds' RAM copies already on their way to flash (96.6 + 58.1 MiB against a 60 MiB grant):
it looked unsatisfiable, stripped the lane's checkpoints and refused the new one ('larger than the whole budget'), so
that mind went to flash with none and came back cold. Now both make-room loops count resident bytes; a lane gives up
its oldest unpinned checkpoint, never her newest while anything else is left; the refusal says what it means.

Receipt (qwen35-0.8b hybrid, M5, --cache-ram 60, three minds with ~38 MiB of checkpoints each through a two-mind pool,
3 rounds): every return cache_n 3300 (was 3 of 6 cold); 8 minds to flash with their checkpoints; 0 lane-checkpoint
evictions; 0 refusals. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ine process (engine_pid; Codex on ggml-org#6087: a stream must never land on a replacement engine)

Receipt (qwen35-0.8b, M5): engine_pid = this process -> answered ('new'); engine_pid = 1 -> 400 'engine_pid names another
engine process'. The OS call lives beside the file mapping (server-mapped-file.cpp). 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…carnation on /props); /minds/prefetch refuses any other, typed (Codex: a pid is reused, never an identity)

Drawn once per process from std::random_device; the core reads it with the pool and sends it back. Replaces the pid
check and its OS call. Receipt (qwen35-0.8b, M5): the /props token -> answered ('new'); 5 -> 400 'incarnation names
another engine'; absent -> 400. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…must never guess a default)

- /minds/prefetch answers {mind, elapsed_ms}; mind is one of lane | parked | unknown | deferred_no_parked_id |
  deferred_pool_full | minds_off (mind_place). Was a success bool and free text; the handler also asserted the
  wrong result type (copied from slot erase).
- learn_outcome: learned_on is none | slot | side_sequence (none = no learning ran); live_sequence_preserved is its
  own field, stated by the path that ran (true for every refusal before custody and every side learn, false only
  when the slot path cut her sequence), never inferred from success.
- Every learn refusal sets the typed refusal (failure is detail only): busy, unsupported, no_adapter,
  prefix_mismatch, no_messages, no_checkpoint, no_side_sequence, residency, replay_failed, optimizer_failed, plus the
  ledger's names and residency_revoked / effects_uncertain. Before, a refused side learn reported refusal 'none'.

Receipt (qwen35-0.8b, M5): never served -> unknown; on the lane -> lane; after another mind took the lane -> parked
(0.001-0.002 ms each). 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ver she is (Codex: a bool pin with no release keeps a checkpoint forever)

The turn receipt reports timings.mind.pinned_at (the pinned checkpoint's position); the core sends {page, pinned_at,
incarnation} back to release it. On a lane or parked: unpinned now. On flash: recorded on her record and applied
when her checkpoints come back. The checkpoint stays as an ordinary one the budget may evict. Typed reply
{release: released | released_on_flash | not_pinned | unknown_mind}; a replaced engine refuses (400).

Receipt (qwen35-0.8b, M5, learning lane --train-dir, ~3.3k-token turns): pinned_at 3300; lane release -> released;
again -> not_pinned; unknown page -> unknown_mind; a pinned mind moved off her lane (parked) -> released; wrong
incarnation -> 400. Not exercised: the released_on_flash path. 0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… of the same length shared pinned_at, so a late release could free the newer turn's pin)

common_prompt_checkpoint.pin: the id (per engine process; 0 = not pinned) replaces the bool, through eviction, the
policy, the side learn's commit, the flash bytes (8 bytes) and the pending releases of a flashed mind. Receipt:
timings.mind.pin (+ pinned_at, information only). POST /learn/release takes {page, pin, incarnation}.
Also fixed: the close-checkpoint eviction in create_checkpoint erased pinned checkpoints, so a pin never survived
her next turn.

Receipt (qwen35-0.8b, M5, --train-dir, ~3.3k-token append-only turns; three minds through a two-lane pool):
parked, no release while away -> after her return: released (pin survived);
on flash (--cache-ram 60, 2 flashes), no release while away -> returns from flash with cache_n 3300 -> released;
released while on flash -> released_on_flash -> returns whole -> not_pinned (applied on read-back);
two pinned turns at the same position -> pins 1 and 2; releasing 1 -> released, 2 still pinned -> released.
0 warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits November 16, 2026 18:32
…efetch result type on the ERASE handler: every /slots/:id?action=erase aborted the server, caught by Windows CI test_slot_erase); the prefetch handler gets the assertion it never had

My e8ee0b2 message also claimed the prefetch handler 'asserted the wrong result type (copied from slot erase)': wrong.
It had no assertion; my edit replaced the next function's. Retracted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ds (Ubuntu CI: 'struct ckpt has no member named pin'), plus the case it guards: a pinned checkpoint is never the victim and an all-pinned store yields end()

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 Nov 17, 2026
… behind mind_table; server-context-minds.inc deleted (CONTINUUM-ENGINE 4.12.1)

- engine/mind_table_resident.cpp: the fragment's methods moved whole into a class private to the file; the engine
  fields it read became dependencies (mind_table_config of startup facts, the memory pool, the page-IO worker, the
  slots); verbs renamed to the interface (enabled, prefetch, seat, release_pin, reap)
- make_resident_minds(): minds_init's checks as a typed refusal (kv_unified, page dir), its parked-id setup in the
  constructor; built in load_model right after the pool
- make_room(room_from): the coldest-parked flash plus the idle-lane flash that lived in the slots fragment; callers
  name their scope (a placement may take an idle lane's mind, a checkpoint's host bytes only parked minds), so no
  caller's behavior changed
- lend_id/return_id/free_ids replace park_free read and written by learning, the routes and the minds code;
  host_bytes(host_count) replaces the checkpoint code iterating the minds
- learn_pin_clock stays on the engine for the learner

Every translation unit parses; the class compiles -Wall -Wextra clean.

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

Copy link
Copy Markdown
Author

Independent review of exact fork head 0df8dc4 paired with core ggml-org#6087 d5c4e5dcacb7b2b1be2b11ab62d92a62e7b7f736: changes required before merge.

  1. P1 — resident failure falls through to destructive purge. tools/server/server-context.cpp:1933-1955: when flash_coldest() and idle-lane flash_out() fail, the code restores slot.prompt, exits the minds branch, then enters the old loop and calls slot.prompt_clear(). This destroys precisely the state the failure branch says it preserves. End the resident branch with a refusal when no legal move succeeds. Replay a forced save failure and prove page identity, tokens, target and draft remain intact.

  2. P1 — mutable free count is used as immutable pool identity. /props at server-context.cpp:5079 returns park_free.size() as parked_ids. Core MobileVLM convert.py error ggml-org/llama.cpp#6087 compares the entire ResidentMinds value on rediscovery and returns MindsMismatch. Parking one mind changes that number without changing the engine. Report total parked capacity separately from free IDs; replay discovery before/after park, prefetch and unpark and verify the same pool remains accepted while a changed incarnation is rejected.

  3. P1 — failed flash copies escape the host budget. server-context.cpp:2708-2710 excludes all m.ram via checkpoint_bytes(false), including copies whose disk writes failed and therefore remain indefinitely. server-context-minds.inc:188 allocates the whole state/checkpoint copy without admission. A slow/failing disk can retain these copies while new checkpoints consume the supposedly freed budget. Keep pending/failed copies charged until actual release and admit any transfer peak through the existing owner. Replay blocked writes and ENOSPC with memory/accounting evidence; no destructive fallback.

  4. P1 — page length validation can wrap. server-context-minds.inc:87,274: a+b+d and 24+h[0]+h[1]+h[2] are unchecked u64 additions used to approve pointer ranges. Corrupt lengths can wrap to a small sum, pass the check and produce out-of-range pointer arithmetic/assign. Validate each slice against remaining bytes (or checked arithmetic), and reject before mutating either sequence. Include overflow, truncation and target/draft mismatch cases.

The fork's current real CI checks are green; that does not exercise these failure transitions. The newly pinned core head still has checks running. Fable owns corrections and the M5 deployment; I have made no fork edits or runtime changes. This review does not approve the pair for merge.

…apart; a mind is never purged when no legal move exists (Codex's two blockers on the exact pair 0df8dc4/d5c4e5dca)

1. parked_ids was park_free.size(), the current free count: the first mind that parked changed it, and the core's
   next discovery of the same engine failed with MindsMismatch. It is now the fixed capacity (sequences beyond the
   lanes while minds are on), and parked_free is the free count. The core decodes the new field as unknown (ignored).
2. try_clear_idle_slots: when neither the coldest parked mind nor an idle lane's mind could go to flash, the code
   restored her prompt and FELL THROUGH to the legacy purge, which cleared her. With minds on, a slot holding a mind is
   skipped by that loop (no legal move -> false); an anonymous slot's cached prompt may still be cleared.

tests/unit/test_minds.py (the first server test of resident minds; harness gains n_minds/--minds): the capacity holds
across park and unpark while the free count moves; a returning mind comes back from 'parked' with her prompt from
cache. Not run here: it runs in this window's build or CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… an overflowing sum; a failed flash write's RAM copy counts against the host budget; a flash-out copy is admitted before it is allocated (Codex's remaining P1s on #139)

3. budget: checkpoint_bytes counted a mind's RAM copy only as in-flight, so one whose flash write FAILED (she lives
   in RAM for good) was outside the budget; it now counts as resident. flash_out allocated her full copy without
   admission; it now checks host_budget for what the copy adds (her state + header; her checkpoints are already
   counted) and, over budget, refuses: she stays where she is.
4. lengths: flash_insert accepted size == 24 + h0 + h1 + h2 and ckpt_read (end - r) < a + b + d; a corrupt or
   crafted length could wrap the u64 sum into a 'fitting' total and index far out of bounds. lengths_fit() checks each
   part against what is left; the exact total is compared only after that.

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

Copy link
Copy Markdown
Author

Architecture acceptance correction following Joel's explicit instruction: fixing the four correctness findings does NOT make #139 the intended context-switch implementation. I missed this distinction in my earlier review.

seq_cp / seq_rm walk KV-cell metadata, and llama_state_seq_get_data / set_data serialize/restore cell metadata and per-layer ranges. Avoiding re-prefill does not satisfy the required native-block switch. Do not merge this pair as fulfillment of that design. Any already-authorized live comparison measures the old mechanism only; it is not architecture acceptance.

The required contract is: bind the decode lane to the mind's already-resident native storage through stable descriptors; no state-sized cell/layer traversal, serialization, repacking or recomputation on that switch. Offload/restore retains the compute layout and transfers only required bytes through existing residency/completion owners. Shared prefixes, recurrent state, draft state, buffer lifetimes and GPU completion fences must be accounted for explicitly. Contiguity alone is not proof that attention kernels can bind that layout without a conversion.

Review must check the actual switch call graph and measure switch work versus context size, with bytes moved and cells visited reported. Fault replay remains native, as requested; do not add Python tooling for this recovery work. Fable owns the revised engine layout/design; Codex independently reviews before implementation or acceptance. Preserve current resident state and active builds while coordinating the deployment phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant