Skip to content

fix: @W-24143688 add stage.api.salesforce.com to Agent API endpoint fallback - #365

Merged
setu4993 merged 1 commit into
forcedotcom:mainfrom
atulkc:aks/add-stage-gateway-fallback
Sep 9, 2026
Merged

setu4993 merged 1 commit into
forcedotcom:mainfrom
atulkc:aks/add-stage-gateway-fallback

Conversation

@atulkc

@atulkc atulkc commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the stage. SFAP gateway host to the endpoint-fallback list in requestWithEndpointFallback, so sf agent preview (and other Agent API calls routed through it) can reach agents on orgs served by stage.api.salesforce.com (the aws-stage1 falcon instance).

Why

requestWithEndpointFallback only tried api., test.api., and dev.api.salesforce.com. Orgs on the aws-stage1 falcon instance are served by stage.api.salesforce.com, which was never attempted — so every request 404s and the CLI throws AgentApiNotFound ("...ensure the user has the necessary permissions..."), which misdiagnoses a routing 404 as an authorization problem. Backend logs confirm the request never reaches the Agent API service; it 404s at the public edge because no attempted host maps to the aws-stage1 backend. The same agent previews fine in the Agent Builder UI, which routes internally through that gateway.

Fixes forcedotcom/cli#3645.

Fixes gus work item: @W-24143688@

Changes

  • src/utils.ts: add 'stage.' to the endpoints fallback list and stage\. to the host-matching regex; update the doc comment.
  • test/utils.test.ts: add a "retry with stage endpoint after dev endpoint 404" case, and update the "all endpoints fail" assertion to expect 4 attempts.

stage. is only reached as the final fallback after api./test./dev. return 404, matching the existing pattern — prod/test/dev behavior is unchanged.

Testing

  • yarn tsc -b — clean.
  • yarn mocha test/utils.test.ts — 67 passing (includes the new stage-fallback test).
  • Verified end-to-end by applying the equivalent change to the installed @salesforce/agents in sf 2.150.6 and re-running sf agent preview -o <aws-stage1 org> -n <Agent>: the request now reaches stage.api.salesforce.com and proceeds past the 404 (previously it failed with AgentApiNotFound before any backend contact).

Follow-up (not in this PR)

The AgentApiNotFound message frames a 404 as a permissions failure. Consider a follow-up to have it report that all Agent API endpoints returned 404 and list attemptedEndpoints, so routing failures aren't misread as auth failures.

@atulkc
atulkc requested a review from a team as a code owner September 8, 2026 19:22
@atulkc atulkc changed the title fix: add stage.api.salesforce.com to Agent API endpoint fallback fix: @W-24143688 add stage.api.salesforce.com to Agent API endpoint fallback Sep 9, 2026
sf agent preview (and other Agent API calls routed through
requestWithEndpointFallback) could not reach agents on orgs served by
the stage.api.salesforce.com SFAP gateway (aws-stage1 falcon instance).
The fallback only tried api., test.api., and dev.api.salesforce.com, so
requests 404'd on every attempt and the CLI threw AgentApiNotFound --
misattributing a routing 404 to a permissions problem.

Add 'stage.' to the endpoint fallback list and the host-matching regex.
Prod/test/dev behavior is unchanged; stage is only reached as the final
fallback after the others 404.

Fixes forcedotcom/cli#3645
@atulkc
atulkc force-pushed the aks/add-stage-gateway-fallback branch from 4586f6a to 058d3b1 Compare September 9, 2026 20:03
@setu4993
setu4993 merged commit 03746e2 into forcedotcom:main Sep 9, 2026
5 checks passed
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.

sf agent preview fails with AgentApiNotFound against staging (aws-stage1) orgs — stage.api.salesforce.com missing from endpoint fallback

2 participants