Commit f0fa43b
hrishi mane
fix(kiro): in-session model + agent switching via set_model/set_mode RPC
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.1 parent da71e1e commit f0fa43b
4 files changed
Lines changed: 209 additions & 68 deletions
File tree
- apps/server
- scripts
- src/provider/Layers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | 252 | | |
261 | 253 | | |
262 | 254 | | |
| |||
300 | 292 | | |
301 | 293 | | |
302 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
303 | 313 | | |
304 | 314 | | |
305 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
70 | 85 | | |
71 | 86 | | |
72 | 87 | | |
| |||
Lines changed: 107 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
| 284 | + | |
286 | 285 | | |
287 | 286 | | |
288 | | - | |
| 287 | + | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
| |||
294 | 293 | | |
295 | 294 | | |
296 | 295 | | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 296 | + | |
| 297 | + | |
302 | 298 | | |
303 | 299 | | |
304 | 300 | | |
305 | 301 | | |
306 | 302 | | |
307 | 303 | | |
308 | | - | |
| 304 | + | |
309 | 305 | | |
310 | 306 | | |
311 | 307 | | |
312 | | - | |
| 308 | + | |
313 | 309 | | |
314 | 310 | | |
315 | 311 | | |
| |||
319 | 315 | | |
320 | 316 | | |
321 | 317 | | |
322 | | - | |
| 318 | + | |
323 | 319 | | |
324 | 320 | | |
325 | 321 | | |
326 | 322 | | |
327 | 323 | | |
| 324 | + | |
| 325 | + | |
328 | 326 | | |
329 | 327 | | |
330 | | - | |
| 328 | + | |
331 | 329 | | |
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
335 | | - | |
| 333 | + | |
336 | 334 | | |
337 | 335 | | |
338 | 336 | | |
| |||
343 | 341 | | |
344 | 342 | | |
345 | 343 | | |
346 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
347 | 385 | | |
348 | 386 | | |
349 | 387 | | |
350 | | - | |
| 388 | + | |
351 | 389 | | |
352 | 390 | | |
353 | 391 | | |
| |||
359 | 397 | | |
360 | 398 | | |
361 | 399 | | |
362 | | - | |
| 400 | + | |
363 | 401 | | |
364 | 402 | | |
365 | 403 | | |
366 | 404 | | |
367 | 405 | | |
368 | 406 | | |
369 | | - | |
| 407 | + | |
370 | 408 | | |
371 | 409 | | |
372 | | - | |
| 410 | + | |
373 | 411 | | |
374 | 412 | | |
375 | 413 | | |
376 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
377 | 460 | | |
378 | 461 | | |
379 | 462 | | |
380 | | - | |
381 | 463 | | |
382 | 464 | | |
383 | 465 | | |
384 | 466 | | |
385 | 467 | | |
386 | 468 | | |
| 469 | + | |
387 | 470 | | |
388 | 471 | | |
389 | 472 | | |
| |||
401 | 484 | | |
402 | 485 | | |
403 | 486 | | |
404 | | - | |
| 487 | + | |
405 | 488 | | |
406 | 489 | | |
407 | 490 | | |
| |||
411 | 494 | | |
412 | 495 | | |
413 | 496 | | |
414 | | - | |
| 497 | + | |
415 | 498 | | |
416 | 499 | | |
417 | 500 | | |
| |||
0 commit comments