Repository navigation
Conversation
|
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Nathan Halko <n***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request. |
|
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Nathan Halko <n***@g***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated. |
616a862 to
2150031
Compare
2150031 to
8a625f7
Compare
|
Thanks for the contribution! Before we can merge this, we need @nhalko-sf to sign the Salesforce Inc. Contributor License Agreement. |
nhalko-sf
left a comment
There was a problem hiding this comment.
Automated pre-review, round 1 of 2 (an extra pair of eyes, not a gate). Verdict: approve with nits, no blockers.
The approach is sound. The try/catch covers exactly the steps after the commit (getBotVersion → retrieve → bundle deploy). That includes the plugin-agent scopedPostRetrieve/scopedPostDeploy listeners that throw from inside pollStatus, so those come back annotated too. A failure of the POST itself, or a response without ids, is correctly left alone. Error names and messages are unchanged, PublishedAgentInfo is additive, and the tests assert real behavior, including a failing telemetry listener. No secrets or tokens show up in logs or telemetry.
Main ask: make the recovery path actionable (inline 1). The <target> that the bundle deploy needs isn't surfaced anywhere, and the finally now strips it from local source.
General (no line anchor)
- Warning: an ambiguous POST failure is still unannotated. If the POST times out or gets a gateway 5xx after Core committed the BotVersion, a retry can still create a duplicate. Fixing that is out of scope, but please say in the
PublishedAgentInfoJSDoc that a missingdata.publishedAgentdoes not prove nothing was committed, or file a follow-up (e.g. re-query the latest BotVersion forbotIdafter a POST timeout). - Suggestion: how callers surface the error. plugin-agent rethrows unchanged, so
dataandactionsshould flow into--jsonoutput and under "Try this". Worth a quick NUT or manual check thatdata.publishedAgentreally appears insf agent publish authoring-bundle --json. vscode-agents (src/commands/publishAgent.tsL133-140) shows onlysfError.message, so VS Code users won't see the don't-republish guidance. Please file and link the follow-up the PR body mentions. - Backwards compatibility: OK. Names and messages are unchanged, and actions are only prepended. A non-object
datamoving underoriginalDatais technically a shape change, but no post-commit error sets one today.
What's good: the commit boundary is exactly right; telemetry is guarded and that's tested; the <target> cleanup in finally fixes a real local-source pollution bug; and the tests assert the exact data, the action order and the telemetry payload.
|
|
||
| # publishedBeforeFailureActions | ||
|
|
||
| The agent was already published to the org as %s before this step failed. Don't run the publish command again, because that creates another, duplicate version. Fix the cause of the error, then finish the step that failed. |
There was a problem hiding this comment.
1. Warning: the recovery action isn't actionable on its own. "Fix the cause of the error, then finish the step that failed" doesn't say how. If the retrieve failed, the bundle deploy never ran. If the deploy failed, the new finally (scriptAgentPublisher.ts L340-345) has already removed <target> from the local bundle-meta. Either way, a manual sf project deploy start would deploy the bundle without <target>developerName.vN</target>, so it wouldn't be linked to the committed version. The user (or a coding agent) is likely to give up and republish, which is the duplicate this PR prevents.
Suggest naming the target in the action, and adding it to PublishedAgentInfo (e.g. target?: string, set once botVersion resolves) so --json callers can finish the job programmatically:
| The agent was already published to the org as %s before this step failed. Don't run the publish command again, because that creates another, duplicate version. Fix the cause of the error, then finish the step that failed. | |
| The agent was already published to the org as %s before this step failed. Don't run the publish command again, because that creates another, duplicate version. Fix the cause of the error, then finish the remaining steps: retrieve the agent metadata if that step failed, then deploy the authoring bundle with `<target>%s</target>` set in its bundle-meta.xml. |
(This needs a second %s argument from toPublishedAgentError. Fall back to generic phrasing when botVersion is unresolved.)
| let botVersion: { developerName: string; versionNumber: number } | undefined; | ||
| try { | ||
| botVersion = await this.getBotVersion(response.botVersionId); | ||
| if (!this.skipRetrieve) { | ||
| await this.retrieveAgentMetadata(botVersion); | ||
| } | ||
| await this.deployAuthoringBundle(botVersion.developerName); | ||
| } catch (error) { | ||
| throw await this.toPublishedAgentError(error, response, botVersion); | ||
| } |
There was a problem hiding this comment.
2. Suggestion: record which step failed. errName alone doesn't identify the stage. Deployment Failed can come from the plugin-agent scopedPostDeploy listener or from SDR, and getBotVersion reuses the deploy action text. Tracking a step ('botVersionLookup' | 'retrieve' | 'bundleDeploy') inside the try, and passing it to toPublishedAgentError for the telemetry event, the debug log and optionally data.publishedAgent.failedStep, would make agent_publish_post_commit_failed diagnosable. It would also let the action in comment 1 name the remaining steps exactly.
| } finally { | ||
| // 3.remove the target from the local authoring bundle meta.xml file, even if the deploy threw | ||
| // (poll timeout, a scopedPostDeploy listener), so it never lingers in local source | ||
| delete authoringBundle.AiAuthoringBundle.target; | ||
| await writeFile(this.bundleMetaPath, xmlBuilder.build(authoringBundle)); | ||
| } |
There was a problem hiding this comment.
3. Suggestion: a write failure in finally masks the deploy error. If writeFile throws here (EACCES, or the file is locked by an editor), it replaces the deploy/poll error. The replacement still gets the published annotation, but the root cause is lost. Consider a nested try/catch with a debug log:
| } finally { | |
| // 3.remove the target from the local authoring bundle meta.xml file, even if the deploy threw | |
| // (poll timeout, a scopedPostDeploy listener), so it never lingers in local source | |
| delete authoringBundle.AiAuthoringBundle.target; | |
| await writeFile(this.bundleMetaPath, xmlBuilder.build(authoringBundle)); | |
| } | |
| } finally { | |
| // 3.remove the target from the local authoring bundle meta.xml file, even if the deploy threw | |
| // (poll timeout, a scopedPostDeploy listener), so it never lingers in local source | |
| delete authoringBundle.AiAuthoringBundle.target; | |
| try { | |
| await writeFile(this.bundleMetaPath, xmlBuilder.build(authoringBundle)); | |
| } catch (cleanupError) { | |
| getLogger().debug('Failed to remove target from authoring bundle meta.xml', { | |
| bundleMetaPath: this.bundleMetaPath, | |
| errMsg: cleanupError instanceof Error ? cleanupError.message : String(cleanupError), | |
| }); | |
| } | |
| } |
(Trade-off: swallowing the error means a <target> can still linger silently. A debug log plus an appended action may be the better balance.)
| it('should not annotate errors when the publish POST itself fails', async () => { | ||
| process.env.SF_MOCK_DIR = join('test', 'mocks', 'publishAgentJson-Error'); | ||
| $$.SANDBOX.stub(connection, 'singleRecordQuery') | ||
| .withArgs("SELECT Id FROM BotDefinition WHERE DeveloperName='test_agent'") | ||
| .throws(new SfError('No record found', 'SingleRecordQuery_NoRecords')); | ||
| const telemetryStub = $$.SANDBOX.stub(Lifecycle.getInstance(), 'emitTelemetry').resolves(); | ||
|
|
||
| publisher = new ScriptAgentPublisher(connection, sfProject, agentJson, false); | ||
|
|
||
| const error = await expectPublishError(); | ||
|
|
||
| expect(error.name).to.equal('CreateAgentJsonError'); | ||
| expect(error.data).to.not.have.property('publishedAgent'); | ||
| expect(telemetryStub.called).to.be.false; | ||
| }); |
There was a problem hiding this comment.
4. Suggestion: this test covers a response without ids, not a POST that throws. The publishAgentJson-Error mock returns a body without botId/botVersionId, so it exercises the CreateAgentJsonError branch. Please add a case where the request rejects (HTTP 4xx/5xx thrown by MaybeMock.request) and assert there's no publishedAgent and no telemetry, so both pre-commit shapes are pinned down.
…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.
nhalko-sf
left a comment
There was a problem hiding this comment.
Automated pre-review, round 2 of 2 (an extra pair of eyes, not a gate). Verdict: approve. There are no blockers and one optional nit (inline).
84ef183 fixes all round-1 findings. The <target> value matches deployAuthoringBundle (${developerName}.${botVersionName}).
| # | Round-1 finding | Status |
|---|---|---|
| 1 | The recovery action wasn't actionable (name <target>) |
Fixed: target is now on PublishedAgentInfo, there's a target-specific message plus a generic fallback, and both are tested |
| 2 | Record which step failed | Fixed: failedStep is in the data, the debug log and telemetry, and is tested for all three steps |
| 3 | writeFile in finally masks the deploy error |
Fixed: it's now in a nested try/catch, and a test covers the poll throwing |
| 4 | No test for a rejecting POST | Fixed |
| 5 | Ambiguous POST failure not annotated | Fixed: JSDoc says to re-query the latest BotVersion before retrying |
| 6 | How callers surface the error | Out of scope here. The vscode-agents UI still shows only sfError.message, so it needs its own follow-up item |
General (no line anchor)
- Cleanup failure: if the cleanup
writeFileitself fails,<target>stays in local source with only a debug log. That's acceptable, since the recovery action tells the user to set it anyway, but that branch has no test. --jsonoutput: whetherdata.publishedAgentreachessf agent publish --jsonoutput can only be checked in plugin-agent.- CI: the unit-test jobs were still running at review time. The other checks, including CLA, pass.
|
|
||
| # publishedBeforeFailureTargetActions | ||
|
|
||
| The agent was already published to the org as %s before this step failed. Don't run the publish command again, because that creates another, duplicate version. Fix the cause of the error, then finish the remaining steps: retrieve the agent metadata if that step failed, then deploy the authoring bundle with `<target>%s</target>` set in its bundle-meta.xml. Without the target, the bundle isn't linked to the version that was already published. |
There was a problem hiding this comment.
Nit (optional): this message always says "retrieve the agent metadata if that step failed", even when the publisher ran with skipRetrieve and no retrieve happened. failedStep already tells callers which step failed, so it's only wording. Consider dropping the retrieve clause when the retrieve was skipped.
…was skipped @W-24949433@
…-post-commit-error
What does this PR do?
Follow-up to #350 (W-23735101).
publishAgentJsoncommits the new BotVersion in its first step (the POST toai-agent/v1.1/authoring/agents[/<botId>/versions]). The steps after that can still throw:getBotVersion,retrieveAgentMetadata(agentRetrievalError) anddeployAuthoringBundle(authoringBundleDeploymentError). When one does,sf agent publish authoring-bundlefails, and the error has nobotIdorbotVersionId. 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 newtoPublishedAgentError. The rethrown error:data.publishedAgent = { developerName, botId, botVersionId, versionNumber?, target?, failedStep }, wherefailedStepisbotVersionLookup,retrieveorbundleDeploy;<target>(<agent>.<version>) the bundle-meta.xml needs for a manual deploy, and it only mentions the retrieve step when retrieve wasn't skipped;agent_publish_post_commit_failedtelemetry, both includingfailedStep.deployAuthoringBundle: the<target>cleanup in the bundle-meta now runs in afinally. 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.PublishedAgentInfo. This is additive only. Its JSDoc notes that a missingdata.publishedAgentdoesn'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,dataandactionsshow 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 buildand lint are clean.test/agentPublisher.test.ts:data.publishedAgent, the don't-republish action and telemetry;getBotVersionfailure reports the BotVersion Id without aversionNumber;publishedAgentinto the error's existingdata;<target>is removed from the local bundle-meta even when the deploy poll throws;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 ESMwriteFileimport isn't practical to stub.yarn testfails 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)