Skip to content

fix: scope the kiro-cli readiness gate to backends that sign in via it - #10414

Closed
amansk wants to merge 2 commits into
kirodotdev:mainfrom
amansk:fix/kiro-readiness-gate-scope
Closed

amansk wants to merge 2 commits into
kirodotdev:mainfrom
amansk:fix/kiro-readiness-gate-scope

Conversation

@amansk

@amansk amansk commented Sep 12, 2026 •

Copy link
Copy Markdown

Problem / Motivation

Goal: On a Claude Code, Codex or other foreign-harness deployment, regenerate, rewind, edit-resend and /v1/chat/completions work without kiro-cli being installed or signed in.

On main, kiro_readiness.reject_if_kiro_unverified asks "is kiro-cli ready?" for every backend. So on a deployment whose sessions run on claude-agent-acp, codex-acp, goose and so on, those four routes answer kiro_prerequisite_required 503 whenever kiro-cli is absent or signed out, although the selected backend never spawns that binary.

Why it matters

Anyone who runs KiroCrew on a foreign harness loses core chat operations to a permanent 503 about a tool they turned off. The only fix open to them is installing and signing in to a kiro-cli they do not want.

Not a goal

What changed

The gate applies only while the session the caller acts on uses a backend in backends_retired_by_host_logout() (positive membership; an unreadable config keeps the gate).

Mechanism What it does
Verdict (kiro_readiness.py) selected_backend(key, state=) reads the installed provider factory's backend pair (member threads via members.select_provider_backend), falling back to config; live_session_signs_in_via_kiro_cli reads a live session's own uses_kiro_identity_store, and only when SessionManager.is_provider_alive answers True; a dead row is evicted and rebuilt on the installed factory, so it never answers for its successor. reject_if_kiro_unverified takes signs_in_via_kiro_cli= or session_key=+state=, and keeps main's max_age_secs.
Destructive reruns (chat_regenerate.py, chat_rewind.py) Regenerate judges the live session first; rewind and edit-resend judge the backend the installed factory will build. Each re-derives the verdict under the slot lock before its first destructive write. _reauthorize_after_await (slot identity plus session and transcript ownership) runs before each readiness read and after each readiness await, so an app never learns another session's sign-in state through the 503. On a foreign harness, a slot whose last turn ended AcpAuthRequired (_last_turn_auth_required) is refused with harness_sign_in_required 503 under the lock, before the first destructive write; the next ordinary send rewrites that flag.
/v1/chat/completions (openai_compat.py) One ownership predicate (_reject_unowned_app_slot over deny_app_slot_session_access) runs for every app caller before the readiness peek, absent targets included, and again on the slot the request obtains after each await. The collectors translate a foreign turn's end: _last_turn_auth_required -> OpenAI 401 authentication_error; any other error row with no reply text -> 500 server_error. On a foreign backend streaming defers prepare(), so a failure before output keeps its HTTP status.
/api/models, /api/sessions/usage (handlers/agents.py, handlers/sessions.py) Both spawn kiro-cli themselves, so they pass signs_in_via_kiro_cli=True and stay gated exactly as on main.
reload_provider_factory (session_lifecycle_parts/fleet.py) Builds the new factory before installing config and factory, so a failed build keeps the previous pair together.

The shared ownership predicate gives the two app 403 bodies a code, so error-code-baseline.json ratchets openai_compat.py from 17 to 15. The spec (docs/system-specs/modules/acp-client.md, docs/system-specs/modules/learn-cron-dashboard.md, docs/system-specs/modules/claude-code-provider.md) records the scoped gate, the live-session and installed-factory verdicts, the usage exception and the 401/500 translation.

Backwards compatibility

Breaking for /v1/chat/completions. On a backend the gate stands aside for, a turn that ends signed out now returns HTTP 401 authentication_error. On every backend, kiro included, a turn that ends with an error row and no reply text now returns HTTP 500 server_error. Both used to return HTTP 200 with empty content. App-isolation 403 bodies on that route now carry code: app_token_forbidden. External SDK clients get a standard OpenAI error instead of silent emptiness, which is the fix.

Tests

  • test_kiro_spawn_readiness_gate.py: the gate applies exactly to the identity-store backends over every id in ACP_BACKENDS_KNOWN; a foreign backend never consults the service; an unreadable config keeps the gate; member threads are judged by their own backend; reruns judge the installed factory, re-check under the lock, and refuse before mutation when a switch into a signed-out kiro-cli lands mid-request; a foreign rerun on a slot whose last turn ended signed out is refused before truncation, and goes through once the flag clears (red without the refusal); /api/models and both usage routes stay 503 on a foreign backend with a signed-out kiro-cli; an AST scan fails on any production call that hands the gate no input.
  • test_kiro_spawn_readiness_gate.py::test_a_row_that_is_not_positively_alive_does_not_answer: a dead, unknown or unprobeable foreign row answers None, so the gate falls back to the installed factory (the dead-row case is red without the liveness check).
  • test_openai_compat.py: ownership precedes the readiness peek, including for an absent slot (red without it), and is re-checked after each await; the endpoint gates on the live session's and the installed factory's backend; auth-required turns return the 401 envelope on blocking and streaming paths; a foreign turn that fails without the auth verdict returns 500 on both paths (red on the previous head), a kiro-backed turn that fails with no reply returns 500 too, while an error row after reply text keeps the 200 reply; a kiro-backed stream prepares before any output.
  • test_api_models_entitlement.py, test_chat_regenerate_cov80.py, test_dashboard_chat_rewind.py, test_session_config_hot_reload.py: as listed in each file's new tests.
  • test_kiro_prerequisite_handlers.py, test_relay_archive.py, test_slot_ownership_checkpoint.py: stubs and fixtures follow the widened gate surface; the reruns still answer 503 before mutation on a signed-out kiro backend.

Local run on the head: the 10 files above plus test_error_code_contract.py, 489 passed; every test module that references a touched module (200 files), 9728 passed, 2 skipped; black --check, scripts/check_file_line_cap.py and scripts/check_harness_parity.py clean.

Manual verification

Not run live. The 401 path needs a signed-out claude-agent-acp or codex-acp process whose stderr the shared auth vocabulary recognises; the tests reach that verdict by setting _last_turn_auth_required. Any other startup failure now ends as the 500 above.

Screenshots / video

N/A: backend-only change, no frontend file touched.

Pattern harvest

Rule candidate: semgrep
Pattern: a backend or capability verdict read from SessionManager._sessions[key].provider without is_provider_alive(key) is True -- a dead row answers for the session get_or_create will build in its place. chat_turn/slash_commands._slash_command_backend already applies the liveness test; this PR's live-session peek missed it in one round.

no linked issue: contributed fix scoped by the fork author; no tracked issue exists for it.

@amansk
amansk requested review from a team and cixuuz September 12, 2026 20:03
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 12, 2026
@dwu96

dwu96 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 4f3704f

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 4f3704ff8d51b0da2a8b9c1a958132ac67759e50 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Before merge, run one turn live against a signed-out claude-agent-acp or codex-acp. The 401 response and the rerun refusal both rely on _last_turn_auth_required, and the tests only ever set that flag by hand.

[DESIGN-REVIEWED] 4f3704f

Description read

[DESCRIPTION-READ] c30592bba24c0c8c71a67a5ba50991e25e5ccf21a547dd3dd764f2c8981f1b06

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 Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of 4f3704ff8d51b0da2a8b9c1a958132ac67759e50 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The kiro-backed /v1 500 is outside the Goal, and the live-or-factory backend verdict copies the one _slash_command_backend already has.

