Skip to content

fix(kas): name the failing runtime's route in its sign-in prompt - #39128

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
JalaluddinYazdani:fix/39077-per-runtime-kas-route
Nov 20, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
JalaluddinYazdani:fix/39077-per-runtime-kas-route

Conversation

@JalaluddinYazdani

@JalaluddinYazdani JalaluddinYazdani commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A chat whose KAS engine is refused for sign-in gets the sign-in prompt for its own engine's route, not the route of whichever chat spawned last.

The KAS signed-out prompt was built from kas_route._LAST_SPAWN_ROUTE, the route of the last KAS spawn in the whole process. That covers the message text (host_auth._with_kas_route), the row's translated token (host_auth.kas_signed_out_route) and, since #36888, the row kind (recovery._relay_takes_crew_sign_in → kas_bundle.last_relay_takes_crew_sign_in). When a second chat spawns its engine on another route between the failing chat's spawn and its error, the refused chat shows the other chat's sign-in row: kiro-cli's commands instead of Kiro Crew's Sign in, or the reverse (#39077).

Why it matters

The sign-in row is the only thing that tells a signed-out user what to do. A wrong row sends them to a sign-in that does not start their engine: kiro-cli login for a chat on Crew's own engine, or Crew's Sign in for a relay pinned to kiro-cli's launcher. It hits gateways with chats on more than one route, which the relay-to-bundle fallback and the runtime sharing preview make common. It is timing-dependent, so it shows up as "sometimes the wrong prompt".

Not a goal

  • Changing what each route's prompt says, or which row kind a route gets.
  • Changing the process-wide readers that describe the next or latest spawn on purpose: the warm-pool extract check (kas_extract_repair._spawns_kas_relay) and the engine card (kas_bundle.last_kas_route, GET /api/kas-bundle).
  • Threading a route through callers that hold no runtime (transport_errors's frame formatter, doctor, the CLI). They keep the last-spawn reading.

What changed (motivation → approach → change)

Symptom: wrong sign-in row under concurrent spawns. Cause: the route is read from one process-wide slot at message time and at render time, instead of from the runtime that failed. Change: carry the failing runtime's route into the sentence, and read it back from the sentence.

  • acp/harness/kas.py: KasHarness.spawn_route is set next to each note_spawn_route call, on both the relay and the bundle arm. The harness is per runtime (harness_for builds a fresh instance).
  • acp/runtime_class.py: AcpRuntime.kas_spawn_route reads the cached harness's spawn_route. It is None before a spawn and on other harnesses, and it never resolves a harness.
  • agent_sdk/host_auth.py: signed_out_message(..., *, route=<unset>). A passed route (including None) is used as-is; unset keeps the process-wide reading. The new kas_sentence_route(text) returns the route whose sentence leads text (every route a spawn records, launcher forms included), None for the bare sentence, or NOT_A_KAS_SENTENCE. kas_signed_out_route is built on it.
  • acp/session_provider.py (stream connection failure, _translate_dead) providers/acp_runtime_start.py (three start and create-session arms) and acp/runtime_session_load.py (a governance read refused because Crew's sign-in is dead) pass the runtime's kas_spawn_route.
  • agent_sdk/kas_bundle.py: relay_takes_crew_sign_in(route) is split out of last_relay_takes_crew_sign_in, which now calls it.
  • dashboard/chat_turn/recovery.py: _relay_takes_crew_sign_in(text) uses the sentence's route. Text that is not a KAS signed-out sentence keeps the last-spawn reading, so other backends' rows are unchanged.
  • docs/system-specs/modules/kas-auth.md and acp-client.md say which reading applies where.

Analysis on the issue: #39077 (comment)

Backwards compatibility

Compatible: signed_out_message's new parameter is keyword-only with a default that keeps today's behavior. last_relay_takes_crew_sign_in and kas_signed_out_route keep their signatures and their answers for every input they could see before, except a route-led sentence read while the slot points elsewhere, which is the bug.

Removes nothing: no key, function, row kind or record is removed or renamed; one public helper (kas_bundle.relay_takes_crew_sign_in) is added.

Tests

Proof: not provable -- prove.py timed out

Manual revert check instead: with src/ checked out at main (60a1064) and the tests at head (c816792), the 30 new or extended test cases listed below fail (30 failed); on head they pass (30 passed). Most of the main-side failures are the missing route= keyword. The two harness tests fail on behavior: KasHarness records no spawn_route and AcpRuntime has no kas_spawn_route.

  • test/test_kas_route.py::TestHarnessRoute::test_a_runtime_keeps_its_own_route_after_another_chat_spawns: the harness and AcpRuntime.kas_spawn_route keep the bundle route after another spawn moves the slot to the relay; None before a spawn.
  • test/test_kas_route.py::TestHarnessRoute::test_an_operator_launcher_names_kiro_cli_login (extended): the relay arm records its route.
  • test/test_agent_sdk_host_auth.py::test_a_kas_message_for_a_runtime_names_that_runtimes_route: a passed route wins over the slot in both directions (bundle vs launcher); None gives the bare sentence; unset keeps the slot; another harness ignores the route.
  • test/test_agent_sdk_host_auth.py::test_every_route_reason_reads_back_from_its_own_sentence: every REASON_* constant in kas_route reads back through kas_sentence_route as the route that wrote it, so a reason added later and missed in its list fails here instead of quietly keeping the English.
  • test/test_transient_notice_parity.py::test_the_row_follows_the_route_its_sentence_was_written_for: row kind and token follow the sentence for 6 written routes × 4 moved slots (24 cases).
  • test/test_acp_session_provider.py::TestAcpSessionProviderRuntimeDeadTranslation::test_a_kas_sign_in_prompt_names_this_runtimes_route: a dead KAS runtime's AcpAuthRequired names its own route while the slot says launcher.
  • test/test_kas_token_refresh_recovery.py::TestAFailClosedStart::test_a_refused_sign_in_names_this_runtimes_route: a start whose governance read Kiro refused for a dead Crew sign-in names the runtime's own route.

All 85 test files that reference the touched names: 4881 passed, 7 skipped (pytest -n0, macOS). black and flake8 are clean on every changed file. scripts/local-gate.py was not run to completion: its related set for host_auth is most of the backend suite, and on this host it would take hours with one worker.

Manual verification

N/A — unit coverage sufficient: the race is between two spawns and one error render in one process. The tests reproduce it deterministically by moving the process-wide slot between writing the sentence and building the row.

Real-machine verification

N/A -- the defect is in-process message and row selection, reproduced deterministically by the unit tests above; no host-specific path is involved.

Related Issues

Closes #39077

Sibling sweep

Swept: git grep -n "last_spawn_route\|_LAST_SPAWN_ROUTE\|last_relay_takes_crew_sign_in" -- src/
Sibling: src/kiro_crew/agent_sdk/host_auth.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_turn/recovery.py -- changed here
Sibling: src/kiro_crew/acp/kas_extract_repair.py -- not affected -- predicts the next spawn of a pool, which the last spawn describes
Sibling: src/kiro_crew/agent_sdk/kas_bundle.py -- not affected -- last_kas_route feeds the engine card, a process-wide diagnostic

Pattern harvest

Rule candidate: review-prompt
Pattern: a per-session message built from a process-global "last X" slot set by every session

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

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

@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 Nov 18, 2026
@JalaluddinYazdani

Copy link
Copy Markdown
Contributor Author

@bolichen97 could you review this PR when you have a moment? It fixes #39077: the KAS sign-in prompt and its row now follow the failing runtime's own route instead of the last spawn in the process. Maintainer approval is also needed to run the fork workflows. Thanks!

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

Copy link
Copy Markdown
Contributor

@JalaluddinYazdani I approved the held CI runs on ca8d677 and read the change. Carrying the route on the runtime (KasHarness.spawn_route → AcpRuntime.kas_spawn_route), and reading the row's route back from its own sentence, both look right to me.

Fast Gate fails on the comment-history check, which flags issue numbers in added comments:

Dropping the number and keeping the sentence passes. The AI review lanes start once Fast Gate is green, and I'll approve after they report.

Optional: kas_sentence_route finds the route by rebuilding the sentence for a hand-kept list of routes, and a new REASON_* falls back to English until someone adds it there. A small test that checks every REASON_* constant in kas_route is in that list would catch a missed one.

AI-assisted, sent by Bolin Review bot

@JalaluddinYazdani
JalaluddinYazdani force-pushed the fix/39077-per-runtime-kas-route branch from ca8d677 to c73dc83 Compare November 18, 2026 17:39
@JalaluddinYazdani

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks for approving the runs and reading the change.

  • Comment-history (Fast Gate): fixed in c73dc83. All eight issue-number references this PR added are gone (the three you listed, plus the other test docstrings and two spec lines); each sentence is kept. COMMENT_HISTORY_BASE_REF=origin/main python3 scripts/check_comment_history.py passes on the diff.
  • REASON_* coverage (optional): added test_every_route_reason_reads_back_from_its_own_sentence in test/test_agent_sdk_host_auth.py. It walks every REASON_* constant in kas_route, builds the route a spawn would record for it, and checks kas_sentence_route reads it back. With one reason dropped from the list it goes red.

Still one commit. Since the last head: black, flake8 and the flake-pattern ratchet are clean, and the 5 touched test files pass (385).

@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 Nov 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

@JalaluddinYazdani thanks for c73dc83; the comment and REASON_* test changes look good. Fast Gate now fails on the harness gate: src/kiro_crew/agent_sdk/host_auth.py:1096 (if backend != ACP_BACKEND_KAS: in _with_kas_route) tests harness identity by inequality against one backend, which the gate reads as letting every other harness inherit the branch. Writing it as a positive test, for example if backend == ACP_BACKEND_KAS: around the route lookup, with route = None otherwise, keeps the behaviour and passes. I'll approve once Fast Gate and the AI lanes are green.

AI-assisted, sent by Bolin Review bot

@JalaluddinYazdani

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks. Fixed in e9f537f:

  • Harness gate: _with_kas_route now tests if backend == ACP_BACKEND_KAS: around the route lookup, with route = None in the else. Behaviour is unchanged. check_harness_parity.py passes on the diff ("Kiro identity tested positively").
  • Rebased onto main 47f50ced56. fix(kas): renew a refused crew sign-in instead of failing every start #38978 added a new KAS sign-in failure in runtime_session_load.py: a governance read refused because Crew's sign-in is dead. It still built its message from the process-wide route, so it now passes route=self.kas_spawn_route like the other runtime sites. A new test, test_kas_token_refresh_recovery.py::TestAFailClosedStart::test_a_refused_sign_in_names_this_runtimes_route, fails without that line.

Still one commit. Comment-history, harness parity, black and flake8 are clean. 567 tests across the 8 touched or related test files pass, and the 30 new or extended cases fail with src/ at main and pass on the head.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] c816792

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c816792

@bolichen97

Copy link
Copy Markdown
Contributor

@JalaluddinYazdani e9f537f has one real red, Backend Tests (3.12, 1): test_runtime_bindings.py::test_each_owner_names_the_fields_it_writes_and_reads[kiro_crew.acp.runtime_session_load] reports kas_spawn_route as an extra field read. _wait_managed_mcp now reads self.kas_spawn_route, so runtime_session_load.py has to list it in its module docstring's "Instance fields read" block, next to _acp_backend and the others. The GPT lane failed on a tool error (review incomplete), not a finding; I've re-run it. Add that one line and push, and I'll approve the new head once it's green.

AI-assisted, sent by Bolin Review bot

A KAS sign-in prompt was led by the route of the last KAS spawn in the
whole process (kas_route._LAST_SPAWN_ROUTE), and the translated row's
route token re-read that slot at render time. When a second chat spawned
on another route between one chat's spawn and its error, the refused chat
named the other chat's engine (the Kiro sign-in card instead of
kiro-cli login, or the reverse), or lost its token.

