fix(core): skip Discord hooks for Discord-triggered jobs#214
fix(core): skip Discord hooks for Discord-triggered jobs#214oheckmann74 wants to merge 3 commits into
Conversation
…uplicate messages When a job is triggered from Discord, the Discord manager already streams all output to the channel in real-time via the onMessage callback. The hooks system was also firing Discord after_run/on_error hooks, causing duplicate messages in the channel. This fix: - Adds triggerType to HookContext so hooks know how a job was triggered - Populates triggerType from job metadata's trigger_type field - Filters out Discord-type hooks when triggerType is "discord" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughJob hook execution now omits Discord-type hooks when the job's trigger is Discord. Changes
Sequence DiagramsequenceDiagram
participant Trigger as Job Trigger
participant Controller as Job Controller
participant Executor as Hook Executor
Trigger->>Controller: start job (includes triggerType)
Controller->>Controller: buildHookContext (includes triggerType)
Controller->>Controller: if triggerType == "discord" then remove discord hooks from after_run/on_error
Controller->>Controller: log if hooks were filtered
Controller->>Executor: executeHooks(filtered hooks, hookContext)
Executor-->>Controller: execution result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/hooks/types.ts (1)
152-159: Consider using theTriggerTypeenum for stronger type safety.The
triggerTypefield is typed asstring, but theTriggerTypeSchemainstate/schemas/job-metadata.tsdefines a specific set of valid values ("manual","schedule","webhook","chat","discord","slack","web","fork"). Using the inferredTriggerTypetype would provide better type safety and IDE autocomplete.♻️ Suggested improvement
+import type { TriggerType } from "../state/schemas/job-metadata.js"; + /** * How the job was triggered (e.g. "manual", "schedule", "discord", "slack") * * Used to prevent duplicate notifications - for example, Discord hooks are * skipped when triggerType is "discord" because the Discord manager already * streams output to the channel in real-time. */ -triggerType?: string; +triggerType?: TriggerType;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/hooks/types.ts` around lines 152 - 159, The triggerType property is currently typed as string; change it to use the project's TriggerType type/enum for stronger typing and autocomplete by importing the TriggerType (or the exported type inferred from TriggerTypeSchema) from the job-metadata schema module and updating the declaration triggerType?: string; to triggerType?: TriggerType; (and adjust any related imports/usages in functions that read or set triggerType to match the enum values). Ensure you reference the TriggerType (or exported type name from state/schemas/job-metadata.ts) and update any consumers of the Hooks types to accept the narrowed type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/hooks/types.ts`:
- Around line 152-159: The triggerType property is currently typed as string;
change it to use the project's TriggerType type/enum for stronger typing and
autocomplete by importing the TriggerType (or the exported type inferred from
TriggerTypeSchema) from the job-metadata schema module and updating the
declaration triggerType?: string; to triggerType?: TriggerType; (and adjust any
related imports/usages in functions that read or set triggerType to match the
enum values). Ensure you reference the TriggerType (or exported type name from
state/schemas/job-metadata.ts) and update any consumers of the Hooks types to
accept the narrowed type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fded9310-6a52-4c60-a4fb-32b570681a43
📒 Files selected for processing (2)
packages/core/src/fleet-manager/job-control.tspackages/core/src/hooks/types.ts
Addresses CodeRabbit review feedback — import and use the TriggerType type from job-metadata schema for stronger type safety and IDE autocomplete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/hooks/types.ts (1)
154-162: Consider documenting all trigger variants (or referencing the schema directly).The comment currently shows only a subset of
TriggerTypevalues; this can drift fromTriggerTypeSchemaand mislead future edits. Prefer either listing all enum values or explicitly saying this is a non-exhaustive subset tied tojob-metadata.ts.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/hooks/types.ts` around lines 154 - 162, Update the doc comment for the TriggerType field to avoid misleading readers by either enumerating every variant from TriggerType (or TriggerTypeSchema) or explicitly marking the list as non-exhaustive and pointing to the canonical source; specifically update the comment above triggerType?: TriggerType in types.ts to reference TriggerTypeSchema or job-metadata.ts (or list all enum values from TriggerType) so future changes to TriggerType/TriggerTypeSchema remain authoritative.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/hooks/types.ts`:
- Around line 154-162: Update the doc comment for the TriggerType field to avoid
misleading readers by either enumerating every variant from TriggerType (or
TriggerTypeSchema) or explicitly marking the list as non-exhaustive and pointing
to the canonical source; specifically update the comment above triggerType?:
TriggerType in types.ts to reference TriggerTypeSchema or job-metadata.ts (or
list all enum values from TriggerType) so future changes to
TriggerType/TriggerTypeSchema remain authoritative.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: be7a951c-40d1-42e8-a5bc-e512f0da7cb8
📒 Files selected for processing (1)
packages/core/src/hooks/types.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
onMessage. After the job completes,executeHooksalso fires any configureddiscord-type hooks (after_runandon_error), resulting in duplicate messages in the Discord channel.triggerTypeis"discord", preventing the duplication while leaving all other hook types (shell, webhook, slack) unaffected.triggerTypetoHookContextso hook execution can be trigger-aware.Changes
packages/core/src/fleet-manager/job-control.ts: Filter Discord hooks fromafter_runandon_errorarrays whencontext.triggerType === "discord". PlumbtriggerTypefromjobMetadata.trigger_typeintobuildHookContext().packages/core/src/hooks/types.ts: Add optionaltriggerTypefield toHookContextinterface with documentation.Test plan
after_runhook and trigger a job from Discord — verify only one response appears (not duplicated)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Improvements