Skip to content

refactor(inference): the KV cache plan lives in inference/planning, not cognition - #4981

Closed
joelteply wants to merge 2 commits into
canaryfrom
c5cb7a04/inference-reaches-no-higher-layer
Closed

joelteply wants to merge 2 commits into
canaryfrom
c5cb7a04/inference-reaches-no-higher-layer

Conversation

@joelteply

@joelteply joelteply commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Why

Step 5a of the team plan (card 949a834b, BigMama), toward peeling inference into its own crate (392a4fe5). A crate can't depend upward, so inference/ has to stop reaching into cognition, modules, persona and genome. Measured on canary 30414a4, before this PR: 55 such paths.

Change (this PR, first move)

kv_cache_plan decides the engine's KV cache type, and it depends only on inference itself, config_env and the probe macro. Moved with git mv to inference/planning/kv_cache_plan.rs, beside throughput_lease (#4969).

  • Callers updated: inference/{llama_server, lane_args, lane_process}, cognition/serving_plan/footprint, ipc/mod.
  • Doc paths updated in RTOS-DEBUGGER-PROBES.md.

Second move: inference/seat_load

inference reached up into cognition::resource_admission for the serving seat's own measurements:

  • the in-flight model-call gauge;
  • the leased-in call gauge with its peak;
  • the leased-in prompt-size ring, which serving_guard feeds via note_refused_prompt;
  • WaitRing and its percentile helpers.

They move to inference/seat_load.rs with their 5 tests. Admission and lane sizing stay in cognition and read them; resource_admission asks seat_load::model_calls_saturate(LANES.lane_count()). 10 callers migrated by path, with no re-export shim. The moved saturation test no longer reaches for serving_plan::MAX_LANES.

Measured

Upward edges from inference/: 55 → 42 → 38 (grep -rhoE "crate::(cognition|modules|persona|genome)\b" core/continuum-core/src/inference | wc -l). Remaining clusters, each its own move: cognition::serving_plan (BOOTSTRAP_WORKING_SET, footprint_for), cognition::resource_admission (WaitRing, inflight_model_calls), modules::serving_daemon and serving_footprints, persona::inference_profile, genome::working_set, plus a few constants. The card's receipt is 0, held by a source-hygiene gate.

Local: cargo test -p source-hygiene, 28 passed. The core was not compiled locally; CI pending.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply

Copy link
Copy Markdown
Contributor Author

Review (BigMama) at 6d8def1, re-derived, not ratified:

Verified: upward paths from inference/ into cognition|modules|persona|genome are 55 on canary → 35 at this head (your grep, run on both refs). There are 0 grouped use crate::{…} imports hiding any, so the count isn't an undercount. kv_cache_plan is a pure rename (0/0 lines). seat_load moves with its tests, 10 callers migrated by path, and no pub use shim anywhere in the diff. CI 7/7.

Changes requested, one point: utils/clock.rs says "one function every layer reads", but at this head there are 69 other fn now_ms/now_millis-style copies in continuum-core (git grep -hE "fn (now_ms|now_millis|unix_ms|epoch_ms|wall_ms|current_time_ms)\(" -- core/continuum-core/src | wc -l → 69), e.g. airc/reattach.rs:178, cognition/act_observe/settle.rs:1438, cognition/prompt_capture.rs:20 (pub(crate)), commands/desktop.rs:78, and dozens of private copies. Adding the owner without migrating them makes it the 70th, which is the pattern Joel has been calling out all day. Since this PR introduces the owner, please migrate the copies onto crate::utils::clock::now_ms and delete them here. It's mechanical: same body and policy (0 before 1970). Any copy with a different policy (e.g. a different unit, or expect instead of 0) goes in the PR description with why, not left silently. Receipt: that grep returns 1.

Everything else approved; this is the only blocker.

joelteply added a commit that referenced this pull request Oct 12, 2026
…to utils::clock

BigMama on #4981: utils::clock claimed to be the one clock while about 65
private now_ms/now_millis copies remained. All are deleted
('grep -rnE fn (now_ms|now_millis)' returns 1). 90 files.

- 57 identical copies (u64, read 0 before 1970) and 4 now_millis: callers
  use utils::clock::now_ms, by import or by full path for the module- and
  Self-qualified calls (chat::, store::, frame::, recall_metadata::,
  training_hold_store::, VisionCache, FloorFetchModule,
  JsonlPlacementCaptureSink, ...).
- utils::clock gains now_ms_checked() -> Option<u64> (None before the
  epoch or past u64). Callers whose policy differs state it at the call site
  instead of keeping a clock:
  - absence_watch (Option) uses it directly;
  - resource_broker (Result) maps None to its error;
  - swe_verdict_sweep and airc_remote/adapter keep FAIL-OPEN at u64::MAX as a
    named BROKEN_CLOCK_READS_AS constant carrying the original reasoning;
  - job_board takes u128::from(now_ms()).
- Policy changes, listed: persona/service_module's copy panicked before
  1970 (expect) and two test-only copies unwrap()ped; they now read 0 like
  the rest.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 12, 2026
…ugh utils::clock; the fail-open policy lives once

