Repository navigation
fix(claude): name the offered model when an adopted one is refused after a restart - #40424
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix sits in the shared [DESIGN-REVIEWED] 6a8ed4a Description read[DESCRIPTION-READ] 8fff1ab47f18374a4de024e3048e2505e228a93156553be6da35fa574546f992 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The helper fix is aimed at the cause, and the per-chat client and the shared runtime now use the same code. It leaves a dead copy of the fallback in the shared runtime. Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: let a Claude chat start on the model the policy now offers after its earlier adopted model is refused on a restart. FIX.
[FIRST-PRINCIPLES-REVIEWED] 6a8ed4a Description read[DESCRIPTION-READ] bd834ff061f51602b09fdf26482fcc42daa70738ff6f1157b7271644d6901c46 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
5ceb5ae to
6a8ed4a
Compare
|
span=cbd05e2fa5c4
|
Code change approver recommendation: A person should decideWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed. The fix in the shared Tier: pending: being reviewed. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
Review bot check: no code blocker.
One gate item (team real-machine-verify rule): the Real-machine verification section says The Captain held this only for the tier (10%); I'll put it to the maintainer once the section is settled. AI-assisted, sent by Bolin Review bot |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
I reviewed the whole diff at this head and traced both callers of _substitution_retry_model: the per-chat client's retry and the shared runtime's adopt_substituted_model. The new 3-line guard in client_claude_seed.py sends the offered model when the adopted model is refused. Before this PR the per-chat path re-sent the refused model and gave up. The shared runtime ends with the same result as before. The targeted tests pass at this head. With main's client_claude_seed.py restored, exactly the cache_stale and offered_refused_too cases fail, so the new test pins the bug. The spec paragraph in claude-code-provider.md matches the code.
Done well: the fix lives in the one shared helper, not in each caller, and the tests check the model that each session/new seed actually carried.
Optional:
- The fallback at
src/kiro_crew/acp/harness/claude.py:925-928can no longer run, because the helper now returns the substitute itself.test_a_refused_pin_falls_back_once_to_the_offered_modelreaches it only through a stub. You could shrink the branch toif model == adopted: return False, reword the docstring at 916-918 to match, and drop or retarget that stubbed test.
Problem / Motivation
Goal: A Claude chat whose adopted model is refused after a restart starts on the model the policy now offers, instead of failing to start.
A per-chat Claude chat adopted model A in an earlier start, after the organization policy refused its default and offered A. Later the policy refuses A too and offers B, while the list of models the backend advertised still names A. The Claude process dies and the chat starts again on the same client. The retry asks which model to name, the old list says A is served, and A is what the seed already names, so the client gives up without trying B. The chat cannot start until the cache or the client is reset. Found in review of #40326 (comment 7061547277).
Why it matters
Any Claude chat on a gateway whose model policy tightens while the chat is alive stops starting after its next restart. The user sees a chat that cannot start, with no way to fix it from the chat.
Not a goal
What changed (motivation → approach → change)
Symptom: the per-chat client returns the refusal and never tries the offered model. Cause:
_substitution_retry_modeltrusts the advertised list even for a model the seed already adopted, and that list can be older than the policy that now refuses it. The shared runtime had its own fix for this one case; the per-chat client had none.Change:
_substitution_retry_model(inclient_claude_seed.py) now names the offered model when the pin is the model the seed already adopted. Both callers, the per-chat client and the shared runtime, use this helper, so they take the same branch. The per-chat docstring inclient_claude_session.pyand the substitution-retry paragraph ofdocs/system-specs/modules/claude-code-provider.mdsay so.Backwards compatibility
Compatible: a start that worked before names the same model; only a start that used to fail at once now tries the offered model.
Removes nothing: the change adds one branch to a helper and keeps every existing path.
Tests
test_acp_client_model_substitution.py::TestSubstitutionFollow::test_a_model_adopted_earlier_and_refused_now_falls_back_to_the_offered_one: per-chat client with model A adopted earlier. Cases: no cache, cache agrees (lists B only), cache stale (lists A), B refused too, A offered again, A still allowed. Checks eachsession/newseed: A is never sent again, and B starts.test_claude_shared_runtime.py::test_a_model_adopted_earlier_and_refused_now_falls_back_to_the_offered_one: the same cases on the shared runtime'sadopt_substituted_model. That path already took this branch on main; the test pins that both paths agree.-n0), all green.Proof: PROVEN test/test_acp_client_model_substitution.py::TestSubstitutionFollow::test_a_model_adopted_earlier_and_refused_now_falls_back_to_the_offered_one[cache_stale], test/test_acp_client_model_substitution.py::TestSubstitutionFollow::test_a_model_adopted_earlier_and_refused_now_falls_back_to_the_offered_one[offered_refused_too] (head 6a8ed4a)
Manual verification
N/A — unit coverage sufficient: the tests drive the real retry code with stub
session/newreplies that carry the policy advisory.Real-machine verification
N/A -- reproducing it needs a live Claude gateway whose organization policy refuses a model mid-session, which no test machine has; the stub tests send the same advisory frames.
Related Issues
Closes #40422
Sibling sweep
Swept: git grep -n "_substitution_retry_model|_adopted_substitute_model" -- src/
Sibling: src/kiro_crew/acp/harness/claude.py -- not affected -- it already fell back to the offered model and now gets the same answer from the shared helper
Sibling: src/kiro_crew/acp/client_claude_session.py -- changed here
Pattern harvest
Not generalizable: the defect is one helper trusting a cached list over a refusal that just happened; no other code adopts a model from a policy advisory.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits