feat(acp): kiro-cli v3 token refresh + auth callback wiring - #1483
feat(acp): kiro-cli v3 token refresh + auth callback wiring#1483FakeRocket543 wants to merge 3 commits into
Conversation
Add `kiro_auth` module that reads the cached access token from kiro-cli's sqlite database, refreshes it via AWS SSO OIDC, and persists the refreshed token back. Falls back to `kiro-cli whoami` when the refresh fails. The ACP reader loop now auto-replies to `_kiro/auth/getAccessToken` using the refreshed token and profile ARN from the local store instead of a hardcoded ARN. Also merges consecutive text content blocks and sends `notifications/initialized`, both required by the v3 engine. Generated with Devin
…-failure detection Review of 327a21a found two issues in the kiro-cli v3 auth wiring: H1: when build_auth_response() returned None, the reader loop sent a JSON-RPC *success* with an empty result '{}' instead of an error. The v3 engine then retried prompts against a blank token -> Bedrock 403 -> reconnect storm. Now send a proper error response (code -32001 / -32603) so the engine knows auth is unavailable. H2: the auth-error reconnect trigger matched contains("Access denied") on every inbound error, so ordinary permission/tool errors silently dropped the connection. Narrow to is_auth_token_failure() (bearer token / expired token / InvalidIdentityToken only); generic 'Access denied' now surfaces normally. Also add a 30s refresh-failure cooldown in kiro_auth so a genuinely dead token cannot hammer AWS SSO OIDC or spawn 'kiro-cli whoami' in a tight loop. Adds a regression test pinning the narrowed matcher behavior.
New clippy lints in rust-clippy 1.96 broke `cargo clippy -- -D warnings` on pre-existing test code (unrelated to the kiro auth work): - clippy::bool_assert_comparison: assert_eq!(x, true/false) → assert!(x)/assert!(!x) (cron.rs) - clippy::manual_repeat_n: repeat().take(n) → repeat_n(x, n) (format.rs) - clippy::unnecessary_literal_unwrap: Some(x).unwrap_or(y)/None.unwrap_or(y) on literal values (discord.rs) Pure test-code changes; no behavior or production code affected.
|
Caution This PR is missing a Discord Discussion URL in the body. All PRs must reference a prior Discord discussion to ensure community alignment before implementation. Please edit the PR description to include a link like: |
|
Important CHANGES REQUESTED What This PR DoesMakes kiro-cli v3 agents usable through OpenAB by answering the engine's How It WorksA new Findings
Finding Details🔴 F1: OIDC wire format is camelCase; this code uses snake_case
Fix: use camelCase keys in the request body and 🟡 F2: Auth callback answered for every agent typeThe 🟡 F3:
|
|
Thanks for the contribution - kiro-cli v3 support is genuinely needed, and parts of this design (the narrowed reconnect matcher, the -32001 error reply, the refresh cooldown) are solid. Before we continue with review iterations, the maintainer asks that you first bring this proposal to our Discord server for community discussion. This PR introduces host-side credential handling and changes to the shared ACP connection path that affect every agent backend, so we want alignment on the approach (see the findings in the review comment above, especially F1-F4) before further implementation work. Action items:
I am converting this PR to draft in the meantime so automated review cycles pause while the discussion happens. Feel free to mark it ready for review again once the discussion link is in place. |
kiro-cli v3 token refresh + auth callback for ACP
The kiro-cli v3 engine requires a
_kiro/auth/getAccessTokenJSON-RPC callback from the host, stricter prompt content (single text block per message), andnotifications/initializedbefore it accepts session requests. Without this wiring, kiro v3 sessions fail auth against Bedrock and cannot run.What this does
kiro_authmodule: reads the cached access token from kiro-cli's sqlite store, refreshes it via AWS SSO OIDC (refresh_token + device registration), persists it back; falls back to spawningkiro-cli whoamito trigger its internal refresh._kiro/auth/getAccessTokenwith the refreshed token + profile ARN from the local store (replaces the previous hardcoded ARN).notifications/initializedafterinitialize.is_auth_token_failure); generic "Access denied" surfaces normally instead of silently churning reconnects.kiro-cli whoamiin a loop.cron.rs,format.rs,discord.rs) that were blockingcargo clippy -- -D warnings.Review Contract
Goal
Make kiro-cli v3 agents usable through OpenAB: the ACP connection must supply a valid, auto-refreshed Bedrock access token on demand and stay within the v3 engine's stricter protocol expectations (single text block per prompt,
notifications/initialized).Non-goals
kiro-cli loginfor initial auth.KIRO_HOMEpaths.secrets::tests::resolve_exec_nonzero_exittest failure (environment-dependent, unrelated).cargo fmtdrift (~1500 lines across 17 files, pre-existing).Accepted Residual Risks
reqwest::blockinginsidetokio::task::spawn_blocking— correct today; a future refactor that calls it from an async context would panic. Mitigation: doc comment onget_access_tokenstates the contract.parse_rfc3339fallback assumes UTC when sub-second parsing fails; only reachable for externally-written non-RFC3339 timestamps (the save path round-tripsto_rfc3339cleanly).save_token_datais UPDATE-only (no INSERT fallback) — fine because the row always pre-exists (we just read it)._kiro/auth/getAccessTokencallbacks could race a refresh; window is tiny (callbacks are ~1/hour) and the worst case is a duplicate refresh, not corruption.kiro-cli login" guidance; the 30s cooldown bounds retry cost.Acceptance Criteria
cargo test -p openab-core --lib acp::connection::reader_loop_testspasses, includingauth_token_failure_matcher_is_narrow(generic "Access denied" must NOT reconnect; token-invalidity errors MUST).cargo clippy -p openab-core --lib --tests -- -D warningsis clean.origin/main(280db4d) with no conflicts; reader-loop behavior verified there.Follow-ups
_kiro/auth/getAccessTokenreply shapes (success / -32001 / -32603) via arun_reader_loopduplex test — currently covered by inspection only.cargo fmtnormalization PR.