Skip to content

fix: keep an unsure Jev tier off a smaller context window - #13167

Merged
iamwhatever merged 1 commit into
mainfrom
feat/jev-route-window-guard
Sep 24, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
feat/jev-route-window-guard

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Supersedes #12913. That PR was based on fix/jev-model-route-ratchet, which merged as #12872 and was deleted, so GitHub auto-closed it and refuses to reopen it. Same head branch, same diff, rebased onto main: the ratchet commit is already in main, so what is left here is only the window guard. The refused-downgrade landing reads the ratchet's _jev_route_baseline latch through its own _restore_to.

The defect

model.route applied a tier on the tier alone. A half-sure simple moved a session onto a model with a fifth of the room, and the context meter is a percentage of the served window: a transcript sitting well inside a large window can cross the session's compaction threshold the moment the window shrinks. That turn ends by handing the backend a history it replaces with a summary, and no later switch back recovers it. The spec even carried a guarantee it only partly kept — "routing never silently lands on a smaller window" was true of an id's spelling, not of the window a correctly-spelled pin names.

The two rules

Both live in chat_runner._jev_downgrade_refused, after the target is computed and before set_model is resolved, and both are scoped by model_route.is_smaller_window — the single owner of "is this a shrink", so the two rules cannot come to govern different sets of moves.

  1. Confidence. model_route.permits_smaller_window(p, current=, target=) — a smaller window needs the answer's own probability at MIN_DOWNGRADE_P (0.80) or above. An absent probability does not clear it.
  2. Fit. The target window is known and (used + prompt_tokens(message)) / target_window * 100 >= SessionManager.effective_autocompact_pct(key) — the reading the turn would END on once the window is the smaller one. The meter answers for the history the session already holds, so the prompt this turn SENDS is added at the CHARS_PER_TOKEN divisor the sibling points estimate with — full_message, the person's words under whatever request prefix, replayed history and hook context the turn carries, and deliberately not the excerpt the tier was classified from: without it a large message over a small history clears the test and compacts at the end of that same turn, which is the case the rule exists for. The rule PERMITS a shrink only on a reading that CONFIRMS the target holds this turn. A meter the provider itself calls unknown (context_usage_unknown, True exactly when a 0 means "not measured" rather than "empty" — the post-compaction and resumed state), a meter that cannot be reached, and an unreadable threshold all refuse. That costs one gear and nothing else, because a window that does not shrink never compacts, and it is not a veto on routing but only on shrinking THIS turn. A 0 the provider vouches for is a known small history, so a fresh session downgrades as before, with the prompt weighed beside it.

The current side is the window the session is served on (client.context_window_tokens()) whenever the provider reports one, and the registry only when it does not: that reading is the denominator the meter's own percentage is taken against, so a registry entry lagging it would hide a shrink the meter can already see. It is read ONCE (_jev_current_window) and the landing below is sized by that same number — a landing measured against the other reading can be handed the very window these rules refused, and the row would then say refused for a shrink that happened.

