fix: Bedrock auth regression — "<authenticated>" sent as bearer token - #97
Merged
Merged
Conversation
Codex (gpt-5.6-sol) adversarial review caught an auth regression the earlier review had cleared as inert: pi-agent-core calls Agent.getApiKey before every request and forwards the result as options.apiKey. ModelRuntime.prepareRequest treats an explicit apiKey as an auth override, and the Bedrock provider uses options.apiKey as an AWS_BEARER_TOKEN_BEDROCK bearer token — so every ECS request would have sent the literal string "<authenticated>" instead of SigV4 task-role auth. - Remove getApiKey from the Agent config; ModelRuntime resolves ambient AWS credentials itself. - Keep the fail-loud credential check as a boot-time assert, expanded to the full credential-chain modes the provider supports. - Do not cache a rejected ModelRuntime.create() promise (transient init failure would wedge all channels until task restart). - engines: node >=22 (file-type 22 requires it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Fix all with cubic | Re-trigger cubic
AWS_WEB_IDENTITY_TOKEN_FILE alone can't authenticate — the SDK's fromTokenFile needs AWS_ROLE_ARN too (EKS IRSA sets both). Without this the guard passes on a config that fails at first request, defeating the fail-loud intent. Flagged by cubic on #97. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Urgent: production is currently broken. PR #96 was squash-merged at commit
834d3c9d, missing the final fix commit (748abb98) on the branch, and the deploy ofe49eac3fhas already completed — so the live ECS task has this bug and every Bedrock request will fail auth.The bug
Agent.getApiKeyis not inert (as PR #96 review had concluded):pi-agent-corecallsgetApiKeybefore every model request and forwards the result asoptions.apiKeyinto the stream function.ModelRuntime.prepareRequest()treats an explicitapiKeyas an auth override, short-circuiting ambient credential resolution.options.apiKeyas anAWS_BEARER_TOKEN_BEDROCKbearer token:bearerToken = options.bearerToken || options.apiKey || ...Net effect: every request authenticates with the literal string
"<authenticated>"instead of SigV4 task-role auth.Found by an adversarial Codex (gpt-5.6-sol) review; each link verified against the installed 0.82.1 packages.
The fix
getApiKeyfrom the Agent config —ModelRuntimeresolves ambient ECS credentials itself, which also restores normal AWS SDK temporary-credential refresh during long tasks.AWS_CONTAINER_CREDENTIALS_FULL_URI,AWS_WEB_IDENTITY_TOKEN_FILE,AWS_BEARER_TOKEN_BEDROCK).ModelRuntime.create()promise — a transient init failure would wedge every channel until the ECS task restarts.engines: node>=22(file-type 22 requires it; Docker/CI already run 22).Test results
234/234 tests passing,
npm run checkclean. Note the suite mocks streaming, so nothing in CI exercises the real auth path — worth watching the bot's first Bedrock call after this deploys.🤖 Generated with Claude Code
Summary by cubic
Fixes a Bedrock auth regression that sent the literal "" as a bearer token, restoring SigV4 task‑role auth and normal credential refresh. Also tightens the web‑identity boot guard to require
AWS_ROLE_ARN.Bug Fixes
getApiKeyfrom the Agent config soModelRuntimeresolves AWS credentials.AWS_WEB_IDENTITY_TOKEN_FILEandAWS_ROLE_ARNfor web identity.ModelRuntime.create()promise to prevent wedging channels after transient init failures.Dependencies
engines.nodeto ">=22.0.0".Written for commit cc60dd4. Summary will update on new commits.