Skip to content

fix(auth): settle token refresh launch failures - #426

Closed
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/token-cache-refresh-launch-failures-20261005
Closed

sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/token-cache-refresh-launch-failures-20261005

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #425.

Catch provider exceptions raised before getAsync returns its future and route them through completeAsync. This releases the in-flight slot, settles the same waiting futures and applies advisory backoff consistently with asynchronous failures.

Reuse the protected launch path for forced refreshes chained after earlier requests. The chained provider launch uses whenCompleteAsync with an explicit common-pool executor, following the repository callback rule rather than executing on the previous refresh's completing thread.

Validation

Five new tests cover foreground/mandatory launch failures, advisory stale-token delivery and backoff with an injected clock, joined forced-refresh callers, recovery and an exceptional-future control.

  • Unchanged main: four failures and one passing control.
  • Auth, credential-provider and credential-cache suites: 87 tests passed, zero skips.
  • Kotlin formatting and the complete core Kotlin format check passed.
  • Type-resolved Detekt checks passed on the two changed files with existing rules and baselines. The initial full-core Detekt attempt exhausted its configured heap and was cancelled; a full repository lint pass is not claimed.
  • Whitespace checks passed.
./gradlew :anthropic-java-core:test --tests 'com.anthropic.auth.*' --tests 'com.anthropic.credentials.*' --tests 'com.anthropic.config.CredentialsCacheTest'

Tested on macOS arm64 with JDK 21.0.12.1. Live authentication, full API tests and Java 8 runtime execution were not run. No public signatures or dependencies changed. Launch failures now produce exceptionally completed futures instead of escaping synchronously and leaving later requests pending.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner October 5, 2026 09:58
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

The auth and credential suites pass (87 tests), together with the changed-file Detekt checks and core Kotlin formatting check. Could a maintainer approve the pending CI workflow?

@tomer-ant

Copy link
Copy Markdown
Contributor

Closing along with #425. The reasoning is in #425 (comment).

@tomer-ant tomer-ant closed this Oct 14, 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.

Synchronous async-provider failures leave token-cache refresh futures unresolved

2 participants