Skip to content

fix(kiro): stop leftover CLI profile ARN from collapsing a second account - #4482

Merged
lidge-jun merged 6 commits into
devfrom
codex/260913-carry-4435
Sep 13, 2026
Merged

lidge-jun merged 6 commits into
devfrom
codex/260913-carry-4435

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

  • Reported by @ren-min-wan-sui in Kiro second account disappears shortly after successful login #4435: adding a second Kiro account succeeded and briefly showed two rows, then the new account vanished from both the dashboard and ~/.opencodex/auth.json.
  • Reproduced against the account store, not the GUI. Kiro is not a single-slot provider, and saveCredential already keeps two slots when accountIds differ — including two accounts that share an email. The collapse is an identity upsert: after kiro-cli login, SQLite state can still hold the previous api.codewhisperer.profile ARN, import treated that leftover ARN as accountId, and the new tokens overwrote the first slot.
  • Same-session whoami is now the live identity when the CLI token still matches the import. The Builder ID service profile ARN is never persisted as accountId / kiro.profileArn. A session switch still discards whoami ([Bug]: Kiro provider profileArn required 400 for Builder ID accounts on gated models #993).

Verification

  • bun test tests/providers/kiro/kiro-review-regressions.test.ts tests/providers/kiro/kiro-oauth.test.ts tests/oauth/oauth-store-multi.test.ts tests/oauth/oauth-reauth-bind.test.ts
  • bun run typecheck
  • bun run structure:check
  • bun run privacy:scan
  • Local full suite not run (lane policy). This is the I2 tip; hosted ci.yml on this exact head is the lane gate.

Stacked on #4479 (codex/260913-carry-4430).

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

…p ci]

JSON null appliedFingerprint/appliedAt is treated as unset, matching
appliedMarkers(). An still-invalid desktopProfile is salvaged by dropping
that field only, so one bad Claude Desktop marker cannot replace the
operator config with defaults.

Closes #4430
…ount

Same-session whoami is the live Kiro identity. SQLite state can still hold
the previous profile after a CLI switch, and using that ARN as accountId
upserted the new login onto the first slot. The Builder ID service profile
is also excluded from account identity.

Closes #4435
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 13, 2026 07:04
@coderabbitai

coderabbitai Bot commented Sep 13, 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: Advanced

Run ID: 2d19e569-2be3-4891-8486-8bd1b393e81d

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-13T07:08:39.162726Z f496a32 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the bug Something isn't working label Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 77 / 80

설명
이 PR은 #4435(@ren-min-wan-sui)를 고친다. Kiro 두 번째 계정을 추가하면 대시보드에 잠깐 두 줄이 보이다가, 새 계정이 대시보드와 ~/.opencodex/auth.json에서 사라졌다. GUI 버그가 아니라 account store upsert 문제다. kiro-cli login 뒤 SQLite state에 이전 api.codewhisperer.profile ARN이 남을 수 있고, import가 그 leftover ARN을 accountId로 쓰면 새 토큰이 첫 슬롯을 덮는다.

수정은 src/oauth/kiro.ts에서 동일 세션 whoami를 live identity로 우선하고, SQLite leftover ARN을 accountId로 쓰지 않는다. accountScopedProfileArn은 Builder ID service profile ARN을 계정 identity로 절대 쓰지 않는다. #993 세션 스위치 가드(토큰이 바뀌면 whoami 폐기)는 유지해, whoami가 없을 때만 imported가 fallback이다. 테스트는 whoami 우선·Builder ID ARN 비식별·두 번째 계정 붕괴 방지·같은 이메일이라도 다른 profile ARN이면 두 슬롯 유지를 잠근다. structure/runtime.md oauth 행에 한 문장을 추가했다.

우선순위 77은 멀티 계정 데이터가 조용히 사라지는 운영 사고를 막고, 변경이 kiro oauth+테스트로 매우 좁기 때문이다. tip b4dec3469 / 2.53.0, types/config 분할 무관.

src/oauth/kiro.ts accountScopedProfileArn / whoami-first resolvedProfileArn - leftover SQLite ARN으로 upsert하지 않음. Builder ID service ARN 제외.

tests/providers/kiro/kiro-oauth.test.ts / kiro-review-regressions - #4435 재현·회귀, #993 세션 스위치 유지.

structure/runtime.md oauth 행 - 계약을 한 문장으로 고정.

심볼 #4435 / #993 - whoami 우선이 #993을 깨지 않는지 테스트가 핵심. diff상 세션 스위치 discard는 유지.

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

  • 이미 붕괴된 auth.json을 복구하는 원샷 마이그레이션이 필요한지(이번 PR은 신규 add-account 경로).
  • #4435를 머지와 동시 닫을지.

