Skip to content

fix: return botVersionId when publish fails after the BotVersion commit @W-24949433@ - #403

Open
nhalko-sf wants to merge 4 commits into
forcedotcom:mainfrom
nhalko-sf:nh/W-24949433-publish-post-commit-error
Open

nhalko-sf wants to merge 4 commits into
forcedotcom:mainfrom
nhalko-sf:nh/W-24949433-publish-post-commit-error

Conversation

@nhalko-sf

Copy link
Copy Markdown
Collaborator

What does this PR do?

Follow-up to #350 (W-23735101).

publishAgentJson commits the new BotVersion in its first step (the POST to ai-agent/v1.1/authoring/agents[/<botId>/versions]). The steps after that can still throw: getBotVersion, retrieveAgentMetadata (agentRetrievalError) and deployAuthoringBundle (authoringBundleDeploymentError). When one does, sf agent publish authoring-bundle fails, and the error has no botId or botVersionId. Callers, including CI loops and coding agents, can't tell the version actually landed. They retry, and each retry creates another BotVersion.

Changes:

  • publishAgentJson: wraps the post-commit steps in a try/catch and rethrows through a new toPublishedAgentError. The rethrown error:
    • keeps the original error name, message and actions;
    • adds data.publishedAgent = { developerName, botId, botVersionId, versionNumber?, target?, failedStep }, where failedStep is botVersionLookup, retrieve or bundleDeploy;
    • puts an action first saying the agent is already published as version N and should not be republished. When the version is known, it names the <target> (<agent>.<version>) the bundle-meta.xml needs for a manual deploy, and it only mentions the retrieve step when retrieve wasn't skipped;
    • logs a debug line and sends agent_publish_post_commit_failed telemetry, both including failedStep.
  • deployAuthoringBundle: the <target> cleanup in the bundle-meta now runs in a finally. It no longer stays in local source when the deploy poll or listener throws. A failed cleanup write is logged at debug level and doesn't replace the deploy error.
  • New exported type PublishedAgentInfo. This is additive only. Its JSDoc notes that a missing data.publishedAgent doesn't prove nothing was committed, since a POST timeout can still follow a commit.

Nothing changes on the success path. Error names are the same, and with sf … --json, data and actions show up in the output automatically. plugin-agent and vscode-agents don't key on these error names, actions or data, so the change is non-breaking for them. (vscode-agents shows only .message, so VS Code users won't see the don't-republish action. Surfacing it there is a small follow-up, to be filed separately.)

Testing

  • yarn build and lint are clean.
  • mocha: 477 passing, 1 pending. That includes 6 new cases in test/agentPublisher.test.ts:
    • a retrieve failure after the commit keeps its name, message and actions, and gains data.publishedAgent, the don't-republish action and telemetry;
    • a getBotVersion failure reports the BotVersion Id without a versionNumber;
    • a bundle-deploy failure merges publishedAgent into the error's existing data;
    • a failure of the publish POST itself is left unannotated, because nothing was committed;
    • <target> is removed from the local bundle-meta even when the deploy poll throws;
    • a publish POST that rejects (4xx/5xx) is left unannotated and emits no telemetry.

The recovery action also names the target and skips the retrieve clause under skipRetrieve, both asserted in the existing cases. The cleanup-write failure path has no unit test, because the ESM writeFile import isn't practical to stub.

  • yarn test fails only in link-check, on external 403/429 responses for README and CODE_OF_CONDUCT links. That's unrelated to this change.

What issues does this PR fix or reference?

@W-24949433@ (child of W-23735101)

Replaces #398 (moved to a fork).

…e failed step @W-24949433@

Address pre-review round 1: add target and failedStep to PublishedAgentInfo, name the
<target> in the recovery action, tolerate a failed bundle-meta cleanup, document that a
missing publishedAgent is not proof nothing was committed, and test a rejecting POST.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants