Skip to content

[29.1] Don't reuse a Payables Agent user that has no permissions in the company - #14674

Open
Jatin Kumar (Explorer986) wants to merge 1 commit into
releases/29.1from
backport/640641-releases-29.1
Open

Jatin Kumar (Explorer986) wants to merge 1 commit into
releases/29.1from
backport/640641-releases-29.1

Conversation

@Explorer986

@Explorer986 Jatin Kumar (Explorer986) commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #14527

Backports #14527 to releases/29.1.

What & why

When a company is deleted and recreated with the same name, the agent user of the deleted company still exists in the environment, with the same agent user name. The setup found it by that name and reused it, but its permissions belonged to the deleted company, so the first task (an uploaded invoice or the trial upload) failed with "The task cannot be set to ready because the agent has no access control permissions in the ... company".

Now the lookup by user name only reuses an agent that can access the current company, using the same check the agent framework runs before it accepts a task. Otherwise the setup creates a new agent, which gets its default permissions when it's created, so the first task works. An agent linked in the company's setup is used as before.

On this release the Payables Agent setup code is still in one codeunit, so the same change is made in GetAgent there.

Linked work

Fixes AB#661009

Risk & compatibility

Low. Only the fallback by user name changes, and only for an agent without access to the current company, which couldn't process tasks there anyway.

@Explorer986
Jatin Kumar (Explorer986) requested a review from a team November 29, 2026 07:32
@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 Team: Finance GitHub request for Finance area labels Nov 29, 2026
@github-actions github-actions Bot added this to the Version 29.1 milestone Nov 29, 2026
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Accept with Suggestions

What this PR does

Rejects a same-name Payables Agent that cannot access the current company. This lets setup create a replacement when a company has been deleted and recreated with the same name.

The check uses the same allowed-company query and current-company filter as task creation. Clearing the rejected Agent makes GetAgent return false and gives setup a blank security ID, so the existing creation path creates a new agent with current-company permissions. Creation handles the surviving user's name collision. Eligible fallback agents and the configured-security-ID fast path remain unchanged.

Problem-solution fit

Fit: Strong

The change addresses the stale-agent permission failure at discovery instead of granting permissions to the old user. It stays focused on name-based fallback; the separate activation terms and mailbox checks are unchanged.

Suggestions

S1 (🟠 Moderate): Add regression coverage for fallback agent eligibility
Add a Payables Agent regression test for a same-name agent without current-company permissions. Verify that setup creates a new agent with permissions and that an eligible fallback agent is still reused. Existing task-permission tests do not exercise this lookup.

Risk assessment and necessity

Risk: Low and limited to name-based discovery when the configured agent cannot be found. The company-access check matches task creation, including all-company permissions. Public signatures, posting logic, amounts and ledger entries are unchanged. The coverage gap is non-blocking; this review is source-only, with no independent release-specific runtime verification.

Necessity: Without this change, a surviving same-name agent without current-company access can be reused and the first task fails. Recovery otherwise requires repairing agent setup or permissions. The small release adaptation is proportionate to that failure.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=14674 round=1 by=alexei-dobriansky at=2026-11-29T22:17:31.3242243Z lastSha=ed748d0ad54c1d6c66eec7ab7e0d62d6e4632172 reviewKey=3ce8d9a670756bc67410a9da9e8e5b3d28adc6bedc6468694c076edf644058b9 suggestions=S1@1dced2e5

This branch was successfully deployed

1 active deployment
triage — ed748d0a Deployed Nov 29, 2026 by Explorer986 via Classify team ownership #12330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Team: Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants