Skip to content

feat(api-service): use new workflow run count table in usage page#10074

Open
djabarovgeorge wants to merge 4 commits intonextfrom
polish-workflow-run-count-usage
Open

feat(api-service): use new workflow run count table in usage page#10074
djabarovgeorge wants to merge 4 commits intonextfrom
polish-workflow-run-count-usage

Conversation

@djabarovgeorge
Copy link
Contributor

@djabarovgeorge djabarovgeorge commented Feb 23, 2026

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

What changed

This PR transitions workflow run analytics from trace-based data to a count-based rollup table approach. It introduces a new feature flag (IS_WORKFLOW_RUN_COUNT_ENABLED) to toggle between data sources while maintaining backward compatibility. The change affects both API use cases that build analytics charts and the dashboard component that renders them, with new repository methods added to query aggregated workflow run counts.

Affected areas

  • api: Updated build-workflow-by-volume-chart and build-workflow-runs-trend-chart use cases to read from WorkflowRunCountRepository with feature-flagged conditional logic that falls back to the legacy workflow runs data path.
  • dashboard: WorkflowRunsTrendChart component now checks the new IS_WORKFLOW_RUN_COUNT_ENABLED flag instead of the deprecated traces-based flag.
  • application-generic: Added getWorkflowVolumeData() and getWorkflowRunsTrendData() methods to WorkflowRunCountRepository to query aggregated workflow run counts with date range and environment/organization filtering.
  • dal: Enhanced NotificationTemplateRepository.findByTriggerIdentifierBulk() with overloaded signatures supporting optional field projection via a select parameter.
  • shared: Registered WorkflowRunCountRepository in ANALYTICS_PROVIDERS and replaced the deprecated IS_WORKFLOW_RUN_TREND_FROM_TRACES_ENABLED flag with IS_WORKFLOW_RUN_COUNT_ENABLED in the feature flags enum.

Key technical decisions

  • Feature flag-gated rollout: Both API use cases check IS_WORKFLOW_RUN_COUNT_ENABLED to conditionally route between the new count-based queries and legacy workflow runs path, enabling safe gradual migration.
  • New repository methods execute ClickHouse queries aggregating by workflow_run_id (for volume) and date/event_type (for trends).
  • Field projection support added to findByTriggerIdentifierBulk with conditional population of the steps.template relation to optimize query performance.

Testing

No new tests were added. The feature is behind a feature flag allowing manual verification and gradual rollout before full migration.

… data instead of traces

- Replaced TraceLogRepository with WorkflowRunCountRepository in build-workflow-runs-trend-chart.usecase.ts.
- Updated feature flag from IS_WORKFLOW_RUN_TREND_FROM_TRACES_ENABLED to IS_WORKFLOW_RUN_TREND_FROM_ROLLUP_ENABLED.
- Modified chart building logic to utilize workflow run counts for trend data.
- Added new method getWorkflowRunsTrendData in WorkflowRunCountRepository for fetching trend data from the database.
…port

- Introduced new method getWorkflowVolumeData in WorkflowRunCountRepository to fetch workflow volume data.
- Updated BuildWorkflowByVolumeChart to utilize workflow run counts based on feature flag for rollup data.
- Integrated notification template fetching to associate workflow names with their identifiers in the chart data.
- Refactored chart building logic to accommodate both rollup and standard workflow run data.
@netlify
Copy link

netlify bot commented Feb 23, 2026

Deploy Preview for dashboard-v2-novu-staging failed. Why did it fail? →

Name Link
🔨 Latest commit a85397d
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/69bae5e1e44aa500080e1e55

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

Hey there and thank you for opening this pull request! 👋

We require pull request titles to follow specific formatting rules and it looks like your proposed title needs to be adjusted.

Your PR title is: feat(api-service): use new workflow run count table in usage page

Requirements:

  1. Follow the Conventional Commits specification
  2. As a team member, include Linear ticket ID at the end: fixes TICKET-ID or include it in your branch name

Expected format: feat(scope): Add fancy new feature fixes NOV-123

Details:

PR title must end with 'fixes TICKET-ID' (e.g., 'fixes NOV-123') or include ticket ID in branch name

@github-actions
Copy link
Contributor

LaunchDarkly flag references

❌ 1 flag removed

Name Key Aliases found Info
IS_WORKFLOW_RUN_TREND_FROM_TRACES_ENABLED IS_WORKFLOW_RUN_TREND_FROM_TRACES_ENABLED ✅ all references removed

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 719b2c2b-1ca1-496a-935a-c0886917ca81

📥 Commits

Reviewing files that changed from the base of the PR and between 924a4cd and a85397d.

📒 Files selected for processing (1)
  • apps/api/src/app/shared/shared.module.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/src/app/shared/shared.module.ts

📝 Walkthrough

Walkthrough

Feature-flagged switch to use rollup-based workflow run counts: adds WorkflowRunCountRepository query methods, registers the repository, introduces IS_WORKFLOW_RUN_COUNT_ENABLED flag, updates two analytics use cases and the dashboard to prefer count-based data when enabled, and adds overloads to NotificationTemplateRepository.findByTriggerIdentifierBulk.

Changes

Cohort / File(s) Summary
API usecases
apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/...build-workflow-by-volume-chart.usecase.ts, apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/...build-workflow-runs-trend-chart.usecase.ts
Add feature-flag gate IS_WORKFLOW_RUN_COUNT_ENABLED to switch data sources; inject WorkflowRunCountRepository and FeatureFlagsService; add/rename private methods to build charts from workflow run counts; adjust control flow to fall back to legacy paths when flag is off.
Analytics providers wiring
apps/api/src/app/shared/shared.module.ts
Export and register WorkflowRunCountRepository in ANALYTICS_PROVIDERS.
Dashboard UI
apps/dashboard/src/components/analytics/charts/workflow-runs-trend-chart.tsx
Switch feature flag key to IS_WORKFLOW_RUN_COUNT_ENABLED and render final vs legacy chart based on new flag.
Analytics repository (ClickHouse)
libs/application-generic/src/services/analytic-logs/workflow-run-count/workflow-run-count.repository.ts
New repository methods: getWorkflowVolumeData(...) and getWorkflowRunsTrendData(...) to query ClickHouse for workflow volumes and trends.
DAL - Notification templates
libs/dal/src/repositories/notification-template/notification-template.repository.ts
Add overloads and implementation changes for findByTriggerIdentifierBulk to support optional select projection and conditional population of steps.template.
Shared types
packages/shared/src/types/feature-flags.ts
Replace enum flag IS_WORKFLOW_RUN_TREND_FROM_TRACES_ENABLED with IS_WORKFLOW_RUN_COUNT_ENABLED.
Manifest / package
manifest_file, package.json
Small dependency/manifest adjustments related to new/updated packages.

Sequence Diagram(s)

sequenceDiagram
  participant Dashboard
  participant API as Novu API
  participant UseCase as BuildChart UseCase
  participant FF as FeatureFlagsService
  participant CountRepo as WorkflowRunCountRepository
  participant TemplateRepo as NotificationTemplateRepository
  participant CH as ClickHouse

  Dashboard->>API: Request chart data
  API->>UseCase: execute(startDate,endDate,env,org)
  UseCase->>FF: isEnabled(IS_WORKFLOW_RUN_COUNT_ENABLED)
  alt flag ON
    UseCase->>CountRepo: getWorkflowVolumeData(env,org,start,end)
    CountRepo->>CH: execute volume query
    CH-->>CountRepo: rows [{workflow_run_id,count},...]
    CountRepo-->>UseCase: rows
    UseCase->>TemplateRepo: findByTriggerIdentifierBulk(env, identifiers, select:['identifier','name'])
    TemplateRepo->>DB: query templates
    DB-->>TemplateRepo: templates with names
    TemplateRepo-->>UseCase: mapped names
    UseCase-->>API: chart payload (workflowName,count)
  else flag OFF
    UseCase->>UseCase: buildChartFromWorkflowRuns(...) (legacy flow)
    UseCase-->>API: chart payload (workflowName,count)
  end
  API-->>Dashboard: return chart payload
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • scopsy
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title does not follow the required Conventional Commits format. While it uses a valid type (feat) and contains a scope, the scope 'api-service' is not in the allowed list. Valid scopes are: api, dashboard, worker, ws, webhook, shared, dal, application-generic, js, react, react-native, nextjs, providers, framework, root. Change the scope from 'api-service' to 'api' to comply with the Conventional Commits requirements. The corrected title should be: 'feat(api): use new workflow run count table in usage page'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts (1)

44-81: The rollup chart-building logic is well-structured. Good use of selective field projection (['name', 'triggers']) and the fallback to workflow_run_id when no template name is found.

One consideration: workflow_run_id in the rollup table stores a trigger identifier, not an actual workflow run ID. This naming mismatch could confuse future maintainers reading this code. A clarifying inline comment at line 61 would help, e.g., noting that workflow_run_id is actually a trigger identifier in this context.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`
around lines 44 - 81, Add an inline clarifying comment in
buildChartFromWorkflowRunCount explaining that the rollup column workflow_run_id
actually contains a trigger identifier (not a real workflow run ID) to avoid
confusion for future maintainers; place the comment near where workflowVolumes
is mapped to triggerIdentifiers / when reading row.workflow_run_id (references:
buildChartFromWorkflowRunCount, workflowVolumes, triggerIdentifiers,
nameByIdentifier) so it's obvious why we use workflow_run_id as the lookup key
for template names.
libs/dal/src/repositories/notification-template/notification-template.repository.ts (1)

66-98: Clean overload design for field projection support.

The conditional steps.template population (line 93) is a good optimization. One subtle note: when select is provided without _id, MongoDB still returns _id by default, so consumers will get _id even if not listed in select. This is likely desirable but worth being aware of — the Pick<NotificationTemplateEntity, K> return type won't include _id in its type signature unless explicitly selected, creating a minor type/runtime mismatch.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@libs/dal/src/repositories/notification-template/notification-template.repository.ts`
around lines 66 - 98, The runtime projection currently omits explicit _id
handling so MongoDB will still include _id by default while the TypeScript
return type Pick<NotificationTemplateEntity, K> may not include it; update
findByTriggerIdentifierBulk to ensure projection matches the types by adding
_id: 1 whenever a select array is provided (i.e., when building projection from
select ensure projection._id = 1 if not already present), and keep the rest of
the logic (projection variable, baseQuery, query population, and the returned
mapEntities) unchanged so runtime and types remain consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`:
- Around line 30-41: The code silently ignores workflowIds when the rollup
feature flag is enabled; update the call-site and implementation so workflowIds
are not dropped: change buildChartFromWorkflowRunCount to accept an optional
workflowIds parameter and apply that filter inside its logic (or if filtering by
workflow is not supported, at minimum add a clear log via processLogger.warn
inside build-workflow-by-volume-chart.usecase.ts before returning to state that
non-empty workflowIds are being ignored when isRollupEnabled is true),
referencing the isRollupEnabled check and the functions
buildChartFromWorkflowRunCount and buildChartFromWorkflowRuns so the behavior is
explicit.

In
`@apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts`:
- Around line 35-39: When isRollupEnabled is true the code calls
buildChartFromWorkflowRunCount and silently drops the workflowIds filter; update
the branch that currently returns buildChartFromWorkflowRunCount(startDate,
endDate, environmentId, organizationId) to check if workflowIds is non-empty and
emit a warning via the use case's logger (e.g., this.logger.warn or existing
logging utility) stating that workflowIds are ignored for rollup mode, or
alternatively make buildChartFromWorkflowRunCount accept and apply workflowIds
if the rollup data supports it; reference the isRollupEnabled flag and the
buildChartFromWorkflowRunCount / buildChartFromWorkflowRuns call sites when
implementing the change.

---

Nitpick comments:
In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`:
- Around line 44-81: Add an inline clarifying comment in
buildChartFromWorkflowRunCount explaining that the rollup column workflow_run_id
actually contains a trigger identifier (not a real workflow run ID) to avoid
confusion for future maintainers; place the comment near where workflowVolumes
is mapped to triggerIdentifiers / when reading row.workflow_run_id (references:
buildChartFromWorkflowRunCount, workflowVolumes, triggerIdentifiers,
nameByIdentifier) so it's obvious why we use workflow_run_id as the lookup key
for template names.

In
`@libs/dal/src/repositories/notification-template/notification-template.repository.ts`:
- Around line 66-98: The runtime projection currently omits explicit _id
handling so MongoDB will still include _id by default while the TypeScript
return type Pick<NotificationTemplateEntity, K> may not include it; update
findByTriggerIdentifierBulk to ensure projection matches the types by adding
_id: 1 whenever a select array is provided (i.e., when building projection from
select ensure projection._id = 1 if not already present), and keep the rest of
the logic (projection variable, baseQuery, query population, and the returned
mapEntities) unchanged so runtime and types remain consistent.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3dd25d and 4779b96.

📒 Files selected for processing (7)
  • apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts
  • apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts
  • apps/api/src/app/shared/shared.module.ts
  • apps/dashboard/src/components/analytics/charts/workflow-runs-trend-chart.tsx
  • libs/application-generic/src/services/analytic-logs/workflow-run-count/workflow-run-count.repository.ts
  • libs/dal/src/repositories/notification-template/notification-template.repository.ts
  • packages/shared/src/types/feature-flags.ts

Comment on lines +30 to +41
const isRollupEnabled = await this.featureFlagsService.getFlag({
key: FeatureFlagsKeysEnum.IS_WORKFLOW_RUN_TREND_FROM_ROLLUP_ENABLED,
defaultValue: false,
organization: { _id: organizationId },
environment: { _id: environmentId },
});

