chore(memory): BDR-116 amendment 2, LRN-217, TODO + journal, router-cap-residuals contract + plan

This commit is contained in:
bchanot committed 2026-10-13 21:37:30 +02:00
1 parent 1be57a382c
commit 2b91ce26bd
6 files changed
+211 -1

No files matched your search

+2
View File
@@ -1424,6 +1424,8 @@ Branch feature/user-writing-web-rules, UNMERGED (human gate).
- **Amendment (2026-10-13, feature/router-downgrade-cap, commit 2ce203a, user decision)**: W4-B "EFFORT ONLY" clause superseded. Classifier writes full phase route; main may move DOWN on a guess, never above session model (`wantedModel` ranks vs `sessionModel`, not `cur`: breaker fallback sonnet→opus, never haiku); `ultrathink` floor model beats guess. `mainModelSwitch` default **true**, fail-closed picker (non-boolean → off + log). Caps measure COLD READ (LRN-216): `coldRead(M) = tokens − served[M].tokens` within `CACHE_TTL_MS` 1 h, else whole context; `downgradeMaxTokens` 120000 (user delegated value), `upgradeMaxTokens` 200000 same measure; served record written EVERY main step, dropped by `/clear` + `/route reload`, stale (context < record) = cold. No return bypass (warm return cheap by construction). Model-loaded helper skill inside best-tier run → effort only (`belowRun`). Window outgrown (haiku 200k) → back to session model. `/effort` typed between turns drops guess for that turn only (`engineBase` per turn). Rejected: user `/model` suspends classifier (baseline moves, guess follows; `/route classify off` pins) — trade-off accepted; raw context-size cap (r1: refused cheap re-down to warm sonnet, forced cold fable read); engine-model return bypass (premise false after N sonnet turns). Residuals TODO 2026-10-13: unrowed agent `parentModel` inheritance on demoted turn, `session.usage` lag vs new prompt, TTL const. Gates: 3 lenses CONCERNS (10 MAJOR) → r2; confirmation FATAL(7) BLOCKER → r3; feater DONE 450 tests; verifier CONFORME 10/10 first pass; security PASS. Links [[LRN-216]], [[EVAL-047]], [[LRN-204]].
- **Amendment 2 (2026-10-13, same branch, commit 1be57a3, user "fix les residus")**: three residuals closed. (1) Spawn pin NARROW: built-in `general-purpose` only (`INHERITING_AGENTS` + `offers.source === 'built-in'`), no explicit model, no row, no fork/workflow, main's own child, main BELOW session model (`ranksAbove(session, turnModel)`), session model ranked + up → sent `sessionModel` verbatim, cause `session`. Rejected: "no model + no row = inherits" (r1 BLOCKER ×2: frontmatter `model:` invisible to the hook, would override plugin/project agents; LRN-217); any `turnModel` (upgrade would drag agents down). (2) Prompt estimate: `ceil(codePoints/3)` of text + `context` + main's TYPED skill body, summed, first baseline kept; pure `withEstimate` in shared `readingFor` + `mainPlan` (texts = step); `noteServed` RAW (inflated record would trip compaction path); consumed at first main step of its turn; mid-turn → `pendingEstimate` next turn; `document` attachment → unknown → blocked. (3) TTL: `cacheTtlMs` from engine enum `'5m'|'1h'` on main's PostModelSwitch (`agent_id` events ignored), kept across `/clear`, show prints `ttl N min`. Residuals left (TODO): TTL before first switch event = 60 min assumption; hooks-below context / dropped prompt = conservative; `onAutoSwitch` targets main's `lastPlan` for sub-agent fallbacks (pre-existing); LIVE CHECK whether `parentModel` follows the rewrite. Gates: 3 lenses (FATAL ×2, CONCERNS) → r2, confirmation CONCERNS(3) → r3, feater DONE 472 tests, verifier CONFORME 7/7, security PASS. Links [[LRN-217]], [[LRN-216]].
## BDR-117 — shared gstack helpers live in lib/gstack-removed.sh, not in a new lib [accepted] (2026-10-12)
- **Decision**: C5 /refactor 2026-10-12. profile.sh + toggle-external.sh duplicated gstack_skills + park/unpark moves. Host gstack_skills/gstack_parked_names/gstack_park/gstack_unpark in lib/gstack-removed.sh; each takes dirs as args, no caller globals; plain-statement call only (errexit, [[LRN-215]]).
- **Why**: only sourced file 5 fixture suites copy next to both scripts; new lib = every fixture breaks.
+1
View File
@@ -610,3 +610,4 @@ rules:
## 2026-10-13
- model-router /feat `downgradeMaxTokens` (user: switch on by default, classifier may switch model early, back up to fable on reflection). Plan r1 context-size cap → challenge: cap must measure COLD READ (LRN-204), bypass dropped, classifier down-only vs session model; confirmation pass FATAL(7), BLOCKER served-record-on-routed-steps-only → r3. feater DONE 450 tests, verifier CONFORME 10/10, security PASS, commit 2ce203a on feature/router-downgrade-cap. Doc-sync + BDR/LRN/EVAL pending.
- Residuals /feat (user "fix les residus"): plan r1 → 3 lenses FATAL×2 (BLOCKER: `e.model===undefined && route===undefined` ≠ "inherits", frontmatter model invisible to the hook) → allowlist `INHERITING_AGENTS` + built-in source + below-session guard; estimate via shared `withEstimate`, raw served record; TTL enum lookup. Confirmation CONCERNS(3) → r3. feater DONE 472 tests, verifier CONFORME 7/7, security PASS, commit 1be57a3. Doc-sync + capitalize pending.
+4
View File
@@ -1805,3 +1805,7 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s
## LRN-216 — Capping a main-loop model switch = cap the COLD READ (context − target's warm prefix), never the context size; the warm record must be written on EVERY main step
- **Context**: model-router downgrade cap 2026-10-13. r1 compared context size to cap → after N coding turns sonnet warm, fable cold; context crosses cap → next coding turn starts on fable (cold) and cheap re-down refused = worst outcome. r2 fixed measure, but wrote `served` only on routed steps → unrouted steps on session model invisible → return to fable refused above 200k (confirmation pass BLOCKER). Per-model prefix cache (LRN-204): cost of switch INTO M = tokens − tokens at M's last step if within TTL, else all; context smaller than record = history rewritten (compaction) = cold.
- **Apply**: any "switch model when cheap" logic: (1) keep `{at, tokens}` per model id, written at every step of the loop whatever the routing; (2) cost = delta vs that record within TTL, whole context otherwise or when record > current; (3) unknown size = blocked; (4) no special-case "return to session model" bypass, the measure covers it. A guess-sourced route ranks vs the SESSION model, not the current one, or a breaker fallback walks down to the cheapest tier. Links [[BDR-116]], [[LRN-204]], [[EVAL-047]].
## LRN-217 — In an `agent.spawn` hook, "no explicit `model` and no routing row" does NOT mean "inherits the parent": the agent's frontmatter `model:` is invisible to the hook; only an allowlist of types known to inherit is safe, and `agent.offer.source` tells a built-in from a shadowing definition
- **Context**: model-router residuals 2026-10-13, plan r1 pinned every unrowed, model-less spawn to the session model during a demoted turn. Two lenses BLOCKER: engine 2.1.296 builds the spawn input as `model: e.model` (Agent tool param only); frontmatter model never reaches `agent.spawn` nor `agent.offer`; `route === undefined` also covers frozen forks/workflows (hook model ignored) and project-source skips; nested spawns carry the SUB-AGENT's `parentModel`; `turnModel` is set on upgrades too. A repo/user `general-purpose.md` can shadow the built-in with its own `model:` → `offers.get(type) === 'built-in'` is the discriminator.
- **Apply**: before rewriting a spawn's model, prove the agent would inherit: allowlist of built-in types with no frontmatter (`general-purpose`), source `built-in`, not fork/workflow, `parentAgentId` undefined, and the parent really sits below the baseline. Record what the hook cannot see as a `shortcut:` at the allowlist. Links [[BDR-116]], [[BDR-115]], [[LRN-203]].
+3 -1
View File
@@ -3,7 +3,9 @@
## 2026-10-13 — model-router: cold-read cap, switch on by default, classifier routes down (feature/router-downgrade-cap)
Contract `.claude/tasks/contracts/2026-10-13-router-downgrade-cap-0013.md`, plan r3 `.claude/tasks/plans/2026-10-13-router-downgrade-cap-0013.md`.
- [x] /feat run: 3 lenses (10 MAJOR) → r2; confirmation pass FATAL(7) (BLOCKER: served record only on routed steps) → r3; feater DONE (19 tests + 3 extra, 450 pass), GATE 0 MET 4/4, verifier CONFORME 10/10 first pass, security PASS. Commit 2ce203a.
- [ ] Residuals (accepted, from the challenge): (1) unrowed sub-agent with no explicit model spawned during a demoted turn may inherit the demoted `parentModel` (robustness #10): all repo agents rowed, built-ins carry `model=`; settle with a spawn test if a built-in ever drops its pin. (2) `session.usage().context.tokens` may lag the new prompt (robustness #11): a big paste can slip under the cap; economic guard, not a hard limit. (3) `CACHE_TTL_MS` = 60 min is this account's TTL assumed as a const; the engine's `PostModelSwitch.cache_ttl` field suggests it varies — adopt it when observed. (4) Observed during the run: `route` tool answered "model session model (model unknown to the table)" after settings.json `model` turned to `opus` (written by another session) — check `/route show` in a fresh session.
- [x] Residuals (1)-(3) closed 2026-10-13, commit 1be57a3 (contract `.claude/tasks/contracts/2026-10-13-router-cap-residuals-1902.md`, plan r3): session pin for built-in `general-purpose` spawned by main below the session model; prompt-size estimate (text + context + typed skill body, code points / 3) added to the cap's size at the first main step unless usage grew by half; `document` attachment = unknown = blocked; engine `cache_ttl` ('5m'|'1h') adopted from main's PostModelSwitch. 3 lenses (2 BLOCKER same finding: frontmatter model invisible to the hook) → r2; confirmation CONCERNS(3) → r3; feater DONE 472 tests; verifier CONFORME 7/7; security PASS. Residual (4) "model unknown to the table" not reproduced since (later route answers named claude-fable-5-1): closed as transient.
- [ ] Residuals left (accepted): TTL known only after the first PostModelSwitch of the process (no API exposes the account TTL; 60 min default before); hooks-below `context` and a dropped prompt leave the estimate conservative/stale; `onAutoSwitch` targets main's `lastPlan` even for a sub-agent's auto fallback (pre-existing); `agent_id: null` on a main switch (if the engine ever sends null) would freeze sessionModel/TTL updates.
- [ ] LIVE CHECK: does `parentModel` follow the turn.step rewrite or the session model? Read general-purpose's step-0 `message.model` in a transcript during a demoted turn (if it is already the session model, the pin is a harmless no-op).
- [ ] Live check (next sessions): a coding prompt on fable → spinner `sonnet-5-5/medium`; a reflect turn after → fable; above 120k cold read the skip line once; `/route show` cap text.
## 2026-10-12 — code-clean whole repo (chore/code-clean)
@@ -0,0 +1,37 @@
# CONTRACT — router-cap-residuals
- date: 2026-10-13 | flow: feat | branch: feature/router-downgrade-cap (working branch, commit in place)
- status: active
## REQUEST (verbatim — IMMUTABLE)
User: "tres bien, fix les residus"
(the residuals = the three accepted residuals of the downgrade-cap run, TODO.md 2026-10-13 entry, items (1)-(3); item (4) "model unknown to the table" was a one-off observation, not a residual to code)
/feat arguments: model-router: close the three residuals of the downgrade-cap run (TODO 2026-10-13). (1) An unrowed sub-agent with no explicit model spawned while main is demoted (turnModel set) must not inherit the demoted parentModel: spawn it on the session model. (2) The cap reads `session.usage().context.tokens`, which may not include the prompt just submitted: estimate the submitted prompt's size at prompt.submit and add it to the tokens of that turn's first main step before the cap check. (3) `CACHE_TTL_MS` is a 60 min constant: adopt the engine's `cache_ttl` carried by PostModelSwitch events when present (parse `5m`/`1h` forms), fall back to the constant. Same branch feature/router-downgrade-cap.
## CLARIFICATIONS
Q: prompt-size estimate unit / A: delegated — code points / 3, rounded up (conservative: French and code tokenize denser than English)
Q: add the estimate blindly, or detect whether usage already counts the prompt? / A: delegated — detect: usage read at prompt.submit vs at the turn's first main step; the estimate is added only when the growth is under half the estimate (the prompt was not counted)
Q: hand-off log word for a spawn pinned to the session model / A: delegated — `session` (model cause), verbose line only
Q: `/route show` shows the TTL? / A: delegated — yes, inside the switch word: `on (downgrade, cap 120000 tokens cold, ttl 60 min)`
Q: which spawns may be pinned? / A: [r2, challenge BLOCKER] only built-in types with no frontmatter model (`general-purpose`), main's own non-fork non-workflow children, when main sits BELOW the session model; the hook cannot see a frontmatter `model:`, so any wider rule would override agents' own pins
Q: estimate consumption / A: [r2] first main step after the submit; carried across a turn end when unconsumed; texts read the same adjusted size (pure peek); the served record stays raw
## ACCEPTANCE CRITERIA
1. `spawnTarget` pins a spawn to `st.sessionModel` (verbatim) ONLY when: no explicit `model`, no row, not a fork, no workflow, `parentAgentId` undefined (main's own child), `subagentType` in the allowlist `INHERITING_AGENTS` (`general-purpose`: built-in types with no frontmatter model) AND offered with source `built-in` (`st.offers`; a shadowing repo/user agent of that name, or no offer record, is never pinned), `turnModel` set AND ranking BELOW the session model (demotion or breaker fallback, never an upgrade), session model ranked and not down. Everything else is untouched. Hand-off bookkeeping: `wanted` set, model cause `session`. A `shortcut:` comment names the frontmatter blind spot.
2. Prompt-size estimate: `prompt.submit` (any origin; text plus `context` entries) and `skill.prompt` (ONLY main's typed skill, never a sub-agent preload) ADD `ceil(codePoints / 3)` to a pending estimate (sum; the FIRST entry's usage read is the baseline); a `document` attachment marks the estimate unknown. A mid-turn submit (`turnId` set) is pending for the NEXT turn (baseline reset at promotion). A pure `withEstimate(st, raw)` returns `raw + estimate` when the baseline is unknown or usage grew by less than half the estimate, `undefined` when unknown, else `raw`; it is applied in the shared reading path (`readingFor`, texts) AND in `mainPlan` (step), so both agree. `noteServed` records the RAW size. The estimate is consumed by the first main step of its turn; an unconsumed one is carried across the turn end with its baseline reset (added at the next step), never dropped.
3. TTL: `State.cacheTtlMs` initialised to `CACHE_TTL_MS` (60 min), replaced on a PostModelSwitch event whose `cache_ttl` is one of the engine's two values (`'5m'` → 5 min, `'1h'` → 60 min; anything else ignored); events carrying `agent_id` change neither the TTL nor `sessionModel`. `coldRead` uses `st.cacheTtlMs`. The TTL survives `/clear` and is NOT reset by `/route reload`.
4. `/route show` switch word reads `on (downgrade, cap <N> tokens cold, ttl <M> min)` when on; `off (downgrade)` unchanged; the existing show test is migrated.
5. Tests in `hooks/register.test.ts`: (a) general-purpose during a demoted turn → session model; (b) no route → untouched; (b2) rowed feater → row wins; (b3) fork → untouched; (b4) nested spawn → untouched; (b5) non-allowlisted unrowed type → untouched; (b6) upgraded main (haiku session → fable) → untouched; (d) pasted prompt counted before the first step (cap 110000, raw 100000, estimate 20000 → refused); (e) growth = half → not added → allowed, growth < half → added → refused; (f) consumed by the first step, carried across turn end when unconsumed; (g) `'5m'` → 6 min old record cold, `'1h'` → 59 min old warm; (h) sub-agent switch event leaves TTL and sessionModel; (i) `/clear` keeps the TTL; (j) show ttl text default and after `'5m'`; (k) document attachment blocks the first step's switch; (l) typed skill body counted, (l2) a preload during an in-flight spawn adds nothing; (b7) a shadowed `general-purpose` (source `projectSettings`) is never pinned. Estimate tests run with `classify: false`. Migrated existing tests, expectations re-derived, never weakened: the show text test (ttl suffix) and `toast: a downgrade held by the cap says so` (its cold-read figure now includes the typed `/feat` prompt's estimate, 6 tokens for 17 code points, plus any typed body counted).
6. Whole mod suite green.
CHECK: make test suite=lib/tests/mods.test.sh 2>&1 | tail -1
EXPECT: all suites green
EVIDENCE: MET exit=0 marker-found :: all suites green
7. `coldRead` reads `st.cacheTtlMs`, not the constant; the allowlist exists.
CHECK: cd mods/model-router && ! grep -n "CACHE_TTL_MS" hooks/register.ts | grep -q "now - hit.at" && grep -q "cacheTtlMs" hooks/register.ts && grep -q "INHERITING_AGENTS" hooks/register.ts && echo CRIT7-OK
EXPECT: CRIT7-OK
EVIDENCE: MET exit=0 marker-found :: CRIT7-OK
## FILE SCOPE
- mods/model-router/hooks/register.ts
- mods/model-router/hooks/register.test.ts
(README/USAGE/CHANGELOG via STEP 6 doc-sync)
@@ -0,0 +1,164 @@
# PLAN — router-cap-residuals (feat, r3: r2 + confirmation CONCERNS(3) closed below)
Contract: .claude/tasks/contracts/2026-10-13-router-cap-residuals-1902.md
## Files
1. mods/model-router/hooks/register.ts
2. mods/model-router/hooks/register.test.ts
## Approach
- (1) Demoted-turn spawn pin, NARROW (`spawnTarget` ~l.2890, `spawnModelCause`,
`handoffOf` ~l.3160) [BLOCKER: the hook cannot see an agent's frontmatter `model:`;
`e.model === undefined && route === undefined` is NOT "inherits"]. New const
`INHERITING_AGENTS: ReadonlySet<string> = new Set(['general-purpose'])` next to
`PROJECT_SOURCES` (~l.155), comment: "built-in types with no frontmatter model: an
undefined `model` makes them inherit the spawning loop's model". `spawnTarget`
rewrites to `st.sessionModel` (verbatim, keeps `[1m]`) ONLY when ALL hold:
`e.model === undefined && route === undefined`, `!e.fork && e.workflow === undefined`
(frozen: engine ignores a hook model), `e.parentAgentId === undefined` (main's child:
`parentModel` IS main's model), `INHERITING_AGENTS.has(e.subagentType)`, `st.offers.get(e.subagentType) === 'built-in'`
[r3 #1: a repo or user `general-purpose.md` shadowing the built-in may carry a
frontmatter model; no offer record = deny], `st.turnModel !== undefined` and `ranksAbove(st, canonical(sessionModel),
canonical(turnModel))` (main sits BELOW the session model: demotion or breaker
fallback, never an upgrade), session model ranked and not in `st.down`. Else
`undefined` (today's path). `handoffOf`: the "has a hand-off" condition adds
`sp.wanted !== undefined`; `spawnModelCause` returns `'session'` when `route ===
undefined && e.model === undefined && sp.wanted !== undefined`. `shortcut:` comment at
the allowlist: "the frontmatter model of other types is invisible to the hook; widen
the set when the engine exposes it on agent.offer".
- (2) Prompt estimate (State, `prompt.submit` ~l.3560, `skill.prompt` ~l.3462,
`readingFor` ~l.1387, `mainPlan` ~l.3240, `endMainTurn` ~l.3282):
`State.promptEstimate: { tokens: number; usage: number | undefined; unknown: boolean }
| null`. `addEstimate(st, text, usage)`: estimate = `Math.ceil(Array.from(text).length
/ 3)`; a pending entry SUMS the tokens and KEEPS the first baseline (`usage`); a fresh
one takes `usage` = `await readTokens($)` at that moment. `prompt.submit` (any
origin, mid-turn too): `addEstimate` with `e.text`; if the input carries a
`document` attachment (check the kit type for the attachments field; if absent in the
input type, skip this clause and say so in the report) set `unknown = true`.
`skill.prompt`: `addEstimate` with `e.text` ONLY when the prompt is main's TYPED skill
(the `typedPath` verdict, exposed from `armTypedSkill` for rowed and unrowed names
alike; a preload inside an in-flight spawn — `spawning > 0` — adds nothing) [r3 #2],
called BEFORE `confirmSkill` so the dialog and toast see the body.
`prompt.submit` also counts the code points of `e.context ?? []` entries (hooks above
attached them; hooks-below context arrives after `next`, residual) [r3 #6].
`withEstimate(st, raw): number | undefined` PURE (no mutation): `raw` when
`raw === undefined || st.promptEstimate === null`; `undefined` (blocked) when
`est.unknown`; `raw + est.tokens` when `est.usage === undefined || raw − est.usage <
est.tokens / 2`; else `raw`. Used by BOTH `readingFor` (texts: snapshot,
mainQuestion, toastChange) and `mainPlan` → step and texts agree.
`mainPlan`: `const raw = await readTokens($)`; `read = { tokens: withEstimate(st,
raw), now }` for `decideFor`; `noteServed(st, plan, { tokens: raw, now })` records the
RAW size (an over-estimate in the record would trip the compaction path); then
`st.promptEstimate = null` (consumed by the first main step of the turn the prompt
belongs to). Mid-turn submits (`e.turnId !== undefined`) go to
`st.pendingEstimate` instead, promoted by `endMainTurn` into `promptEstimate` with the
baseline reset to `undefined` (the codebase convention for mid-turn input:
`pendingPrompt`/`pendingSlash`) [r3 #4: whether the engine injects a mid-turn prompt
into the running turn is unverified; next-turn is the conservative reading]. An
unconsumed `promptEstimate` at turn end is likewise carried (baseline reset), never
dropped.
- (3) TTL (`CACHE_TTL_MS` ~l.224, `coldRead` ~l.1188, `SwitchIn` ~l.3325,
`onModelSwitch`, `resetSession`): `State.cacheTtlMs` initialised to `CACHE_TTL_MS`,
listed in `resetSession`'s `kept`, untouched by `reloadCommand`. `SwitchIn` gains
`cache_ttl?: unknown` and `agent_id?: unknown`. `const CACHE_TTLS: Readonly<Record<
string, number>> = { '5m': 300000, '1h': 3600000 }` (the engine's closed enum);
`ttlOf(v: unknown)` = `typeof v === 'string' && hasKey(CACHE_TTLS, v) ? CACHE_TTLS[v]
: undefined`. `onModelSwitch`: when `e.agent_id !== undefined` (a sub-agent's switch)
do NOT write `sessionModel` nor the TTL (breaker handling unchanged); else `const ttl
= ttlOf(e.cache_ttl); if (ttl !== undefined) st.cacheTtlMs = ttl` before the
`st.off` return. `coldRead` compares against `st.cacheTtlMs`. Const comment: "1 h
default; replaced by the engine's `cache_ttl` at the first model-switch event".
- (4) `switchWord(st)` → `on (downgrade, cap ${st.cfg.downgradeMaxTokens} tokens cold,
ttl ${Math.round(st.cacheTtlMs / 60000)} min)`; `off (downgrade)` unchanged.
## Edge cases
- Session model unknown (''), unranked or down → no pin, engine decides.
- Upgraded main (haiku session lifted to fable by a plan route) → no pin: the agent
inherits fable as today.
- Fork / workflow / nested / project-source / non-allowlisted type → untouched.
- Estimate: `readTokens` failing at submit → baseline undefined → added (conservative);
`tokens` unknown at the step → stays unknown → blocked. Two queued pastes → summed.
`document` attachment → unknown → every switch blocked that turn.
- Mid-turn submit: consumed by the first main step after it; none follows → carried to
the next turn, baseline reset.
- A prompt dropped by a later hook leaves a stale estimate for the next step (accepted:
conservative; residual).
- TTL takes effect only after the first PostModelSwitch event of the process; before it
the 60 min default holds (residual, named in TODO: no API exposes the account TTL).
- Sub-agent PostModelSwitch events never move `sessionModel` or the TTL.
## Tests (register.test.ts) — contract letters
- Helpers: `typed($, text)` (l.878) / `queued` for prompts, `clearSession` (l.4507) for
/clear, `usageVar`, `switchTo(from, to, source, cache_ttl = '5m')` (add the optional
4th param typed `'5m' | '1h'`); `home: { classify: false }` for the estimate tests
(bootRig has no classify bottom hook).
- Migration: `text: show names the switch and its cap` (~l.5188) expects `switch: on
(downgrade, cap 120000 tokens cold, ttl 60 min)`. `toast: a downgrade held by the cap
says so` (~l.5202): `typeFeat` submits `/feat add a thing` (17 code points → estimate
6) on usage 300000, so the toast now reads `cold read 300006 tokens over 120000`
(plus the skill body's estimate if `typeFeat` also runs skill.prompt with a body: the
executor derives the exact figure and states it in the report) [r3 #3].
- `switchTo(from, to, source, cache_ttl = '5m', agent_id?)`; (i) registers a bottom
`on('session.end', …)` before boot (bootRig has none); (f) uses `queued($,
'composer', …)` for the mid-turn case and a FRESH rig for the carried case [r3 #7].
- (a) `spawn: general-purpose during a demoted turn starts on the session model`
(fable rig, route mechanical, step → haiku, spawn general-purpose with `parentModel:
HAIKU` → bottom gets `model: FABLE`).
- (a) fires `offerOf($, 'general-purpose', 'built-in')` before the spawn [r3 #1].
- (b7) `general-purpose` offered from `projectSettings` (shadowed) → untouched [r3 #1].
- (b) same spawn, no route in force → untouched. (b2) `feater` (rowed) during a demoted
turn → SONNET (row wins). (b3) `general-purpose` with `fork: true` → untouched. (b4)
nested: `parentAgentId: 'a1'` → untouched. (b5) a non-allowlisted unrowed type
(`code-explorer`) → untouched. (b6) haiku session upgraded to fable by a plan route,
spawn general-purpose → untouched (inherits fable).
- (c) = (b2).
- (d) `cap: a pasted prompt counts before the first step`: `home: { classify: false,
downgradeMaxTokens: 110000 }`, usageVar 100000, `typed` 60000-code-point text
(estimate 20000), route implement → refused, log `cold read 120000 tokens over
110000`.
- (e) `set(110000)` before the step (growth 10000 = half) → nothing added → 110000 ≤
110000 → SONNET; sibling `set(109999)` (growth 9999 < half) → added → 129999 →
refused.
- (f) consumed: after (d)'s first step, a second step same turn sees raw (route implement
at raw 100000 → SONNET); carried: `typed` mid-turn (with `turnId`) then `endTurn`, next
turn's first step adds it (refused at the 110000 cap with raw 100000).
- (g) `switchTo(FABLE, FABLE, 'command', '5m')`, record 6 min old → cold (refused above
cap); `switchTo(..., '1h')`, record 59 min old → warm (allowed).
- (h) sub-agent switch event (`agent_id: 'a1'`, `'5m'`) → TTL and `sessionModel`
unchanged (`/route show` ttl still 60 min).
- (i) `clearSession` keeps a 5 min TTL.
- (j) show: `ttl 60 min` default; `ttl 5 min` after a `'5m'` event.
- (k) `cap: a document attachment blocks the FIRST step's switch` (`attachments: [{
type: 'document' }]` exists on PromptSubmitInput, d.ts ~7198) — first step blocked,
second step raw [r3 #7].
- (l) `cap: a typed skill's body counts` (`SkillPromptInput.text`), and (l2) `a preload
during an in-flight spawn adds nothing` [r3 #2].
- Run: `make test suite=lib/tests/mods.test.sh`.
## Disposition (STEP 0.6)
- honors BDR-116 amendment 2026-10-13 / LRN-216: the record stays RAW and on every main
step; the cap alone reads the adjusted size; the TTL is one state value `coldRead`
reads.
- honors BDR-115 (spawn hook sets a model once; explicit `model` wins; an agent moves UP
from its frontmatter, never below): the pin covers only types with no frontmatter
model, and only lifts them back to the session model.
- honors LRN-206 (kit: one bottom hook per event): `usageVar`/`switchTo` reuse.
## CHALLENGE SUMMARY (r1 → r2)
- BLOCKER (correctness #1 = robustness #1): frontmatter invisible → allowlist
`INHERITING_AGENTS` + fork/workflow/nested/project-source guards + tests (b3-b5).
- MAJOR: upgrade sets `turnModel` (c#2, r#3) → `ranksAbove(session, turnModel)` + (b6);
texts vs step (s#1, c#5, r#10) → pure `withEstimate` in `readingFor`; test (e) values
(s#5, c#3) → boundary 110000/109999; TTL enum (s#3, c#4, r#8) → two-value lookup, (h)
rewritten as the sub-agent case; mid-turn estimate dropped at turn end (r#4) → carried
with baseline reset; served inflation (r#5, c#6) → RAW record; overwrite (r#6) → sum;
attachments/skill body (r#7, c#9) → unknown flag + skill.prompt estimate; sub-agent
switch events (r#9) → ignored for sessionModel/TTL; rig names (s#4, c#8) → `typed`,
`clearSession`, show test migration; `switchWord(st)` (s#6).
- Residuals kept (TODO): TTL known only after the first switch event; a dropped prompt
leaves a conservative stale estimate; hooks-below `context` not counted; sub-agent auto
fallback marks main's model down (pre-existing, `onAutoSwitch` targets `lastPlan`);
LIVE CHECK: does `parentModel` follow the turn.step rewrite or the session model? read
general-purpose's step-0 `message.model` in a transcript during a demoted turn (if it
is already the session model, the pin is a no-op) [r3 #5].
- Confirmation pass r2: CONCERNS(3), closed by the [r3 #n] changes above.
- Deferred BLOCKERs: none.