Switch model via session.mutate on session-authority gateways #503
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #503"
general
weight: 0.35
Giton22
Found by a Hermes watch contract audit of Kyllene
masteragainst hermes-agent v0.23.4. There's no issue to close.What was wrong
On a session-authority gateway (
gateway.ready.session_authority: true, the gateway-hosted Webapp listener), switching a live chat's model always failed. The pill flipped to the new model, flipped back, and a red banner showed the rawuse_session_mutation_model.ChatSession.setModel(ChatSession.kt:1867-1891 on master) always sentconfig.set {key: "model", value: "<m> --provider <p> --session"}.AuthorityRequests.prepare(AuthorityRequests.kt:37-47) leavesconfig.setas it is.-
session_tui_config.py:17,:187-194route themodelkey tobusy_config.-
session_busy_controls.py:31-35raisesAuthorityRefusal('use_session_mutation_model'), which goes out as wire 4001 (session_controls.py:414-419).- This is on purpose (upstream ae2fd61c50). A pick on the authority is
session.mutateoperation: "model":expected_generationis required, and the payload values must be strings. A guarded (expensive) target answersstatus: "confirmation_required"with aconfirmtoken, and only that token applies it.- Upstream's own desktop client makes the same rewrite (
apps/desktop/src/api/canonical-protocol.ts:474-477)./api/wsdon't have the refusal.Audit claims, checked
| Claim | Result |
|---|---|
|
setModelsendsconfig.set model "<m> --provider <p> --session"(+confirm_expensive_model) | Confirmed || The authority refuses it via
busy_config,use_session_mutation_model, 4001 | Confirmed. On v0.22.1 the check raisesRuntimeStoreError, but the wire reply is the same. v0.22.2 has no authority. || The replacement is
session.mutatemodel{model, provider[, confirm]}| Confirmed, with corrections: the desktop rewrite is at canonical-protocol.ts:474-477, not 456-475,expected_generationis required, andconfirmis the gateway's token string (a boolean isinvalid_params). ||
config.setreasoning/fast/yolo still work; only model breaks | Confirmed. Those paths are unchanged. || Older gateways still need
config.set| Confirmed. The legacytui_gatewayhas nosession.mutate. |The fix
client.sessionAuthority,setModelsendssession.mutatewith:-
operation: "model"andpayload: {model, provider}-
expected_revisionandexpected_generation(the session's fences)- a fresh
request_idmutateBranchbecamemutateFenced(operation, …), which branch and model both use. A stale-fence refusal is sent once more at the fences it carries, and a second one rolls back with "The chat changed on the gateway while switching the model."confirmation_requiredstill returnsNeedsConfirmation. Itsconfirmtoken is kept for that model and provider and goes back aspayload.confirmwhen the user confirms. A stale token just asks again. The UI is unchanged.deferred, which counts as switched. v0.22.1 has no deferred pick and refuses it assession_busy; the banner then says "The model can't change while a reply is running. Switch it when this one is done." instead of the raw reason.confirm_requiredorstatus: "confirmation_required". Every version sends both, but either is enough.session.mutatewith -32601 gets today'sconfig.set. Every authority version in the window has the method, so this is only a guard.session_authorityabsent or false) keepconfig.setexactly as before: same method and params, no new keys.session.updatedwithconfirmation_required). It is left for a follow-up.Back-compat: hermes-agent v0.22.0 to v0.23.4
The mode switch is
gateway.ready.session_authority(JsonRpcClient.sessionAuthority), not a version number.| Version | Legacy sidecar (
config.set model) | Session authority (session.mutatemodel) ||---|---|---|
| v0.22.0 | Unchanged request;
config.setwithconfirm_expensive_modelis intui_gateway/methods_config_set.py| No session authority || v0.22.1 | Unchanged |
validate_action('model', …)inhermes_state_mutations.pyaccepts{model, provider}and{…, confirm: "<token>"}, rejects a boolean confirm (run in-process);expected_generationrequired (session_mutations.py:105); no deferred pick, so a running turn issession_busy(handled) || v0.22.2 | Unchanged | No session authority |
| v0.22.3 | Unchanged | Same
validate_actionresults (in-process); deferred pick present || v0.22.7 | Unchanged | Same
validate_actionresults (in-process). Live:config.set model→ 4001use_session_mutation_model;session.mutatemodel →{"revision":1,"execution_generation":1,"operation":"model","model":"test-model-b","provider":"custom"};session.info→test-model-b|| v0.23.4 | Unchanged |
parse_mutation('model', …)inpersistence/authority/runtime.pygives the same results (in-process). Live: same refusal and acceptance as v0.22.7, plus the app run below |Legacy rows were checked from source, not live: the request on that path is byte-for-byte what
mastersends. The scripted live probe of each version's dashboard/api/ws(the legacy path, and where v0.22.0 and v0.22.3 serve their sockets, since they have no Webapp listener) failed before any chat call, because the dashboards refused the script's ws-ticket after a password login (401). So v0.22.0 and v0.22.3 were not run live.Tests
New
shared/core/src/commonTest/.../chat/ModelSwitchTest.kt(FakeGateway; authority and legacy):theSessionAuthoritySwitchesWithAFencedModelMutation: checks the method, operation, fences, request id and string payload, that noconfig.set modelis sent, and that reasoning still usesconfig.set.anExpensivePickOnTheSessionAuthorityIsConfirmedWithTheGatewaysToken: the token goes back as a string.aStaleConfirmationOnTheSessionAuthorityAsksAgain: also checks that a token is only sent for its own pick.aPickDuringATurnOnTheSessionAuthorityIsDeferredNotFailedaStaleFenceOnTheSessionAuthorityIsRetriedOnceWithTheCurrentOnesaSecondStaleFenceOnTheSessionAuthorityRollsBackWithAReadableErroraGuardedPickMarkedOnlyByItsStatusStillAsksaPickDuringATurnOnAnEarlySessionAuthorityIsExplained(v0.22.1'ssession_busy)aSessionAuthorityWithoutModelMutationsFallsBackToConfigSet(-32601)anOlderGatewayStillSwitchesOverConfigSet:config.set … --session, thenconfirm_expensive_model: true, and nosession.mutate.Runs:
./gradlew :shared:core:testAndroidHostTest --tests "dev.hermeskotlin.core.chat.ModelSwitchTest"- With the fix: 10/10 pass.
- With
master'sChatSession.kt(first commit's tests): 6 of 7 fail. Only the legacy test passes, as it should../gradlew :shared:core:testAndroidHostTest :shared:ui:testAndroidHostTest: BUILD SUCCESSFUL, 2328 tests, 0 failures (before the status-only test;ModelSwitchTestandChatSessionTestre-run after it: pass). This includesChatSessionTest's existing legacy model test and the #467 branch tests../gradlew :androidApp:assembleDev :desktopApp:compileKotlinJvm :androidApp:lintDebug: BUILD SUCCESSFUL.Live gateway run
Kyllene Dev from this branch on the emulator, against hermes-agent v0.23.4's Webapp listener (
session_authority: true). The fake model logs the model each turn asks for:1. In an open chat, sent "turn before switch". Fake model:
request model=test-model.2. Picked Test Model B. The pill stays on Test Model B and no banner shows (before this fix the gateway refused with
use_session_mutation_model; the pill flipped back and a red banner showed it).3. Sent "turn after switch". Fake model:
request model=test-model-b.The request probe (raw
/api/ws) on v0.23.4:v0.22.7 gave the same three answers.
Not covered live: the confirmation round trip on a real guarded (expensive) model, since the fake model never triggers a guard. Its shape comes from source, and the unit tests cover it.
Review follow-up
revision_conflict) without the current revision and generation. v0.22.3 and later include them. The banner then showed the raw reason. It now says "The chat changed on the gateway while switching the model." This also covers a branch on v0.22.1. Test:aStaleFenceWithoutTheCurrentOnesRollsBackWithAReadableError, which fails without the fix.Live matrix (raw JSON-RPC, each tag's own gateway and test home)
| Version | Session authority:
config.set model/session.mutate model/ booleanconfirm/ stale fence | Legacy dashboard/api/ws:session.mutate/config.set model … --session(±confirm_expensive_model) ||---|---|---|
| v0.22.0 | No authority (no
session_mutations.py) | -32601 / applied || v0.22.1 | 4001
use_session_mutation_model/ applied,session.updatedrevision 1 /invalid_params/revision_conflictwithout fences | -32601 / applied || v0.22.2 | No authority (no
session_mutations.py) | -32601 / applied || v0.22.3 | same / applied /
invalid_params/revision_conflictwith fences | -32601 / applied || v0.22.4, v0.22.5, v0.22.6, v0.22.7 | same as v0.22.3 | -32601 / applied |
| v0.23.0, v0.23.1, v0.23.2, v0.23.3, v0.23.4 | same as v0.22.3 | -32601 / applied |
Every stable tag from v0.22.0 to v0.23.4 is in the table; canary tags are left out.
v0.22.1, v0.22.3, v0.22.4 and v0.22.5 have no Webapp listener and serve the authority only on a loopback listener that takes a control-socket ticket, so the phone can't reach it. They were probed with hermes' own local client. The legacy dashboards were probed the way the app signs in: password login, ws-ticket, then the ticket subprotocol. Their
customprovider needs a namedcustom_providersentry before a legacy switch resolves; that is a test-setup detail, andmastersends the same request.App run on the emulator (v0.23.4, head 53c43b51)
test-model. Picking Test Model B keeps the pill with no banner, and the next turn asks fortest-model-b. Switching back givestest-model, so a second fenced switch works. A pick during a running turn: the running turn keepstest-model, and the next one asks fortest-model-b.master: a reduse_session_mutation_modelbanner, and the pill flips back.hermes dashboard): the turn before the pick asks fortest-model, and the turn after asks fortest-model-b, with no banner.