An unknown window on either side refuses nothing (known_window gates on model_registry.has_known_window, because model_window answers a guessed reference for an id it does not list, and vetoing on a guess pins routing to the session's own model for every unlisted one). Because that answer refuses nothing, the lookup asks the registry both as the id is WRITTEN and case-folded: both registry lookups are spelling-sensitive while resolve_model accepts a pin on a lossless fold and answers the spelling the owner wrote, so Claude-Haiku-4.5 asked only as written reads as unknown and carries the shrink. . and - stay unfolded — the registry keeps those entries distinct and they are two different windows. A zero reading is "not measured yet" — the state a fresh session and a just-compacted one share — and also refuses nothing.

A refused tier lands one gear up: the medium pin while its own window is not the one just refused, else the pre-route baseline, else the model is left alone. The landing is handed the same baseline value the unpinned restore gets (_restore_to), not the raw latch, because that value is already emptied while the model-fallback ladder holds the session: the latch there names the primary the ladder walked away from, and landing a refused tier on it would ask for the model that just failed.

The refusal row carries the suppressed tier and its p under error smaller-window-refused, so which rule refused is readable from the row, and publishes no receipt. It is written at each exit that discards the tier rather than once where the rules answer: the locked re-pick guard drops the whole answer, and rows are durable and never rewritten, so one appended before that guard would outlive a decision nothing acted on. The two exits that return BEFORE those locks — no landing to ask for, and no switch seam at all — never reach that guard, so each asks the same premise itself through the one predicate that answers it (_jev_route_premise_moved: the arming flag, the model the turn started on, the shared pick epoch).

Both rules size the id that was ASKED for, so the FIT rule is asked once more after the switch and before any prompt is streamed, against the window the session is now SERVED on. A config-option backend answering a tier-policy substitution leaves the turn on a different model whose id can still read as the requested one; only the meter says otherwise, because it is rebased to whatever serves. A turn that landed on a window the rules did not authorise is put back on the one it had, and the refusal is recorded like any other dropped tier.

Both rules are deliberately not in AcpClient.set_model: an owner picking a smaller window by hand is the answer to the question this point asks, and a check there would refuse the pick too.

Why 0.80

Read off ~/.kiro/crew/decisions/decisions-*.jsonl, n=17 answered simple:

  • The probabilities cluster below 0.75 and above 0.86 — nothing lands in between, so the floor sits in a gap rather than on a slope.
  • 0.80 and 0.85 keep and drop exactly the same 17 answers. Since they are equivalent, the value already in the tree (tool_risk.RISKY_CONFIDENCE_THRESHOLD) is the one taken rather than a second number.
  • 0.90 is rejected: it drops a genuinely simple answer at p=0.86, leaving 1 of 17 effective.
  • 0.70 is rejected: it passes p=0.72 and p=0.75, neither of which is a self-contained request.
  • Hand-read of the 10 lowest-p simple answers: 9 are plans, judgement calls or multi-instruction turns.

It is a plain module constant, not a config knob, for memory.recall's KEEP_THRESHOLD reason: it is the meaning of the answer, and a configurable floor is a second, undocumented way to turn the rule into a no-op.

The rules are deliberately one-way. A symmetric floor would kill the medium tier outright — every medium answer in the sample is under 0.80 — and would push low-p complex answers back toward a possibly smaller baseline, which is worse.

Prompt

One sentence added beside the three tier descriptions: being wrong in the two directions does not cost the same, so simple is for a request that is self-contained and wholly visible. It names no model and no price, the rule the descriptions already follow.

What was tested

python3 -m pytest test/test_decisions_model_route.py test/test_decisions_model_route_apply.py -q → 116 passed. With the base PR's own ratchet file: 132 passed.

One test per rule branch: pure function (both directions, the shrink owner on unknown windows, the floor inclusive at its own value plus 0.75 <= MIN_DOWNGRADE_P <= 0.85, a bool is not a probability, no config knob), landing (medium pin, medium pinned to the refused window, unpinned medium, nothing to land on), and the apply path driven through the real runner hook: refused → medium, refused → pre-route baseline over two turns, same window passes, unknown window passes, fit rule refuses at 150k/200k, fit rule passes at 10k, a pick landing during the decide await leaves no refusal row, a refused pin under an active fallback ladder never attempts the failed primary, a registry entry lagging the served window still refuses, the landing is sized by the same reading the rules refused on, a large prompt over a small history is refused, a prompt that alone will not fit is refused on a fresh session, a pin the owner cased differently is still sized, an unmeasurable meter refuses while a vouched-for zero does not, a substituted served model is put back while one that holds is left alone, and an empty landing writes no row once a pick has landed.

Sixteen mutations, each caught, and each by the test that owns its branch:

Mutation Caught by
floor → 0.99 the two-sided bound test, and both "applies at the floor" cases
every move reads as a shrink 7 tests
landing skips the medium pin 5 tests
fit rule never refuses the two fit tests
refusal row written once up front test_a_pick_landing_during_the_await_leaves_no_refusal_row
landing reads the raw latch test_a_refused_pin_never_attempts_the_failed_primary
current window from the registry only test_a_registry_entry_that_lags_the_served_window_still_refuses
landing sized by a second reading test_the_landing_is_sized_by_the_same_reading_the_rules_refused_on
fit reading drops the prompt entirely test_the_rule_sizes_the_prompt_it_is_given
fit rule sized by the typed words, not the assembled prompt test_the_hook_is_handed_the_prompt_the_turn_sends
window lookup asks the owner's spelling only test_a_pin_the_owner_cased_differently_is_still_sized
unmeasured session exempts the prompt test_a_prompt_that_alone_will_not_fit_is_refused_on_a_fresh_session
an unknown meter permits the downgrade test_an_unmeasurable_reading_refuses_and_a_vouched_for_zero_does_not
an unreachable reading permits the downgrade test_a_reading_that_cannot_be_reached_refuses
no re-check of the window the switch landed on test_a_substituted_served_model_is_put_back
the rule ignores the served window it was handed test_a_substituted_served_model_is_put_back
empty landing records without asking the premise test_an_empty_landing_writes_no_row_when_a_pick_landed

Green locally: check_black_formatting.py (with the pinned 26.3.1), check_subprocess_encoding.py, isort, flake8, mypy src/kiro_crew (1699 files), check_comment_history.py gated at the base, check_brand_name.py, docs-lint.sh.

Docs

docs/system-specs/modules/decisions.md §11 gains one paragraph: both rules, which shrink they are scoped by, where the current window is read, the landing order, which baseline the landing is handed, and where the refusal row is written. The §5 row-schema sentence gains smaller-window-refused, and the over-broad guarantee is narrowed to what the id comparison actually promises. src/kiro_crew/docs/decisions.md mirrors only the error-word sentence, which is the paragraph it shares.

SessionManager.effective_autocompact_pct is the one line the fit rule cannot work without: the authoritative "override else global" resolution lives on CompactionCoordinator, and chat_runner has no public read of it and no precedent for reaching a private sessions._ attribute. It is the READ half of the existing public set_autocompact_pct.

model_registry is imported at model_route.py's module top rather than inside the function — this module is itself reached lazily from the turn path, so the statement costs nothing on any boot path, and the sibling helper's now-redundant local import of the same module is dropped with it. The point module is passed into _jev_downgrade_refused instead of re-imported there, because the whole decisions package is reached lazily from chat_runner and a second import statement would be a second place holding that decision.

Pattern harvest

Rule candidate: review-prompt

Pattern: an automated switch that moves a live session onto a smaller resource — a context window, a token budget, a timeout — applied from a classification alone, without reading the session's current consumption against the target's capacity. The defect class is not "the classifier was wrong"; it is that the applying seam never asked whether the target could hold what the session already has, so a correct-looking classification produces an irreversible loss (here: the backend replaces the history with a summary at the end of that same turn).

Nine checks a reviewer can apply to any such seam, all nine visible in this diff:

  1. Does the decision read the answer's own confidence, or only its value? model.route was the last of the three decision points still using p for logging only. The same question belongs on every point that applies an answer rather than displaying it.
  2. Is the guard on the automatic path or on the mechanical one? A capacity check placed in the shared executor (AcpClient.set_model) would also refuse a human picking that model by hand, which is the very answer the automatic path is guessing at. The guard belongs where the decision is made.
  3. Does the rule's reading cover the thing the turn is about to do, or only what already happened? The fit rule compared a meter that answers for the history the session already holds, while the turn it was deciding for adds its whole prompt on top — so the rule passed exactly the case it exists to refuse. A guard measured on the wrong side of the event it guards is not a partial guard.
  4. Which way does a guard fail when it cannot measure? This one shipped failing OPEN four times over: an unlisted window, a cased pin, an unmeasured meter, an unreachable meter — each a different surface, each the same defect, and each reached by ordinary means rather than an extreme one. Patching them one at a time produced a fifth every round. The collapse is a single principle: permit a shrink only on a reading that confirms the target holds; anything unmeasurable means do not downgrade. It is cheap here because not downgrading is free — the turn keeps a window at least as large, which never compacts — and it is not a veto on routing, only on shrinking this turn. Ask of any guard: is its unmeasurable branch on the safe side, and is the safe side actually cheap? When it is, write the principle rather than the four patches.
  5. Does the check run against what was REQUESTED or against what actually took? Every window rule here sized the id asked for, while a tier-policy substitution can leave the turn on a different model — and the post-switch code re-read only the served NAME, which can still be the requested one. An authorisation that is never re-tested against the thing that actually happened is an authorisation for something else. Ask where the decision's subject is read again after the action, and whether the value read there is the one that can differ.
  6. When a function receives two texts, is it given the one its rule is about? This hook takes the person's words (what the tier is classified from) and the assembled prompt (what the turn sends). Handing the first to a rule about what fits reads as correct at every call site and silently drops every injected prefix. A unit test on the function cannot see which one it got, so the call site needs its own assertion.
  7. Does every consumer of a corrected reading get the corrected one? Changing where the current window comes from fixed the rule and left the landing call reading the old source, so a refusal could be sized by one number and its landing admitted against another. Both review lanes found exactly this, independently, on the revision that fixed only the rule. The reading now has one name and one call site.
  8. Is the durable record written before or after the last gate that can drop the decision? Every exit has to ask, not just the one on the path the diff describes: two exits here return before the locks and needed the premise predicate of their own. A row appended when a rule answers, on a path whose later locked guard can discard the whole answer, outlives a decision nothing acted on — and these rows are never rewritten. The record belongs at the exits that actually discard.
  9. Does a new fallback path reuse the value the surrounding code already sanitised, or the raw one? The pre-route baseline has two spellings here: the raw latch, and the copy the restore branch empties while the model-fallback ladder holds the session. A new landing that reaches for the raw one silently re-opens the case the sanitised copy exists to close, and reads as correct because the raw name is the more obvious one.

Not a semgrep or lint candidate: each check needs the seam's semantics (which direction is the shrink, whose threshold applies, whether the reading is measured yet, which exits are terminal, which of two same-typed values is the sanitised one), and a syntactic rule would fire on every set_model call site including the manual pick it must not touch.

@iamwhatever
iamwhatever requested review from a team and cixuuz September 23, 2026 19:53
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of 17c8404888eb89510d3f65327a17f5913ab9926c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

PR description documents a superseded refusal design ("lands one gear up on medium", _restore_to); code and spec ship stays-put — the record misleads readers.

Watch

  • Description↔diff mismatch: "A refused tier lands one gear up: the medium pin … else the pre-route baseline" and the mutation rows "landing skips the medium pin | 5 tests" have no backing code — chat_runner.py refuses with "A refused tier STAYS PUT" and never consults _restore_to on that path. Anyone acting on the PR record (backports, release notes, future reviews) inherits the wrong behavior; the in-repo spec is correct.
    Clears when: the description is rewritten to the stays-put + rollback-precondition design actually at HEAD.
  • The 0.80 floor was calibrated on 17 simple answers but governs every shrink, and the description itself says "every medium answer in the sample is under 0.80" — so on a map whose medium pin is a smaller window, medium downgrades are categorically refused and routing's savings quietly collapse to simple-only, visible only in refusal rows.
    Clears when: medium-answer probabilities are read against the floor the same way, or the spec states medium shrinks are intentionally floor-bound.
  • The put-back's failure story isn't the designed one: the comment says a raising restore "is still reported as the refusal it is," but the exception reaches the outer handler, which writes switch-failed, never _record_refused, and the turn streams on the unauthorized smaller window.
    Clears when: the restore await is handled locally so the row carries smaller-window-refused (or the comment and spec state the switch-failed outcome).

[DESIGN-REVIEWED] 17c8404

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 17c8404888eb89510d3f65327a17f5913ab9926c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The description promises a refused tier "lands one gear up" via _restore_to; the diff ships stays-put — the prose being approved describes code that isn't here.

Not justified as shipped

  • Item 5 — undeclared: the description says "A refused tier lands one gear up: the medium pin … handed the same baseline value the unpinned restore gets (_restore_to)" and "written at each exit that discards the tier rather than once where the rules answer", while the diff and its own spec text say "A refused tier STAYS PUT … nothing is asked of the provider at all" and "written where the rules answer, before the locks" — no refusal path reads _restore_to (grepped: its 3 uses are the pre-existing restore computation).
    Clears when: the author confirms stays-put is the intended shape and rewrites the description to it.
  • Item 9 — rides along: the _advertised = provider_advertised_ids(client) extraction's comment says the list answers "where a refused downgrade may land", but no landing consults it (grepped _advertised in chat_runner.py: 1 consumer, the routed_model call) — residue of the removed landing.
    Subtraction: inline the call as before and delete the comment.
    Clears when: the extraction and stale comment are gone, or a second consumer exists.
  • Item 6 — rides along: the TIER_ASYMMETRY prompt sentence changes classification for every routed turn and is not the window guard; declared under "## Prompt".

What this change ships

Inventory (10 items) — 7 justified

Intent: keep a low-confidence or ill-fitting tier answer from moving a chat onto a model with a smaller context window, whose compaction is irrecoverable — a FIX (enforces the base spec's own pin, "routing never silently lands on a smaller window").

  1. A downgrade under the 0.80 confidence floor keeps the session's model — justified
  2. A confident downgrade is refused when history plus this turn's prompt would cross the compaction threshold in the smaller window — justified
  3. A downgrade is refused when the backend never named a model to go back to — justified
  4. A switch that lands on a smaller served window than authorized is put back before streaming — justified
  5. A refused tier stays put — undeclared: description promises a one-gear-up landing that does not ship
  6. The tier question gains an asymmetry sentence biasing simple — rides along: declared, not the window guard
  7. New smaller-window-refused log row carrying the refused p — justified
  8. New public SessionManager.effective_autocompact_pct read — justified
  9. _advertised read-once extraction with a stale landing comment — rides along: residue of the removed landing
  10. Owner and module specs updated in the same commit — justified

[FIRST-PRINCIPLES-REVIEWED] 17c8404

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ human override accepted

Human judgment by @iamwhatever overrides the GPT 5.6 finding for 17c8404888eb89510d3f65327a17f5913ab9926c; the recorded reason is authoritative for this commit.

[GPT-OVERRIDE] 17c8404

This comment is updated in place on each push.

The model was not re-run because an authorized human decision supersedes it.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 17c8404888eb89510d3f65327a17f5913ab9926c: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 17c8404888eb89510d3f65327a17f5913ab9926c — this comment is updated in place on each push.

Review details

A post-switch rollback that raises records switch-failed instead of the refusal the code just marked — advisory only, nothing blocks.

FINDING — src/kiro_crew/dashboard/chat_runner.py:4835 — when the post-switch window re-check sets _refused = True and the rollback await set_model_fn(_live_model) raises (ACP set_model raises AcpModelUnavailable/transport errors), control leaves the async with into except Exception, which never reads _refused and writes error=ERROR_SWITCH_FAILED before returning, so if _refused: await _record_refused() is skipped and the durable row says the provider refused the tier when the tier in fact applied and only the restore failed — and the warning names _target though the failing call was _live_model → Fix: begin the except Exception arm with if _refused: await _record_refused(); return, and log _live_model as the id on that arm.

[OPUS-REVIEWED] 17c8404

Verdict parsed from the review's SHA-scoped output markers for commit 17c8404888eb89510d3f65327a17f5913ab9926c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 17c8404888eb89510d3f65327a17f5913ab9926c: <one-sentence reason>

@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from b4e8d86 to 5e2b77f Compare September 23, 2026 20:54
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 23, 2026
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from 5e2b77f to 1068527 Compare September 23, 2026 21:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 23, 2026
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch 4 times, most recently from ebb7798 to 563e03a Compare September 23, 2026 23:01
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 23, 2026
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from 563e03a to 79e6880 Compare September 23, 2026 23:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from 79e6880 to 41c460a Compare September 24, 2026 16:15
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from 41c460a to 40cbeaf Compare September 24, 2026 16:30
model.route applied a tier on the tier alone, so a half-sure `simple`
moved a session onto a model with a fifth of the room. The context meter
is a percentage of the SERVED window, so a transcript sitting well inside
a large one can cross the session's compaction threshold the moment the
window shrinks, and that turn ends by handing the backend a history it
replaces with a summary no later switch back recovers. The spec even
carried a guarantee it only partly kept: "routing never silently lands on
a smaller window" was true of an id's spelling, not of the window a
correctly-spelled pin names.

Three rules now stand between the tier's model and the seam that applies
it, and each applies ONLY to a move to a SMALLER window. They are scoped
by `is_smaller_window`, the single owner of that question, so they cannot
come to govern different sets of moves, and an unknown window on either
side refuses nothing.

The ROLLBACK rule is asked first, because it is a question about the seam
rather than about the turn: a shrink is only ever applied because it can
be TAKEN BACK if what actually serves turns out smaller still, and the
model to go back to is the one the session was already on. A session the
backend never named a model for reads that as "" -- there is no id to ask
for -- so a smaller window is refused on exactly the grounds an unknown
one is: nothing here confirms the turn could be put back. A window at
least as large needs no way back, so an upgrade pays nothing for it.

The CONFIDENCE rule is the point's own floor. MIN_DOWNGRADE_P is 0.80, a
plain module constant for memory.recall's KEEP_THRESHOLD reason -- it is
the meaning of the answer rather than a knob.

The FIT rule refuses when the turn's own reading would land at or above
this session's compaction threshold in the target window. Its estimate no
longer reads token-dense text as a quarter of its size: CHARS_PER_TOKEN
answers for LATIN text, and CJK, Indic or symbol-dense input tokenizes
several times denser, so only ASCII is divided and every other character
counts as a token of its own. That is the conservative direction and the
only safe one here -- it can refuse a downgrade the prompt would have
fitted, which costs one turn on a larger window, while the opposite costs
a history nothing recovers.

A refused tier STAYS PUT. The turn keeps the window it already has, which
is a window these rules read and accepted, and nothing is asked of the
provider at all: there is no switch to undo, nowhere to land, and no turn
to stop. The row carries the suppressed tier and its p under error
smaller-window-refused, written where the rules answer and behind the
same premise predicate the apply path takes, because rows are durable and
never rewritten and one appended for a superseded answer would outlive a
decision nothing acted on.

The CURRENT side is the window the session is served on whenever the
provider reports one, and the registry only when it does not: that
reading is the meter's own denominator, so a registry entry lagging it
would hide a shrink the meter can already see.

Both rules size the id that was ASKED for, so a backend answering a
tier-policy substitution is asked once more after the switch, against the
served window, and a turn that landed on a window the rules did not
authorise is put back on the one it had -- which the ROLLBACK rule is
what makes expressible. A substitution under an UPGRADE can still reach
that check with nothing named to go back to, and then the turn keeps the
model it is on: the residual any switch that cannot be undone has always
had. A raise from either switch takes the paths a failed set_model
already took.

Both rules sit on the routing path and NOT in AcpClient.set_model: an
owner picking a smaller window by hand is the answer to the question this
point asks, and a check there would refuse the pick as well.

The prompt gains one sentence saying which direction an error costs more.
It names no model and no price, the rule the tier descriptions already
follow.
@iamwhatever
iamwhatever force-pushed the feat/jev-route-window-guard branch from 40cbeaf to 17c8404 Compare September 24, 2026 17:28
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 17c8404: design A accepts this residual by choice — the abort path it asks for was removed after producing four one-shot-state defects; a downgrade now requires a rollback target, so this site is reachable only by backend substitution, which pre-PR code streamed on silently without any recheck

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 17c8404888eb89510d3f65327a17f5913ab9926c.

design A accepts this residual by choice — the abort path it asks for was removed after producing four one-shot-state defects; a downgrade now requires a rollback target, so this site is reachable only by backend substitution, which pre-PR code streamed on silently without any recheck

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 24, 2026 23:35

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 17c84048. No hardcoded model id in source (the two haiku ids are test fixtures). _jev_downgrade_refused runs before set_model and refuses a smaller window on missing/low p (< 0.80), unknown usage, an unreadable threshold, an unnamed current model, or usage+prompt reaching the smaller window's compaction threshold; after a switch it re-checks the served window and switches back. full_message is only used locally for token estimation; the only new text sent to routing is the fixed TIER_ASYMMETRY. Nine mutations of the guards each redden the tests.

Non-blocking: in the post-switch branch the comment says a switch-back that raises "is still reported as the refusal it is", but the except records ERROR_SWITCH_FAILED and the turn stays on the smaller window; align the comment or the category.

@iamwhatever
iamwhatever merged commit d5a533c into main Sep 24, 2026
137 of 141 checks passed
@iamwhatever
iamwhatever deleted the feat/jev-route-window-guard branch September 24, 2026 23:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 24, 2026
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…#13167)

model.route applied a tier on the tier alone, so a half-sure `simple`
moved a session onto a model with a fifth of the room. The context meter
is a percentage of the SERVED window, so a transcript sitting well inside
a large one can cross the session's compaction threshold the moment the
window shrinks, and that turn ends by handing the backend a history it
replaces with a summary no later switch back recovers. The spec even
carried a guarantee it only partly kept: "routing never silently lands on
a smaller window" was true of an id's spelling, not of the window a
correctly-spelled pin names.

Three rules now stand between the tier's model and the seam that applies
it, and each applies ONLY to a move to a SMALLER window. They are scoped
by `is_smaller_window`, the single owner of that question, so they cannot
come to govern different sets of moves, and an unknown window on either
side refuses nothing.

The ROLLBACK rule is asked first, because it is a question about the seam
rather than about the turn: a shrink is only ever applied because it can
be TAKEN BACK if what actually serves turns out smaller still, and the
model to go back to is the one the session was already on. A session the
backend never named a model for reads that as "" -- there is no id to ask
for -- so a smaller window is refused on exactly the grounds an unknown
one is: nothing here confirms the turn could be put back. A window at
least as large needs no way back, so an upgrade pays nothing for it.

The CONFIDENCE rule is the point's own floor. MIN_DOWNGRADE_P is 0.80, a
plain module constant for memory.recall's KEEP_THRESHOLD reason -- it is
the meaning of the answer rather than a knob.

The FIT rule refuses when the turn's own reading would land at or above
this session's compaction threshold in the target window. Its estimate no
longer reads token-dense text as a quarter of its size: CHARS_PER_TOKEN
answers for LATIN text, and CJK, Indic or symbol-dense input tokenizes
several times denser, so only ASCII is divided and every other character
counts as a token of its own. That is the conservative direction and the
only safe one here -- it can refuse a downgrade the prompt would have
fitted, which costs one turn on a larger window, while the opposite costs
a history nothing recovers.

A refused tier STAYS PUT. The turn keeps the window it already has, which
is a window these rules read and accepted, and nothing is asked of the
provider at all: there is no switch to undo, nowhere to land, and no turn
to stop. The row carries the suppressed tier and its p under error
smaller-window-refused, written where the rules answer and behind the
same premise predicate the apply path takes, because rows are durable and
never rewritten and one appended for a superseded answer would outlive a
decision nothing acted on.

The CURRENT side is the window the session is served on whenever the
provider reports one, and the registry only when it does not: that
reading is the meter's own denominator, so a registry entry lagging it
would hide a shrink the meter can already see.

Both rules size the id that was ASKED for, so a backend answering a
tier-policy substitution is asked once more after the switch, against the
served window, and a turn that landed on a window the rules did not
authorise is put back on the one it had -- which the ROLLBACK rule is
what makes expressible. A substitution under an UPGRADE can still reach
that check with nothing named to go back to, and then the turn keeps the
model it is on: the residual any switch that cannot be undone has always
had. A raise from either switch takes the paths a failed set_model
already took.

Both rules sit on the routing path and NOT in AcpClient.set_model: an
owner picking a smaller window by hand is the answer to the question this
point asks, and a check there would refuse the pick as well.

The prompt gains one sentence saying which direction an error costs more.
It names no model and no price, the rule the tier descriptions already
follow.

Co-authored-by: Joe Guo <zejiangg@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants