Skip to content

The Core runs a turn to its end: no slicing; prefill at full batch; the slicing machinery deleted - #6208

Merged
joelteply merged 13 commits into
codex/frame-prefill-estimatefrom
fable/run-to-end
Nov 21, 2026
Merged

joelteply merged 13 commits into
codex/frame-prefill-estimatefrom
fable/run-to-end

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The Core runs a resident's turn to its end instead of cutting it into slices shared with every ready mind. Joel, 2026-11-21: "you don't cut it up, run single lane; context switching is faster." This serves the minds by giving each turn the whole engine for its duration and cutting the switches that were adding up to 8.5 s inside one turn.

Why (measured on the M5, build 56913f6, 2026-11-21 04:14-04:29 UTC, via #6207's receipts)

Per finished turn median p90 max
switches 48 326 520
switch_ms 880 5,040 8,525
total_ms 51,040 377,831 606,098
admission to first progress (ms) 639 778 1,282

Restoring a mind is cheap (checkpoint_ms 3 to 33 ms). The cost was the one-second service budget slicing each turn among 4 to 5 ready minds.

What changes

  • frame::pick: the bound mind's started turn (prefilling or decoding) keeps the Core until it ends. With none in progress, the next is the least remaining work discounted by wait, so a long wait still comes forward; a tie keeps the bound mind.
  • Each prefill chunk is the engine's full batch, bounded only by her checkpoint boundary.
  • persona.engine.turn carries request, so completions join their transitions by identity (Codex's note on A turn reports every transition from generate_text to its first engine frame, keyed by its request id #6207).

Deleted

SERVICE_BUDGET_MS, share_ms, the bound-time input to pick, Driver::bound_since, Driver::prefill_sample and its two updates, the ready count threaded through pick, step and prefill_chunk, and Candidate::decoding (now started). driver.rs goes from 941 to 928 lines.

Risk, named

Slicing was added after the M5 on 2026-11-18, when short tails waited 300 to 360 s behind cold prefills. The 11-21 read shows 71 to 98% reuse on most turns. Whether a cold prompt still needs its own handling is measured on the deploy below, not assumed.

Checks (cargo exit statuses captured directly)

  • cargo check -p continuum-engine --tests: exit 0
  • cargo test -p continuum-engine --lib persona_scheduler: 12 pass (the pick test rewritten for the new rule)
  • ratchets vs origin/codex/frame-prefill-estimate: exit 0

Deployed

M5, deploy verified, running ad41267 (dark window 197 s). The comparison read for 04:44:45 to 04:59:45 UTC follows as a comment.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 2 commits November 20, 2026 22:37
…on't cut it up, run single lane; context switching is faster")

The frame policy gave every ready turn a slice of a one-second service budget, so a turn in
progress was cut into frames shared with every other ready mind. Measured on the M5 (56913f6,
2026-11-21 04:14-04:29 UTC): 20 to 520 switches per turn at 12 to 25 ms each, up to 8.5 s of
switch_ms inside one turn, and warm turns waiting ~600 ms for a slice before their first frame.

Now the bound mind's started turn (prefilling or decoding) keeps the Core until it ends. When none
is in progress, the next is the least remaining work discounted by wait (a long wait still comes
forward; no mind starves), a tie keeping the bound mind. Each prefill chunk is the engine's full
batch, bounded only by her checkpoint boundary.

Deleted: SERVICE_BUDGET_MS and share_ms; the bound-time input to pick; Driver::bound_since;
Driver::prefill_sample and its two updates; the `ready` count threaded through pick, step and
prefill_chunk; Candidate::decoding (now `started`). driver.rs 941 -> 928 lines.

The 2026-11-18 reason for slicing (short tails waiting 300-360 s behind cold prefills) is named in
frame.rs; the 11-21 read shows 71-98% reuse on most turns. Whether a cold prompt still needs its own
handling is measured on deploy, not assumed.

check 0; persona_scheduler tests 12 pass (pick test rewritten for the new rule); ratchets vs
origin/codex/frame-prefill-estimate 0.

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

Copy link
Copy Markdown
Contributor Author

Run to end vs slicing, M5, two 900 s windows

  • Slicing: 56913f6, 04:14:13 to 04:29:14 UTC.
  • Run to end: ad41267, 04:44:45 to 04:59:46 UTC.
  • Both windows parsed across rotated logs. My first extract read only the current log file and missed the first 13 minutes of the run-to-end window, so that summary is superseded by this one.
Slicing Run to end
Requests entered / dropped 24 / 0 43 / 0
Turns finished 20 39
Tokens generated 4,877 13,943 (2.9×)
Prefill rate (finished turns) 229 tok/s 574 tok/s (full-batch chunks)
Decode rate 33.3 tok/s 31.1 tok/s
Switches per turn, median / max 48 / 520 1 / 1
Switch ms per turn, median / max 880 / 8,525 40 / 92
Turn total, median / p90 / max 51.0 / 377.8 / 606.1 s 61.3 / 155.6 / 286.9 s
Admission to first progress, median / p90 / max 0.64 / 0.78 / 1.28 s 36.0 / 140.7 / 193.0 s

Per resident under run to end (no starvation; each is served regularly):

Resident Turns Median wait to first progress Longest
Aris (8044b75b) 11 30.6 s 148.7 s
Aiko (75ece751) 9 35.9 s 193.0 s
Benchy (2f50b223) 10 50.6 s 146.9 s
Atlas (e5f4141d) 8 51.7 s 140.7 s

Open at the boundary: three requests entered in the window's last 20 s and were admitted (one had first progress). None was a long-queued wait.

Reading:

  • Throughput nearly tripled on the same hardware, and the whole-turn tail more than halved.
  • The cost is queue wait before a turn starts: four continuously busy minds on one Core each wait for roughly the others' turns. This is head-of-line by construction, bounded by aging in pick. No resident was starved.
  • For coding turns (flat value curves) that trade is right. For a deadline (a live call's reply), the book's rule applies: the reply's latest safe start preempts at a token boundary. That is not implemented yet, and is the next change for live work, not a reason to slice coding turns.
  • Caveat: two windows with different arrivals (24 vs 43, partly because faster service brings the next act sooner) are not a controlled replay. A replay of a fixed roster through both policies is the stronger test.

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 at frame::pick: the no-starvation claim fails across completed turns. Example at each boundary: an old unbound 84000-token candidate and a new bound 1-token tail that waited 1 ms. Integer cost for the short tail is zero; even when the old candidate eventually reaches zero the active tie-break still selects the short tail. A backlog of short turns from the bound resident can repeat indefinitely. Protect aged demand at turn boundaries with the existing queue age/order, preserving run-to-end within a turn. Add a repeated-arrivals regression covering this tie. The 900s trial showed all four served, but cannot prove starvation freedom; 36s median and 193s max admission-to-progress remain material for interactive use. Also avoid recomputing all candidates on every decode when an active started turn already determines the pick.

…literals #6207 missed compile

- persona.engine.refused: a turn that ends without an answer (refused, failed, or a caller that
  hung up) now writes a terminal transition with its typed reason and time since admission; it
  wrote only a warning before, so it vanished from the receipts (independent review of #6179,
  finding 6). Every admitted turn ends in exactly one of this or persona.engine.turn.
- core/continuum-core/tests/{qwen35_chat_pipeline_full,llamacpp_metal_throughput}.rs: four
  TurnPrompt literals lacked #6207's `request` field, so those (ignored) test targets did not
  compile; CI's lib-test jobs never built them, and I had checked only the engine and cognition
  crates (finding 1, my miss).

cargo check -p continuum-engine -p continuum-core --tests: 0; persona_scheduler tests 12 pass;
ratchets vs origin/codex/frame-prefill-estimate: 0.

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

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At ce8a894 the new refusal receipt covers driver.step errors, but suspend still drains every admitted turn and sends only Emit::End(Error). A graceful stop with one active and one queued request therefore leaves both missing from terminal accounting. The holding branch also returns on a closed submission channel while turns can still exist. Centralize admitted-turn termination across those paths, drain the record stage before shutdown acknowledgement, and replay stop with two admitted request IDs. Verify each ID joins exactly one terminal result, including the retained-state reason.

…osed, each with exactly one terminal record; a stop is acknowledged after its records are written

Codex on ce8a894: a graceful stop drained admitted turns with only an Emit error, and the
closed-submission path returned with turns still admitted: both left no terminal record.

- driver/ending.rs (new): `Ending` (Answered, Refused(TurnError), Stopping, Closed) and
  `Driver::end`, the one place an admitted turn leaves the engine: it writes the turn row
  (answered) or persona.engine.refused with the reason, releases a one-off, and tells the caller.
  The loop's answer and error arms, the stop's drain and the closed channel all go through it.
- A stop is handed back from `take` (`Stop`) and acknowledged by the loop only after
  `settle_records`: both outboxes drained, then a record-stage `Barrier` answered (FIFO), so its
  last records are written before the acknowledgement. The closed path settles them too.
- `Advanced::Done` carries exactly an answer (`tokens_generated`, `elapsed_ms`) instead of any
  TokenEvent; the turn row moved from `step` into `end`.
- driver.rs: 1008 -> 942 lines after the split (the 1,000-line gate).

check -p continuum-engine --tests 0; check -p continuum-core --tests 0; persona_scheduler tests 12
pass; ratchets vs origin/codex/frame-prefill-estimate 0. Live stop replay follows on the PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: L and removed size: M labels Nov 21, 2026

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8e597e1 now routes drained turns through Driver::end. Stop acknowledgement still returns the successful native suspend result when the record barrier sender has disappeared: settle_records logs records_unsettled and returns (), then acknowledge calls report(stop.reply, stop.suspended). Preserve the successful native snapshot while separately reporting the unconfirmed terminal records to the lifecycle caller. Test closing the record stage before barrier ACK; the caller must distinguish it from confirmed completion. Also test a stalled Emit sink with queued output: settle_records joins emit.drain with record.drain before observing the record ACK. Verify stop can finish independently of that caller. Prior boundary fairness finding remains open.

…en; a stalled caller never holds it

Codex on 8e597e1: (1) a record stage that ended before answering the barrier still yielded a
fully settled acknowledgement; (2) settle_records joined Emit's drain, so a caller that stopped
reading her answer held the whole stop.

- `settle` (driver/ending.rs), a function of the two outboxes: Emit is flushed but never awaited;
  the record outbox is drained, then the barrier awaited; a record stage that ended reads
  `Records::Unconfirmed` (probe persona.engine.records_unconfirmed).
- `Suspended` carries `records: Records`. The suspend now returns `Suspension` (what it did
  natively); the acknowledgement assembles `Suspended` with the records outcome, so no placeholder
  is written and overwritten. The stop's custody report keeps its state (records are telemetry, never
  custody) and appends "the records of the turns it ended were not confirmed written" when so.
- Tests (driver/ending_tests.rs, real flow stages): records read Written only when the record stage
  confirms them, Unconfirmed when it ended first; a stalled Emit sink with queued output never holds
  the settle, and its output is left for its caller. Mutation-checked: forcing Written fails the first.

check -p continuum-engine -p continuum-core --tests 0; persona_scheduler tests 14 pass; ratchets 0.

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

Copy link
Copy Markdown
Contributor Author

Live stop replay, M5, build 67abfaa (2026-11-21 05:49:01 to the stop at 05:53:02 UTC)

Residents ran for 4 minutes. I recorded which admitted request ids had no terminal record yet, then ran a graceful continuum stop, then continuum start.

admitted: 9  in flight at stop: 3
--- every admitted id, its terminal records (must be exactly 1):
047c17ab-fcf2-48f2-b733-9593b7973883 terminal=1 (in flight at stop) reason=the engine is stopping: her state is preserved
29f6b8b7-c8b4-4e33-a35f-4099d2cc2483 terminal=1  
2adfea98-0f14-4581-adeb-e4f6379f6478 terminal=1 (in flight at stop) reason=the engine is stopping: her state is preserved
6922a099-e3a5-4048-bd09-ef5e08af8d1b terminal=1  
8d42b544-32ea-4854-afb7-c654721beee2 terminal=1 (in flight at stop) reason=the engine is stopping: her state is preserved
8db0d508-b936-4fb8-9db1-992f0628c2ed terminal=1  
9cfc7b23-941d-46f1-b759-219323693e56 terminal=1  
b4b932e7-bb9a-4f59-b5bb-39f0a011113c terminal=1  
warmup terminal=1  
--- stop's own report:
  • Every one of the 9 admitted ids, the warmup included, joins exactly one terminal record. The 3 in flight at the stop each ended in persona.engine.refused with the stopping reason.
  • The stop preserved 4 minds and retained 0. No records_unconfirmed fired, so the records were confirmed written before the acknowledgement.
  • Restarted through the supported path; running build 67abfaaf6a (verified with continuum ping).
  • Still open: the fairness and head-of-line finding from the run-to-end window (median 36 s from admission to first progress).

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 67abfaa: settle drains the record queue and waits for its FIFO barrier; an unread answer cannot hold the stop. Closed record stage yields Unconfirmed independently of native custody. The two focused tests and M5 replay resolve my shutdown findings. Fairness at turn boundaries and interactive head-of-line latency remain open, so this is acceptance of shutdown behavior only.

joelteply and others added 4 commits November 21, 2026 00:10
…ically as her live turn (Joel, 2026-11-21: "Replay should be as realistic as regular mode")

cognition/replay-request gave every replay a fresh persona id, so the engine served it as a stranger
with nothing cached: every replayed turn was a cold prefill, unlike live turns that reuse 71-98%
of their prompt (the M5 windows of 2026-11-21).

- `identity`: `isolated` (the default, unchanged: a fresh mind, cold) or `resident` (the source
  persona's own mind, so her parked blocks are reused exactly as her next live turn would reuse them).
- The engine's identity and the capture's owner are now separate: the capture is always owned by a
  fresh replay identity, so a replay never enters her prompt history or her learning, whichever
  mind served it.
- The result names the identity it was served as.
- A resident replay interleaving with her live loop is safe (one serial queue per mind; reuse is
  checked against the actual prompt) but spoils a measurement, so a measuring run holds and
  despawns her first. No cross-layer hosting check (cognition must not import mind).

The validator (request_replay tests) extends the isolation test: a resident replay is served as her
own mind and its capture is still owned by a separate replay identity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…efaulted field, not an Option

- persona.engine.decode_refused (continuum-persona-llama unified_tier): when llama_decode refuses a
  step, the probe records the step (from, tokens), the context geometry (n_ctx, n_ctx_seq,
  n_seq_max, n_batch, n_ubatch) and every execution stream's occupant and highest position. The M5,
  2026-11-21: cold 26-36k resident replays were refused "no KV slot" (llama_decode returned 1)
  about 31 s into prefill, and the source alone cannot tell other streams' cells, full-batch
  chunks or fragmentation apart (Codex's request: measure before inferring a cause). Its first
  dependency on continuum-base (the floor) and tracing.
- ReplayRequestParams::identity is `ReplayIdentity` with a serde default (absent = isolated) instead of
  `Option` + unwrap_or_default at two sites (the unwrap ratchet).

check -p continuum-persona-llama -p continuum-engine -p continuum-cognition --tests 0; request_replay
tests pass; persona-llama builds with metal; ratchets vs origin/fable/run-to-end 0.

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

The M5, 2026-11-21 (persona.engine.decode_refused, e61b5cf): a 26,633-token resident replay was
admitted to a 24,576-token stream (n_ctx 49,152 / n_seq_max 2), prefilled for ~31 s, and refused by
the engine at the chunk that crossed the end (from 22,623 + 2,048 tokens). The engine spent the work
and then failed; the object model's Core answers Infeasible when a need exceeds its cap.

- admission.rs (new): `StreamCapacity` (the applied geometry's n_ctx_seq) admits a prompt only with
  room for one generated token, else `Infeasible { prompt_tokens, capacity }` (typed, with Display).
- The driver holds its `StreamCapacity` from the geometry it applied, checks every turn at `admit`,
  tells the caller with the numbers, and records persona.engine.infeasible keyed by the request id.
  A refused turn was never admitted, so it has no other transition.
- Live deliberation already fits prompts to the published n_ctx_seq (delib.turn.demand
  context_window=24576 tonight); this guards every caller that does not fit its own: replays, and
  external drivers.

persona_scheduler tests 15 pass (the admission validator added); check engine + core tests 0;
ratchets vs origin/fable/run-to-end 0; driver.rs 953 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits November 21, 2026 01:53
Replay as realistic as live (identity=resident); refused decodes say what the engine held; the Core refuses an oversized prompt at the door
@github-actions github-actions Bot added size: XL and removed size: L labels Nov 21, 2026
joelteply and others added 2 commits November 21, 2026 03:16
…, no "written" the log never confirmed

Codex's full review at 162fbe5, each finding with a validator that fails on the old code:

- P1 frame.rs: the cost was integer division, so an aged and a fresh one-token tail both cost
  zero and affinity won every tie; a bound mind that kept arriving starved an older one. Costs now
  compare exactly (cross-multiplied); an equal cost goes to the longer wait; only a full tie keeps
  the bound mind. Validator: repeated arrivals of the bound mind, the older mind served on its
  first round.
- P2 driver.rs + ending.rs: when every submission handle dropped, the loop flushed Emit once and
  dropped what a full Emit still held with the driver, answer ends included. `Driver::close` ends
  every turn, settles records, and hands Emit to a drain owner on the stage runtime (`hand_off`),
  in order; the engine thread never waits on Emit and the stop acknowledgement stays independent.
  Validator: a saturated Emit stage, its outbox handed off, all eight outputs in order.
- P2 record.rs / probe_file_sink.rs: `Records::Written` confirmed only that the tracing callbacks
  returned, and the sink dropped write/flush errors. The probe floor now owns one count of failed
  probe-log writes (continuum-base `probe_writes`), the sink counts each line it cannot write, and
  a settle reads `Records::Processed { write_failures }` since the previous settle; durability is
  never claimed. Validator: a sink on a disk that refuses writes counts the failure; a settle
  reports a failure counted in its window, once.

Touched files leave clean: the probe sink's unbounded single-file `new` had no production caller
(boot rolls) and is deleted, its 12 tests move to the rolling constructor; its serialization names
its disk boundary; `DEFAULT_MAX_LOG_FILES` is now the appender's `KEEP` (8, what the broker's
rotation pool budgets), not a second count of 7.

engine persona_scheduler 18 pass, kernel probe_file_sink 16, base probe_writes 1; mutation of the
tie order and of the hand-off each fails its validator; check engine/kernel/core tests 0; ratchets
vs origin/codex/frame-prefill-estimate 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ded off reach their callers

Codex on 8f386fb: `Driver::close` hands a full Emit outbox to its drain owner, then the driver
thread called `StageWorker::stop()` on both stages before that task necessarily ran, so the ends it
had not yet pushed came back `Stopped` and were dropped.

A stage already ends by itself once its last producer is gone and it has handled what it took, and
after `run` returns the only producers left are the driver's (dropped) and the drain owner's (dropped
when drained), so the thread now waits on `driver::finish`, which joins both stages and never stops
them. Startup failures and early returns drop their inputs too, so the join always returns.

Validator: a full Emit handed off, then `finish` exactly as the thread runs it: all eight ends
reach the caller in order. Mutating `finish` to stop before joining fails it.

persona_scheduler 19 pass; check engine + core tests 0; ratchets vs origin/codex/frame-prefill-estimate 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 598c1ca into codex/frame-prefill-estimate Nov 21, 2026
47 checks passed
@joelteply
joelteply deleted the fable/run-to-end branch November 21, 2026 10:08
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