Skip to content

feat(chat): pick a backend per chat - #19599

Closed
billygerhard wants to merge 1 commit into
kirodotdev:mainfrom
billygerhard:feat/chat-backend-slot
Closed

billygerhard wants to merge 1 commit into
kirodotdev:mainfrom
billygerhard:feat/chat-backend-slot

Conversation

@billygerhard

@billygerhard billygerhard commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A dashboard chat can be switched to a different backend (for example Claude instead of Kiro) by an agent tool, and keeps that choice across restarts. The dashboard dropdown that lets a person do the same is Phase 2.

Today every dashboard chat runs on the gateway's one global backend. Sub-agents can already pick a backend per run (#18150); a chat cannot. This is Phase 1 of the design in rfc-chat-backend-selection (plan: #13892).

Why it matters

Users who run more than one backend want to choose per conversation: a coding chat on Claude, a cheap triage chat on Kiro. A person gets that choice with the Phase 2 dropdown. This PR serves the agent's half of the job: an agent that opens worker chats with session_create (a conductor fanning work out, or a cron job) can move one of those chats to another backend when the first backend hits its quota or cannot run the task, without closing it and losing its transcript. The tool goes through the existing session-control gate and its creator fence, so an agent can switch only the sessions it created, never a chat a person opened; switching a person's own chat waits for the dropdown, where the person clicks.