KasHarness now records the route its own spawn took (spawn_route), the
runtime exposes it (AcpRuntime.kas_spawn_route), and the five failure
sites that hold the runtime pass it to host_auth.signed_out_message.
kas_signed_out_route reads the route from the sentence itself. Callers
with no runtime in hand keep the process-wide reading, as do the
warm-pool extract check and the engine card, which describe the next or
latest spawn on purpose.

Closes kirodotdev#39077
@JalaluddinYazdani
JalaluddinYazdani force-pushed the fix/39077-per-runtime-kas-route branch from e9f537f to c816792 Compare November 19, 2026 16:19
@JalaluddinYazdani

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks. New head c816792, still one commit, rebased onto main 60a1064bc0.

  • Binding test: src/kiro_crew/acp/runtime_session_load.py:22 now lists kas_spawn_route under "Instance fields read". The module only reads it (:1005) and never writes it, so the write list is unchanged. runtime_class.py is the only other owner this PR touches, and it already matched. test/test_runtime_bindings.py passes all 410 cases, and the PR's related files pass 897.
  • GPT lane: your re-run, run 44418489011 attempt 2, failed before review started: gh: API rate limit exceeded for installation ... (HTTP 403), then could not read the merge-base of 893c379c9a and e9f537f65a; failing closed. This is runner infra, not the diff, so nothing changed for it. The new head starts a fresh lane run.

Comment-history (against main), harness parity, black, flake8 and isort are clean. The fork runs for the new head need your approval.

@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 Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Revision c816792f5c54ca1e58e9c638da7264785ba91746 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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

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

Design-Verdict: PASS

The fix reads the failing runtime's own route, so another chat's spawn can no longer pick the wrong sign-in prompt. Nothing blocks.

Notes

  • The route is turned into English text, and the dashboard row then works the route back out by matching that text against a fixed list of route sentences (kas_sentence_route re-renders each candidate). A structured route field on AcpAuthRequired would be simpler: the row kind would come straight from that field, and a new reason or a change to describe() would not need the list kept in step.
  • kas_sentence_route builds its candidate sentences with signed_out_message(ACP_BACKEND_KAS, route=route) and no environ/platform_name. On a host where _with_spawn_login_command rewrites the kiro-cli login command, a launcher sentence matches no candidate. The row kind then falls back to the last spawn in the process, which is the race this PR fixes. A structured field avoids this too.

[DESIGN-REVIEWED] c816792

Description read

[DESCRIPTION-READ] a3dc8590a82e1b46c88e166ca39db680e899988f12930c6b7f06ac1218e58e45

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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of c816792f5c54ca1e58e9c638da7264785ba91746 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

The fix targets the cause: each runtime's own route goes into the sentence and is read back from it. One unfixed sibling remains, listed in the note.

Notes

  • Item 3 — symptom-level (point patch): I counted the signed_out_message( call sites in src/. Six now pass route=. Two more are signed-out paths for one specific failing session and still read the process slot, and the sibling sweep (last_spawn_route|_LAST_SPAWN_ROUTE|…) does not list them. dashboard/chat_threads.py:1255 throws away the exception's text and rebuilds the message from the slot, so a thread turn still shows another chat's route. acp/client_start.py:1394 writes the init-time signed-out error without a route. Subtraction: in chat_threads.py:1255, delete the signed_out_message(backend or "") rebuild and reuse str(exc), which already carries the runtime's own route.

What this change ships

Inventory (6 items) — 5 justified

Intent: a signed-out chat on KAS is shown the sign-in prompt for its own engine's route, not the route of whichever chat spawned last. FIX (#39077).

  1. A chat's sign-in message names the route its own runtime spawned on, not the last spawn in the process — justified
  2. The row kind (kiro-cli sign-in vs Crew Sign in) follows the route the sentence names — justified
  3. The translated kas_signed_out token's route is read from the sentence — symptom-level, thread-turn sibling unfixed
  4. New public kas_bundle.relay_takes_crew_sign_in(route) — justified
  5. New KasHarness.spawn_route / AcpRuntime.kas_spawn_route per-runtime record — justified
  6. Spec text in kas-auth.md and acp-client.md says which reading applies where — justified

[FIRST-PRINCIPLES-REVIEWED] c816792

Description read

[DESCRIPTION-READ] c95e4a15b7165b49c637cf56122b16761b3403375cf156c9bcf54381032b5ea0

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 20, 2026
@bolichen97 bolichen97 closed this Nov 20, 2026
@bolichen97 bolichen97 reopened this Nov 20, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

@JalaluddinYazdani sorry for the slow reply. The binding-test fix on c816792f5c is what I asked for, and both AI lanes passed on that head. A later GPT lane run failed on a review-CLI error on our side, so I reopened the PR to restart the lanes and approved the fork runs. I'll approve and turn on auto merge once they're green.

AI-assisted, sent by Bolin Review bot

@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 c816792f5c. The binding-test fix lists kas_spawn_route under the instance fields runtime_session_load reads, which is what test_runtime_bindings.py asked for, and the sign-in prompt now names the failing runtime's route. Every CI job is green and both AI lanes passed on this head; the two red "Publish readiness signal" runs predate the lanes and the readiness check is being refreshed.

AI-assisted, sent by Bolin Review bot

@bolichen97
bolichen97 enabled auto-merge (squash) November 20, 2026 11:06
@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 20, 2026
@bolichen97
bolichen97 merged commit 574d1ee into kirodotdev:main Nov 20, 2026
199 of 201 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 20, 2026
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signed-out sign-in prompt reads the process-wide last spawn route, not the failing runtime's

2 participants