if (isRollupEnabled) {
return this.buildChartFromWorkflowRunCount(startDate, endDate, environmentId, organizationId);
}

return this.buildChartFromWorkflowRuns(startDate, endDate, environmentId, organizationId, workflowIds);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Same observation as the trend chart: workflowIds is silently ignored when rollup is enabled.

When the rollup flag is on, buildChartFromWorkflowRunCount ignores the workflowIds parameter. This is the same pattern as in BuildWorkflowRunsTrendChart. If this is expected, consider at minimum adding a log when workflowIds is non-empty but unused.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`
around lines 30 - 41, The code silently ignores workflowIds when the rollup
feature flag is enabled; update the call-site and implementation so workflowIds
are not dropped: change buildChartFromWorkflowRunCount to accept an optional
workflowIds parameter and apply that filter inside its logic (or if filtering by
workflow is not supported, at minimum add a clear log via processLogger.warn
inside build-workflow-by-volume-chart.usecase.ts before returning to state that
non-empty workflowIds are being ignored when isRollupEnabled is true),
referencing the isRollupEnabled check and the functions
buildChartFromWorkflowRunCount and buildChartFromWorkflowRuns so the behavior is
explicit.

Comment on lines 35 to 39
if (isRollupEnabled) {
return this.buildChartFromWorkflowRunCount(startDate, endDate, environmentId, organizationId);
}

return this.buildChartFromWorkflowRuns(startDate, endDate, environmentId, organizationId, workflowIds);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Note: workflowIds filter is silently ignored when rollup is enabled.

When isRollupEnabled is true, buildChartFromWorkflowRunCount doesn't accept or use the workflowIds parameter from the command, meaning any workflow-specific filtering the caller requested is silently dropped. If this is intentional (rollup table doesn't support per-workflow filtering), consider logging a warning when workflowIds is provided but ignored, so callers aren't surprised by unfiltered results.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts`
around lines 35 - 39, When isRollupEnabled is true the code calls
buildChartFromWorkflowRunCount and silently drops the workflowIds filter; update
the branch that currently returns buildChartFromWorkflowRunCount(startDate,
endDate, environmentId, organizationId) to check if workflowIds is non-empty and
emit a warning via the use case's logger (e.g., this.logger.warn or existing
logging utility) stating that workflowIds are ignored for rollup mode, or
alternatively make buildChartFromWorkflowRunCount accept and apply workflowIds
if the rollup data supports it; reference the isRollupEnabled flag and the
buildChartFromWorkflowRunCount / buildChartFromWorkflowRuns call sites when
implementing the change.

…charts

- Changed feature flag from IS_WORKFLOW_RUN_TREND_FROM_ROLLUP_ENABLED to IS_WORKFLOW_RUN_COUNT_ENABLED in build-workflow-by-volume-chart and build-workflow-runs-trend-chart use cases.
- Updated WorkflowRunsTrendChart component to reflect the new feature flag.
- Removed deprecated feature flag from the shared types.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/novuhq/novu@10074
npm i https://pkg.pr.new/novuhq/novu/@novu/providers@10074
npm i https://pkg.pr.new/novuhq/novu/@novu/shared@10074

commit: a85397d

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts (1)

35-37: ⚠️ Potential issue | 🟡 Minor

workflowIds is ignored when count path is enabled

Line 36 switches to buildChartFromWorkflowRunCount(...) without preserving workflowIds. This silently changes API behavior under the feature flag.