Not justified as shipped

  • Item 5 — oversized: the Goal is foreign-harness deployments, and ## Not a goal excludes "Any change to how kiro-backed sessions are gated". Yet "On every backend, kiro included, a turn that ends with an error row and no reply text now returns HTTP 500".
    Subtraction: in _terminal_failure, return "server" only for turns where not signs_in_via_kiro_cli, so kiro turns keep main's behaviour.
    Clears when: the mechanism is removed, or a human amends the Goal.
  • Item 2 — duplicate of dashboard/chat_turn/slash_commands.py:_slash_command_backend: that function already does the same thing ("positively live provider answers for itself… otherwise the factory's member-aware selection"). The new live_session_signs_in_via_kiro_cli + rerun_signs_in_via_kiro_cli + selected_backend trio is a second spelling. The only difference is that it reads the installed factory pair, where the existing one reads disk config.
    Subtraction: delete one of the two spellings and have both callers use the remaining one.
    Clears when: one spelling is deleted, or the description says why disk config is correct for slash commands but wrong for reruns.

What this change ships

Inventory (8 items) — 5 justified

Intent: let Claude Code, Codex and other foreign-harness deployments regenerate, rewind, edit-resend and use /v1/chat/completions without kiro-cli. This is a FIX.

  1. Reruns and /v1 skip the kiro-cli 503 on non-identity-store backends — justified
  2. Verdict uses the live session's backend, else the installed factory's (member-aware) — duplicate of _slash_command_backend
  3. A foreign rerun after a signed-out turn gets a new harness_sign_in_required 503 — justified
  4. /v1 on a foreign harness: a signed-out turn returns 401 authentication_error, and streaming defers headers — justified
  5. /v1 on kiro: an error with no reply returns 500 instead of an empty 200 — oversized, rides along
  6. App-ownership 403 runs before the readiness peek, adds the session/transcript checks, and gains code — rides along
  7. Readiness re-checked under the slot lock before destructive writes — justified
  8. reload_provider_factory builds the new factory before installing it — justified

[FIRST-PRINCIPLES-REVIEWED] 4f3704f

Description read

[DESCRIPTION-READ] 300c08b1298f02cbf74b078fc9e35ee236a69b90fc21ebf3f4e8193b7ce37245

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 Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4f3704f

@amansk
amansk force-pushed the fix/kiro-readiness-gate-scope branch from 4a55b29 to 2e4e52b Compare September 12, 2026 20:34
@amansk

amansk commented Sep 12, 2026

Copy link
Copy Markdown
Author

Dispositions for the review findings, addressed in the amended first commit (95ad68b6f):

  • First Principles, dead helper (fixed): selected_backend_signs_in_via_kiro_cli() is deleted along with its two doc mentions; the gate keeps composing backend_signs_in_via_kiro_cli() over selected_backend(), and the description now says so.
  • First Principles, api_completions sibling (fixed): the completions gate moved to after the slot is known and passes backend=live_session_backend(...) when the id names a slot with a live session, the same rule regenerate applies; no id, or a slot with no live session, still gates on the configured backend. Pinned by test_openai_compat.py::TestApiCompletionsBlocking::test_gates_on_the_live_sessions_backend_after_a_hot_switch, and the live-session paragraph in acp-client.md now names the endpoint.
  • GPT 5.6, deferred KiroCrewConfig import (rebutted): the deferral is deliberate and its docstring says why: kiro_readiness is imported by every gated handler and kiro_crew.config is heavier than anything else it needs. The same shape is used elsewhere in the dashboard for that reason. Kept as is.
  • Design, live_session_backend lenient getattr chain (noted, not changed): a public peek on the session manager is a fair follow-up, but widening the session manager's surface is outside this fix; the pin's SimpleNamespace._sessions mirrors exactly what chat_runner reads for /compact.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 12, 2026
@amansk
amansk force-pushed the fix/kiro-readiness-gate-scope branch from 2e4e52b to 88ed004 Compare September 12, 2026 21:23
@amansk

amansk commented Sep 12, 2026

Copy link
Copy Markdown
Author

Dispositions for the second round, addressed in the amended first commit (97b668d7a):

  • GPT 5.6, existence oracle in api_completions (fixed): the app-isolation 404 for member slots now runs before the readiness gate's live-session peek, so an app token gets the uniform 404 whether or not the member slot holds a live kiro session. Pinned by test_openai_compat.py::TestApiCompletionsBlocking::test_app_token_member_slot_is_404_before_the_live_session_peek.
  • First Principles, LLMProvider.acp_backend as a second spelling of uses_kiro_identity_store (fixed by subtraction): both properties are deleted. live_session_backend() is replaced by live_session_signs_in_via_kiro_cli(), which returns the provider's existing uses_kiro_identity_store declaration as a tri-state, and reject_if_kiro_unverified takes that verdict as signs_in_via_kiro_cli=, outranking backend=. The specs name the new function and the H14 reading.
  • GPT 5.6, function-local KiroCrewConfig import (rebutted, unchanged): as in the previous round, the deferral is deliberate and documented in the docstring: this module is imported by every gated handler and kiro_crew.config is heavier than anything else it needs.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 16, 2026
@NicholasRBowers NicholasRBowers added needs-pr-triage PR scanner: awaiting automated triage drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 19, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author.

Assessment: the conflict is a single import-block union in chat_regenerate.py; the one real test failure is the readiness gate moving below the slot lookup (effective_session_key(slot) reads slot.key, which the pinning test's stub slot does not have); everything else is infra or stale-base drift that a rebase re-evaluates.

Details

Conflict — one hunk, mechanical. A trial merge against current main (654 commits ahead of this branch's merge base) conflicts in exactly one file, src/kiro_crew/dashboard/chat_regenerate.py, and it is an import-block union: main added reject_if_slot_under_construction to the chat_utils import, this PR added live_session_signs_in_via_kiro_cli to the kiro_readiness import. Both sides are kept. Every other file in the diff auto-merges, including docs/system-specs/modules/acp-client.md, handlers/sessions.py and test_chat_regenerate_cov80.py.

Backend Tests (macOS) (2) + (Windows) (2) — the PR's own, and the fix is mechanical. test/test_kiro_prerequisite.py::TestKiroPrerequisiteHandlers::test_destructive_chat_routes_reject_before_mutating_history gets 500 with text/plain from POST /api/chat/slots/paused/regenerate, i.e. an unhandled exception, deterministically on two different OSes. Root cause: api_chat_slot_regenerate now runs the readiness gate after the slot lookup, because it needs the slot to compute live_session_signs_in_via_kiro_cli(state, effective_session_key(slot)). effective_session_key is getattr(slot, "linked_session_key", "") or _history_key_for(slot.key), and that test's slot is SimpleNamespace(messages=messages) — no key — so slot.key raises AttributeError before the gate ever runs. live_session_signs_in_via_kiro_cli itself is fully defensive and is not the thrower.

The invariant that test defends still holds — the gate is still honored before the truncate — so this is a stub-shape break, not a policy break. Two in-scope fixes: give that test's slot stub a key, or derive the live-session hint without reading slot.key. Either stays inside the PR's intent; the design is not being changed.

Backend Tests (macOS) (1) — stale-base drift. test/test_apps_backend_coverage.py::TestDependencyInstall::test_concurrent_provisioning_is_serialized_by_the_deps_lock fails on [Errno 2] No such file or directory: '.kirocrew-deps.lock'. The 12-file diff here touches no app-provisioning code; this same red was diagnosed as base drift on another PR at a similar distance behind main. The rebase re-evaluates it.

Detect changed surface and Resolve desktop matrix — GitHub infra, not this PR. Both failed with API rate limit exceeded for installation at 2026-09-12 21:27 UTC. The jobs that read as cancelled (PR Hygiene, Inclusive Language, SAST, Screenshot Evidence, Automated Rule Check) cascade from that, and so do the four fork Stage-2 lanes, which report could not run / no leg reported rather than a verdict.

The AI verdicts on record are stale. Design Review PASS, Opus 4.8 no blocking findings, First Principles CONCERNS and GPT 5.6 BLOCKING are all stamped on 2e4e52b04, two heads back. Your 21:24 UTC disposition says GPT's sole blocking finding (openai_compat.py:264, readiness lookup leak) was fixed in 97b668d7a, which is in the current head — the lanes just never re-ran to see it, because the rate-limit failure took their trigger down with it. A rebase mints a new head and re-fires CI and all five lanes, which is how this gets re-judged. First Principles' advisory CONCERNS still needs a disposition against whatever head comes out of that.

No human reviews and no unresolved review threads, so nothing here is waiting on a maintainer's opinion.

If you'd prefer I don't touch this PR, add the pr-no-autofix label.

@NicholasRBowers
NicholasRBowers force-pushed the fix/kiro-readiness-gate-scope branch from 88ed004 to adcb9da Compare September 19, 2026 07:13
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]

Drive-to-green push: rebased onto current main (88ed004 → adcb9da). Changes in this push, each with why:

  1. Rebase onto origin/main — the branch was ~650 commits behind and GitHub reported a merge conflict. One conflict hunk, in src/kiro_crew/dashboard/chat_regenerate.py's import block: main added reject_if_slot_under_construction to the chat_utils import while this branch added live_session_signs_in_via_kiro_cli to the kiro_readiness import. Resolved as the union — both imports kept, no logic touched.

  2. Test-stub repair in test/test_kiro_prerequisite.py (folded into the fix commit to stay within the 2-commit hygiene allowance): test_destructive_chat_routes_reject_before_mutating_history failed deterministically on macOS/Windows shards with an HTTP 500. The branch's gate call derives the live-session hint via effective_session_key(slot), which reads slot.key — and the test's stub (SimpleNamespace(messages=messages)) carried no key, so the handler raised AttributeError before the gate ran. The stub now carries key="paused" (the slot key every real slot has). The test's invariant is untouched and still enforced — the readiness gate still refuses all three destructive routes (503) before any history mutation. Production code was not relaxed; the gate stays ordered after the slot lookup exactly as this PR designed.

  3. No other code changes. The docs: commit is preserved as-is. The previously-red test_apps_backend_coverage.py deps-lock failure was stale-base drift and passes after the rebase, as does the full related-test set locally (559 passed; isort/flake8/mypy clean).

The prior Detect changed surface / Resolve desktop matrix reds were GitHub API rate-limit failures at 2026-09-12T21:27Z; this new head re-fires them along with all five review lanes (the recorded AI verdicts were two heads stale).

Original work by the PR author — credited in the amended commit body; fix commit carries a Co-authored-by: Kiro Crew trailer.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 19, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Readiness sweep 2026-09-29 — audited READY (LOOSENS net; the residual "auth recogniser only tested against synthetic frames" is accepted from the sweep's side, with the live capture as a follow-up), and the PR's own tests pass on the main+PR merge tree. It went dirty while this wave's earlier merges landed: error-code-baseline.json now conflicts with main. Everything else auto-merges cleanly.

A rebase onto current main (re-sort the baseline) is all that is needed; ping when readiness is green again and the sweep will approve and merge.

@bolichen97

Copy link
Copy Markdown
Contributor

Readiness sweep 2026-09-29: rebased onto main b5ca357 to clear the conflict in error-code-baseline.json; the baseline was regenerated on the rebased tree with python test/test_error_code_contract.py --update (main's handlers_instances.py 12→11 kept, this PR's openai_compat.py 18→16 kept; totals missing_code 1089); no source adaptation was needed; commits kept as 2, author preserved; verified locally: the PR's 8 test files + test_error_code_contract.py, test_chat_regenerate_refusal_codes.py, test_api_health.py, test_api_models_retry.py, test_chat_slot_continue.py (897 passed), then every test module referencing the touched src modules + test_agent_sdk_host_auth.py (9512 passed, 5 skipped), black --check clean. Nothing else changed.

@bolichen97

Copy link
Copy Markdown
Contributor

Readiness sweep 2026-09-29: rebased head 1089442 is mergeable and CI is green (the earlier Windows/macOS reds were timing flakes in unrelated tests), but the fork GPT 5.6 lane holds a security-class blocking finding on the PR's own design that the sweep will not resolve on the author's behalf: dashboard/openai_compat.py:831 -- a foreign-harness startup auth failure still returns an empty success; the lane asks to preserve a typed foreign auth-failure verdict and translate it in both collectors. @NicholasRBowers @amansk over to you; ping when pushed and the sweep will re-check and merge (LOOSENS-net change, accepted from the sweep's side).

Copy link
Copy Markdown
Contributor

PR triage 2026-10-05 (automated, read of the full diff against origin/main @ a97659df):

Rebase needed. The head (1089442, base b5ca357) is 915 commits behind main and git merge-tree conflicts in 8 files: kiro_readiness.py, openai_compat.py, chat_regenerate.py, chat_rewind.py, handlers/agents.py, handlers/sessions.py, acp-client.md, error-code-baseline.json. These main changes are the ones to rebase onto:

Merge discussion with #16886 (open). Both PRs change how /api/sessions/usage behaves when kiro-cli is not ready on a non-kiro deployment, and both edit kiro_readiness.py and test_kiro_spawn_readiness_gate.py. This PR returns the unavailable marker by backend membership. #16886 adds kiro_spawn_allowed and reads the balance with Crew's own KAS credential. The two goals can work together, but the usage handler should end up with one gate. Agree on the order before either one lands.

The breaking change (401 instead of an empty 200 on /v1/chat/completions) is already declared in the description. The open openai_compat.py:831 finding from the 2026-09-29 sweep is still the merge blocker. This triage adds no new blocking finding.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Revision 4f3704ff8d51b0da2a8b9c1a958132ac67759e50 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • History is cut before the auth check on foreign harnesses. span=ccfb23323204

fixed in b5274fa: the second clearing route the lane named. On a foreign harness, regenerate, rewind and edit-resend now refuse with harness_sign_in_required 503 under the slot lock, before the first destructive write, when the slot last turn ended AcpAuthRequired (_last_turn_auth_required, written by each turn at its end).
kiro_readiness.refuse_rerun_after_signed_out_turn; pinned by test_a_foreign_rerun_after_a_signed_out_turn_refuses_before_truncating (all three routes, red without the refusal; the same request goes through once the flag clears).
The residual is a signed-out harness with no failed turn on this slot yet; there the replacement turn stays the authority, as the description says.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • The new 500 also reaches kiro turns, not just foreign ones. span=117231725641

fixed in b5274fa by declaring it, not gating it: an error row with no reply is an empty 200 on kiro too, so a 500 is the right answer there as well.
Backwards compatibility now lists the kiro-backed change, acp-client.md says the no-reply rule runs on every backend, and test_kiro_backed_turn_failing_with_no_reply_is_a_server_error pins it.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • Item 8 — zero consumers: the model_list_backend_unsupported 503. span=870726668cf0

fixed in b5274fa: the block is removed. /api/models is main again apart from its gate call, and test_api_models_refuses_a_backend_with_no_advertised_selection plus the refusal half of the readiness-gate test are gone with it.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • Item 9 — one consumer, generalized: the gate backend= parameter. span=24802a75a7ff

fixed in b5274fa: the parameter is removed. api_models passes signs_in_via_kiro_cli=True, the same as both usage routes, because each spawns kiro-cli itself. The AST call-site test now accepts only signs_in_via_kiro_cli, session_key and state.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • Item 4 — undeclared: the 500 on kiro-backed turns. span=2e402899dc9f

fixed in b5274fa: declared. Backwards compatibility now says the no-reply 500 applies on every backend, kiro included; test_kiro_backed_turn_failing_with_no_reply_is_a_server_error pins it.

On a Claude Code, Codex or other foreign-harness deployment, regenerate,
rewind, edit-resend and /v1/chat/completions answered
kiro_prerequisite_required 503 whenever kiro-cli was absent or signed out,
although those sessions never spawn kiro-cli.

reject_if_kiro_unverified now applies only when the session the caller acts
on uses a backend in backends_retired_by_host_logout(). Reruns judge the live
session first, then the installed provider factory's backend, re-derive the
verdict under the slot lock before the first destructive write, and re-check
app ownership (session and transcript halves) before and after each readiness
await. /v1/chat/completions gates on the same verdict, after one shared
ownership predicate, and translates a foreign turn's end: AcpAuthRequired ->
OpenAI 401 authentication_error; any other error row with no reply text ->
500 server_error, so an unconfigured harness that dies at startup is never an
empty 200. On a foreign backend streaming defers prepare() so a pre-output
failure keeps its HTTP status.

/api/models refuses a backend with neither an advertised selection nor a
kiro-cli sign-in before resolving kiro-cli, and hands the gate its own
snapshot. /api/sessions/usage stays gated on every backend
(signs_in_via_kiro_cli=True): the scrape spawns kiro-cli itself, and the
dashboard already hides the pill on a non-kiro harness (kirodotdev#15370).
reload_provider_factory builds the new factory before installing it.

Rebased onto current main: the first-run override is dropped (kirodotdev#13888 gives
the first-run screen its own coding-agent choice), the app-ownership pieces
use main's slot_ownership helpers, and the usage membership change is
dropped to leave that handler to kirodotdev#16886.
@iamwhatever

Copy link
Copy Markdown
Contributor
  • A dead foreign session bypasses readiness for its Kiro replacement span=04b44db6832d

fixed in 5105f80: live_session_signs_in_via_kiro_cli now answers only when state.sessions.is_provider_alive(key) is True, the test chat_turn/slash_commands._slash_command_backend uses. A dead, unknown or unprobeable row answers None, so regenerate and /v1/chat/completions fall back to the installed factory backend and a signed-out kiro-cli replacement is refused before truncation.
Pinned by test_a_row_that_is_not_positively_alive_does_not_answer (dead case red without the check).

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • regenerate trusts a dead session row harness, so the kiro-cli gate stands aside span=19bae690bb4c

fixed in 5105f80 with the fix the finding named: the live verdict is accepted only when await state.sessions.is_provider_alive(session_key) is True; otherwise None and the caller falls back to selected_backend(...). Covers regenerate and /v1/chat/completions, the two callers of the peek.
Pinned by test_a_row_that_is_not_positively_alive_does_not_answer.

@iamwhatever

Copy link
Copy Markdown
Contributor
  • The safeguard for history on foreign harnesses is unverified. span=182ce8af7074

needs-a-decision: the lane clears this only with a live run or recorded stderr fixture of a signed-out claude-agent-acp and codex-acp turn setting _last_turn_auth_required. CI cannot produce that state, and this worker host has neither harness signed out. @NicholasRBowers @bolichen97: please either capture it (KIROCREW_ACP_RECORD_FRAMES on a host with each harness installed and signed out, committed as a recorded: live fixture) or accept the residual here.
Without the capture, the refusal is still strictly additive: when the flag never fires the rerun behaves as described in the PR (replacement turn is the authority; the tail stays in archive/).

@iamwhatever

Copy link
Copy Markdown
Contributor
  • selected_backend and the live peek reach into SessionManager privates. span=74261e9cca18

rebutted as out of scope: a public SessionManager.backend_for(key) widens the session manager surface, which this fix does not need. The drift risk is pinned instead: test_the_live_verdict_follows_a_backend_switch_on_a_real_session_manager drives a real SessionManager with the fallback set to the wrong answer, so a rename goes red. The liveness half now goes through the public is_provider_alive.

@iamwhatever

Copy link
Copy Markdown
Contributor
  • Item 4 — oversized: the harness_sign_in_required refusal. span=abc09224805f

needs-a-decision: this refusal was added to clear the Design lane on the previous head (span ccfb23323204, which offered it as one of two ways to clear). Removing it re-opens that Design concern unless a maintainer accepts the durable-truncation trade instead. The two lanes ask for opposite things, so a maintainer must pick: keep the refusal, or remove it and accept the trade.

@iamwhatever

Copy link
Copy Markdown
Contributor
  • Item 5 — oversized: the readiness re-checks after every await. span=9e95b5e0fb1c

rebutted: the under-lock re-derivation and the post-await ownership re-checks each answer a GPT security-class finding upheld in an earlier round of this PR (switch into signed-out kiro-cli during the request; slot rebound during the readiness await). Each has a red-before-green test in test_kiro_spawn_readiness_gate.py. Removing them re-opens fenced findings the GPT lane does not accept as deferrable.

@iamwhatever

Copy link
Copy Markdown
Contributor
  • Item 8 — rides along: completions ownership widened to deny_app_slot_session_access. span=dae3d5b1b1f0

rebutted: the widening is caused by this PR. The readiness peek now reads the slot's linked session, so an app that owns a channel-linked slot could otherwise learn that session's sign-in state through the 503; this was a GPT finding in an earlier round. The same predicate already guards edit-resend on main.

@iamwhatever

Copy link
Copy Markdown
Contributor
  • Item 9 — rides along: reload_provider_factory builds before installing. span=3cd1cd0b47b0

rebutted: the reruns now read the installed config/factory pair (selected_backend(state=)). If a rebuild raised after _cfg was replaced, that pair would name a backend the installed factory does not build, and the gate would judge the wrong harness. Building first keeps the pair consistent; two lines, pinned by test_session_config_hot_reload.py.

- Refuse a foreign-harness rerun with harness_sign_in_required 503 under the
  slot lock when the slot's last turn ended AcpAuthRequired, before the first
  destructive write.
- Trust a live-session verdict only while is_provider_alive(key) is True: a
  dead row is evicted and rebuilt on the installed factory, so it must not
  answer for its kiro-cli successor.
- On /v1/chat/completions refuse an app for an absent target before the
  readiness gate too, so a signed-out kiro-cli is not a slot-existence oracle.
- Drop the unreachable /api/models model_list_backend_unsupported refusal
  and the one-caller backend= gate parameter; /api/models passes
  signs_in_via_kiro_cli=True like the usage routes.
- Declare and pin that a kiro-backed completion failing with no reply is a 500.
@iamwhatever

Copy link
Copy Markdown
Contributor
  • App callers can enumerate unscoped slots while Kiro is signed out span=095e4482e18a

fixed in 4f3704f with the named fix: _reject_unowned_app_slot now runs for every app caller before readiness, absent targets included (an app can never use an absent slot: the slot it would create is unscoped and is refused anyway).
Pinned by test_app_probing_an_absent_slot_gets_the_403_before_readiness (red without the change).

@iamwhatever

Copy link
Copy Markdown
Contributor
  • kiro_readiness module docstring contradicts the spawn sites explicit True override span=8b86604430b8

fixed in 4f3704f: the docstring now says the reruns and /v1/chat/completions apply the latch per session, while the poll-driven spawn sites pass signs_in_via_kiro_cli=True and stay gated whatever the selected harness.

@bolichen97

Copy link
Copy Markdown
Contributor

Thanks for this PR. It now conflicts with main. Could you rebase onto the latest main and resolve the conflicts? We will review it again once it is rebased and CI is green.

@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #32839; thanks for the start.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for this work! It continued in #32839, which has now merged. Closing this one as superseded by #32839.

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.

8 participants