Repository navigation
fix(acp): route model selection to the config option ACP 1.3 defines - #37
Merged
Merged
Conversation
Every ACP model selection failed with "conn.setSessionModel is not a
function". ACP 1.3 has no session/set_model — it is absent from the SDK's
AGENT_METHODS and ClientSideConnection exposes no setSessionModel — but
AcpAgentConnection still declared one, and createConnection attaches the
real ClientSideConnection with an `as unknown as` cast that erases the
structural check. So the dead name type-checked and threw at runtime, on
every startThread({ model }), for every agent. startThread catches and
debug-logs, so the only symptom was a session quietly running on the
agent's default model.
Drop the declaration and its dispatch case; session/set_model now rides
dispatch's default arm and goes out verbatim through the SDK's generic
request(), so agents accepting it as a vendor extension keep working.
Then route by what the agent advertises: session/set_config_option
against the `model` option when it publishes no models.availableModels,
session/set_model when it does. The read path already made exactly this
distinction (modelIdFromCapabilities, modelsFromCapabilities); the two
disagreeing let a host list models it could not then select. The config
option's reply also carries the full refreshed config set, where
set_model answers {} and refreshes only via an async notification — and
on Kimi the model determines which thought levels exist, with
applyReasoning reading runtimeCapabilities right afterwards.
Pin the class, not just the case: a runtime list of AcpAgentConnection's
methods, kept in step with the interface by two type assertions, is
asserted against the real ClientSideConnection.prototype. Re-adding
setSessionModel fails it with "expected 'undefined' to be 'function'".
The old test could not catch this — it drove a hand-written stub that
had the method, so the stub and the interface agreed with each other and
both disagreed with the shipped SDK.
Verified against Kimi Code CLI 0.29.2.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
setModel runs in startThread; applyReasoning runs in startTurn, a later call — not "immediately after". The substance is unchanged (the model write must leave refreshed capabilities behind for reasoning to pick the right thought level), but the sequencing claim was wrong. Re-probed against Kimi Code CLI 2.0.0: still no `models` capability, so model remains a config option. Its thought levels are ["on"] under K2.7 Coding and ["low","high","max","on"] under K3. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Every ACP model selection was failing with
conn.setSessionModel is not a function— thrown client-side, before the request ever left the process.ACP 1.3 has no
session/set_model. It is absent from the SDK'sAGENT_METHODS, andClientSideConnectionexposes nosetSessionModel:But
AcpAgentConnectionstill declaredsetSessionModel, andcreateConnectionattaches the realClientSideConnectionwith anas unknown as AcpAgentConnectioncast that erases the structural check. So a name the SDK does not implement type-checked, and threw at runtime — for every agent, on everystartThread({ model }).AcpAgentClient.startThreadcatches and debug-logs, so the only symptom was a session quietly running on the agent's default model.The fix
Drop the dead method.
session/set_modelnow ridesdispatch's default arm and goes out verbatim through the SDK's genericrequest(), so agents that still accept it as a vendor extension keep working.Route by what the agent advertises.
setModelsendssession/set_config_optionagainst themodeloption (category: "model", or a literalmodelid) when the agent publishes nomodels.availableModels, andsession/set_modelwhen it does.The read path has always made exactly this distinction —
modelIdFromCapabilitiesandmodelsFromCapabilitiesboth fall back to the config option. The two disagreeing is what let a host list models it could not then select.Preferring the config option is not only spec-correctness: its reply carries the agent's full refreshed config set, where
session/set_modelanswers{}and refreshes only via an asyncconfig_option_updatenotification. That matters on Kimi, where the model DETERMINES which thought levels exist.applyReasoningpicks fromruntimeCapabilitieson the followingstartTurn, so the refresh this write leaves behind is what it reads:thinkingvalues (CLI 2.0.0)kimi-code/kimi-for-coding(K2.7 Coding, the default)ononlykimi-code/k3low,high,max,onCorrection (after merge): selecting
k3does not makereasoning: "low"work.reasoningValueForThoughtLevelonly maps low-effort onto an off-like value, and K3's levels are graded with no off, so"low"matches nothing on either model. Fixed in #39.A model write routed through a config option records both
currentModelIdandconfigValues[id]in the session's runtime state, so a consumer readingthread_settings.modelneed not know which route the agent exposed.Measured against Kimi Code CLI 0.29.2 and 2.0.0
Both return a
modelconfig option and nomodelscapability at all — this is the shape the routing is for (0.29.2 shown):session/set_config_option {configId: "model", value: "kimi-code/k3"}is accepted and echoes the newcurrentValue, with the rest of the config set refreshed alongside it.Worth stating plainly, since it narrows the claim: Kimi does also still honour
session/set_model. It replies{}and applies the change via notification (verified in isolation — model wentkimi-for-coding→k3). So for Kimi specifically, removing the dead method alone restores the behaviour. The routing is what keeps this working on an agent that implements only what ACP 1.3 defines, and what makes the post-write capability refresh synchronous.Tests
test/model-selection-route.test.ts— four cases over Kimi's real wire payload: config-option route for a no-modelsagent,session/set_modelretained for anavailableModelsagent, a refused write not reported as applied, andthread_settings.modelcarrying a config-option-routed selection.The regression guard is the part worth reviewing. The old test could not have caught this: it drove a hand-written stub that had
setSessionModel, so the stub and the interface agreed with each other and both disagreed with the shipped SDK.acp-connection.test.tsnow asserts every methodAcpAgentConnectiondeclares against the realClientSideConnection.prototype, with the runtime list kept in step with the interface by two type assertions. Re-addingsetSessionModelfails it with exactly the runtime shape of the bug:Checks
pnpm typecheck,pnpm test(349 passing),lint:boundaries,lint:licenses,lint:deps— all clean.🤖 Generated with Claude Code