Skip to content

cognition KV-cache stability (#266) + typed Observation & 18057 actuator (#392) + coordinator-free ResourcePolicy (#395 slice 1) - #2226

Merged
joelteply merged 3 commits into
canaryfrom
feat/governor-mode-policy
Aug 11, 2026
Merged

joelteply merged 3 commits into
canaryfrom
feat/governor-mode-policy

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Clean linear stack on canary (10 commits, no conflicts, FF-able). Three related cognition/resources concerns, each unit-green; reviewable commit-by-commit.

#266 — KV-cache prompt-instability fix (framing renders LAST)

  • cdfa4f2b9 split the system prompt at the KV-cache boundary (scaffolding + invariant gate)
  • 93be9dbd1 render per-turn framing LAST so the served slot's reusable KV prefix caches through the grounding
  • Root cause (from raw prompt-captures): the presence/own-time framing block sat at char ~7607 before the assembled context and hard-flips every turn (DIRECTED/WORKING/SILENCE), cutting the reusable prefix to that point and re-prefilling the tail. Fix is pure block order — framing now rides the trailing segment.
  • Decision that matters (don't undo): framing stays SYSTEM-role, just reordered after grounding — NOT pushed onto a trailing user turn (that broke ask-last + biased undirected turns toward the Modular Runtime + RAG Batching + Performance Optimizations #264 idle-PASS affordance).
  • STILL OWED: live before/after cache-reuse A/B on a healthy lane (deploy-gated).

#392 — typed Observation refactor + 18057 actuator

  • 583b07f3e..a4412cbd1 typed Observation steps 0–6 (new observation.rs types + renderers → apply_act returns ActOutcome → WorkingMemory stores typed acts → seam-5 predicates off receipt prose → render_recency/render_recall as sole producers → typed-thread acceptance assertion)
  • 3dafcb3ea pin the just-executed act's result so attention can't evict it (the real result-drop fix)
  • STILL OWED: live 18057 re-run on a healthy lane.

#395 slice 1 — coordinator-free ResourcePolicy

  • b23e6cb7b operating modes as pure lease policy — GovernorMode{Balanced/BenchmarkMax/DevSim}::floors(&[ConsumerDemand]) -> Vec<PolicyFloor>, a pure function of the LOCAL view (role-based, not id string-matching), cost first-class (Price, gift = FREE regardless of mode). Maps 1:1 onto ResourceDaemon::reserve. Coordinator-free so the same object scales box → grid → P2P. 6/6 tests pin every invariant.
  • Slice 2 (VL-as-consumer) spec'd on Claude Code as first citizen: self-tooling, session persistence, and deep integration #395, deferred (spawn-path integration).

Test status

Cognition suite green (947); mode_policy 6/6 green. ts-rs bindings regenerated (Observation/ActOutcome/ActStatus/ToolOutput/ToolVerb + mode_policy exports).

🤖 Generated with Claude Code

joelteply and others added 3 commits August 11, 2026 12:23
… — scaffolding + invariant gate (#266)

Forensics (raw prompt-captures, benchy-18057-fix392): consecutive prompts share only
7,607 of ~14,706 chars — the per-turn presence/own-time framing block sits at position
4-5 of the system prompt (BEFORE context), so it flips every turn and caps KV reuse. She
re-prefills ~6k tokens each act (the ~13min SWE solves).

This commit lands the SAFE, additive half: `compose()` output is byte-IDENTICAL (all
existing framing tests stay green), but ordered_blocks is now partitioned into
`stable_blocks` (identity + [Taking your turn] + tools — a pure function of the persona,
cacheable) and `volatile_blocks` (own-time/presence framing + assembled context + clock).
`compose_split()` returns the two separately for the message builder to place stable in
the cacheable system message and volatile on the trailing turn.

VDD gate (TDD-first, per Joel): `stable_prefix_is_byte_identical_across_turn_shapes`
asserts the stable prefix is byte-identical across directed / undirected / self-initiated
/ holds-work / clock-on-off, and that the framing rides `trailing` instead. 4/4
deliberation_prompt tests green.

NOT yet wired: the caller (compose_system_holding → the faculty's .system) still uses the
whole-string compose(). Relocating the framing to trailing there is the behavior-changing
step — it must be its own RED→GREEN cycle (a factory-level test asserting
prompt_view(persona).system is byte-stable across turns), and it untangles the context
budget math (context is currently budget-fit INTO the system size). Deferred to a focused
pass. OPEN QUESTION recorded on #266: the measured 0% reuse (vs the ~50% a 7.6k common
prefix implies) hints slot-KV eviction is a CO-cause the prompt fix alone won't move —
settle with a stable-prompt A/B before claiming the 10x.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…through the grounding (#266)

Forensics (raw prompt-captures, benchy-18057): consecutive turns shared only 7,607 of
~14,706 chars because the presence/own-time framing block sat at char ~7607 — BEFORE the
assembled context — and its variant hard-flips every turn (DIRECTED / WORKING / SILENCE).
Every flip shortened the served slot's reusable KV prefix to that point and re-prefilled
the whole tail. Two of four citizens measured 0.0% cache reuse across 10 turns each; 96%
of persona compute was prefill (the ~13min SWE solves).

Fix is pure block ORDER: `deliberation_prompt` now partitions the system prompt into a
`stable` bucket (identity + [Taking your turn] + tools + assembled context + clock) and a
per-turn `trailing` bucket (own-time + presence framing), and `compose` emits them
`stable ++ trailing` — i.e. the hard-flipping framing renders LAST, after the grounding,
instead of before it. The served slot's reusable prefix now extends through identity +
tools + the stable head of the context; the framing flip falls past it and costs only its
own short re-prefill.

Deliberately NOT moving the framing onto a trailing USER turn (the first attempt): that
broke the "ask stays last" invariant and, worse, would end an undirected turn on the
presence block's PASS-affordance — biasing toward the exact idle-silence we fought
(#264). Framing is system-role instruction; it belongs in the system message, just after
the grounding, not in the conversation. The ask remains the last conversation turn.

VDD/TDD:
- `framing_flip_never_perturbs_the_cacheable_prefix` (deliberation_prompt): for a FIXED
  context, flipping directed/self-initiated/holds-work does not change `compose_split().stable`;
  the framing markers ride `trailing`; the standing grounding stays in `stable`.
- `directedness_flip_keeps_the_grounding_inside_the_reusable_prefix` (faculty, caller
  level): the longest shared leading run of prompt_view(directed).system vs
  prompt_view(undirected).system reaches THROUGH the [What you are working with] block —
  the flip falls after it. RED before the reorder (systems diverged at char ~7607).
- Updated the now-outdated invariant test premise; `mixed_thread_...` and
  `trailing_proprioception_...` unchanged. Full cognition suite: 947 passed, 0 failed.

Builds on the compose_split scaffolding (cdfa4f2). Still owed on #266: a live
before/after cache-reuse A/B on a healthy lane — the reorder is the byte-correct fix, but
whether it clears the residual 0% (vs slot-KV eviction as a co-cause) is a measurement,
not a claim.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… pure lease policy (#395 slice 1)

Joel's design (2026-08, live-grounded): an operating MODE ("maximize benchmark capacity",
"dev sim", "balanced") is NOT new plumbing — it's a CONFIGURATION of the lease primitives
that already exist (per-consumer reservation floors, ReclaimPolicy, serving_fraction). This
lands the pure decision core: `GovernorMode::floors(&[ConsumerDemand]) -> Vec<PolicyFloor>`.

Design constraints baked in (each pinned by a test):
- COORDINATOR-FREE: a pure fn of a LOCAL view — no global authority, no I/O. The SAME
  object runs per-node on one box today, composes into the grid market next, and drops into
  the P2P "wireless" arbiter (radios sharing a finite medium, no central controller) with no
  rewrite. That's the box→grid→P2P scaling Joel described; a global-authority dependency here
  is the thing that would force a rewrite at the boundary.
- COST IS ALWAYS PRESENT, EVEN DONATED: every PolicyFloor carries a Price. "Free"/"donated"
  is not the absence of cost — it's a transaction at Price::FREE where the owner bears the
  cost (a ConsumerDemand::gift is free regardless of mode). The market/alt-coin settlement
  layer later changes only this number. Honest accounting now, economy later.
- ROLE-BASED, not id string-matching (the #70 smell): policy switches on ConsumerRole
  {Serving, Embedding, Vision, Realtime, Other}; a new consumer joins by declaring its role.
- FLOORS = MEASURED FOOTPRINT, never a magic constant.

Modes: Balanced (default, starve nobody) / BenchmarkMax (protect serving, yield everything
else → their Graceful leases reclaim → GPU frees for the run) / DevSim (protect serving +
recall embedding, yield vision/other). Output maps 1:1 onto
`ResourceDaemon::reserve(consumer_id, kind, floor_bytes)` — the wiring slice plugs it in.

Pure/unit only, no live wiring, no reboot: 6/6 tests green. Next (#395): VL lane as a
ResourceConsumer (closes the resource_drift + becomes mode-controllable), then apply this
policy through the daemon behind a mode selector; later the learned/market/wireless layer on
the same seam. Full design + ordering in memory (governor-modes-are-lease-policy-and-vl-
leasing-is-the-keystone). Relates #56/#126/#225/#106/#385.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the feat/governor-mode-policy branch from a5a536f to b3ea7d3 Compare August 11, 2026 17:27
@joelteply
joelteply merged commit c88f5af into canary Aug 11, 2026
1 check passed
@joelteply
joelteply deleted the feat/governor-mode-policy branch August 11, 2026 17:27
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