You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bedrock aws-sdk auth: ExpiredTokenException after credential file refresh (regression in v2026.5.3) #77551
After upgrading to v2026.5.3-1, the gateway no longer picks up refreshed AWS credentials from ~/.aws/credentials during its lifetime. Every credential rotation (e.g. mwinit / ada credentials update) causes ExpiredTokenException until the gateway is manually restarted.
This did not happen on the previous version — the gateway would seamlessly use fresh credentials after file refresh.
After credentials rotate (new session token written to ~/.aws/credentials), all Bedrock calls fail:
ExpiredTokenException: The security token included in the request is expired
Failover decision: surface_error reason=auth
Only fix is restarting the gateway service
Expected behavior
The gateway should re-read ~/.aws/credentials when the current token expires or fails with an auth error, matching AWS SDK v3's default credential provider behavior.
Possible root cause
The ~/.aws/credentials file has no expiration field (common with mwinit/ada tooling). Without an expiration timestamp, the SDK's fromIni() provider assumes credentials are permanent and never triggers a refresh. If v2026.5.3 moved to a singleton BedrockClient (vs. per-request instantiation in prior versions), the cached credential provider would hold stale tokens indefinitely.
Environment
OpenClaw: v2026.5.3-1
Platform: Amazon Linux 2 (Cloud Desktop)
Node: 22.18.0
Auth: shared credentials file (~/.aws/credentials) via AWS_PROFILE=default
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.
Summary
Keep open. The report matches a real Bedrock auth surface on current main: docs promise AWS SDK default-chain auth for Bedrock, but the aws-sdk sentinel path leaves no refreshable runtime-auth state, so OpenClaw's auth-error refresh hook cannot help when the underlying shared credentials go stale.
Reproducibility: yes. for the OpenClaw-side refresh gap, from source inspection: aws-sdk sentinel auth clears runtimeAuthState, and auth-error refresh is gated on that state. A live AWS rotation repro was not run, so the full ExpiredTokenException path remains source-reproducible rather than live-reproduced.
Next step
This is a narrow, provider-owned regression candidate with clear source paths, but the repair should first validate AWS SDK v3 credential-provider behavior with rotated shared credentials.
Review details
Best possible solution:
Keep the AWS SDK default-chain contract, but make the Amazon Bedrock provider/runtime path invalidate or recreate stale shared-credential resolution on auth-class failures without adding a user-facing config knob.
Do we have a high-confidence way to reproduce the issue?
Yes for the OpenClaw-side refresh gap, from source inspection: aws-sdk sentinel auth clears runtimeAuthState, and auth-error refresh is gated on that state. A live AWS rotation repro was not run, so the full ExpiredTokenException path remains source-reproducible rather than live-reproduced.
Is this the best way to solve the issue?
No current-main fix is present. The narrowest maintainable direction is provider-owned Bedrock credential refresh/recreation on auth failures, with regression coverage for shared credentials that rotate without an expiration field.
Acceptance criteria:
pnpm test src/agents/pi-embedded-runner/run/auth-controller.test.ts extensions/amazon-bedrock/index.test.ts extensions/amazon-bedrock/embedding-provider.test.ts
pnpm test extensions/amazon-bedrock
pnpm check:changed
What I checked:
Current docs define the expected auth contract: The Bedrock provider docs say Bedrock auth uses the AWS SDK default credential chain, not an API key, and list shared config/env/instance-role credentials as supported. Public docs: docs/providers/bedrock.md. (docs/providers/bedrock.md:9, d0cae0d9500e)
Auth-error refresh cannot run for sentinel-only Bedrock auth:maybeRefreshRuntimeAuthForAuthError immediately returns false when runtimeAuthState is missing, which is the current sentinel fallback state for Bedrock aws-sdk auth without a provider runtime-auth hook. (src/agents/pi-embedded-runner/run/auth-controller.ts:544, d0cae0d9500e)
Bedrock plugin registers stream wrapping but no runtime-auth hook: The Amazon Bedrock plugin registers provider metadata, config API key resolution, stream wrapping, failover classification, and thinking profiles; the inspected registration does not provide prepareRuntimeAuth for refreshable AWS SDK credentials. (extensions/amazon-bedrock/register.sync.runtime.ts:432, d0cae0d9500e)
Dependency surface relevant to the regression: The current main dependency set pins @mariozechner/pi-ai at 0.71.1 and Bedrock runtime dependencies are plugin/root-owned; the fix needs validation against that provider transport and AWS SDK v3 credential behavior. (package.json:1678, d0cae0d9500e)
Likely owner history sampled: Current-line blame points the Bedrock docs/plugin/auth-controller content at the grafted current snapshot by Vincent Koc; available local history also shows Peter Steinberger split the embedded run auth controller and later mirrored Bedrock runtime dependencies. (src/agents/pi-embedded-runner/run/auth-controller.ts:349, d0cae0d9500e)
Likely related people:
Vincent Koc: Current-line blame on the Bedrock provider registration, Bedrock docs, and aws-sdk sentinel tests points to the grafted current snapshot authored by Vincent; local history also shows prior Bedrock docs work under this name. (role: recent maintainer; confidence: medium; commits: 841eb81baf37, dcf2c6d7f14d; files: extensions/amazon-bedrock/register.sync.runtime.ts, docs/providers/bedrock.md, src/agents/pi-embedded-runner/run/auth-controller.test.ts)
Peter Steinberger: Available local history shows Peter split the embedded run auth controller and later made a Bedrock runtime dependency fix, both adjacent to the reported auth/runtime boundary. (role: adjacent owner; confidence: medium; commits: 18dc98b00e43, d74a12264aa5; files: src/agents/pi-embedded-runner/run/auth-controller.ts, extensions/amazon-bedrock/package.json, package.json)
Remaining risk / open question:
The exact failing AWS credential-cache behavior still needs dependency-level validation with rotated shared-credentials files that omit expiration metadata.
A robust fix may need either a provider-owned Bedrock runtime-auth seam or a focused upstream/provider-transport change rather than a small auth-controller-only patch.
Codex review notes: model gpt-5.5, reasoning high; reviewed against d0cae0d9500e.
Maintainer repro note: I can get enough locally to prove the SDK/cache side of this without secrets.
Local evidence:
~/.profile provides AWS_PROFILE and AWS_REGION; aws sts get-caller-identity resolves the profile.
Bedrock control-plane proof is blocked for this local identity: aws bedrock list-foundation-models returns AccessDeniedException for bedrock:ListFoundationModels, so I cannot do a real Bedrock invoke/list proof from this account.
A temp-file AWS SDK probe reproduces the reported stale-read class: after rewriting AWS_SHARED_CREDENTIALS_FILE, a fresh defaultProvider() still returned the first access key; defaultProvider({ ignoreCache: true }) returned the rewritten access key.
Current @mariozechner/pi-ai@0.73.0 creates BedrockRuntimeClient without an ignoreCache credential provider hook, and its public Bedrock options do not expose a credential-provider override.
So this stays open. The likely fix is provider-owned Bedrock runtime wiring that forces shared INI reloads for aws-sdk auth, or an upstream pi-ai option to pass credentialDefaultProvider/defaultProvider({ ignoreCache: true }) into BedrockRuntimeClient. I did not patch pi-ai directly here because dependency patches need maintainer approval.
Live Bedrock proof used a long-lived OpenClaw-wrapped Bedrock process with a scratch AWS shared credentials file: first call failed with the intentionally bad profile, the same credentials file was rewritten to the working profile, and the next Bedrock stream returned OK without restarting the process.
Targeted verification passed: pnpm test extensions/amazon-bedrock/index.test.ts extensions/amazon-bedrock/discovery.test.ts extensions/amazon-bedrock/embedding-provider.test.ts.
That patch moved Bedrock AWS SDK auth refresh into the Amazon Bedrock plugin itself:
extensions/amazon-bedrock/aws-credential-refresh.ts now reloads the AWS shared config/credentials files with ignoreCache: true unless static AWS env credentials or Bedrock bearer-token auth are in use.
extensions/amazon-bedrock/register.sync.runtime.ts refreshes before Bedrock Converse payload construction/control-plane calls.
extensions/amazon-bedrock/embedding-provider.ts creates a fresh BedrockRuntimeClient per invoke and destroys it after use, so refreshed shared-file credentials are picked up without a gateway restart.
The auth-profile follow-up in 8e17910 also treats aws-sdk profiles as config routing metadata, not persisted credentials, and keeps doctor migration/docs aligned.
Activity
clawsweeper commentedon May 4, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.
Summary
Keep open. The report matches a real Bedrock auth surface on current main: docs promise AWS SDK default-chain auth for Bedrock, but the
aws-sdksentinel path leaves no refreshable runtime-auth state, so OpenClaw's auth-error refresh hook cannot help when the underlying shared credentials go stale.Reproducibility: yes. for the OpenClaw-side refresh gap, from source inspection:
aws-sdksentinel auth clearsruntimeAuthState, and auth-error refresh is gated on that state. A live AWS rotation repro was not run, so the full ExpiredTokenException path remains source-reproducible rather than live-reproduced.Next step
This is a narrow, provider-owned regression candidate with clear source paths, but the repair should first validate AWS SDK v3 credential-provider behavior with rotated shared credentials.
Review details
Best possible solution:
Keep the AWS SDK default-chain contract, but make the Amazon Bedrock provider/runtime path invalidate or recreate stale shared-credential resolution on auth-class failures without adding a user-facing config knob.
Do we have a high-confidence way to reproduce the issue?
Yes for the OpenClaw-side refresh gap, from source inspection:
aws-sdksentinel auth clearsruntimeAuthState, and auth-error refresh is gated on that state. A live AWS rotation repro was not run, so the full ExpiredTokenException path remains source-reproducible rather than live-reproduced.Is this the best way to solve the issue?
No current-main fix is present. The narrowest maintainable direction is provider-owned Bedrock credential refresh/recreation on auth failures, with regression coverage for shared credentials that rotate without an expiration field.
Acceptance criteria:
What I checked:
docs/providers/bedrock.md. (docs/providers/bedrock.md:9, d0cae0d9500e)aws-sdk, the runner falls back to__aws_sdk_auth__and setsruntimeAuthStateto null. (src/agents/pi-embedded-runner/run/auth-controller.ts:365, d0cae0d9500e)maybeRefreshRuntimeAuthForAuthErrorimmediately returns false whenruntimeAuthStateis missing, which is the current sentinel fallback state for Bedrockaws-sdkauth without a provider runtime-auth hook. (src/agents/pi-embedded-runner/run/auth-controller.ts:544, d0cae0d9500e)prepareRuntimeAuthfor refreshable AWS SDK credentials. (extensions/amazon-bedrock/register.sync.runtime.ts:432, d0cae0d9500e)@mariozechner/pi-aiat 0.71.1 and Bedrock runtime dependencies are plugin/root-owned; the fix needs validation against that provider transport and AWS SDK v3 credential behavior. (package.json:1678, d0cae0d9500e)src/agents/pi-embedded-runner/run/auth-controller.ts:349, d0cae0d9500e)Likely related people:
extensions/amazon-bedrock/register.sync.runtime.ts,docs/providers/bedrock.md,src/agents/pi-embedded-runner/run/auth-controller.test.ts)src/agents/pi-embedded-runner/run/auth-controller.ts,extensions/amazon-bedrock/package.json,package.json)Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against d0cae0d9500e.
jtatum commentedon May 6, 2026
This breaks IMDS tokens as well
steipete commentedon May 7, 2026
Maintainer repro note: I can get enough locally to prove the SDK/cache side of this without secrets.
Local evidence:
~/.profileprovidesAWS_PROFILEandAWS_REGION;aws sts get-caller-identityresolves the profile.aws bedrock list-foundation-modelsreturnsAccessDeniedExceptionforbedrock:ListFoundationModels, so I cannot do a real Bedrock invoke/list proof from this account.AWS_SHARED_CREDENTIALS_FILE, a freshdefaultProvider()still returned the first access key;defaultProvider({ ignoreCache: true })returned the rewritten access key.@mariozechner/pi-ai@0.73.0createsBedrockRuntimeClientwithout anignoreCachecredential provider hook, and its public Bedrock options do not expose a credential-provider override.So this stays open. The likely fix is provider-owned Bedrock runtime wiring that forces shared INI reloads for
aws-sdkauth, or an upstreampi-aioption to passcredentialDefaultProvider/defaultProvider({ ignoreCache: true })intoBedrockRuntimeClient. I did not patchpi-aidirectly here because dependency patches need maintainer approval.steipete commentedon May 7, 2026
Fixed on main in c018d84 / 4721ca8.
What changed:
End-to-end proof from the same long-lived Node process using a scratch AWS_SHARED_CREDENTIALS_FILE:
Local verification:
steipete commentedon May 7, 2026
Fixed on current main.
Proof:
OKwithout restarting the process.pnpm test extensions/amazon-bedrock/index.test.ts extensions/amazon-bedrock/discovery.test.ts extensions/amazon-bedrock/embedding-provider.test.ts.Closing this as fixed by main.
steipete commentedon May 7, 2026
Fixed on current
mainby c018d84.That patch moved Bedrock AWS SDK auth refresh into the Amazon Bedrock plugin itself:
extensions/amazon-bedrock/aws-credential-refresh.tsnow reloads the AWS shared config/credentials files withignoreCache: trueunless static AWS env credentials or Bedrock bearer-token auth are in use.extensions/amazon-bedrock/register.sync.runtime.tsrefreshes before Bedrock Converse payload construction/control-plane calls.extensions/amazon-bedrock/embedding-provider.tscreates a freshBedrockRuntimeClientper invoke and destroys it after use, so refreshed shared-file credentials are picked up without a gateway restart.The auth-profile follow-up in 8e17910 also treats
aws-sdkprofiles as config routing metadata, not persisted credentials, and keeps doctor migration/docs aligned.Closing as fixed on
main.