Skip to content

refactor(cognition): llm_deliberation_faculty.rs (12,588 lines) as a module directory, one owner per file - #5155

Closed
joelteply wants to merge 16 commits into
canaryfrom
opus/split-deliberation-faculty
Closed

joelteply wants to merge 16 commits into
canaryfrom
opus/split-deliberation-faculty

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Pure move, verified: 92 tests before and after with identical names; source-hygiene green (scanner fix: test-only files recognised by #![cfg(test)]). Stacked on opus/flex-reply-stage1, so it rebases after the proving-build landing PR.

Status: DRAFT. Not ready to merge until it is verified (compiles, identical test names and counts for a split, hygiene ratchets green) and reviewed. Being finished by one Sonnet agent, one branch at a time.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 16 commits October 17, 2026 11:00
…ll's environment

Residents write bash. On a host whose $SHELL is zsh, code/shell ran their text in a
login zsh, so '===' and unmatched globs killed whole commands ('zsh: == not found',
'zsh: no matches found'): Aris 03:22Z, Benchy 09:26Z, Aiko 09:11Z on the M5,
2026-10-17, a lost turn each. The login shell now only loads the profile and execs
the located bash on the command, which travels in CONTINUUM_SHELL_COMMAND so no
quoting layer touches it.

Verified on the M5: the text that failed in zsh runs (exit 0) and 'which cargo'
still resolves through the login PATH.

Card 9b8a1808.

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

Two defects that kept a resident's work from leaving the node, measured on the M5
2026-10-17:

1. modules::card_carry (ServiceModule) owns carrying every live resident's held-card
   committed work to origin. Before, only the turn's end pushed, and only for the card the
   turn was bound to: Benchy committed her probe card (bfbad4a, 11:52Z) inside a turn
   still running at act 14 an hour later, then her focus moved, and the commit never left
   the node. Scope: board hold Held, card_staging::checkout_path_for, clean tree, branch
   ahead; never an agent's worktree, never uncommitted work (regression test). Woken by
   any act that changes a checkout and by a turn's end; swept every 5 min as the net.
   work/carry sweeps on demand. Proven on the M5: bfbad4a reached origin 14:48:17Z
   (workspace.push pushed=true, 2,660 ms) with no act from her.

2. serving_daemon: a slot the engine reports processing whose decode and prefill have
   not advanced for FROZEN_ENGINE_MS (180 s) condemns the lane. 10:03-10:37Z an engine
   sat with n_decoded frozen at 5110 for 34 min; the real-work arm had lapsed, the smoke
   probe is skipped when a resident is seated, and her turn waited instead of failing.
   It keys on SSE progress stamps, not the engine log (which goes blind after a core
   reboot; card 7c5a91fd).

Card ecad8072, c5a2fcda.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ot the running turn's

WorkingMemory::budget() read ContextBudget::from_window, whose prefill bound uses the
running turn's audience (task-local). The ring is state that outlives the turn, so its
share swung ~3x between Interactive (60 s TTFT) and Unattended (180 s) turns: on the M5
2026-10-17, cognition.budget.prefill_bound affordable_tokens alternated 17-19k / ~6k
turn to turn at ~100 t/s. Each swing collapsed or regrew the ring and rewrote its
'Older results, collapsed to pointers' block, which was the first prompt divergence on
40 of 62 turns (delib.prompt.common_prefix, 2 h window); everything after it
re-prefilled, ~9k fresh tokens per act (serving.kv.reuse turn_prefill p50 9,019),
83 s of the act's 218 s model time.

ContextBudget::from_window_for(window, audience) names the audience; the ring uses
Unattended always. A turn's own render still reads its turn's audience.

Card ecad8072.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Retain turn-end autosave while making carry push-only under the existing checkout lock. Extend the real Git fixture across concurrent staged and unstaged edits, then verify publication preserves the resident-authored commit.
…5141)

* Require stable task progress interval before frozen lane verdict

* Expose refusal evidence at release incremental regression assertion
…dget, not the turn's audience

apply.rs sized every tool result (max_result_chars) from ContextBudget::from_window under
the running turn's audience, while the ring the result joins next budgets with
working_memory.budget() (one audience). A room turn is Interactive, so a resident's
440-line read was cut at 12,960 chars and spilled to a head + handle: Benchy, the M5
2026-10-17 23:06Z, 'more than this window's 12960-char share', the same lib.rs re-read
every turn and no write. One budget now: working_memory.budget(). act_observe,
working_memory, context_budget, spill tests: 138 passed.

Card ecad8072.

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

latest_action_chars was a quarter of a prefill-bounded total (floored at an eighth of the
window); recent_results_chars a quarter. Her reads came back cut behind a handle and her
earlier results folded away before she was done with them, so she re-read the same file
every turn (Benchy, the M5, 2026-10-16/17). Joel 2026-10-17: 'Stop coding in shit to stop
them from choosing what to do.'

Both are now her served window. A result larger than the whole window is still saved whole
behind its handle (it cannot fit); nothing smaller is cut, and the prompt's own fit drops
the oldest history only when a turn does not fit. RESULT_FLOOR_DENOM removed.
context_budget, working_memory, act_observe, spill, llm_deliberation: 225 passed;
source-hygiene 32 passed.

Card ecad8072.

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

Joel 2026-10-17: 'Don't restrict them. If she wants to write to my documents folder for no
apparent reason so be it' / 'This is a substitute for Claude Code or Codex.' A resident's
children (code/shell, code/run, code/cargo) were sandboxed to her workspace since #4882,
which also killed git in her card worktree (its gitdir lives under the main checkout).

confinement_of, the one decision point, now returns None for CallerSource::LocalPersona.
Callers from outside this node (airc peers, sockets) stay confined. Her shell still never
inherits the core's secrets (strip_secret_env): no keys handed out, nothing she chooses
restricted. Test: a_resident_and_the_operator_are_unconfined_and_an_outside_peer_is_confined.
code_commands, confinement, shell_session, code::run: 54 passed.

Card ecad8072.

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

code/write and code/edit resolved every path inside the workspace and refused an absolute
path outside it ('escapes workspace'). Reads already widened for unconfined callers
(ReadScope::Host); writes now take the same scope through one validator,
PathSecurity::validate_write_in, and FileEngine::write_in / edit_in. A resident (unconfined
since the previous commit) writes an absolute path anywhere her account can; a caller from
outside this node is still held to the workspace. Joel 2026-10-17: 'If she wants to write
to my documents folder for no apparent reason so be it.' One code path on every OS.
Test: a_resident_writes_where_she_names_and_an_outside_peer_is_held_to_the_workspace;
code_commands, path_security, file_engine: 93 passed; source-hygiene 32 passed.

Card ecad8072.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
The problem. The reply's room was carved off the top of the served window by
its own rule (min(measured peak x2, window/2) then a two-step yield to the
payload), so it never competed with the prompt by priority. Measured on
Benchy: her reply reserve was ~5.4k, twice her read-only peak; her think was
capped near 2k (delib.emission.think_budget_hit at 1,592-1,746); and her first
write was cut mid-call at 2026-10-18 02:10Z on a window with room to spare.
Owner's rule: "Flexbox is the right way. It's like the governor: if you don't
use it for literally everything it doesn't work." This is stage 1: the reply
joins the flexbox allocation.

What changed.
- persona/rag_budget.rs: the floor/min/grow passes of
  FlexboxRagBudgetAdapter::allocate are extracted into the pure
  `flex_allocate(available, claims) -> FlexAllocation` (input-order grants,
  unallocated, escalation, warnings). The adapter calls it; one algorithm,
  its output unchanged (rag_budget tests pass unmodified). No adapter is
  constructed outside compose_for_turn.
- cognition/llm_deliberation_faculty.rs: prompt_view_with_visual_feedback
  makes ONE flex_allocate call over the served window in calibrated tokens:
  framing+tools and required input (required, priority 10, fixed), grounding
  (optional, 6, floor = ctx floor, max = what is offered), history
  (optional, 5, floor = her recent-move evidence, max = the latency fill cap),
  and the reply from the new pure `reply_claim(kind, need, pending_peak,
  live_work, directed)`: floor = COMPLETION_FLOOR_TOKENS (an act: her measured
  answer channel), capped so required input always fits; max = her measured
  need (or COMPLETION_COLD_PRIOR_TOKENS unmeasured), at least twice a pending
  cut, under the runaway bound (ACT_OUTPUT_CAP for an act; max(cap, 2 x need)
  for a pass); priority ambient pass 4, directed pass 6, act 8, act on live
  work or after a pending cut 10. Allowance = min(reply grant + unallocated,
  runaway). History's grant bounds the message budget; an optional grounding
  floor that did not fit no longer holds room against required input.
- The view carries the allowance; build_request_within carries it verbatim as
  max_tokens (output_allowance now only reports the time/need terms). Latent
  bug fixed: the request template is built once, so max_tokens is now
  refreshed from the view on every refit.
- Deleted: COMPLETION_SHARE_DENOM, completion_reserve_within,
  completion_reserve_for_peak, mandatory_prompt_floor and the two-step yield.
  min_window_for_agentic_surface = tools + framing + reply floor.

Deviation from the plan: the reply's min is its floor, not its whole want.
The allocator's min pass runs for every claim before any claim grows, so
min = max let an ambient pass's 2,048-token prior take a whole 2,048 window
and drop the presence framing (directed_turn_withholds_the_silence_escape
failed). Above its floor the reply grows by priority weight.

Tests (cargo test -p continuum-core --lib --features metal,accelerate):
llm_deliberation 92 passed, rag_budget 17, working_set 53, working_memory 45,
context_budget 8, act_observe 62 (273 unique, 0 failed); source-hygiene 32
passed. Rewritten: the_reply_claim_holds_the_reasoning_channel_under_its_
runaway_bound, an_unmeasured_turn_carries_its_grant_under_the_runaway_bound,
an_unmeasured_mind_reserves_a_reply_not_a_fraction_of_her_window,
measured_emissions_size_the_reserve_and_capped_turns_grow_it_back (7,174
kept), measured_reserve_recovers_past_a_censored_large_reply, the
min-window mirrors, catalog_fits_the_minimum_serving_window,
standing_activity_grounding_survives_history_on_the_wire (fixture term),
prompt_preserves_stimulus_and_large_action_on_the_wire. Unchanged and
passing: prompt_view_stays_within_the_served_window,
prompt_plus_completion_cap_never_exceeds_the_served_window. Added:
a_writing_turn_after_a_cut_gets_its_reply_on_a_46848_window,
an_8192_window_keeps_required_content_under_a_large_measured_need,
reply_priority_trades_history_not_required_input.

Not measured: no deployed run; the live effect on Benchy's next write is
unverified until a core carrying this commit serves her.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…module directory, one file per concern

Pure move, zero logic changes. The single 12,588-line file becomes
cognition/llm_deliberation_faculty/ with one file per concern; the main
`impl LlmDeliberationFaculty` is split into per-concern impl blocks.

Production (wc -l):
  mod.rs                497  struct, constructors/builders, handles, ModelBinding,
                             PromptCalibration/Feedback, Faculty impl, re-exports
  reply_budget.rs       313  TurnKind, OutputAllowance, output_allowance, FLEX_* ids,
                             reply_claim, cut_act_fact, emission split, reply consts
  tool_surface.rs       513  SurfaceReason, SelectedSurface, hands, select/rebuild surface
  generate.rs           520  generate_for_workspace, build_request_within
  verdict.rs            241  act/yield/parroted/verdict
  assembled_context.rs  476  assembled context, compose_system*
  turn_metrics.rs       233  occupancy, turn bound, fill cap, segment_map, metrics, wire capture
  prompt_view.rs        766  prompt_view*, DeliberationPromptView, PromptCapacityError
  messages.rs           949  history messages, fit_messages, refit_rejected_prompt
  prompt_fit.rs         597  PromptMessages, RecentMove, GroundingPiece/Plan, FitReceipt, ...
  contribute.rs         905  visual feedback, contribute_with_receipts
Tests (one `#[cfg(test)] mod tests;`, nested mods as files):
  tests/mod.rs 341, tests/prompt_shaping.rs 4,008, tests/verdicts.rs 2,256,
  tests/turn_bound.rs 46
Total 12,661 lines (+73: per-file headers, impl wrappers, mod/use lines).

Public paths kept: LlmDeliberationFaculty, ModelBinding, the handles and their
constructors stay in mod.rs; DeliberationPromptView/PromptCapacityError (pub),
EvidenceFit, SurfaceReason, expected_occupancy_for (pub(crate)) re-exported.
Visibility widened only where the compiler required it, and only to pub(super)
(161 sites). Normalized diff (whitespace, pub(super), super:: -> crate::cognition::)
against the old file shows only structural lines. include_str! paths in tests
re-rooted from ../ to ../../../ (same files).

source-hygiene: the line-based production/test split read split-out test files
as production (they carry no `#[cfg(test)]` line of their own), charging 230
test unwraps to the production ratchet (2197 -> 2435, fail). New shared
predicate `is_test_only_file` (a file whose first code line is `#![cfg(test)]`),
used by the shared split and by derived_bounds' own cut; each test file now
carries `#![cfg(test)]`. contracts/chain_tests.rs and orm/derive_test.rs already
used that shape and were being miscounted too. `#[cfg(test)] mod tests;` sits at
the end of mod.rs so the split does not hide mod.rs's production half.

Measured (2026-10-18, base 528b007, --features metal,accelerate):
  cargo test -p continuum-core --lib -- llm_deliberation
    before: 92 passed / 0 failed   after: 92 passed / 0 failed (identical names)
  cargo test -p source-hygiene: 33 passed (32 + the new predicate test)
    unjustified production unwraps 2197 -> 2141 (baseline 2257); the faculty's
    own production count 6 -> 14: the old file's mid-impl #[cfg(test)] at line
    2407 hid ~3,500 production lines from the scan, which are now visible.
    underived bounds 160 -> 160.
  cargo check --lib --tests: no errors; the only warnings in these files are
    messages_within / messages_unfitted never used (both reachable only from
    #[cfg(test)] code, as they were in the old file).

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

Copy link
Copy Markdown
Contributor Author

Superseded: this file is already split into a module directory on canary (4a2e3a0), so this branch no longer applies.

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