test: fix flaky agent create NUT (Bot User race) - #484
Draft
nico-pappagianis wants to merge 1 commit into
Draft
Conversation
The 'agent create' NUT generated a spec with no agentUser and ran 'agent create' against it, so agentSettings.userId was never set and core auto-created the licensed Bot User in the same transaction as the BotDefinition save. The pre-save validation trigger intermittently could not see the fresh license/permset assignment, failing with 'User doesn't have access to agent.' Shared setup already provisions an agent user via 'org create agent-user' and exposes it through getAgentUsername(), but it was only wired into publish, not create. Write that already-committed user into the spec's agentUser field so 'agent create' threads agentSettings.userId and core reuses it instead of racing on a new one.
Contributor
|
This PR lacks any commits of the 'fix' or 'feat' type, and therefore will not trigger a release. To silence all further warnings, react to this warning comment (or any other) with the 👀 emoji. NOTE: If your repo uses squash commits, make sure to add the appropriate conventional commit prefix (e.g., 'fix:', 'feat:', 'chore:', etc) in the squash commit message. |
nico-pappagianis
added a commit
that referenced
this pull request
Aug 28, 2026
Reuse the Bot User pre-provisioned in shared setup by writing agentUser into the spec, instead of letting core auto-create one in the same transaction as the BotDefinition save. That auto-create intermittently races the pre-save validation trigger and fails with "User doesn't have access to agent". Mirrors #484.
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.
What
test/nuts/z0.agent.create.nut.ts(agent create > should create new agent in org) fails intermittently, pod-dependent, with:Root cause
The
customeragentType maps to core'sEinsteinServiceAgent, which requires a Bot User holding the Digital Agent license +AgentforceServiceAgentUserpermset.agent createonly setsagentSettings.userIdwhen the spec YAML has anagentUserfield (src/commands/agent/create.ts). The NUT generated a spec with noagentUser, soAgent.createreceived nouserIdand core auto-created the Bot User in the same transaction as the BotDefinition save. The pre-save validation trigger intermittently cannot see the fresh license/permset assignment and rejects with "User doesn't have access to agent."Shared setup already provisions an agent user via
org create agent-userand exposes it throughgetAgentUsername(), but it was only wired into publish (z2), not create.Fix
Write the already-committed agent user into the spec's
agentUserfield before runningagent create, so the command threadsagentSettings.userIdand core reuses the committed user instead of racing on a fresh one. Mirrors the analogous fix in@salesforce/agents(forcedotcom/agents#358).Testing
yarn build(compile + lint) passes.Test-only change; no runtime code touched.