Skip to content

test: fix flaky agent create NUT (Bot User race) - #484

Draft
nico-pappagianis wants to merge 1 commit into
mainfrom
chore/fix-nut-user-race-condition
Draft

test: fix flaky agent create NUT (Bot User race)#484
nico-pappagianis wants to merge 1 commit into
mainfrom
chore/fix-nut-user-race-condition

Conversation

@nico-pappagianis

Copy link
Copy Markdown
Collaborator

What

test/nuts/z0.agent.create.nut.ts (agent create > should create new agent in org) fails intermittently, pod-dependent, with:

Error creating agent : User doesn't have access to agent.
isSuccess: false

Root cause

The customer agentType maps to core's EinsteinServiceAgent, which requires a Bot User holding the Digital Agent license + AgentforceServiceAgentUser permset. agent create only sets agentSettings.userId when the spec YAML has an agentUser field (src/commands/agent/create.ts). The NUT generated a spec with no agentUser, so Agent.create received no userId and 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-user and exposes it through getAgentUsername(), but it was only wired into publish (z2), not create.

Fix

Write the already-committed agent user into the spec's agentUser field before running agent create, so the command threads agentSettings.userId and 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.
  • The NUT needs a scratch org + default dev hub, not run in this environment. Because the failure is a race, verify with several runs across pods before trusting green.

Test-only change; no runtime code touched.

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.
@github-actions

Copy link
Copy Markdown
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.
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.

1 participant