Skip to content

Add optional agentId to ruleTrigger for easy filtering on UI#1322

Closed
visagang wants to merge 3 commits intoSciSharp:masterfrom
visagang:features/vguruparan
Closed

Add optional agentId to ruleTrigger for easy filtering on UI#1322
visagang wants to merge 3 commits intoSciSharp:masterfrom
visagang:features/vguruparan

Conversation

@visagang
Copy link
Copy Markdown
Contributor

No description provided.

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add optional AgentIds to rule triggers for agent-specific filtering

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add optional AgentIds property to IRuleTrigger interface for UI filtering
• Implement agent-specific rule trigger filtering endpoint in controller
• Enable filtering triggers by agent ID with fallback to all triggers
Diagram
flowchart LR
  A["IRuleTrigger Interface"] -->|"adds AgentIds property"| B["AgentIds: string[]"]
  C["AgentController"] -->|"new endpoint"| D["GET /rule/triggers/{agentId}"]
  D -->|"filters by AgentIds"| E["Filtered Triggers"]
  E -->|"returns"| F["AgentRuleViewModel List"]
Loading

Grey Divider

File Changes

1. src/Infrastructure/BotSharp.Abstraction/Rules/IRuleTrigger.cs ✨ Enhancement +6/-0

Add optional AgentIds property to interface

• Add new optional AgentIds property to IRuleTrigger interface
• Property defaults to empty array for backward compatibility
• Documented as UI display/filtering only, not used in execution logic

src/Infrastructure/BotSharp.Abstraction/Rules/IRuleTrigger.cs


2. src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs ✨ Enhancement +14/-0

Add agent-specific rule trigger filtering endpoint

• Add new HTTP GET endpoint /rule/triggers/{agentId} for agent-specific filtering
• Filter triggers by agent ID with fallback to all triggers if AgentIds is empty
• Return filtered triggers as AgentRuleViewModel objects sorted by name
• Preserve existing /rule/triggers endpoint for retrieving all triggers

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Apr 13, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. AgentIds.Contains null dereference📘
Description
The filter condition can dereference x.AgentIds when it is null because x.AgentIds?.Count() == 0
evaluates to false and the || then evaluates x.AgentIds.Contains(agentId). This can cause a
runtime NullReferenceException at the API boundary instead of returning a safe fallback.
Code

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs[12]

+        triggers = triggers.Where(x => x.AgentIds?.Count() == 0 || x.AgentIds.Contains(agentId));
Evidence
PR Compliance ID 2 requires explicit null/empty guards at API boundaries and correct boolean logic
to avoid dereferencing potentially-null values. The new predicate uses || and calls
x.AgentIds.Contains(agentId) even when x.AgentIds is null.

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs[12-12]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The predicate `x.AgentIds?.Count() == 0 || x.AgentIds.Contains(agentId)` can throw when `x.AgentIds` is null.
## Issue Context
This is an API endpoint filter and should defensively handle null/empty `AgentIds` without exceptions.
## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs[12-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs Outdated
@visagang visagang closed this Apr 13, 2026
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