너의 추천
즉시 머지하세요. #4435를 이 PR로 닫으세요. 이미 덮어쓴 사용자는 수동 재로그인 안내면 충분합니다.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f496a321f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/oauth/kiro.ts
Comment on lines +305 to +306
const resolvedProfileArn = accountScopedProfileArn(identity.profileArn)
?? accountScopedProfileArn(imported.profileArn);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid the stale ARN fallback for profileless whoami

When a fresh login switches from an account-scoped profile to Builder ID, whoami can succeed with an email plus the fixed service ARN (or no ARN). accountScopedProfileArn(identity.profileArn) is then undefined, so this fallback reuses the previous account's SQLite profile; because saveCredential matches accountId before email, the new credentials overwrite the first slot—the collapse this patch is meant to stop. Treat a successfully revalidated whoami identity as authoritative even when it has no account-scoped ARN.

Useful? React with 👍 / 👎.

Comment thread src/oauth/kiro.ts
Comment on lines 308 to +309
const base = metadataFromImported(imported) ?? {};
if (resolvedProfileArn && !base.profileArn) base.profileArn = resolvedProfileArn;
if (resolvedProfileArn) base.profileArn = resolvedProfileArn;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recompute the region when replacing the imported profile

When whoami supplies profile ARN B over stale SQLite ARN A, metadataFromImported(imported) has already retained apiRegion inferred from A, and this block replaces only profileArn. Since resolveKiroApiRegion prioritizes apiRegion over the new profile's region, a cross-region second account is subsequently sent to the old account's endpoint; filtering the Builder ID service ARN likewise leaves its inferred us-east-1 behind. Clear or recompute profile-derived apiRegion whenever the imported profile is discarded or replaced.

Useful? React with 👍 / 👎.

Comment thread src/oauth/kiro.ts
Comment on lines +187 to +190
/** Account identity must never use the request-scoped Builder ID service profile. */
function accountScopedProfileArn(value: unknown): string | undefined {
const parsed = parseKiroProfileArn(value);
return parsed && parsed !== KIRO_BUILDER_ID_SERVICE_PROFILE_ARN ? parsed : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update all mapped OAuth structure documents

This changes src/oauth/, but only structure/runtime.md is updated; structure/INDEX.md maps that source area to structure/runtime.md, structure/transports/inventory.md, and structure/providers/xai-grok.md. The scoped repository rule requires every mapped document to be updated in the same change, so synchronize the other two documents (or correct the ownership map if they no longer describe OAuth).

AGENTS.md reference: src/AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

@lidge-jun
lidge-jun changed the base branch from codex/260913-carry-4430 to dev September 13, 2026 07:57
@lidge-jun
lidge-jun merged commit 990cd8c into dev Sep 13, 2026
11 checks passed
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
Lane I2 of the contributor carry train: two reported defects with no source branch.

lidge-jun#4430 (samwang0041-star) — 2.52.0 treated claudeCode.desktopProfile.appliedFingerprint=null as fatal and replaced the whole configuration with defaults. Accepting null is the immediate fix; the landing also narrows the reset path so one invalid field cannot destroy a user's providers.

lidge-jun#4435 (ren-min-wan-sui) — a second Kiro account disappeared shortly after a successful login, because a leftover CLI profile ARN collapsed it onto the first.

Cross-platform CI run 34745142783 concluded success on 3238428, the exact head merged here, which already contains a merge of origin/dev. lidge-jun#4479 carries no ci check of its own; its head commit carries [skip ci] by design and this cumulative tip run covers its content, under the owner-authorized tip-only CI economy for this batch.

No Co-authored-by trailer: both links are ordinary implementations with no contributor branch behind them, and the reporters are credited in the pull request descriptions.
@ren-min-wan-sui

Copy link
Copy Markdown

This issue still occurs after the fix in #4482.

Environment:

  • OpenCodex 2.63.0
  • Kiro CLI 2.24.0
  • macOS
  • Adding the account through the web dashboard’s “Add account” button

After logging in with a second Kiro account, I still cannot keep two separate accounts. The account appears to revert to the previous one.

Local investigation found a possible remaining cause:

  • The installed source includes the fix from this PR.
  • kiro-cli whoami --format json currently returns no usable email or profile ARN on my machine.
  • The import logic still falls back to the profile ARN cached in SQLite.
  • The existing OpenCodex account uses that same cached ARN.

An isolated reproduction using dummy credentials and the installed code confirmed that importing new tokens with the old cached ARN updates the existing account slot instead of creating a second account. The account count remains 1.

This reproduces an account-identity collision, although I have not confirmed whether it fully explains the behavior of my live login.

Could you please investigate this fallback path and reopen #4435 if appropriate?

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