optimze crontab identity#1378
Conversation
PR Summary by QodoFix crontab hook identity propagation across HookEmitter async boundaries
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1. Case-sensitive Triggers.Contains match
|
| HookEmitter.Emit<ICrontabHook>(_services, hook => | ||
| { | ||
| if (hook.Triggers == null || hook.Triggers.Contains(item.Title)) | ||
| { | ||
| hook.OnAuthenticate(item); | ||
| } | ||
| }, item.AgentId); | ||
|
|
||
| // Phase 2 - Execute. | ||
| await HookEmitter.Emit<ICrontabHook>(_services, async hook => | ||
| { | ||
| if (hook.Triggers == null || hook.Triggers.Contains(item.Title)) | ||
| { |
There was a problem hiding this comment.
1. Case-sensitive triggers.contains match 📘 Rule violation ≡ Correctness
hook.Triggers.Contains(item.Title) uses default (case-sensitive/culture-sensitive) string equality, which can break identifier-like trigger matching when casing differs. This violates the requirement to use ordinal, case-insensitive comparisons/collections for identifier lookups.
Agent Prompt
## Issue description
`ScheduledTimeArrived` matches triggers using `hook.Triggers.Contains(item.Title)` which is case-sensitive by default. The compliance requirement is to use ordinal, case-insensitive comparisons for identifier-like strings.
## Issue Context
This PR introduced/rewrote the trigger-filtering logic in `ScheduledTimeArrived` (now executed in two phases), and the trigger match is performed in both phases.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs[136-148]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| HookEmitter.Emit<ICrontabHook>(_services, hook => | ||
| { | ||
| if (hook.Triggers == null || hook.Triggers.Contains(item.Title)) | ||
| { | ||
| hook.OnAuthenticate(item); | ||
| } | ||
| }, item.AgentId); | ||
|
|
||
| // Phase 2 - Execute. | ||
| await HookEmitter.Emit<ICrontabHook>(_services, async hook => | ||
| { | ||
| if (hook.Triggers == null || hook.Triggers.Contains(item.Title)) | ||
| { | ||
| await hook.OnTaskExecuting(item); | ||
| await hook.OnCronTriggered(item); | ||
| await hook.OnTaskExecuted(item); |
There was a problem hiding this comment.
2. Hook instances may differ 🐞 Bug ≡ Correctness
ScheduledTimeArrived now resolves ICrontabHook implementations twice (once for Phase 1 auth, again for Phase 2 execution); if any hook is registered as transient, OnAuthenticate can run on a different instance than OnCronTriggered, breaking per-hook state that was initialized during authentication.
Agent Prompt
## Issue description
`CrontabService.ScheduledTimeArrived` performs two separate `HookEmitter.Emit` calls, which re-resolve hooks from DI each time. This can produce different hook instances for transient lifetimes, causing `OnAuthenticate` state to be lost before `OnTaskExecuting/OnCronTriggered/OnTaskExecuted`.
## Issue Context
- Today, the known `ICrontabHook` registrations in-repo are `AddScoped`, so this may not reproduce right now, but the contract doesn’t enforce that and plugins can introduce transient hooks.
## Fix Focus Areas
- Resolve the hook list once and reuse it for both phases (or add an overload that accepts an already-resolved hook list).
- file: src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs[129-153]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.