Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Microsoft.Agent.PayablesAgent;

using System.Agents;

codeunit 3319 "PA Agent Archiving" implements IAgentArchiving
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

procedure IsArchivingSupported(): Boolean
begin
exit(false);
end;
}
Comment thread
krupybalu marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion src/Apps/W1/PayablesAgent/app/PAAgentMetadata.EnumExt.al
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ enumextension 3304 "PA Agent Metadata" extends "Agent Metadata Provider"
value(3303; "Payables Agent")
{
Caption = 'Payables Agent', Locked = true;
Implementation = IAgentFactory = "Payables Agent", IAgentMetadata = "Payables Agent", IAgentTaskExecution = "PA Agent Task Execution";
Implementation = IAgentFactory = "Payables Agent", IAgentMetadata = "Payables Agent", IAgentTaskExecution = "PA Agent Task Execution", IAgentArchiving = "PA Agent Archiving";
}
}
2 changes: 1 addition & 1 deletion src/System Application/App/Agent/Setup/AgentCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ page 4315 "Agent Card"

CopilotAvailabilityTxt := AgentImpl.GetCopilotAvailabilityDisplayText(Rec);
AgentIsArchived := Rec.Substate = Rec.Substate::Archived;
ArchiveActionEnabled := (not AgentIsArchived) and Rec."Can Curr. User Configure Agent";
ArchiveActionEnabled := (not AgentIsArchived) and Rec."Can Curr. User Configure Agent" and AgentImpl.IsArchivingSupported(Rec);
Comment thread
krupybalu marked this conversation as resolved.
Outdated
StateEditable := not AgentIsArchived;
end;

Expand Down
16 changes: 16 additions & 0 deletions src/System Application/App/Agent/Setup/AgentImpl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,28 @@ codeunit 4301 "Agent Impl."
if Agent.Substate = Agent.Substate::Archived then
exit; // Archiving is terminal; idempotent no-op avoids the platform "archived agent cannot be modified" error on re-archive.

if not IsArchivingSupported(Agent) then
Comment thread
krupybalu marked this conversation as resolved.
Error(ArchivingNotSupportedErr);

if Agent.State <> Agent.State::Disabled then
Error(DeactivateBeforeArchivingErr);

Agent.Substate := Agent.Substate::Archived;
Agent.Modify(true);
end;

procedure IsArchivingSupported(Agent: Record Agent): Boolean
Comment thread
krupybalu marked this conversation as resolved.
Outdated
var
AgentArchiving: Interface IAgentArchiving;
begin
if IsNullGuid(Agent."User Security ID") then
exit(false);

AgentArchiving := Agent."Agent Metadata Provider";
Comment thread
krupybalu marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Error\ Handling}$

AgentImpl.IsArchivingSupported(Agent) (local overload) does AgentArchiving := Agent."Agent Metadata Provider"; exit(AgentArchiving.IsArchivingSupported());, which requires every enum value of "Agent Metadata Provider" to implement IAgentArchiving. Confirmed by inspecting the current enum extensions: the default "SDK Mock Agent" value (MockAgentMetaProv.EnumExt.al), "SO Agent" (SOAMetadataProvider.EnumExt.al) and "Custom Agent" (CustomAgentMetadataProvider.EnumExt.al) do NOT declare an IAgentArchiving implementation. Casting such a value to the IAgentArchiving interface variable raises an unhandled AL runtime error ("enum value does not implement interface") instead of returning a Boolean. This directly contradicts the new test assertion added in the same PR, Assert.IsTrue(Agent.IsArchivingSupported(AgentId), 'Archiving should be supported for a type that does not opt out') in AgentTest.Codeunit.al (ArchiveDisabledAgentSetsArchived, ~line 997), which calls IsArchivingSupported on an agent created via GetOrCreateDefaultAgent — i.e. an "SDK Mock Agent" — and expects true, but the call will error instead. The same crash risk applies in production to the AgentCard/AgentList archive actions for SO Agent and Custom Agent users. Add an explicit guard (e.g. check whether the interface is implemented, or default to a Boolean via a safe pattern) so agent types that have not opted into IAgentArchiving return a sane default instead of throwing.

Agent judgement — not directly backed by a BCQuality knowledge article.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.35.4


exit(AgentArchiving.IsArchivingSupported());
end;

procedure IsArchived(AgentUserSecurityID: Guid): Boolean
var
Agent: Record Agent;
Expand Down Expand Up @@ -628,6 +643,7 @@ codeunit 4301 "Agent Impl."
AgentDoesNotExistErr: Label 'Agent does not exist.';
AgentArchivedCannotBeModifiedErr: Label 'The agent is archived and cannot be modified.';
DeactivateBeforeArchivingErr: Label 'Deactivate the agent before archiving it.';
ArchivingNotSupportedErr: Label 'This type of agent cannot be archived yet.';
Comment thread
krupybalu marked this conversation as resolved.
Outdated
AutoLbl: Label 'Auto';
NoActiveAgentsErr: Label 'There are no active agents setup on the system.';
NoAgentsAvailableNotificationLbl: Label 'Business Central agents are currently not available in your country.';
Expand Down
2 changes: 1 addition & 1 deletion src/System Application/App/Agent/Setup/AgentList.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ page 4316 "Agent List"
begin
CopilotAvailabilityTxt := AgentImpl.GetCopilotAvailabilityDisplayText(Rec);
AgentIsArchived := Rec.Substate = Rec.Substate::Archived;
ArchiveActionEnabled := (not AgentIsArchived) and Rec."Can Curr. User Configure Agent";
ArchiveActionEnabled := (not AgentIsArchived) and Rec."Can Curr. User Configure Agent" and AgentImpl.IsArchivingSupported(Rec);
end;

local procedure SetCompanyFilter()
Expand Down
Loading