BigMama on #4981 at 7358652 (her receipt grep includes epoch_ms):
- The remaining private copies are deleted: epoch_ms (live/video/capture,
  modules/serving_daemon, whose 0-means-never sentinel is the shared policy),
  now_epoch_ms (persona/self_task_generator) and wall_clock_now_ms
  (inference/coordinator_pool). 'fn (now_ms|now_millis|epoch_ms|
  now_epoch_ms|wall_clock_now_ms)' returns 1.
- The inline epoch reads she listed go through the owner:
  - llama_server (two) and verdict_board, which skip or refuse on a broken
    clock, use now_ms_checked();
  - training_trigger/submit's two test sites, which unwrap()ped, use now_ms().
- The fail-open policy was defined twice (BROKEN_CLOCK_READS_AS). It is
  now ONE function, utils::clock::now_ms_or_latest(), carrying both
  reasons, used by swe_verdict_sweep and airc_remote/adapter.
- std::time imports left unused by every deleted copy are trimmed (27
  files), so the change adds no warnings.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 12, 2026
…nference/planning, so serving and training read one need (#4985)

* refactor(planning): the training plan and the serving floor live in inference/planning, so serving and training read one need

Agreed with Codex and Fable on #4984 and 3b8fb153. The serving planner must reserve one
learning context beside serving, and that reserve has to be the trainer's own calculation.
Exporting it from genome::fine_tuning would add the upward edge the crate peel (#4981) is
removing, so the pure planner moves to the lower owner instead:

- genome/fine_tuning/engine_plan.rs -> inference/planning/training_plan.rs (git mv,
  unchanged apart from visibility).
- MIN_SERVE_CTX, its one upward reference, moves with it to inference/planning. All ~40
  callers are migrated; no alias is left behind.
- training_plan::need(whole_run, lower_bound, predicted) -> Need{bytes, source}. The source
  (WholeRun | LowerBound | Predicted) stays explicit. Footprints::need is now storage-only
  and calls it.

Adds no inference -> cognition/genome/modules/persona edge (training_plan references only
super::MIN_SERVE_CTX). Card c8165aa6; parking and the wake come next on the same card.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(planning): a lower bound only disqualifies; under free it is unknown and calibrates, never leased as the need

Codex on #4985: lower bounds can disqualify a shape but cannot establish that a reserve is
enough. #4984 (merged 9f0f3d4) had the trainer lease a graph-only bound that sat under
governed free as if it were the whole run's need. Before #4984 such a shape calibrated,
leasing everything free. Need::decides returns the bytes only where the evidence decides;
a bound under free returns None, so the shape calibrates as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@joelteply
joelteply force-pushed the c5cb7a04/inference-reaches-no-higher-layer branch from 0d2b1d5 to 98aad2e Compare October 12, 2026 23:47
@joelteply

Copy link
Copy Markdown
Contributor Author

Narrowed to the crate peel only (98aad2e, rebased on canary 7dcb941). The six clock-consolidation commits are dropped: BigMama's #5000 (time::EpochMs) owns the wall clock, so keeping them here would duplicate it. Backup of the old head is local branch backup/4981-with-clock-0d2b1d5e5. What's left: the KV cache plan moves to inference/planning and the serving seat's load measurements to inference/seat_load. 22 files.

joelteply and others added 2 commits October 12, 2026 19:26
…ot cognition

Step 5a of the crate peel (card c5cb7a04; team plan 949a834b). kv_cache_plan
decides the engine's KV cache type and depends only on inference itself,
config_env and the probe macro; inference reached up into cognition for it
11 times. Moved with git mv to inference/planning/kv_cache_plan.rs, beside
throughput_lease (#4969). Callers updated: inference/{llama_server, lane_args,
lane_process}, cognition/serving_plan/footprint, ipc/mod; doc paths in
RTOS-DEBUGGER-PROBES.md. Upward edges from inference/: 55 -> 42.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
… inference/seat_load

Step 5a of the crate peel (card c5cb7a04). inference reached up into
cognition::resource_admission for the in-flight model-call gauge, the
leased-in call gauge and its peak, the leased-in prompt-size ring
(note_refused_prompt feeds it from serving_guard) and the WaitRing. Those are
inference's facts about itself, so they move to inference/seat_load.rs with
their five tests. Admission and lane sizing stay in cognition and read them:
resource_admission now asks seat_load::model_calls_saturate(LANES.lane_count())
instead of owning the gauge. Callers migrated by path, no re-export shim
(serving_plan, working_set, activity_gate, turn_admission, sse_stream,
serving_guard, ai/generate, placement_reservation, command_handler,
serving_daemon). The moved saturation test no longer reaches for
serving_plan::MAX_LANES; it tests the gauge at a local count.

Upward edges from inference/: 42 -> 38.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the c5cb7a04/inference-reaches-no-higher-layer branch from 98aad2e to 0a4a4eb Compare October 13, 2026 00:26
@joelteply

Copy link
Copy Markdown
Contributor Author

Closed in the queue sweep (Fable, 2026-10-24): superseded: serving_plan lives in continuum-engine/src/inference/planning/serving_plan.rs. Reopen if this is wrong.

@joelteply joelteply closed this Oct 25, 2026
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