Not a goal

  • No UI in this PR; the composer dropdown and its route are Phase 2. The person sees a pick through the switch notice, and it is undone with session_set_backend("") from another session (a chat's own agent cannot switch the chat it is running in), so until the dropdown ships, undoing a switch takes a second session. This PR adds no field nothing renders; the slot row gains backend with the dropdown that reads it. Until the dropdown, the Side Chat tools indicator (GET /api/chat/side/tools) and the composer's model list (GET /api/models) still describe the gateway backend; the dashboard model routes and session_set_model check a model against the chat's own backend. Picking a listed gateway model in a chat moved to Claude is refused with the existing ... the claude backend does not accept; select a listed model or 'auto'. and the chat keeps its model.
  • Phase 2 keeps the stored backend spelling (governance name, or "" for the default), so a saved pick reads back unchanged.
  • No custom or user-registered backends; only the backends governance already allows and that are installed.
  • The conversation carries over. The new backend's cold start replays the chat's transcript, as after a model switch, so a chat moved off a spent quota picks up where it stopped. This PR updates the RFC's switching rule (docs/request-for-change/rfc-chat-backend-selection.md §2), which said the opposite, and adds no replay cutoff. §4 now names this PR's route.
  • No change to channel-linked chats or crewmate direct messages (dashboard chats only, per the RFC).
  • Refusing a turn when a picked backend is later blocked is the RFC's open question; this PR keeps the existing fallback to Kiro, and that turn starts on the fallback's default model rather than the model chosen for the pick (the slot keeps both).
  • No warm-pool change: a picked chat cold-starts its sessions, as an explicit spawn_run(backend=...) does today, even when the pick names the gateway's own backend.

What changed (motivation → approach → change)

#18150 already made a session start on a requested backend and keep it through reset and compaction. A chat only lacked a place to store a pick and a way to set it, so this PR adds exactly those and reuses the sub-agent path for everything else. The dashboard route the dropdown will call ships with the dropdown in Phase 2.

  • _ChatSlot.backend, persisted with the slot's metadata. It stores a backend name such as kiro or claude; "" means no pick (gateway default).
  • chat_handlers.switch_slot_backend, the one switch. It validates the pick with the same resolver and refusal codes as spawn_run(backend=...) and takes the model switch's locks. The swap happens between turns: the switch only saves the pick and queues the reset a model pick queues, and the next turn start resets the session onto the pick before acquiring it, so a turn in flight is never cut and finishes on the old backend. That turn start also resets a picked chat's live session that runs another backend (a hard Stop's respawn that started before the pick). A backend change resets the chat's model, and any pending model pick, to the new backend's default (as a gateway provider change does); the new session replays the conversation. A crewmate direct-message session is refused (member_session): it follows agent.member_acp_backend. The caller's authorization is re-run after every await, before anything changes.
  • POST /api/session-control/set-backend, body {"target", "backend"}: the agent's route. session_control.set_backend_target (owned by session_control_parts/turn_control.py, beside reload_target) runs authorize_target before the switch and again after each lock await, like every other session-control verb, so the session-control switch, the self/channel-linked/mirrored refusals and the workspace boundary apply, every caller is held to the creator fence, and each refusal is recorded in the SEL. The switch notice names the caller. Registered as an internal-secret route.
  • A fork keeps the parent's pick, beside the model and effort it already copies.
  • A gateway provider switch clears the model only on chats with no pick; a picked chat's backend did not change, so it keeps its model.
  • Both dashboard allocation sites pass backend_override only when the slot has a pick, so an unpicked chat allocates with exactly today's arguments. Reset and compaction successors keep the pick through allocation_identity. A hard Stop respawns on the gateway default, as on main; the next turn start then resets a picked chat onto its pick.
  • Every place that works out a chat's backend before its session exists honours the pick, as allocation does, through one helper (chat_runner.slot_backend) where it resolves a slot's backend: session_set_model's model check, the dashboard's model routes (a single chat is judged on its pick; the all-chats route judges unpinned chats together and each chat again under its locks on its current pick, leaving one its backend cannot run unchanged and reporting it under unchanged), the selection-capabilities read, the slash-command and /compact checks, the app-agent host check, the inherited-model probe, and the eager spawn's resume decision. Thread replies and side-panel turns also start on the pick, and their read-only tool posture is decided by the picked backend through the same helper, so a Kiro gateway's read-only allowance never reaches a chat picked onto Claude. A retained side session is rebound when the pick changes. A backend change also counts as a binding change for an eager handshake already in flight, so its session is torn down instead of kept.
  • Sub-agents of a picked chat start on the pick, so a shared child (which runs in the parent's process) and a dedicated child agree; spawn_run(backend=...) still wins, and a crewmate's worker keeps the backend its kit needs. The run records that inherited pick (inherited_backend, persisted with the run's state) apart from its own backend, so a spawn_continue resumes on the backend the conversation started on even after the parent switches. A continuation never takes the parent's current pick.
  • MCP tool session_set_backend, beside session_set_model, posting to the session-control route, and on the channel-agent block list with its siblings.
  • Session-control docs and tool counts updated (37 -> 38).

Backwards compatibility

Additive. A chat with no stored pick behaves exactly as before: the metadata field defaults to "" and the allocation keywords are unchanged when it is empty. Older slot metadata without the field decodes to no pick.

The all-chats model route (POST /api/chat/slots/model) keeps its response shape; a pinned chat its backend cannot run is reported under unchanged. The eager-spawn binding tuple (_slot_binding, internal) gains the pick. Removes nothing else: no existing key, route, validator or record is removed or tightened.

Tests

  • test/test_chat_slot_backend.py (new). Switch: a pick is saved and a reset is queued for the next turn, with nothing torn down now, and the replay carries the pre-switch conversation (a no-op switch posts no notice); a turn in flight is left to finish on the old backend; an empty pick returns to the default; re-picking the same backend changes nothing; pinning the backend the chat already runs on keeps its model and pending pick; a backend that cannot start is refused with the shared refusal codes; a switch clears the previous backend's model and drops a pending model pick made for it; a crewmate DM session is refused; a chat with no live session keeps the pick; a caller gate that turns false after the probe changes nothing. Turn start: a picked chat whose live session runs another backend is reset (including a switch made while a hard Stop's respawn was starting), one already on its pick is kept, and an unpicked chat is left alone. Allocation: an unpicked chat adds no allocation keyword; a picked chat's real turn (through turn_harness.run_turn) allocates its session with backend_override; the pick round-trips through the slot metadata line. Agent verb: it switches a reachable session, records an allowed SEL event and posts one notice naming the backend and the caller (a refused switch or a re-pick of the current backend posts none); it refuses the caller itself (self_target), a fenced caller's session it did not create (not_creator), and any call with session control off; the switch's own refusal is returned and audited; the tool posts to /api/session-control/set-backend with the caller's verified key, and accepts "" to return to the default. test/test_session_control_set_model.py: a model pick is checked against the chat's own backend. A cold picked chat reports its own backend for selection capabilities and slash commands. A fork keeps the parent's pick. The dashboard's single-chat model route checks a model against the chat's own pick; the all-chats route leaves a pinned chat its backend cannot run unchanged and reports it under unchanged, while the unpinned chats still switch. A chat unpinned while an earlier chat's reset awaits is still checked on its new backend. test/test_config_live.py: a gateway provider switch keeps a picked chat's model. A turn on a pick governance has since disallowed still starts, through the factory's existing fallback to Kiro, and sends no model; an unpicked, a "kiro" and an allowed pick still send theirs; an unpicked, a selectable and a "kiro" pick are left alone. A hard Stop's respawn that registers on the old backend after the turn-start check, or keeps a cleared pick, is reset and reclaimed on the pick. The switch notice loads a lazy transcript off the loop before appending. test/test_chat_threads.py and test/test_side.py: a picked chat's thread reply and side turn allocate with backend_override and take their tool posture from the pick (a Claude-picked chat on a Kiro gateway gets REJECT_ALL); a Claude-to-Codex switch rebinds the retained side session. A switch landing during a thread turn does not change the backend that turn allocates on. A pick governance has since disallowed decides no posture (no Claude read-only shape on a session that degrades).
  • Updated composition (MCP route table and boot order), running-reader, registration, tool-title and session-control doc tests for the new field, routes and tool.

Manual verification

N/A — no UI in this PR; the route and tool are covered end to end by the unit tests above. The dropdown PR will carry a live check with screenshots.

Related Issues

Part of #13892. Implements Phase 1 of the design in rfc-chat-backend-selection. Supersedes #15978.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@billygerhard
billygerhard requested review from a team and KiroCrewCaptain as code owners October 12, 2026 22:47
@billygerhard billygerhard mentioned this pull request Oct 12, 2026
5 tasks done
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 86115ade670ce61619300243b3c3e5ca16f6b0de touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of f7618708f8df2892c5e3945f6d4ab4a0ea8b2207 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: the per-chat pick is opt-in, with no pick every chat behaves as on main, and nothing in the repo already lets you set a backend per chat.

What this change ships

Inventory (9 items) — 9 justified

Intent: let an agent move a chat it created to another backend without losing the transcript, and keep that choice across restarts. This is an ADDITION.

  1. An agent can switch a chat it created to another backend with the new session_set_backend tool. The switch takes effect at the next turn. — justified
  2. A chat's backend pick is saved with the chat and survives a restart. — justified
  3. After a switch, the new backend receives the transcript, the model resets to that backend's default, and the chat shows a notice. — justified
  4. Thread replies and side-panel turns run on the chat's pick, and their tool permissions follow the picked backend. — justified
  5. A forked chat keeps its parent's backend pick. — justified
  6. Sub-agents of a picked chat start on the pick, and a continuation resumes on the backend it first ran on. — justified
  7. A gateway provider switch no longer clears the model on chats that have a pick. — justified
  8. A chat whose pick is not allowed falls back to Kiro and posts a one-time notice saying so. — justified
  9. Model checks (picker, all-chats route, session_set_model), slash-command checks and /compact checks now judge a chat by its picked backend. — justified

[FIRST-PRINCIPLES-REVIEWED] f761870

Description read

[DESCRIPTION-READ] e5c9428df1d3c95009233086f2f0d189e654bf9449a29b6bc57b2807d3e01dca

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 86115ade670ce61619300243b3c3e5ca16f6b0de via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the pick is a new, defaulted slot field, the swap reuses the queued-reset and sub-agent backend paths, and the creator fence keeps agents off chats a person opened.

Notes

  • The PR rewrites RFC §2 from "context is not carried over" to "the conversation is carried over". That now sends a chat's history to a second provider. An implementation PR is reversing a design decision here, so get the RFC owner's sign-off on docs(rfc): per-chat backend selection #19438 rather than settling it in this diff.
  • RFC Alternatives still says "Degrade an unavailable pick to Kiro. Rejected". Yet "Not a goal" keeps "the existing fallback to Kiro" for a pick that is later blocked. Make the RFC's open question say that this gap ships in Phase 1, so the two parts of the RFC agree.
  • The description is cut off inside ## Backwards compatibility. The readers I could check are private helpers this diff refactors; the rest is unverified.

[DESIGN-REVIEWED] 86115ad

Description read

[DESCRIPTION-READ] 144444c3d364d4c977faa528f35bd5e2b3a5154741dd6b0e24ed5170c94d3ca3

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 86115ade670ce61619300243b3c3e5ca16f6b0de via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 86115ad

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — 🔴 changes requested (blocking)

Reviewed 86115ade670ce61619300243b3c3e5ca16f6b0de via the fork AI-review pipeline; updated in place on each push.

Adjudication upheld 2 of 2 blocking finding(s); those must be resolved before merging.

BLOCKING -- src/kiro_crew/subagent_manager/backend_inheritance.py:25 -- Queued runs lose the parent's backend after a restart

inherited = sessions.allocation_backend_override(info.parent_session_key)
Trigger: A Claude-picked dashboard chat submits spawn_run without an explicit backend; admission queues it, and a gateway restart leaves it for durable replay. The queue pump rebuilds the run and _run_inner_impl calls this lookup before the parent's native session exists.
Outcome: The lookup returns None, and queue parameters retain only the explicit backend. The worker therefore cold-starts on the gateway default instead of the parent's persisted Claude pick.
Anchor: defect
Fix: Capture inheritance at admission, preserve it separately in durable queue parameters, and use that recorded value when dispatching the restored run.

BLOCKING -- src/kiro_crew/dashboard/chat_turn/slash_commands.py:688 -- Compact refuses a backend that the pending reset cannot activate

and not slot._pending_reset_history_key
and not _off_backend_pick(state, slot, KiroCrewConfig.load(), _live_provider)
Trigger: An idle Kiro chat has a child awaiting spawn approval; its creator switches it to installed DeepSeek, then the user sends /compact. Approval-waiting children do not hold user messages, so _run_chat reaches _turn_slash_gate before admission.
Outcome: The pending reset excludes the live Kiro provider, and the DeepSeek pick produces an unsupported-command refusal. Attached children defer both reset and off-backend reclaim, so the session that would execute the command remains Kiro and supports compaction.
Anchor: defect
Fix: Use the child-aware retirement decision already used by _slash_command_backend, retaining the live provider's compact capability while attached children defer its reset.

[BLOCK-MERGE] 86115ad
[GPT-REVIEWED] 86115ad

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 — MEDIUM, and the wrong backend is silent. inherit_parent_backend (patch backend_inheritance.py:19) reads allocation_backend_override, which gets its value only from a live session (patch claims.py:1970-1971). After a restart there is no live session, so it returns None. Durable queue params hold only the explicit backend (admission/gate.py:605), so nothing restores the pick and the replayed run starts on the gateway default without telling anyone. The fix is small: one more inherited_backend queue key carried through to the field that already exists on SubagentInfo. That cost is below the harm.

F2 — LOW, a visible and wrong /compact refusal that clears once the children finish. Confirmed at patch slash_commands.py:979-984: the compact gate checks _pending_reset_history_key and _off_backend_pick but not subagents_attached_async, while _slash_command_backend (patch :931-938) does check it. The fix reuses that existing retiring predicate, so it adds no new mechanism. Upholding costs the author one review round, and that is less than the remedy cost would need to be to justify a downgrade.

[ADJUDICATION] 86115ade670ce61619300243b3c3e5ca16f6b0de total=2 uphold=2 downgrade=0
UPHOLD F1 src/kiro_crew/subagent_manager/backend_inheritance.py:25 reason=harm-warrants-remedy
UPHOLD F2 src/kiro_crew/dashboard/chat_turn/slash_commands.py:688 reason=harm-warrants-remedy
[GPT-ADJUDICATED] 86115ade670ce61619300243b3c3e5ca16f6b0de

@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch 2 times, most recently from 4a7fb63 to ab3e71d Compare October 13, 2026 00:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 13, 2026
@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch from ab3e71d to 66e1412 Compare October 13, 2026 01:25
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 13, 2026
@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch from 66e1412 to 2352ca2 Compare October 13, 2026 02:28
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 13, 2026
@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch from 2352ca2 to e63a8b2 Compare October 13, 2026 03:12
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 13, 2026
@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch from e63a8b2 to 6850221 Compare October 13, 2026 05:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention labels Oct 13, 2026
@billygerhard
billygerhard force-pushed the feat/chat-backend-slot branch from 6850221 to 020e9e9 Compare October 13, 2026 05:55
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 13, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 7068483.

This PR lets an agent move one dashboard chat to another backend. It adds session_set_backend and POST /api/session-control/set-backend, and stores the pick on the slot. The switch reuses the model-switch locks and reset, and re-runs authorize_target after every await. I found no definite defect in the switch, rollback or allocation paths.

What blocks approval:

  1. Human review is required by policy. The PR adds a cross-session control verb behind the session-control authorization gate (session_control.py L6892). It also changes how side and thread turns choose their read-only tool posture (side.py L472). A maintainer needs to review both.
  2. Nobody has replied to the current-head AI items. First Principles CONCERNS (item 9): switch_slot_backend is shaped as an HTTP handler for a route this PR does not ship, so set_backend_target parses response.text back into JSON. Please post a target=first-principles disposition, or remove the round-trip. Design also raised two points: a pick that governance later blocks silently runs on Kiro, and slot.backend == pick treats "" and "kiro" as different on a Kiro gateway (chat_handlers.py L7220). Each needs a disposition.

This clears when every AI item has a disposition and a maintainer has reviewed the authorization and tool-posture changes. CI on this head is green. I read the tests but did not run them.

— crew-pr-reviewer (r100)

@iamwhatever

Copy link
Copy Markdown
Contributor

Holding for a human maintainer. I found no definite defect, but this PR adds a cross-session control verb and changes tool posture.

Reviewed head: 6475a050e9fb37ee08e057159d4ae6082cd44e73

session_set_backend runs authorize_target before the switch and again after each lock await (session_control.py#L7086-L7183). switch_slot_backend reuses the model-switch locks, the busy refusal and the rollback, and it now treats "" and "kiro" as the same backend (chat_handlers.py#L1234-L1357). Every AI lane is PASS or has no findings on this head, and CI is green.

What would clear the hold:

  • A maintainer reviews the new verb's authorization and the side-panel tool-posture change (side.py#L465-L486). The user's rules reserve these for a human.
  • Replies to the two PASS asks on this head. Design asks what a user sees when governance later denies a saved pick: today it falls back to Kiro and only the log says so (chat_runner.py#L740-L755). First Principles asks whether spawn_run(backend=...) sub-agents respawn on their own backend after a hard Stop.
  • Our r100 HOLD still has no reply. A short disposition saying which items this head fixes (for example the ""/"kiro" check) would close it.

— crew-pr-reviewer (r103)

@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at 0542e614a18e4852a5c402837772d273b951ea19 for human review. I found no definite defect in what I read.

This PR adds a cross-session control verb, session_set_backend (set_backend_target, route /api/session-control/set-backend), behind the authorize_target gate. It also changes how side-panel and thread turns pick their read-only tool posture (side.py), and hard-Stop respawns now honour any recorded backend_override. The repository owner reserves authorization and tool-posture changes for a maintainer.

Still unanswered on this head:

  • First Principles PASS ask: the RFC is still draft on base. Confirm Phase 2 keeps the persisted backend spelling before it lands in slot metadata on disk.
  • Design PASS check: a chat moved to Claude on a Kiro gateway still lists the gateway's models in the composer, and the slot-model route now refuses them. Say what error the person sees until Phase 2.
  • Our earlier HOLDs (r100, r103) have no reply. The description now covers the sub-agent respawn ask with a test.

This clears when each lane ask has a target=first-principles / target=design disposition for this head and a maintainer reviews the authorization and tool-posture changes. CI on this head is green.

— crew-pr-reviewer (r107)

@iamwhatever

Copy link
Copy Markdown
Contributor

Holding reviewed head 875bd71 for a human maintainer. I found no definite defect in what I read.

  • Human review required. The PR adds a cross-session control verb behind authorize_target (set_backend_target, route). It also changes how side and thread turns choose their read-only tool posture (side.py).
  • Conflict. GitHub reports CONFLICTING. docs/architecture/mcp.md and src/kiro_crew/docs/index.md conflict with current main.
  • Unanswered AI concern. The First Principles CONCERNS on this head has no disposition: the RFC is still status: draft on main, while this PR fixes the stored backend spelling and the tool's contract. The Design PASS note on the truncated Backwards compatibility section also has no reply.

The description now covers the Design question from r107 about the refused-model message, and Phase 2 is tracked on #13892. This clears with a rebase, a target=first-principles disposition for the new head (or the RFC marked non-draft, or a maintainer override), a reply to the Design note, and a maintainer review of the authorization and tool-posture changes. CI on this head is green.

— crew-pr-reviewer (r108)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 9e23697 for human review (deep check). This head is a rebase of 875bd71 with no source change: a per-file line comparison of the two diffs differs only in two doc context lines and a test hunk that moved with main's test split. The PR adds a cross-session control verb, session_set_backend, and a new internal route. It also derives the side-panel and thread tool posture from the picked backend (side.py#L468). I found no defect: authorize_target runs before the switch and again after each lock await, and a backend that governance disallows decides no posture. Still open: First Principles items 1, 2 and 7 and the Design punchline have no reply, and CI is still running on this head. — crew-pr-reviewer (r108 deep)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 265a213 for a human maintainer.

This PR adds a cross-session control verb, session_set_backend, and a new route POST /api/session-control/set-backend behind authorize_target (turn_control.py#L620). It also derives the side-panel and thread tool posture from the picked backend (side.py#L548). The owner reserves authorization and tool-posture changes for a maintainer. CI is green and the branch merges cleanly.

Current-head AI items with no reply:

  • Opus: after the reset await, switch_slot_backend does not re-run still_ours() before appending the notice (chat_handlers.py#L1348-L1386). A tab closed during teardown still gets the notice, and the verb audits allowed for a slot that is gone. The docstring promises the re-check, and the reload path makes it (session_relaunch.py#L310). Smallest fix: if not still_ours(): raise _target_replaced() after the reset and its retry.
  • Design watch 1: the RFC §2 reversal (the transcript goes to the new backend's provider) needs the RFC maintainer's sign-off on docs(rfc): per-chat backend selection #19438 or here.
  • Design watch 2: an agent's pick is not visible in the composer and can only be undone from another session. A maintainer needs to accept shipping the tool before Phase 2.

This clears when each item has a fix or disposition and a maintainer reviews the authorization and tool-posture changes. A fix needs a fresh review. No PR code was run locally.

— crew-pr-reviewer (r116)

@github-actions

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — ✅ PASS

Which legitimate operations does 9597d76d3b659d5fc29903502f2a7aeb97add1d8 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

adjudicated, zero confirmed regressions

Scope-Verdict: PASS

Reason: This PR adds a feature: a per-chat backend pick and a new session_set_backend session-control verb. It does not touch the shell deny composite (sensitive-bash, exfil, deny-rules), so the adjudicated rows are controls that are expected to stay allowed. What got stricter is outside the classifier: the channel-agent tool blocklist, authorize_target on the new route, and new model-rejection re-checks on the model-switch paths. Those are named under UNADJUDICATED; the new refusals all sit on the new verb, and only a narrow race window on existing model paths could newly refuse, so I could not confirm a regression there and none is demonstrated.

TIGHTENING: the channel-agent blocklist and new model-rejection re-checks on model-switch paths -- they refuse a channel agent (or an unauthorized caller) changing which backend another session's next turn runs on, and they stop a model id from being stored for a backend that cannot run it. The blocklist hunk is CHANNEL_AGENT_BLOCKED_TOOLS: ... + # Same containment reason for the backend the next turn starts on. + "session_set_backend", in src/kiro_crew/channel.py. The re-check hunks are in slot_model.py (reason = _model_rejected_reason(model_name, session_keys=(session_key,), pick=slot_backend_override(slot).get("backend_override")) under the locks) and model_switch.py (backend = slot_backend(slot, member_backend, default_backend); model_name = _judged_on(backend) after the lock await).

ADJUDICATED: 12 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: Candidates cover posix, windows and any. The diff makes no new shell assumptions about paths, separators or interpreters; its only platform-sensitive surfaces are which harness executables exist and where chat history lives. The posix rows cover these: .venv/bin/python test runs, which claude codex kiro-cli, and a ~/.kirocrew/history grep. The windows rows mirror them: .venv\Scripts\python.exe, where.exe, and Select-String with $env:USERPROFILE\.... The any rows are platform-neutral: kirocrew config get agent.acp_backend / agent.member_acp_backend, claude --version, codex --version, and a scoped git diff --stat. No platform the diff assumes is left without a candidate.

UNADJUDICATED:

  • Guard 1, channel-agent tool blocklist (CHANNEL_AGENT_BLOCKED_TOOLS in src/kiro_crew/channel.py).
    • Call path: a channel-linked agent turn calls MCP tool session_set_backend, and the channel tool filter refuses it before POST /api/session-control/set-backend.
    • Inputs I would have submitted: a channel agent calling session_set_backend {"target":"<own slot>","backend":"claude"}. This verb is new, so nothing existing is newly refused.
  • Guard 2, authorize_target on the new route.
    • Call path: api_session_control_set_backend → _require_internal → set_backend_target._gate → switch_slot_backend(still_ours=...).
    • Inputs I would have submitted: a conductor setting backend:"codex" on a worker it created; any caller passing backend:"" to return to the default.
    • Note: the verb has no allow_self, so a session cannot switch its own backend.
  • Guard 3, switch preconditions in switch_slot_backend: _requested_backend validation, relay_archive_refusal, and the member_session 409 for crewmate DM keys.
    • Inputs I would have submitted: backend:"kiro" on a Kiro gateway (meant to be a no-op), and a backend that is installed but needs a restart.
  • Guard 4, new model-rejection re-checks under the locks.
    • Call paths: api_chat_slot_model (new model_rejected 400 after _app_cancel_denied), and api_chat_slots_model, which now puts a pinned slot whose backend cannot run the model into unchanged. The pre-check there also skips pinned slots, so a bulk request no longer fails just because one chat is pinned.
    • Also set_model_target, which re-runs _judged_on after the busy check.
    • Inputs I would have submitted: a dashboard model-picker switch to a Kiro model id on an unpinned chat; session_set_model to "sonnet" on a Kiro-default chat. Neither should change behaviour, because with no pick slot_backend resolves to the same select_provider_backend(key, member, default) as before.
  • Not a refusal, but changed: config_watch no longer clears slot.model on pinned chats when the provider changes, so a pinned chat keeps its model.

[SCOPE-REVIEWED] 9597d76

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 8 classified, 0 newly refused, 8 still allowed.

No candidate flipped from allowed to refused.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD on b67c3e5.

The Opus item from our r116 hold is resolved: switch_slot_backend now re-runs still_ours() after every await and only queues the reset (chat_handlers.py#L1302-L1353). Opus and GPT report no findings on this head, and every check is green.

What still blocks, and what clears each:

  1. The branch conflicts with main in chat_turn/eager_spawn.py, slash_commands.py, turn_admission.py and test/test_dashboard_server_composition_contract_reach.py. A rebase clears it, and the rebased head needs a fresh review.
  2. First Principles notes that a hard-stopped spawn_run(backend=...) sub-agent now respawns on its override, outside this PR's goal. Please either limit the respawn identity to dashboard chat keys or cite the sub-agent defect it fixes, and reply on the PR.
  3. The PR adds a cross-session verb, POST /api/session-control/set-backend (turn_control.py#L620-L704), takes side and thread tool posture from the pick (side.py#L469-L485), and amends the RFC to replay the transcript to the new backend. A maintainer must review these.

No PR code was run locally.

Reviewed head: b67c3e5c18a3a87cf639c93c30456c33369ff4b5.

— crew-pr-reviewer (r123)

@billygerhard

Copy link
Copy Markdown
Contributor Author

Rebased onto main as 3bb5ce3. On the hard-Stop respawn: the respawn-identity change is removed, so a hard-stopped session (including a spawn_run(backend=...) sub-agent) respawns exactly as on main. A picked dashboard chat whose respawn comes up on the gateway default is moved to its pick by the turn-start backend check, which the RFC §2 text now states.

@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at 8dde2e5 for maintainer review.

Two of our r123 points are cleared. The branch now merges cleanly with main, and the hard-Stop respawn change is gone, so a stopped spawn_run(backend=...) sub-agent respawns as on main. The switch also refuses crewmate worker sessions now. Opus and GPT report no findings, and every check is green.

What still blocks, and what clears each:

  1. Human review is required by policy. The PR adds a cross-session verb and route, POST /api/session-control/set-backend (turn_control.py#L620-L700). It derives side and thread tool posture from the pick (side.py#L481), and it amends RFC §2 to replay the transcript to the new backend. A maintainer and the RFC owner clear this.
  2. First Principles item 8 has no reply on this head. It says the turn-start reset (turn_admission.py#L135-L151) compensates for the hard-Stop respawn dropping the session's identity. Please post a disposition explaining why the compensation stays now that the respawn change is removed, or limit the respawn identity to dashboard chat keys and drop the compensation.

I read the range-diff and CI and did not run the tests.

— crew-pr-reviewer (r127)

@billygerhard

Copy link
Copy Markdown
Contributor Author

Disposition for First Principles item 8 (turn-start reset in turn_admission.py), on head 8dde2e5.

The turn-start check stays because it is how a backend pick is applied at all, not a patch for the old respawn change:

  • The switch no longer touches the live session. It saves the pick and queues a reset through the same deferred path an agent's model pick uses. The turn-start check is the point where a picked chat whose live session runs another backend is moved onto the pick, before the turn takes a session.
  • Removing the respawn-identity change makes this check carry more of the load, not less. A hard Stop now respawns every session on the gateway default, as on main. For a chat with a pick, that respawned session is on the wrong backend, and the turn-start check is what moves it back. Without it, a picked chat would silently run on the gateway default after any hard Stop.
  • The same check covers a pick made while no session exists yet (nothing for the queued reset to act on), and a pick cleared while a respawn on it was still starting.

Chats with no pick, whose session was not started on one, return early and behave exactly as on main. Scoping the respawn identity to dashboard chat keys would bring back the respawn change that review asked to remove, and the check would still be needed for the no-session and cleared-pick cases, so I kept the smaller shape.

@cruisercohen

Copy link
Copy Markdown
Contributor

@iamwhatever item 2 of the r127 hold is answered: billygerhard posted the First Principles item 8 disposition on 8dde2e5 at 11:50 PDT, about 40 minutes after the hold. The turn-start check is now the mechanism that applies a backend pick at all, including the re-apply after a hard Stop, and not compensation for the removed respawn change. Every check is green on this head.

That leaves item 1, the human review by a maintainer and the RFC owner: the cross-session set-backend verb and route, the tool posture derived from the pick, and the RFC §2 amendment. Could you or another maintainer take that review, or say who owns the RFC sign-off? The branch conflicts with main again, so it will need one more rebase before merge.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at f3e3553, for maintainer review.

This head is a rebase of 8dde2e5. The patch is unchanged apart from two doc table rows that moved with main. It merges cleanly, and every check is green. Item 2 of our r127 hold is answered: the First Principles item 8 disposition explains that the turn-start reset is how a pick is applied at all, including after a hard Stop respawns the session on the gateway default. All AI lanes pass with no open findings.

What still blocks is the human review that policy requires. The PR adds the cross-session POST /api/session-control/set-backend verb and route, derives side and thread tool posture from the pick, and amends RFC §2 so a switch replays the transcript to the new backend. A maintainer and the RFC owner clear this.

— crew-pr-reviewer (r128)

@CrysisDeu CrysisDeu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review, comment (not approving yet) at fd8392cd. Reviewed at f3e35538; fd8392cd is a rebase of it (only change: the black-baseline edit dropped, MCP table digest bumped, one pytest marker), so this applies as-is.

Design call for the per-chat / per-member work, so the three PRs stop rebasing in parallel. This PR is the per-CHAT tier and lands first. The per-MEMBER tier is #25485 (kyleseaman's re-port of #11324, scoped to crewmates); #11324 and #16200 close once it is up. Rules both tiers follow: precedence spawn_run(backend=) > chat pick > member pin > member route > default, through ONE resolver (your chat_runner.slot_backend and #25485's crew-aware helper must compose, not duplicate); blank value follows main (#20359: "" / absent = no choice, "kiro" = Kiro), which this PR already does; a pinned backend that is missing or later disallowed fails closed with a visible in-chat notice, never a silent fall-through; crewmate DMs stay refused here (as you have it). Thank you for adopting main's spelling, that saved a round.

Two things to fix before I approve:

  1. MAJOR src/kiro_crew/dashboard/chat_handlers.py:1300, members_parts/member_sessions.py:142: a crewmate worker is refused only when is_crewmate_worker_session(key) is true, and that set lives in memory, filled by note_worker_session when the execution record is read. After a gateway restart a worker slot not yet re-read is not in the set; its conductor (creator, so the fence passes) can set a pick, and because backend_override sits above the member/worker route in select_provider_backend, the next turn starts the worker on a backend outside ACP_BACKENDS_MATE_WORKER_KIT and fails with capability_harness_unsupported. Decide from the durable execution record (or the slot's crew identity), not the in-memory set, and add a restart test.
  2. MAJOR (design) session_control_parts/turn_control.py:620-700, chat_handlers.py:1348-1361: an unfenced caller, which is the owner's own agent in any other dashboard chat, can move any other chat to a different provider; the next turn replays the whole transcript there, with no human confirmation, no visible backend indicator and no UI to undo until Phase 2. Transcript egress to another provider is a human decision. Apply the creator fence to every caller (an agent may re-pick only sessions it created), and leave moving someone else's chat to the Phase 2 UI where a person clicks.

Also: chat_turn/turn_admission.py:890: when governance later disallows the pick the turn silently runs on Kiro with Kiro's default model, log line only; append a one-time in-chat notice or refuse (rule above). subagent_manager/run_start.py:86: a dedicated child (any model, allowed_tools, bare, AWS profile) gets the gateway default while a shared child inherits the pick; default the dedicated child's backend_override to the parent's pick. handlers/side.py:495, chat_threads.py:956: ... if picked else cfg.agent.acp_backend bypasses the member route; always call slot_backend. Add set_backend to the session-control metric op enum. Nits: English-only switch notice (matches existing), drive-by reformat is now gone.

Checked and fine: apps cannot reach the route (_require_internal), channel agents blocked at the tool layer, fenced callers limited to creator, unknown/uninstalled backend refused up front, hand-edited metadata still gated at allocation. CI green, no BLOCK issued so nothing overridden.

Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Thanks @CrysisDeu. All of it is addressed in 5b35d2b254:

  1. Worker after a restart: switch_slot_backend now also reads the slot's durable execution record (_recorded_as_worker) and refuses member_session when it names a crewmate's worker; an unreadable record refuses too. Tests: a worker missing from the in-memory set (the post-restart state) is refused, and so is an unreadable record.
  2. Transcript egress: set_backend_target applies the creator fence to every caller (precomputed_ownership_fenced=True), so an agent re-picks only sessions it created; moving any other chat is left to the Phase 2 UI. The test now checks an unfenced dashboard caller is refused not_creator. Tool description, RFC §2/§4 and the session-control spec say so.

Also:

  • turn_admission.py: a pick the gate degrades now posts a one-time in-chat notice naming the pick and the backend the chat runs on (once per pick, reset when the pick resolves again).
  • run_turn.py: a dedicated child with no backend defaults backend_override to its parent session's pick; spawn_run(backend=) still wins, and a crewmate's worker keeps its kit backend.
  • side.py / chat_threads.py: always resolve through slot_backend, so a crewmate DM's thread and side turn take the member route. Test: a DM thread on a Kiro gateway with a Claude member backend gets Claude's posture.
  • set_backend added to the session-control metric op enum (docs and series bound updated).
  • Fixed the test_slot_running_readers inventory red from the previous push.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Follow-up in 200bca718a (also rebased onto main): the side.py / chat_threads.py change above resolved the posture on the parent chat's key, while the thread and side sessions are allocated under their own keys, which the member route does not match. On a Kiro gateway with a Claude member backend that postured a crewmate DM's thread for Claude while it ran on Kiro, so Kiro got REJECT_ALL. Both now call slot_backend with the session's own key (session_key / side_key), so posture and allocation agree. The thread test now checks that case gets Kiro's read-only shape; it fails without the fix.

A dashboard chat can carry an optional backend pick, set through the session_set_backend MCP tool (POST /api/session-control/set-backend). The pick is validated by the resolver spawn_run(backend=...) uses, persisted on the slot, and passed to session allocation as backend_override; a change ends the current session so the next turn starts on the new backend. An unpicked chat allocates exactly as before. Implements docs/request-for-change/rfc-chat-backend-selection.md Phase 1.
@chenmingwei23

Copy link
Copy Markdown
Contributor

Closing in favour of a fresh, smaller PR: per-session backend selection at session creation (session_create / work_dispatch), built on current main and the single resolver from #25485. Thanks @billygerhard for the groundwork here; the new PR credits you as co-author where it reuses this design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants