Skip to content

fix(readiness): accept Crew's sign-in for turn gates on the KAS bundle route - #25562

Merged
bolichen97 merged 1 commit into
mainfrom
fix/kas-readiness-gate-21957
Nov 14, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/kas-readiness-gate-21957

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: on a KAS engine-bundle host signed in through Crew, with no kiro-cli installed, regenerate, edit-resend, rewind and POST /v1/chat/completions stop answering 503 kiro_prerequisite_required.

#21956 let /api/sessions/usage skip reject_if_kiro_unverified on that setup. The same gate still refused the other callers, because it asks only the kiro-cli prerequisite probe, and on a host with no kiro-cli that probe is never ready.

Why it matters

On the bundle route (agent.kas_bundle: true) chat works: the engine is Crew's own Node build and takes its credential from Crew's sign-in vault. But every rerun and every OpenAI-compatible request was refused with a "Kiro CLI setup or sign-in is required" error for a CLI the route never uses.

Not a goal

  • The KAS relay route (the default, agent.kas_bundle: false). It spawns kiro-cli, so the kiro-cli gate stays its authority.
  • /api/models on the bundle route. Its catalog is kiro-cli --list-models output, so it keeps the kiro-cli gate (see the per-site table).
  • The usage routes, which fix(usage): read credit usage from Crew sign-in without kiro-cli #21956 already handles with _vault_owns_usage.

Intended? / Repro

Intended? No. The gate exists because a signed-out kiro-cli would fail the turn after history was rewritten (src/kiro_crew/dashboard/kiro_readiness.py:251 reject_if_kiro_unverified docstring). On the bundle route kiro-cli is not involved in the turn at all (src/kiro_crew/acp/harness/kas.py:385 KasHarness.resolve_spawn, bundle branch: "no kiro-cli is involved", host_auth=True). #21956 deferred these sites to this issue.

Repro (read on current main):

  • Config agent.acp_backend: kas, agent.kas_bundle: true, kirocrew kas install done, signed in through the dashboard's Sign in, kiro-cli removed.
  • POST /api/chat/slots/<slot>/regenerate → chat_regenerate.py:112 calls reject_if_kiro_unverified(request) → kiro_verified_ready → KiroPrerequisiteService.verified_ready re-probes kiro-cli, which is missing → 503 {"code": "kiro_prerequisite_required"}. The same happens at chat_regenerate.py:449 (edit-resend), chat_rewind.py:126 (rewind) and openai_compat.py:145 (/v1/chat/completions). The user sees the "Kiro CLI setup or sign-in is required" error although a plain send in the same slot works.

What changed (motivation → approach → change)

Symptom: turn-starting endpoints refused on a host that needs no kiro-cli. Cause: the shared gate knows only the kiro-cli probe. Change: the gate learns one more authority, used only by callers whose sole kiro-cli dependency is the turn they start.

  • kiro_readiness.kas_crew_signin_ready(session_key): true when the turn on that session runs on Crew's installed KAS engine bundle (_kas_bundle_turn_sync) AND KasAuthProvider(default_token_store(), allow_env_api_key=False).current() yields a credential. _kas_bundle_turn_sync asks what the KAS harness itself asks, per session: the session's own backend through slot_effort.configured_backend_for_session, the selection _configured_backend_for_slot also runs (one copy: session pick, then crewmate pin, then select_provider_backend; a member thread runs on agent.member_acp_backend, and a governance-denied member backend degrades to kiro, so it is not the bundle turn), agent.kas_bundle (the flag KasHarness reads to take the bundle route), and kas_bundle.installed_bundle(). It does not use kas_bundle.kas_bundle_route(), which asks about the default backend only and would refuse a member thread on KAS under a non-KAS default.
  • kiro_readiness.live_turn_route(state, session_key): a session that already has a live provider is judged by the process it runs, not by the config. get_or_create reuses a live session with no backend check, and an agent.acp_backend change retires only the background runtime, so after the default moves to KAS a retained kiro-cli session would otherwise pass the gate and then fail auth after history was rewritten. The KAS harness now marks its bundle spawn (SpawnPlan.engine_bundle=True), the runtime keeps it (AcpRuntime._kas_engine_bundle), and this reads it, unwrapping the session map's AcpProvider to the AcpSessionProvider it exposes as client. A live session that is not on the bundle, or whose route cannot be read, answers False and keeps the kiro-cli gate. A cold start reads the crewmate's harness pin first (crew_backend=crewmate_backend_pin(...)), as the provider factory does, so a crewmate pinned to kiro-cli under a KAS member backend keeps the kiro-cli gate; a pin that cannot start keeps it too. kas_crew_signin_ready(session_key, live_route) reads the configured selection only for a cold start (None).
  • reject_if_kiro_unverified(..., turn_reuses_session=True): regenerate and /v1/chat/completions run their turn on the live provider, so they read live_turn_route. Edit-resend and rewind call discard_conversation before their turn, which tears the live process down, so the turn cold-starts from the current config; they pass turn_reuses_session=False and are judged on the configured route. A rewind with sub-agents attached swaps the conversation on the live process instead (keep_children -> swap_conversation), so it also passes may_keep_live_process=True: a live process not on the bundle keeps the kiro-cli gate, and otherwise the configured route is judged (fixed in fb415b9 after Opus 5.5 and GPT 6.1 on 438b37c).
  • kiro_readiness.turn_gate_target(state, slot_key): names the session the target slot's turns run on (effective_session_key; None for a slot not created yet). A state or slot it cannot read answers harness_turn=False, so the kiro-cli gate decides and the gate still answers before the handler touches state. The credential call is the same one that answers the engine's _kiro/auth/getAccessToken, so no identity, a refused refresh (RefreshRejected) or a refresh that cannot be attempted (RefreshBlocked) is not ready, and a rerun is still refused before history is rewritten. It reads fresh state on every call; there is no latch to go stale.
  • reject_if_kiro_unverified(..., harness_turn=False, session_key=None): new keywords. With harness_turn=True the gate passes when kas_crew_signin_ready(session_key) holds, without probing kiro-cli; otherwise it falls through to the existing kiro-cli check. Each caller passes the session its turn runs on (effective_session_key of the target slot; None for a slot that does not exist yet, which takes the default backend). The default keeps today's behavior, so a caller that spawns kiro-cli itself stays gated unless it opts in.

Per site:

Site Needs kiro-cli on the bundle route? Change
chat_regenerate.py regenerate No, when the slot's session runs on the bundle engine harness_turn=True, slot's session key
chat_regenerate.py edit-resend No: same harness_turn=True, slot's session key
chat_rewind.py rewind No: same harness_turn=True, slot's session key
openai_compat.py /v1/chat/completions No: runs a slot turn harness_turn=True, the id slot's session key (JSON is parsed before the gate to read it)
handlers/agents.py /api/models Yes: spawns kiro-cli chat --list-models unchanged

Docs: docs/system-specs/modules/learn-cron-dashboard.md, acp-client.md and cli.md describe the rule.

Security

The gate guards destructive reruns, so the new authority is no weaker than the probe it replaces on this route: it requires a credential that resolves (and refreshes) now, read from Crew's vault only; an ambient KIRO_API_KEY does not count. Failure logs carry only the exception type, never its message, since a refresh error can carry response bytes. kiro_crew.auth is imported at call time, keeping cryptography off the handlers' import path. No new route, port or permission.

Open, for a maintainer to rule: GPT 6.1 (security-class, fenced) flags chat_rewind.py:148: rewind with attached subagents keeps the live process (keep_children -> swap_conversation), but the gate judges the configured route. So an idle KAS-bundle slot whose configured backend was switched to kiro-cli, with the kiro-cli probe failing, gets a 503 on Edit & Resend. origin/main returns the same 503 for that input: rerun_signs_in_via_kiro_cli (unchanged here) reads the configured kiro-cli backend, and main calls reject_if_kiro_unverified(request) with no KAS check. The 503 comes before any history change. Judging the configured route also covers the swap's discard_conversation fallback (chat_rewind.py:566). Not changed here. Since fb415b9 the rewind also reads the live process, which only adds refusals, so this 503 still matches main.

Backwards compatibility

Compatible: on every host that is not KAS-on-bundle the gate behaves exactly as on main, and callers that do not pass harness_turn are unchanged.

Removes nothing: no key, field or error path is removed.

Tests

test/test_kas_bundle_readiness_gate.py (new):

  • TestBundleTurn: a default session on the installed bundle route, a member session on KAS, and a member session on KAS under a non-KAS default are the bundle turn; a default session under a non-KAS default, a member session on another backend, nothing installed, the relay route (engine not read) and an unreadable config are not.
  • test_an_unreadable_slot_keeps_the_kiro_cli_gate: a slot or state turn_gate_target cannot read answers (False, None).
  • test_relay_archive.py and test_slot_ownership_checkpoint.py: their gate stubs accept the new keywords.
  • TestCrewSigninReady: a resolvable credential is ready (vault only, allow_env_api_key=False); NotAuthenticated, RefreshRejected and RefreshBlocked are not; off the route the vault is not read.
  • TestGate: a harness turn passes on a Crew sign-in without probing kiro-cli; without one it falls back to the kiro-cli 503; a default caller never consults the Crew sign-in.
  • test_destructive_reruns_gate_on_the_slots_own_session (regenerate, edit-resend, rewind) and test_destructive_rerun_of_an_unknown_slot_gates_on_the_default; test_chat_completions_gates_on_the_target_slots_session and test_chat_completions_for_a_new_slot_gates_on_the_default: each site passes harness_turn=True and the session its turn runs on.
  • test_api_models_off_the_bundle_route_never_consults_the_crew_signin: /api/models stays on the kiro-cli gate.
  • TestLiveTurnRoute: no key, no session map or no live provider is a cold start (None); a live bundle process is True, including through the real AcpProvider → AcpSessionProvider wrapper; a live kiro-cli session, a live KAS relay session, a provider with no readable runtime and a failing session map are False.
  • TestBundleTurn (crewmate pin): a crewmate pinned to kiro-cli under a KAS member backend is not the bundle turn; one pinned to KAS under a non-KAS member backend is; a pin that cannot start keeps the kiro-cli gate.
  • TestLiveRouteSignin: a live route off the bundle refuses without reading the config or the vault; a live bundle route skips the config check but still needs the Crew sign-in; test_live_kiro_cli_session_under_a_kas_default_is_refused pins the reviewer's case end to end (KAS-bundle default, live kiro-cli session, usable vault) to the 503.
  • TestDiscardingRerun: with turn_reuses_session=False, a live bundle session under a non-bundle default is refused (503, vault not read), and a live kiro-cli session under a bundle default passes on the Crew sign-in. With may_keep_live_process=True (rewind), a live kiro-cli session is refused, and a live bundle session under a non-bundle default is refused.
  • test_destructive_reruns_gate_on_the_slots_own_session: regenerate passes turn_reuses_session=True; edit-resend and rewind pass False. Only rewind passes may_keep_live_process=True.
  • test_kas_bundle.py: the bundle spawn plan carries engine_bundle=True.

On main the per-site and gate tests fail: the keyword and kas_crew_signin_ready do not exist.

Proof: not provable -- other: this host runs no local tests; CI runs the new tests

Manual verification

N/A: needs a host with the KAS engine bundle installed, a Crew sign-in and no kiro-cli. Static gates run locally: black, isort, flake8, scripts/check_agent_sdk_boundary.py, scripts/check_file_line_cap.py, scripts/docs_lint.py. Tests run in CI.

Related Issues

Fixes #21957

Sibling sweep

Swept: git grep -n "reject_if_kiro_unverified(" -- src/
Sibling: src/kiro_crew/dashboard/chat_regenerate.py -- changed here (regenerate, edit-resend)
Sibling: src/kiro_crew/dashboard/chat_rewind.py -- changed here
Sibling: src/kiro_crew/dashboard/openai_compat.py -- changed here
Sibling: src/kiro_crew/dashboard/handlers/agents.py -- not affected (spawns kiro-cli; stays gated)
Sibling: src/kiro_crew/dashboard/handlers/sessions.py -- not affected (usage routes skip the gate on _vault_owns_usage since #21956)

Pattern harvest

Rule candidate: review-prompt
Pattern: a readiness gate that asks one harness's prerequisite (kiro-cli) refuses turns that run on a different harness; gate on the harness the target session's turn will use.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

Contributed under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 29, 2026 02:27
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision fb415b9e884d7827f52b2546b3c8048f78abdd8b 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 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of fb415b9e884d7827f52b2546b3c8048f78abdd8b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: the patch adds an opt-in second authority to the gate, every existing caller keeps the kiro-cli default, and it takes nothing away.

Notes

  • /v1/chat/completions now parses JSON before the gate, so a malformed body gets 400 where it used to get 503 kiro_prerequisite_required. The description doesn't mention this ordering change.
  • _kas_bundle_turn_sync repeats the harness's bundle-route rule (backend, flag or automatic switch, Bot pin, installed engine) at the gate. If KasHarness.resolve_spawn exposed one route predicate that both called, the two copies could not drift apart.
  • The backwards-compatibility section falls past the description's truncation. The new keywords all default to today's behaviour, and the kas_route and kas_spawn_takes_bundle signatures only gain optional parameters, so I found no broken reader.

[DESIGN-REVIEWED] fb415b9

Description read

[DESCRIPTION-READ] 1cb7eb2303c70c553a1ca9ea2741578a7991475d93aa25a06a0c2b88be0d70ed

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 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of fb415b9e884d7827f52b2546b3c8048f78abdd8b — 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 to check.

What this change ships

Inventory (9 items) — 9 justified

Intent: on a host that runs Crew's own KAS engine bundle, is signed in through Crew and has no kiro-cli installed, a person can regenerate, edit-resend, rewind and call /v1/chat/completions instead of getting a 503 for a CLI the turn never uses. FIX.

  1. Regenerate on a bundle-route slot with Crew's sign-in no longer answers 503 kiro_prerequisite_required — justified
  2. Edit-resend on such a slot is no longer refused — justified
  3. Rewind on such a slot is no longer refused — justified
  4. /v1/chat/completions is no longer refused, and its JSON body is now parsed before the gate runs (so a malformed body gets its parse error before the gate's 503) — justified
  5. A live session still running kiro-cli keeps the kiro-cli gate even after the configured backend moves to KAS — justified
  6. A spawn now records whether it runs the engine bundle, and the runtime keeps that flag — justified
  7. The KAS route check now takes the session's Bot pin, so its rule 2 is judged the way the spawn judges it — justified
  8. The per-session backend selection is pulled out into configured_backend_for_session, which has 2 consumers — justified
  9. An app caller of /v1 is judged on the default backend, without looking up the slot it names — justified

[FIRST-PRINCIPLES-REVIEWED] fb415b9

Description read

[DESCRIPTION-READ] d0a881f01c5a8481110853e9251e0197e48399ad2e89ba54d50fc5d96789cc58

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 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed fb415b9e884d7827f52b2546b3c8048f78abdd8b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] fb415b9

Verdict parsed from the review's SHA-scoped output markers for commit fb415b9e884d7827f52b2546b3c8048f78abdd8b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable fb415b9e884d7827f52b2546b3c8048f78abdd8b false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of fb415b9e884d7827f52b2546b3c8048f78abdd8b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] fb415b9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt fb415b9e884d7827f52b2546b3c8048f78abdd8b false-positive: <reason, 20 to 500 characters>

@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 29, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch 2 times, most recently from bf87ebe to 870e302 Compare October 29, 2026 04:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 29, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD (policy_sensitive) at 870e3021d7620798221fa16e8b6f6e4c88f9ab29.

The readiness gate in front of regenerate, edit-resend, rewind and /v1/chat/completions gains a second authority. When the session runs on the KAS engine bundle, a Crew vault sign-in that KasAuthProvider can resolve now admits the request in place of the kiro-cli probe (

if harness_turn and await kas_crew_signin_ready(session_key):
). A change to which credential authorizes a gate is reserved for a human reviewer. I found no definite defect. Every failure path answers False and falls back to the existing kiro-cli gate.

AI findings judged non-blocking (Design notes, no author reply):

  • An engine rejecting a credential that resolved would fail the turn after history was rewritten. This is the same residual risk the kiro-cli probe already has.
  • _kas_bundle_turn_sync mirrors the harness's route choice (
    def _bundle_route_selected() -> bool:
    ). Both read agent.kas_bundle and installed_bundle() from the same owner, so they agree today.

This PR also edits the top of openai_compat.api_completions, which #25555 also edits, so whichever lands second needs a rebase. All checks on this head are green.

— crew-pr-reviewer (r135)

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 29, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch from 870e302 to 4803cff Compare October 29, 2026 18:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 29, 2026

@iamwhatever iamwhatever 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.

Request changes at 4803cff31ac0e6bfe3839e3f61a30be3efa04242.

The new KAS-bundle bypass in reject_if_kiro_unverified decides the route from the configured backend (select_provider_backend), not from the session that will actually run the turn (kiro_readiness.py#L163). An existing live session is reused without a backend check (get_or_create.py#L463-L466), and changing agent.acp_backend retires only the background runtime. So after the default is switched to KAS while an idle kiro-cli session is still alive, a regenerate, edit-resend or rewind passes the gate on Crew's sign-in, persists truncated history, and the retained kiro-cli turn then fails auth. That is the history loss this gate exists to prevent. GPT 6.1 raised this as a fenced blocking finding and adjudication upheld it; there is no reply yet.

Smallest fix: when the slot already has a live session, read that session's provider backend and spawn route and allow the vault bypass only when it is the KAS bundle; use the configured selection only for a cold start. Add a test with a live non-KAS session under a KAS default.

The branch also has a merge conflict with main now. This PR changes which credential authorizes a gate, so a human reviewer is still needed after the fix.

— crew-pr-reviewer (r135)

@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch from 4803cff to d617343 Compare October 29, 2026 23:07
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Authorize the live harness, not only new-session defaults

fixed in d617343: a live session is now judged by the process it runs, not by select_provider_backend. live_turn_route (src/kiro_crew/dashboard/kiro_readiness.py) reads the spawn plan the runtime recorded (SpawnPlan.engine_bundle, set only by the KAS harness's bundle route, kept as AcpRuntime._kas_engine_bundle).
A live session not on the bundle (a retained kiro-cli or KAS relay session), or one whose route cannot be read, answers False, and kas_crew_signin_ready then refuses the bypass, so the kiro-cli gate decides and history is not rewritten.
The configured selection is read only for a cold start (no live provider).
test_live_kiro_cli_session_under_a_kas_default_is_refused pins the case: KAS-bundle default, live kiro-cli session, usable vault -> 503.

@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch from 361f30b to 5512608 Compare November 5, 2026 05:07
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 6, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch from 5512608 to 9b48bde Compare November 7, 2026 17:09
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/kas-readiness-gate-21957 branch 3 times, most recently from 625eb44 to b812a00 Compare November 7, 2026 19:38
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Cold-start bundle predicate re-spells the route resolver

fixed in b0bd8a3, the same change as above: the cold-start check asks kas_bundle.kas_route() for the bundle decision instead of deciding from agent.kas_bundle alone. select_provider_backend stays the per-session check.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 7, 2026
bolichen97
bolichen97 previously approved these changes Nov 7, 2026

@bolichen97 bolichen97 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.

Approving head b812a00. The gate shows 97 checks passed, none red or pending, and the branch merges cleanly into main.

What I checked in kiro_readiness.py and its callers:

  • The gate judges the session that will run the turn. For a live session, live_turn_route reads that session's own route. The Crew sign-in bypass applies only when it is the KAS bundle, and a live session on any other route, or one whose route cannot be read, keeps the kiro-cli gate. Only a cold start (None) reads the configured selection, through _kas_bundle_turn_sync and select_provider_backend, so a member thread is judged on agent.member_acp_backend.
  • Regenerate, edit-resend and rewind pass the right flag. chat_regenerate.py and chat_rewind.py pass turn_reuses_session according to whether the turn keeps the live conversation, so a turn that discards it is judged as a cold start.
  • App callers learn nothing about a slot. api_completions judges an app caller on the default backend without looking up the slot it names, so the gate's answer cannot reveal whether that slot exists or how it is routed. No new refusal is added. The JSON body is now parsed before the gate, which only changes the order of two existing errors.
  • Tests pin the live-session cases, including test_live_kiro_cli_session_under_a_kas_default_is_refused, the case from the open change request, and an unreadable route keeping the kiro-cli gate.

The change only lets the KAS bundle route accept Crew's own sign-in, and every other route keeps today's gate. No product regex.

@iamwhatever could you take another look? Your change request on 4803cff asked that a slot with a live session be judged by that session's own backend and route, with the configured selection used only for a cold start, plus a test with a live non-KAS session under a KAS default. Both are in at this head, as above.

@bolichen97

Copy link
Copy Markdown
Contributor

@iamwhatever could you take another look? Your change request on 4803cff looks addressed at head b812a00:

  • The gate now reads the live session's own route first (live_turn_route in kiro_readiness.py). A reused live session gets the vault bypass only when its process is the KAS bundle; a live session on any other route, or one whose route cannot be read, keeps the kiro-cli gate.
  • Only a cold start reads the configured selection. Edit-resend and rewind pass turn_reuses_session=False, since their turn cold-starts.
  • test_live_session_off_the_bundle covers a live non-KAS session, and test_live_bundle_process and test_no_live_provider_is_a_cold_start cover the other two cases.

@CrysisDeu the branch now conflicts with main, so please also update it onto main.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased onto current main at 78df04e (still one commit).

Main's #32839 changed the same three rerun handlers: regenerate, edit-resend and rewind now ask the kiro-cli gate only when rerun_signs_in_via_kiro_cli says the slot's turn runs on a harness that signs in through kiro-cli. KAS is in that set (host_logout_retires_children=True), so this PR is still needed. The resolution keeps main's structure and calls this PR's gate inside main's branch:

  • Each rerun runs if await rerun_signs_in_via_kiro_cli(...) exactly as on main, then inside it calls reject_if_kiro_unverified(request, harness_turn=..., session_key=..., [turn_reuses_session=False]) with turn_gate_target(state, name), as this PR did before. Main's refuse_rerun_after_signed_out_turn path for foreign harnesses is unchanged.
  • Imports: main's three names plus turn_gate_target.
  • kiro_readiness.py module docstring and cli.md paragraph: main's sentence kept, this PR's KAS-bundle sentence appended.

Nothing else changed in this PR's lines.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Honor explicit backend overrides in cold-start readiness

fixed in e2b4510: _kas_bundle_turn_sync now selects with the same inputs as _configured_backend_for_slot and the provider factory. It passes session_backend_pick(session_key) as backend_override, reads the crewmate pin only when there is no pick, and passes the pick to route_pin. reject_if_kiro_unverified hands it the session manager's applied config (state.sessions._cfg); config.json is read only when no applied config exists. This is one function, so all four sites (regenerate, edit-resend, rewind, /v1/chat/completions) take the fix. Tests: test_a_session_created_on_kiro_cli_is_not_the_bundle_turn (a kiro pick under a KAS-bundle default is refused) and test_the_applied_config_decides_not_config_json.

The same push also fixes the four test_kas_bundle_readiness_gate.py reds from the rebase: the fake state now carries sessions=None, which main's rerun_signs_in_via_kiro_cli reads.

iamwhatever
iamwhatever previously approved these changes Nov 8, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Read the bundle flag from the configuration the harness uses

fixed in d0d2f92: _kas_bundle_turn_sync keeps the applied config for backend selection, and now decides the route over a fresh KiroCrewConfig.load(), the read the harness makes at spawn (acp/harness/kas.py _bundle_route_selected). kas_spawn_takes_bundle(on_disk.agent, route_pin(on_disk, ...)) answers the flag off disk first, then the automatic kas_route half. test_the_route_flag_is_read_from_disk_as_the_harness_reads_it pins the reported case: applied config still on the bundle, config.json already off, relay runnable, so the gate keeps the kiro-cli probe.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Second spelling of the slot-backend resolution

Rebutted: _configured_backend_for_slot is not the only other site. The same session_backend_pick → select_provider_backend(..., backend_override=pick, crew_backend=crewmate_backend_pin(...) if pick is None else None) composition is the repo's per-session idiom, spelled at a dozen sites on main: chat_api/slot_model.py:118, chat_api/slot_settings.py:304, chat_turn/app_agent_binding.py:203, chat_turn/eager_spawn.py:804, chat_turn/slash_commands.py:110 and :781, handlers/template_server_request.py:196, session_control_parts/model_switch.py:206, session_transfer_layers.py:327, warm_task_brief_wake.py:152, config/loader_config.py:1514, session_parts/policy.py:421. select_provider_backend's docstring requires every caller to pass crew_backend as that call or None (pinned by test_crewmate_harness.py), so each reader spells it inline by design. _configured_backend_for_slot also cannot be called here as is: the gate holds a session key, not a slot, and this check runs inside asyncio.to_thread, while that helper is async. Folding all of these into one helper is a refactor of main's code outside this fix.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Resolve the crewmate route pin from the applied configuration

fixed in e998adf: the route check now reads each input where the spawn reads it. The bundle flag is on_disk.agent (the harness reads it from disk at spawn), and the Bot pin is route_pin(config, ...) over the applied config, which the provider factory hands to KasHarness.resolve_spawn. test_the_route_pin_is_read_from_the_applied_config pins it.

@KiroCrewCaptain

KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own.

The PR adds a second, opt-in authority to reject_if_kiro_unverified. It only applies to regenerate, edit-resend, rewind and /v1/chat/completions (harness_turn=True). For those callers, a turn that runs on Crew's installed KAS engine bundle passes the gate when Crew's own sign-in vault yields a credential now. Ambient KIRO_API_KEY does not count, and a rejected or blocked refresh is not ready.

I checked the following against the code:

  • configured_backend_for_session: the refactor out of _configured_backend_for_slot keeps the old behaviour.
  • Helper signatures: session_backend_pick, crewmate_backend_pin, route_pin and automatic_switch_allowed(pin) all exist with the signatures the gate uses, and all accept a None session key.
  • Route rule: resolve_kas_route(pin=...) now judges rule 2 the way KasHarness.resolve_spawn does, using ctx.harness_pin.
  • Live sessions: live_turn_route reaches the runtime correctly, through AcpProvider.client to AcpSessionProvider._runtime, then acp_backend and _kas_engine_bundle. That flag is set in the same single place as _kas_host_auth, on every spawn.
  • Fail-closed paths: every unreadable or e

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit fb415b9e88 · 1079 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

…e route (#21957)

On a KAS engine-bundle host (agent.kas_bundle) with a Crew sign-in and no
kiro-cli, regenerate, edit-resend, rewind and POST /v1/chat/completions
answered 503 kiro_prerequisite_required, because reject_if_kiro_unverified
consulted only the kiro-cli probe. Their turn on that route spawns no kiro-cli
and draws its credential from Crew's vault.

reject_if_kiro_unverified takes harness_turn=True plus the session_key of the
turn (turn_gate_target names it from the target slot) for callers whose only
kiro-cli dependency is the turn they start; those are also authorized by
kas_crew_signin_ready(session_key): the session's own backend resolves to KAS
through select_provider_backend (a member thread runs on
agent.member_acp_backend), agent.kas_bundle is on with an engine installed,
and KasAuthProvider.current() yields a credential (no identity, or a refused
or unattemptable refresh, is not ready). A slot the gate cannot read keeps the
kiro-cli gate, as do the kiro-cli spawn sites.
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Findings on 438b37c07f, answered in fb415b9e88:

  • Opus 5.5 and GPT 6.1 (rewind with sub-agents attached keeps the live process): fixed. A rewind now also passes may_keep_live_process=True, so reject_if_kiro_unverified reads the live process too: a live process not on the bundle keeps the kiro-cli gate, and otherwise the configured route is judged (kiro_readiness.py, chat_rewind.py). Edit-resend always discards (discard_conversation), so it keeps the cold-start reading. Two gate tests and one handler assertion pin it; both learn-cron-dashboard.md sentences are updated.

This only refuses more than the previous head, and never more than main, whose gate always asked the kiro-cli probe.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving head fb415b9. Verified on this head: PR Readiness is green, and no main commit since the merge base touches the gated files. The new gate path is limited to regenerate, edit-resend, rewind and /v1/chat/completions (harness_turn=True), and /api/models and the usage scrape keep today's default. Each handler passes the flags that match what it does with the live process (discard_conversation for edit-resend, a possible swap_conversation for rewind). The cold-start check selects the backend from the same inputs as KasHarness.resolve_spawn, including the crewmate pin and an installed engine. The three owning specs are updated in the same commit.

Done well: an app caller is gated on the default backend without a lookup of the slot it names, so the gate cannot reveal whether that slot exists before app authorization. A parametrized test pins this.

Security: the new branch only allows a turn through, and only on a positive vault credential. kas_crew_signin_ready uses KasAuthProvider.current() with allow_env_api_key=False, so an ambient KIRO_API_KEY does not count. A rejected or blocked refresh answers not ready. Any unreadable slot, config, pin or live runtime answers False, and the kiro-cli gate then decides as on main. A live session whose route is not the bundle keeps the kiro-cli gate. The gate checks that a prerequisite is met before history is rewritten; it does not authorize the caller. The known residual (a dead bundle process after a config switch) can only produce a failed turn. No history is lost, because regenerate rewrites nothing unless its turn replies.

The design is signed off under the standing maintainer sign-off for changes by team members.

Optional:

  • #36755 edits the same top of api_completions and kiro_readiness.py, and the two conflict textually. Please name the merge order in both bodies. The PR that lands second could reuse the other one's live-provider read, so the module keeps a single reader of the live route.
  • No test covers self._kas_engine_bundle = plan.engine_bundle in runtime_spawn_launch.py. A case in the style of test_kas_spawn.py would close that gap: await _resolve_spawn_plan(), then assert the flag for the bundle route and for the relay route.
  • The spec says a liveness check would need a new pid reader. SessionManager.is_provider_alive already exists and is not a ratchet needle. Either use it to treat a dead provider as a cold start, or correct that sentence.

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.

Kiro readiness gate returns 503 on KAS + Crew sign-in hosts with no kiro-cli

4 participants