Repository navigation
Conversation
…-24023175@ requestWithEndpointFallback retried every 404 from api.salesforce.com on test./dev./stage.api.salesforce.com. Those gateways only accept connections from inside the Salesforce network, so for a customer org the fallback hit a connect timeout, and because non-404 errors were rethrown immediately the user saw a bare "TypeError: fetch failed" instead of the real 404. - Only try the internal hosts when the org's instance URL is internal (SfdcUrl.isInternalUrl: pc-rnd, stm, crm.dev, ...). Customer orgs use api.salesforce.com only. - Skip a fallback host that can't be reached instead of letting its connection error replace the 404. - AgentApiNotFound now names the request, the hosts tried and any unreachable ones, keeps the 404 as the cause, and suggests checking the org's Agentforce entitlement and user permissions (plus a publish-specific hint for /authoring/agents). Fixes forcedotcom/cli#3634
Detect real network errors instead of a missing statusCode, add the SF_AGENT_API_ENDPOINTS override, drop retries on fallback hosts, strip query strings from the error path, and add tests.
nico-pappagianis
approved these changes
Nov 23, 2026
This branch has not been deployed
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.
Replaces #399 (moved to a fork)
What does this PR do?
Fixes
sf agent publish authoring-bundlefailing with a bareTypeError: fetch failed(UND_ERR_CONNECT_TIMEOUT) on customer orgs.requestWithEndpointFallbackretried every 404 fromapi.salesforce.comontest.,dev.andstage.api.salesforce.com. Those gateways only accept connections from inside the Salesforce network. So when a customer org got a 404 (for example, a scratch org that isn't entitled to agent authoring, while/authoring/scriptsstill works), the retry ontest.apihit a connect timeout. Non-404 errors were rethrown immediately, so that timeout replaced the real 404.Changes (
src/utils.ts):SfdcUrl.isInternalUrl():pc-rnd,stm,vpod,crm.dev, localhost). Customer orgs (*.my.salesforce.com, including develop/scratch/sandbox) callapi.salesforce.comonly.cause), it's skipped. HTTP errors from any host (401/403/5xx,INVALID_SESSION_ID), and network errors onapi.salesforce.comitself, are still thrown right away, as before. Fallback hosts getmaxRetries: 0so an unreachable host is skipped quickly.SF_AGENT_API_ENDPOINTSoverride. Comma-separated fallback gateway prefixes, for examplestage.,test.. It applies to every org, internal or not, and replaces the default chain;nonedisables the fallback. It's for internal orgs whose domain isn't recognized as internal (for example stage orgs on a customer-style domain).api.salesforce.cominstead of tryingtest./dev./stage.. Internal-instance orgs keep the full chain.AgentApiNotFound. The error keeps its name, becausescriptAgent.tsmatches on it. It now names the method and path, the hosts that returned 404 and any unreachable ones, keeps the first 404 ascause, and putsattemptedEndpoints/unreachableEndpointsindata. Itsactionssay to check Agentforce enablement and licensing (Einstein1AIPlatformfor scratch orgs) and user permissions, and to confirm the org's SFAP gateway (Setup > GatewayHawkingInfo, or setSF_AGENT_API_ENDPOINTS). For/authoring/agents, they also note that publishing calls a different Agent API endpoint that may need extra Agentforce entitlements, so validate can pass where publish can't. Query strings are kept out of the message.Example for a customer org, before and after:
Testing
yarn compile,yarn lint(0 errors),yarn test:only: 533 passing, 0 failing.test/utils.test.ts(5 fail onmainwithout this change): an unreachable fallback is skipped; unreachabletest./dev.don't hide the prod 404; an unreachableapi.salesforce.comis still thrown immediately; a prod org makes one call and gets the new message and actions; the publish hint shows only for/authoring/agents; atest.-prefixed URL is normalized on prod orgs; a missing instanceUrl is treated as prod; an HTTP error without astatusCode(INVALID_SESSION_ID), a 503, andUND_ERR_INVALID_ARGfrom a fallback host are rethrown; all three fallbacks unreachable gives the exact message;*.stm/*.crm.devget the chain; fallback hosts get no retries;SF_AGENT_API_ENDPOINTSoverrides andnone. The existing api→test→dev→stage chain tests now use an internalpc-rndinstance URL.test./dev./stage.apimade unreachable to mimic a customer network: publishing to a customer-domain org (Agentforce enabled) succeeded and the debug log shows onlyapi.salesforce.comcalls. On a scratch org withoutEinstein1AIPlatform, released 2.5.0 fails withTypeError: fetch failedand this branch with the clearAgentApiNotFound404./authoring/agentsonly (the reporter's exact case; my scratch org landed on an internal domain), and a stage org.Review note
This assumes
aws-stage1org domains count as internal underSfdcUrl.isInternalUrl(). If they don't, those orgs would lose thestage.fallback added in #365 unlessSF_AGENT_API_ENDPOINTS=stage.is set. Atul Kshirsagar (atulkc), can you confirm?No overlap with #398: different files, and #398 deliberately leaves a failed publish POST unannotated.
What issues does this PR fix or reference?
Fixes forcedotcom/cli#3634
@W-24023175@