Skip to content

fix(kiro): prevent expired token refresh stalls - #681

Open
HanqingAWS wants to merge 1 commit into
justlovemaki:mainfrom
HanqingAWS:fix/kiro-expired-token-refresh
Open

fix(kiro): prevent expired token refresh stalls#681
HanqingAWS wants to merge 1 commit into
justlovemaki:mainfrom
HanqingAWS:fix/kiro-expired-token-refresh

Conversation

@HanqingAWS

@HanqingAWS HanqingAWS commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • refresh expired Kiro access tokens synchronously before unary or streaming generation
  • keep valid near-expiry tokens on the existing non-blocking background refresh path
  • coalesce concurrent forced refreshes for the same credential
  • release provider-level refresh slots after queued credentials finish
  • treat malformed expiry timestamps as expired

Why

When a Kiro access token was already expired, both request paths marked the credential as
needsRefresh but immediately sent the stale token upstream. Kiro then returned:

403: The bearer token included in the request is invalid.

With multiple credentials expiring near the same time, failover selected another expired
credential. The refresh queue also attached global-slot ownership to the first task instead
of the provider queue, so a queued second credential could finish without releasing the
slot. After enough leaked slots, later refreshes never started and all nodes could remain
in “Refreshing” until the service was restarted.

Tests

npx jest tests/kiro-token-refresh.test.js --runInBand

PASS tests/kiro-token-refresh.test.js
Tests: 6 passed, 6 total

The tests cover unary ordering, streaming ordering, the near-expiry background path,
concurrent refresh coalescing, provider refresh-slot release, and malformed expiry values.

Fixes #680

Refresh expired Kiro access tokens before unary or streaming generation, coalesce concurrent refreshes, and keep provider-level global refresh slots from leaking across queued credentials.\n\nRefs justlovemaki#680
@HanqingAWS
HanqingAWS force-pushed the fix/kiro-expired-token-refresh branch from 3332b73 to c519c8c Compare August 6, 2026 06:15
@HanqingAWS HanqingAWS changed the title fix(kiro): refresh expired tokens before requests fix(kiro): prevent expired token refresh stalls Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Kiro Access Token 过期后仍先发送旧 Token,导致 403 与节点卡在刷新中

1 participant