Repository navigation
fix(kas): renew a refused crew sign-in instead of failing every start - #38978
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The renewal and the sign-in error act only on a start that has already failed fail-closed, and they reuse Not checked: whether the pinned KAS engine 0.66.117 keeps a refused token until Notes
What this change shipsInventory (5 items) — 4 justifiedIntent: a KAS start recovers from a token Kiro refused without restarting the gateway, and a dead sign-in says it is a sign-in problem. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 571e028 Description read[DESCRIPTION-READ] 990b0eeb62ed36d866741dd26e186185d1bd2485174f81698f5b70f0c97054b6 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix reuses Notes
[DESIGN-REVIEWED] 571e028 Description read[DESCRIPTION-READ] 1595752686bda251d8c0b15a59e13a38bcfb5399b4976bd61b3fce466c9afb60 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
098d67b to
726a1a2
Compare
|
Dispositions for head 098d67b, fixed in 726a1a2:
|
726a1a2 to
077dca2
Compare
|
Disposition for head 726a1a2, fixed in 077dca2:
|
077dca2 to
571e028
Compare
|
Dispositions for head 077dca2, fixed in 571e028:
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own. When a Crew-owned KAS start fails on a governance read, the PR renews the token the engine was served, matched by its sha256 digest. The renewal reuses the existing ensure_fresh(rejected_access_token) path, so it already has the lock, the re-read and the refused-renewal marker. A refused renewal, an empty vault, or a locally blocked renewal of an expired token now fails at once as AcpAuthRequired. A network failure keeps the retryable governance error, and cli-owned runtimes are skipped. Both callers of _wait_managed_mcp pass the new error up the same way as the old one. The callback's network-error retry is limited by a 10s window and only covers aiohttp connection errors and timeouts; the error mapping is unchanged. Tests against a real TokenStore cover each branch, including concurrent starts, and CI is green. Nothing regresses compared with main. Tier: 2, held for a person: the automated review did not clear it. 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 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Review of head 571e028. We read the full diff and followed both callers of _wait_managed_mcp (create and load). The renewal reuses ensure_fresh(rejected_access_token) under its existing lock, and 5 concurrent starts make one refresh. Only an issuer refusal, an empty vault, or an expired and locally blocked token becomes AcpAuthRequired. A network failure keeps the retryable governance error. The retry loop retries only connection and timeout errors, and no try starts past its window. All 18 tests in the new test file pass on this head. The two fail-closed start cases fail on main.
Security: the runtime keeps only a sha256 digest of the served token, never the token, and nothing logs it. The check runs only on a Crew-owned route, through a positive self._kas_host_auth test. Governance still fails closed. When the renewal check is false, the original fail-closed error is raised again, so no path fails open.
Done well: the tests use a real TokenStore and replace only the HTTP refresh, so the lock, the refusal marker and single-flight run as real code.
Optional:
- No test checks that the runtime records the digest of the token it served. The fixture sets it directly. If the write at runtime_host_requests.py:416 stored None, the renewal would stop working and every test would stay green. A test that serves getAccessToken through _answer_ownerless_request and then asserts the digest would close this gap.
- Any governance api_failure forces a renewal, so an outage that has nothing to do with the token rotates it once per retried start. A disposition for the Design note, or one line in kas-auth.md, would record this.
- Coordinate with #39128: whichever PR merges second should pass route=self.kas_spawn_route to the new signed_out_message call in runtime_session_load.py.
… main (#39387) Backports to release/0.13.0 the fixes from #39342, squashed into one commit and brought up to date with release/0.13.0 after the Kiro Memory preview backport (#39360). Picks, in order; each [pick sha] is the commit on the #39342 branch, whose body has main's cherry-picked-from line: - fix(monitor): wake the session once when its watched PR merges or closes (#37776) [pick 84da419] - fix(security): match deny rules against Windows program suffixes and cmd/PowerShell in-word escapes (#33569) [pick e4941b7] - fix(mimocode): refuse a chat that would answer from Xiaomi's hosted model unsigned (#37629) [pick 1bfdce3] - fix(acp): end a quiet agent-started cycle on the shared runtime's stale gate (#37932) [pick fa870a2] - fix(conductor): re-read goal-conductor after a compaction (#37917) [pick ccdd67c] - fix(security): refuse a command nested past 32 substitutions before the floors walk it (#37875) [pick 2f9bd67] - fix(mates): carry a moved Bot's shell toolsSettings entry as execute_bash instead of holding it (#37973) [pick 16022f4] - fix: hold an app to its own sessions, jobs and runs (#37804) [pick 3dff0c0] - fix(acp): keep a KAS chat's stored record when its resume fails after the load (#37955) [pick 6ceb7b5] - fix(gateway): ignore a repeat SIGTERM during graceful shutdown (#38031) [pick b48287d] - fix(security): keep a quote in a $( ) from hiding a later ssh (#37558) [pick b9fed61] - fix(agent): rebuild takes a server's disabledTools from the kiro global (#38147) [pick c50bbcc] - fix(mcp_gateway): keep the backend when a stub leaves an open listen (#38121) [pick 3e9c7f9] - fix: refresh plan and model list after a kiro-cli sign-in to another account (#38053) [pick 5ad3d36] - fix(slack): keep a picture sent in a linked thread for the dashboard turn (#38076) [pick 7f8903e] - fix: keep a resolved tool policy when the gateway is too slow to answer (#36669) [pick 9be5691] - fix: open owner-only files and prune overlay folders without following links (#36994) [pick 6a1acc9] - fix: refuse the local token mint to app backends (#38113) [pick d166dab] - fix(subagent): hold a spawn's first prompt for its MCP servers (#38127) [pick e3e0298] - fix(security): refuse a headless git --output write with no approver (#36326) [pick 1abee40] - fix(restore): require an explicit mode, never default to replace (#38094) [pick ca86c06] - fix: make the deny gate's shell walk linear in command length (#36437) [pick 22c100b] - fix(chat): let a cancelled background start finish its session teardown (#36664) [pick b1dd34f] - fix(acp): refuse a start when two differing specs declare the agent's name (#38411) [pick 80ccfff] - fix: probe a silent turn while its co-tenant keeps the process busy (#38662) [pick 6354490] - fix(kas): let a reopened chat switch to models its load select omits (#38376) [pick 1640822] - fix(cloud): install a patched node 22 on run on aws instances (#38732) [pick 059cb90] - fix: write member record files without following links (#37303) [pick aac9642] - fix: fail a kas start fast once the host has turned its mcp off (#38677) [pick e147238] - fix(decisions): fall back to HTTP/1.1 when h2 is missing (#38759) [pick fc16482] - fix(mcp_gateway): free a spawn permit when its backend exits before initialize (#38793) [pick a084ba2] - fix(kas): start an app chat whose tool policy hides every kirocrew-cron tool (#38761) [pick ccea5a9] - fix(acp): give the tool-stall watchdog a margin over native waits (#34117) [pick b5d9e89] - fix(mcp): bind the working-folder answer to its launch; observe launch changes behind name grants (#38983) [pick a1069be] - fix(mcp): hide the gateway secret files from the npm install and third-party probe spawns (#39000) [pick 14d8571] - fix(sandbox): fold env name case on Windows in the agent env scrub (#33997) [pick 9bdce76] - fix(apps): let app turns follow the Auto approval mode (#38830) [pick e8336df] - fix: end a dashboard turn stopped while it is still being prepared (#36478) [pick 37fff93] - fix(acp): cleanup_session deletes the record on the session's own host (#39046) [pick 31b5ec4] - fix(acp): scan only the new part of a streamed tool result (#38852) [pick e2870db] - fix(sandbox): make an unscoped session host the OOM victim, not the gateway (#39189) [pick 2be6dde] - fix(security): read aws s3 downloads piped into tail, with 2>&1, or with an AWS_PROFILE prefix (#38271) [pick bf65d97] - fix: redact four display and log paths and use a fixed 502 message for session switch refusals (#38982) [pick 55d9ec7] - fix(sandbox): pin a credential-masking app's folder after the masks on the namespace backend (#34339) [pick afd2b14] - fix(acp): wait for systemd scope admission as its own startup stage (#37008) [pick 3e29c86] - fix(acp): wait for systemd scope admission on the AcpClient spawn path (#38303) [pick 85f0a25] - fix(acp): stamp the spawn instance on the AcpClient child (#38810) [pick f36eb5a] - fix: end the turn when the agent never confirms a stop (#38512) [pick 2665c9d] - fix(kas): renew a refused crew sign-in instead of failing every start (#38978) [pick 2f48cac] - fix(security): keep self-host detection when the ssh verb is a glob (#34056) [pick ab53f10] - fix(security): judge each substitution body for ssh-to-self (#37616) [pick d5b7ac3] - test: check the ssh floor's nesting bound below the gate's depth cap (#37964) [pick 6c9ae1d] - fix(mate): apply held Bot limits on shared claude sessions and refuse unnarrowed KAS children (#39212) [pick 721bbbe] - test(integration): wait out and reset the hidden-chat refresh between boots (#37933) [pick e77586d] - fix(browser): fall back to Kiro's Chromium under Automatic when Chrome's remote debugging is off (#39265) [pick 31912eb] Left out of #39342's set (not needed for 0.13.0): the provider_labels refactor, #34045, #36668, #39120 and #37627. Merge with release/0.13.0: kept both imports in runtime_session_load, runtime_spawn_launch and session_provider; session_allocation lists the memory_policy owner; the keep-record resume path passes kas_memory_mode as main does; dropped the ACP_BACKENDS_SESSION_EVICTION import that moved to session_provider_new_conversation.
Problem / Motivation
Goal: When Kiro refuses the token Kiro Crew gave its own engine, the next start gets a new token without a gateway restart, and a sign-in Kiro will not renew fails at once as a sign-in error.
A macOS user on the KAS engine saw
KAS auth callback: refresh failed (ClientConnectorDNSError). After that every new KAS runtime gotThe bearer token included in the request is invalidon management calls, governance fail-closed, MCP was off, and each start ended asAcpRequestTimeout: KAS managed MCP readiness timed out after 90s. Only a gateway restart fixed it.Why it matters
Every bot check-in and cron on that gateway failed for hours, each after a 90-second wait, and the error pointed at MCP governance instead of the sign-in. Any user on the Crew-owned KAS route can hit it after one refused token.
Not a goal
--auth-method cli): kiro-cli owns that token.What changed (motivation → approach → change)
Why the token stuck: the engine caches the token it was served until that token's own expiry, and it never asks again when Kiro refuses it. Kiro Crew's callback renews only a token that is close to expiry, so a token Kiro refused early went to every new runtime until it expired.
AcpAuthRequiredwith the KAS sign-in message, no retryThe callback retry and the renewal live in
acp/kas_host_auth.py; the fail-closed start calls it fromacp/runtime_session_load.py. The runtime (runtime_host_requests.py,runtime_class.py) keeps only a sha256 digest of the token it served, never the token. The renewal usesensure_fresh's existingrejected_access_tokenand its lock, so many starts at once make one refresh. The sign-in error is the existing KAS signed-out message andAcpAuthRequiredpath. The KAS auth spec (docs/system-specs/modules/kas-auth.md) says what the callback and the fail-closed start do, and names the known limit: sessions that share one engine process keep its cached token until it expires.Backwards compatibility
Compatible: a start that worked still works. The new check runs only after a Crew-owned start already failed on a governance read.
Removes nothing: no field, route, key or behavior is taken away; one error case becomes the sign-in error it really is.
Tests
test/test_kas_token_refresh_recovery.py, against a realTokenStore; only the HTTP refresh is replaced.AcpAuthRequired(not transient, sign-in text, no governance text); renewed keeps the retryableKasGovernanceOffError; a cli-owned runtime is not checked.Determinism: the file ran 3 times in a row green, and with three neighbour files under
-n 4.Proof: PROVEN test/test_kas_token_refresh_recovery.py::TestAFailClosedStart::test_a_renewed_sign_in_keeps_the_retryable_error (head 571e028)
Manual verification
The engine behavior was read from the pinned KAS engine 0.66.117 (
AcpCallbackAuthProvider.ensureTokenreturns the cached token untilexpiresAt; nothing clears it on a refused request). Not run against a live Kiro refusal: that needs a token Kiro rejects before its expiry.Related Issues
Closes #38912
Sibling sweep
Swept: git grep -n "rejected_access_token|answer_get_access_token" -- src/
Sibling: src/kiro_crew/dashboard/handlers/relay_viewer.py -- not affected -- it already renews a token the service answered 401
Sibling: src/kiro_crew/relay_client/lease_signin.py -- not affected -- it already passes the refused bearer to the provider
Sibling: src/kiro_crew/dashboard/sign_in_refresher.py -- not affected -- it already retries a network failure with backoff
Pattern harvest
Not generalizable: the other token consumers already feed a refusal back; only the engine callback could not, because the engine never reports it.
Checklist