Suggested minimal fix
 if (isWorkflowRunCountEnabled) {
+  if (workflowIds?.length) {
+    this.logger.warn(
+      { workflowIdsCount: workflowIds.length },
+      'workflowIds filter is ignored when IS_WORKFLOW_RUN_COUNT_ENABLED is true'
+    );
+  }
+
   return this.buildChartFromWorkflowRunCount(startDate, endDate, environmentId, organizationId);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts`
around lines 35 - 37, The feature-flag branch ignores the workflowIds filter:
when isWorkflowRunCountEnabled is true the code returns
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId) and drops workflowIds, changing API behavior; update
buildChartFromWorkflowRunCount (and any callers) to accept a workflowIds
parameter and pass the existing workflowIds through (e.g., call
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId, workflowIds)), and ensure the new parameter is applied inside
buildChartFromWorkflowRunCount to filter counts by the provided workflowIds.
apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts (1)

37-39: ⚠️ Potential issue | 🟡 Minor

workflowIds filter is dropped in count-enabled mode

Line 38 returns count-based data without applying or acknowledging workflowIds, so requested filtering is silently ignored when the flag is on.

Suggested minimal fix
 if (isWorkflowRunCountEnabled) {
+  if (workflowIds?.length) {
+    this.logger.warn(
+      { workflowIdsCount: workflowIds.length },
+      'workflowIds filter is ignored when IS_WORKFLOW_RUN_COUNT_ENABLED is true'
+    );
+  }
+
   return this.buildChartFromWorkflowRunCount(startDate, endDate, environmentId, organizationId);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`
around lines 37 - 39, The count-path currently ignores the workflowIds filter:
when isWorkflowRunCountEnabled is true the code returns
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId) without honoring workflowIds; update the call or implementation
so workflowIds is passed and applied (e.g., change the call to include
workflowIds or modify buildChartFromWorkflowRunCount to accept and filter by
workflowIds) ensuring the workflowIds variable is used in the count calculation
inside buildChartFromWorkflowRunCount.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`:
- Around line 70-74: The current mapping only reads
template.triggers?.[0]?.identifier so it misses identifiers not at index 0;
update the logic in the loop over templates to iterate all trigger entries
(e.g., for each template in templates, loop through template.triggers) and call
nameByIdentifier.set(identifier, template.name) for each trigger.identifier
found so every trigger identifier is mapped to the template name (use the
existing templates, template.triggers and nameByIdentifier symbols to locate and
fix the code).

---

Duplicate comments:
In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`:
- Around line 37-39: The count-path currently ignores the workflowIds filter:
when isWorkflowRunCountEnabled is true the code returns
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId) without honoring workflowIds; update the call or implementation
so workflowIds is passed and applied (e.g., change the call to include
workflowIds or modify buildChartFromWorkflowRunCount to accept and filter by
workflowIds) ensuring the workflowIds variable is used in the count calculation
inside buildChartFromWorkflowRunCount.

In
`@apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts`:
- Around line 35-37: The feature-flag branch ignores the workflowIds filter:
when isWorkflowRunCountEnabled is true the code returns
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId) and drops workflowIds, changing API behavior; update
buildChartFromWorkflowRunCount (and any callers) to accept a workflowIds
parameter and pass the existing workflowIds through (e.g., call
buildChartFromWorkflowRunCount(startDate, endDate, environmentId,
organizationId, workflowIds)), and ensure the new parameter is applied inside
buildChartFromWorkflowRunCount to filter counts by the provided workflowIds.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4779b96 and 924a4cd.

📒 Files selected for processing (4)
  • apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts
  • apps/api/src/app/activity/usecases/build-workflow-runs-trend-chart/build-workflow-runs-trend-chart.usecase.ts
  • apps/dashboard/src/components/analytics/charts/workflow-runs-trend-chart.tsx
  • packages/shared/src/types/feature-flags.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/src/components/analytics/charts/workflow-runs-trend-chart.tsx
  • packages/shared/src/types/feature-flags.ts

Comment on lines +70 to +74
for (const template of templates) {
const identifier = template.triggers?.[0]?.identifier;
if (identifier) {
nameByIdentifier.set(identifier, template.name);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Template name mapping assumes the matching trigger is always first

Line 71 only reads template.triggers?.[0]?.identifier. If the matched identifier is in another trigger entry, the chart falls back to raw workflow_run_id even though a template name exists.

Suggested fix
-const nameByIdentifier = new Map<string, string>();
+const nameByIdentifier = new Map<string, string>();
+const requestedIdentifierSet = new Set(triggerIdentifiers);
 for (const template of templates) {
-  const identifier = template.triggers?.[0]?.identifier;
-  if (identifier) {
-    nameByIdentifier.set(identifier, template.name);
+  for (const trigger of template.triggers ?? []) {
+    if (trigger?.identifier && requestedIdentifierSet.has(trigger.identifier)) {
+      nameByIdentifier.set(trigger.identifier, template.name);
+    }
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/api/src/app/activity/usecases/build-workflow-by-volume-chart/build-workflow-by-volume-chart.usecase.ts`
around lines 70 - 74, The current mapping only reads
template.triggers?.[0]?.identifier so it misses identifiers not at index 0;
update the logic in the loop over templates to iterate all trigger entries
(e.g., for each template in templates, loop through template.triggers) and call
nameByIdentifier.set(identifier, template.name) for each trigger.identifier
found so every trigger identifier is mapped to the template name (use the
existing templates, template.triggers and nameByIdentifier symbols to locate and
fix the code).

@linear
Copy link

linear bot commented Mar 18, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant