Skip to content

fix(responses): carry rotated Kiro auth context into the terminal continuation (carry of #3502, 2/2) - #3562

Merged
lidge-jun merged 2 commits into
devfrom
codex/260905-kiro-continuation-auth-context
Sep 5, 2026
Merged

fix(responses): carry rotated Kiro auth context into the terminal continuation (carry of #3502, 2/2)#3562
lidge-jun merged 2 commits into
devfrom
codex/260905-kiro-continuation-auth-context

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

When a Kiro bearer is rotated mid-request, the terminal continuation was rebuilt with the failed account's region/profile. applyFailoverSnapshot in src/server/responses/core.ts (:3367/:6699) now carries the rotated account's own routing data into the continuation.

Carries #3502 (author @Ingwannu) onto current dev; contributor hunks reapplied. Supersedes #3502 together with the 1/2 layer.

Stack (merge bottom-up; each layer targets the branch below):

# Layer Branch Base
1 B1 codex/260905-oauth-failover-policy-boundaries dev
2 B2 codex/260905-kiro-continuation-auth-context B1
3 B3 codex/260905-claude-native-fallback B2
4 B4 codex/260905-startup-reconcile-persistence B3
5 B6 codex/260905-combo-failure-classification B4

Depends on the layers below it. Review this PR's diff only. Unit: devlog/_plan/260905_open_work_closeout/ (020, 021, 022).

Verification

  • bun run typecheck — exit 0 on this layer and on the stack top (d0f80e85f).
  • bun test tests/providers/kiro/kiro-auth-context-continuation.test.ts — RED with the core.ts hunk reverted 25 pass / 2 fail (apiRegion expected eu-west-1, received us-east-1), GREEN 53 pass / 0 fail across five files.
  • Stack top: 214 pass / 0 fail across all layers' focused files + layout guard + tests/lab/core-lab-boundary.test.ts.
  • Exact-head hosted CI is the merge gate (no repository-wide local suite by maintainer instruction).

Checklist

  • Targets codex/260905-oauth-failover-policy-boundaries (stack layer)
  • Focused regression test RED before / GREEN after
  • Original author credited via Co-authored-by trailer in the branch commit

Co-authored-by: Ingwannu 186453546+Ingwannu@users.noreply.github.com

t and others added 2 commits September 5, 2026 09:45
Carries the policy half of #3502 onto current dev, rebased, with docs rewritten on top of
#3520 rather than replayed.

1. src/oauth/anthropic-routing.ts consulted the pool's proactive strategy even when the
   pool is disabled, so a disabled pool silently reactivated round-robin/fill-first on the
   reactive 429 path. Reactive recovery now uses the neutral quota picker there.
2. src/oauth/generic-account-failover.ts honoured only enabled === false per provider, so
   a provider-specific true could not opt back in when the global default is false. The
   published narrow-over-broad precedence now applies in both directions, and the typeof
   guard still lets a malformed value fall through rather than taking a provider out of
   service.

The Kiro continuation half of #3502 is split into the next PR in the stack.

Verification:
- bun test tests/routing/always-on-429-failover.test.ts tests/oauth/generic-oauth-failover.test.ts tests/adapters/anthropic/anthropic-sidecar-account-failover.test.ts tests/oauth/adapter-event-oauth-failover.test.ts -> 43 pass / 0 fail (both new assertions RED before the source hunks)
- bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts -> 17 pass / 0 fail
- bun run typecheck -> exit 0

Co-authored-by: Ingwannu <186453546+Ingwannu@users.noreply.github.com>
…tinuation

Second half of the #3502 split. The bounded terminal-guard continuation dispatches a shallow
clone of the parsed request, so a 429 rotation that wrote _kiroAuthContext onto the outer
request only left the clone carrying the FAILED account's region and profile ARN — a rotated
bearer paired with an old identity, which is the mixed-identity failure applyFailoverSnapshot
exists to prevent.

applyFailoverSnapshot now takes the request being retried as a defaulted second parameter and
synchronizes both owners, so every other call site is unchanged. The continuation call site
passes nextParsed.

Verification:
- bun test tests/providers/kiro/kiro-auth-context-continuation.test.ts tests/oauth/generic-oauth-failover.test.ts tests/routing/always-on-429-failover.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts -> 53 pass / 0 fail
  (RED without the core.ts hunk: the third build carried kiro-access-1 with account 0's us-east-1 profile)
- bun run typecheck -> exit 0

Co-authored-by: Ingwannu <186453546+Ingwannu@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 5, 2026 00:50
@lidge-jun lidge-jun added the bug Something isn't working label Sep 5, 2026
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: fd5f1efc-0696-4a6c-985f-39a27e14f255

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 70 / 80

이 PR은 #3561(스택 1층, OAuth proactive 경계) 위에 얹는 #3502의 나머지 반쪽입니다. 문제는 Kiro에서 요청 중간에 계정이 돌아가면, terminal-guard continuation이 parsed얕은 복제본(nextParsed)으로 다시 나가는데, applyFailoverSnapshot이 바깥쪽 parsed._kiroAuthContext만 갱신해서 재시도가 새 bearer + 실패한 계정의 region/profile을 붙이던 mixed-identity 버그입니다. src/server/responses/core.tsapplyFailoverSnapshot이 두 번째 인자 retryParsed를 받고, Kiro일 때 parsedretryParsed 둘 다에 같은 kiroContext를 심습니다. continuation 루프의 generic OAuth 429 팔(:6696 근처)만 applyFailoverSnapshot(snapshot, nextParsed)를 넘기고, 다른 회전 사이트는 기본값(parsed)이라 평소 경로에서는 예전과 같습니다. tests/providers/kiro/kiro-auth-context-continuation.test.ts가 plan → 429 → complete 시퀀스에서 세 번째 build가 kiro-access-1 + account-b profile/region인지 고정하고, generic-oauth-failover.test.ts의 source-guard 정규식도 optional nextParsed를 인정하도록 맞춰 두었습니다. layout 등록도 같이 갔습니다. 지금 dev HEAD(4dde2db97)에는 이 hunk가 없고, base가 #3561 브랜치라 단독으로 dev에 머지하면 안 됩니다. #3561 랜딩 후(또는 스택 통째) 올리는 게 맞고, 둘 다 들어가면 leftover #3502를 닫을 수 있습니다.

src/server/responses/core.ts applyFailoverSnapshot - retryParsed !== parsed일 때만 clone에 쓰는 분기는 맞다. 다만 다른 회전 사이트(스트리밍 루프 등)가 나중에 자신만의 shallow clone을 만들기 시작하면 같은 인자를 안 넘기면 구멍이 다시 난다. 헬퍼 주석에 “continuation clone 소유자에게만 두 번째 인자를 넘겨라”를 한 줄 더 박아 두면 좋다.

src/server/responses/core.ts continuation applyFailoverSnapshot(snapshot, nextParsed) - 호출 한 곳만 고친 범위는 의도대로다. diff만 보면 다른 applyFailoverSnapshot(snapshot) 호출은 그대로다.

tests/providers/kiro/kiro-auth-context-continuation.test.ts - fixture adapter name이 anthropic인 이유는 terminal continuation을 켜기 위함이고 provider id는 kiro로 남는다고 주석에 있다. 이 트릭이 깨지면 테스트가 가짜 GREEN이 될 수 있으니, continuation을 실제로 탄다는 신호가 kiroBuilds 길이 3 외에 더 있으면 좋다(지금은 phase 헤더로 간접 검증).

tests/oauth/generic-oauth-failover.test.ts - applyFailoverSnapshot\(snapshot(?:, nextParsed)?\) 가드는 네 번째 회전 사이트 추가를 막는 목적과 잘 맞는다. 카운트 주석(네 곳)과 함께 읽을 것.

#3502 - #3561+#3562가 랜딩하면 Landed via + landed-via-maintainer로 닫을 leftover다. 지금은 원본과 캐리가 동시에 OPEN이다.

메인테이너의 판단이 필요한 지점

너의 추천
#3561이 CI·보안 리뷰 통과해 dev에 들어간 뒤 이 PR을 바로 올린다(또는 스택 통째). 단독 머지 금지. 랜딩 후 #3502 leftover 정리. types/config 스플릿에 무효화될 PR은 아니다.

이 댓글은 grok-bot이 작성했습니다

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved on exact head 49c48662f5f3bad49f5034d544e168ca41427e0c, reviewing this stacked layer against codex/260905-oauth-failover-policy-boundaries. The continuation clone now receives the same rotated Kiro bearer-bound region/profile context as the outer parsed request; missing Kiro metadata fails away from stale mixed identity rather than preserving the failed account context. Isolated focused verification passed 27/27 and exact-head cross-platform CI is green. Land only after #3561, then retarget/revalidate as required by the stack order.

Base automatically changed from codex/260905-oauth-failover-policy-boundaries to dev September 5, 2026 01:08

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The base has now moved to dev after #3561 was squash-merged as 71cfc8de696007c102c3fc7d644a451ce547cf68, but head 49c48662f5f3bad49f5034d544e168ca41427e0c still descends from the pre-squash parent commit c2ba04a... rather than the new dev tip. My earlier approval was explicitly for the stacked layer against that parent. Please rebase/rebuild the Kiro continuation commit onto current dev so the PR diff contains only layer B2, then rerun exact-head CI; I will re-approve the new head. Do not merge the merely retargeted pre-squash ancestry.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer admin merge (ruleset bypass recorded per MAINTAINERS.md): carry of #3502 (2/2), exact-head CI green on 49c4866 (24 pass / 2 skipped / 0 fail), stack layer above the merged #3561 (71cfc8d). Implementation review 023 found no blocker in this layer. wp2 Stack B of the 260905 open-work closeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants