Skip to content

fix(kiro): use session/set_model for in-session model switching#4

Merged
hrishikeshmane merged 1 commit into
kiro-acpfrom
fix/kiro-in-session-model-switch
Apr 21, 2026
Merged

fix(kiro): use session/set_model for in-session model switching#4
hrishikeshmane merged 1 commit into
kiro-acpfrom
fix/kiro-in-session-model-switch

Conversation

@hrishikeshmane
Copy link
Copy Markdown
Owner

@hrishikeshmane hrishikeshmane commented Apr 21, 2026

Summary

  • Kiro supports session/set_model but not session/set_config_option. The shared AcpSessionRuntime.setModel routes through setConfigOption, which Kiro rejects with -32601 Method not found. The ndJsonRpc parser wraps this as a Die (defect), which the previous Effect.catch couldn't intercept — crashing the turn.
  • Call session/set_model directly via ctx.acp.request() in KiroAdapter, keeping shared ACP infrastructure untouched so Cursor (which uses setConfigOption) is unaffected.
  • Update ctx.session.model immediately after a successful switch, matching the ClaudeAdapter/OpenCodeAdapter pattern. Previously the model was only updated after the prompt completed.
  • Remove redundant model from post-prompt session update.

Files changed

File Change
KiroAdapter.ts Use session/set_model RPC directly; immediate model state update
KiroAdapter.integration.test.ts 3 new tests for in-session model switching
kiro-mock-agent.ts Add model catalog + set_model/set_config_option handlers
acp-mock-agent.ts Add handleSetSessionModel for forward compat

Test plan

  • 11 Kiro integration tests pass (3 new + 8 existing)
  • 8 ACP shared tests pass — no regressions
  • 19 Cursor tests pass — shared infra untouched
  • 58 Claude + AcpRuntimeModel tests pass
  • Manual: switch model in Kiro dropdown, send message, confirm no crash

Kiro supports session/set_model but NOT session/set_config_option.
AcpSessionRuntime.setModel routes through setConfigOption, which Kiro
rejects with -32601 "Method not found". Call session/set_model directly
via the raw request interface in KiroAdapter, keeping shared ACP
infrastructure untouched so Cursor (which uses setConfigOption) is
unaffected.

Also updates session.model immediately after a successful switch
(matching ClaudeAdapter/OpenCodeAdapter pattern) and removes the
redundant model assignment from the post-prompt session update.

Adds 3 integration tests:
- switches model in-session without restarting the process
- updates session.model immediately after in-session model switch
- does not call setModel when model is unchanged between turns

Mock agents updated with handleSetSessionModel for forward compat.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Apr 21, 2026
@hrishikeshmane hrishikeshmane merged commit a140597 into kiro-acp Apr 21, 2026
5 of 7 checks passed
hrishikeshmane pushed a commit that referenced this pull request Apr 25, 2026
Supersedes PR #4's set_model work with a corrected implementation covering
both models (`session/set_model`) and agents (`session/set_mode`), and
closes the first-turn alignment gotcha PR #4 had.

Key learnings from debugging sessions on threads e3a5c1bf (ValidationException),
55afbe27 (silent model swap no-op), 23f518fe (session/load ignores --model),
3e377f8b (UI not rendering post-respawn reply), and 593e16ae (final working
state with 3 set_mode + 4 set_model + 7 prompts, zero respawns):

- Kiro's `session/set_model` RPC only works if kiro-cli acp was spawned
  WITHOUT the `--model` flag. Passing `--model <slug>` at spawn locks the
  model and makes later set_model calls silently no-op.
- Kiro's `session/set_mode` RPC is the agent-equivalent of set_model.
  Kirodex uses it (connection.setSessionMode) and it works. Agent
  switching no longer needs to respawn kiro-cli, eliminating the
  UI artifact where post-respawn replies didn't render cleanly.
- effect-acp's agent SDK doesn't wire `session/set_mode` through its
  core handler dispatcher. `handleExtRequest("session/set_mode", ...)`
  is the correct hook on the mock side.
- AcpSessionRuntime.setConfigOption routes through
  `session/set_config_option` which Kiro rejects with -32601. We bypass
  the upstream helper and issue set_model / set_mode via the raw request
  channel (`ctx.acp.request(method, payload)`) — same pattern as PR #4.
- `ctx.activeMode` and `ctx.activeModel` track the agent/model Kiro has
  confirmed via RPC. Both init to `undefined` at spawn; first turn fires
  the RPC to align Kiro's state with the user's selection even when the
  user-chosen value matches what spawn-`--agent` set (closes PR #4's
  first-turn no-op).

Behavior:
- Single kiro-cli child process per thread. No respawns on agent or
  model change.
- Initial spawn still passes `--agent <name>` as a hint so first turn
  doesn't need set_mode if user stuck with the default. `--model` is
  deliberately NOT passed.
- Known Kiro-side limitation: switching across model families mid-
  conversation (e.g., Claude → DeepSeek) can surface Bedrock
  `ValidationException` from history replay. This is a Kiro product
  bug to be filed upstream; our client surfaces the error rather than
  masking it.

Tests:
- Added regression tests for first-turn set_model/set_mode alignment
- Inverted prior PR #4 test whose invariant was "don't respawn on
  model change" (correct) but failed to assert the set_model RPC
- Dropped `--model` spawn-arg tests (invariant reversed)
- Agent-respawn test replaced with set_mode-in-session test
- Mock agents extended with handleExtRequest("session/set_mode", ...)

Verified end-to-end on thread 593e16ae: 1 initialize, 3 set_mode, 4
set_model, 7 prompts, 0 failures, 0 respawns. 935 server tests pass,
bun typecheck clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant