Skip to content

fix(acp): route model selection to the config option ACP 1.3 defines - #37

Merged
Harold Hunt (huntharo) merged 2 commits into
mainfrom
fix/acp-model-config-option
Sep 18, 2026
Merged

Harold Hunt (huntharo) merged 2 commits into
mainfrom
fix/acp-model-config-option

Conversation

@huntharo

@huntharo Harold Hunt (huntharo) commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

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.

(pwrsnap:acp-pool) › acp startThread: model selection not applied
    model=kimi-code/kimi-for-coding message="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:

session_set_mode:          "session/set_mode"
session_set_config_option: "session/set_config_option"
        ← no session_set_model

But AcpAgentConnection still declared setSessionModel, and createConnection attaches the real ClientSideConnection with an as unknown as AcpAgentConnection cast that erases the structural check. So a name the SDK does not implement type-checked, and threw at runtime — for every agent, on every startThread({ model }). AcpAgentClient.startThread catches 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_model now rides dispatch's default arm and goes out verbatim through the SDK's generic request(), so agents that still accept it as a vendor extension keep working.

Route by what the agent advertises. setModel sends session/set_config_option against the model option (category: "model", or a literal model id) when the agent publishes no models.availableModels, and session/set_model when it does.

The read path has always made exactly this distinction — modelIdFromCapabilities and modelsFromCapabilities both 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_model answers {} and refreshes only via an async config_option_update notification. That matters on Kimi, where the model DETERMINES which thought levels exist. applyReasoning picks from runtimeCapabilities on the following startTurn, so the refresh this write leaves behind is what it reads:

model thinking values (CLI 2.0.0)
kimi-code/kimi-for-coding (K2.7 Coding, the default) on only
kimi-code/k3 low, high, max, on

Correction (after merge): selecting k3 does not make reasoning: "low" work. reasoningValueForThoughtLevel only 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 currentModelId and configValues[id] in the session's runtime state, so a consumer reading thread_settings.model need not know which route the agent exposed.

Measured against Kimi Code CLI 0.29.2 and 2.0.0

Both return a model config option and no models capability at all — this is the shape the routing is for (0.29.2 shown):

"configOptions": [
  { "id": "model", "category": "model", "currentValue": "kimi-code/kimi-for-coding",
    "options": [ "kimi-code/kimi-for-coding", "…-highspeed", "kimi-code/k3", "kimi-code/k3-256k" ] },
  { "id": "thinking", "category": "thought_level", "currentValue": "on", "options": [ "on" ] },
  { "id": "mode", "category": "mode", … }
]

session/set_config_option {configId: "model", value: "kimi-code/k3"} is accepted and echoes the new currentValue, 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 went kimi-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-models agent, session/set_model retained for an availableModels agent, a refused write not reported as applied, and thread_settings.model carrying 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.ts now asserts every method AcpAgentConnection declares against the real ClientSideConnection.prototype, with the runtime list kept in step with the interface by two type assertions. Re-adding setSessionModel fails it with exactly the runtime shape of the bug:

× ClientSideConnection implements setSessionModel
  → expected 'undefined' to be 'function'

Checks

pnpm typecheck, pnpm test (349 passing), lint:boundaries, lint:licenses, lint:deps — all clean.

🤖 Generated with Claude Code

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>
@huntharo
Harold Hunt (huntharo) merged commit a91fb4f into main Sep 18, 2026
2 checks passed
@huntharo
Harold Hunt (huntharo) deleted the fix/acp-model-config-option branch September 18, 2026 01:57
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.

1 participant