Skip to content

improvement(triggers): add tags to all trigger.dev task invocations#3878

Merged
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/trigger-task-tags
Apr 1, 2026
Merged

improvement(triggers): add tags to all trigger.dev task invocations#3878
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/trigger-task-tags

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add trigger.dev tags to all task invocations for better filtering and categorization in the dashboard
  • Tags use field name prefixes (e.g., workflowId:, workspaceId:, userId:) matching trigger.dev's recommended convention
  • Added buildTags helper in TriggerDevJobQueue that auto-derives tags from job metadata for workflow/schedule/webhook executions
  • Added workspaceId to JobMetadata and passed it from all execution call sites
  • Enriched connector sync with knowledgeBaseId, workspaceId, userId tags via lightweight DB lookup

Type of Change

  • Enhancement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 1, 2026 2:51am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 1, 2026

PR Summary

Low Risk
Low risk observability change that only enriches Trigger.dev/BullMQ dispatch metadata and adds tagging for easier filtering; primary risk is mis-tagging or exceeding tag limits affecting task visibility, not execution behavior.

Overview
Adds consistent Trigger.dev tags across background task dispatches (workflow/schedule/webhook jobs, inbox execution, knowledge connector sync, knowledge document processing, notifications, and A2A push notifications) to improve dashboard filtering.

Extends async job enqueue options with workspaceId in JobMetadata and optional tags, and updates the Trigger.dev job-queue backend to auto-derive up to 10 namespace:value tags from job metadata/correlation via a new buildTags helper. Minor UI-only class ordering tweak in the knowledge base edit modal.

Written by Cursor Bugbot for commit e76721c. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR improves observability of trigger.dev task invocations across the codebase by adding structured namespace:value tags to every .trigger() call, making it much easier to filter and investigate runs in the trigger.dev dashboard by workspace, workflow, user, source, or document.

Key changes:

  • buildTags helper added to TriggerDevJobQueue.enqueue to auto-derive tags (workspaceId, workflowId, userId, correlation fields) from job metadata; respects trigger.dev's 10-tag limit via slice(0, 10).
  • workspaceId added to JobMetadata and propagated to all three execution paths (workflow, schedule, webhook).
  • Connector sync (sync-engine.ts) performs a lightweight DB join to enrich tags with knowledgeBaseId, workspaceId, and userId before dispatching.
  • Direct tasks.trigger() call sites (agentmail, A2A push notifications, event/inactivity notifications, document processing) each receive appropriate contextual tags.
  • Tag prefix standardisation: kb:knowledgeBaseId: and doc:documentId: to match the new uniform convention.
  • Minor Tailwind class-ordering cleanup in edit-knowledge-base-modal.tsx.

Confidence Score: 5/5

Safe to merge — all remaining findings are P2 style/cleanup suggestions that do not affect runtime behaviour.

The changes are additive metadata enrichment with no risk to the execution paths themselves. The two P2 findings (unused type parameter and missing workspaceId in getJob reconstruction) are minor polish items. No P0/P1 issues were found.

apps/sim/lib/core/async-jobs/backends/trigger-dev.ts — unused parameter in buildTags and incomplete getJob metadata reconstruction.

Important Files Changed

Filename Overview
apps/sim/lib/core/async-jobs/backends/trigger-dev.ts Adds buildTags helper to derive trigger.dev tags from job metadata. The type parameter is unused and getJob doesn't reconstruct the new workspaceId field.
apps/sim/lib/core/async-jobs/types.ts Adds workspaceId to JobMetadata and tags to EnqueueOptions — clean, minimal interface extension.
apps/sim/lib/knowledge/connectors/sync-engine.ts Adds a lightweight DB lookup to enrich connector sync tags with knowledgeBaseId, workspaceId, and userId; degrades gracefully when the row is absent.
apps/sim/app/api/webhooks/agentmail/route.ts Adds workspaceId and taskId tags to the mothership inbox trigger; result.id correctly maps to workspace ID as confirmed by the surrounding workspaceId: result.id assignment.
apps/sim/lib/knowledge/documents/service.ts Standardises document processing tags from the short kb:/doc: prefixes to the verbose knowledgeBaseId:/documentId: convention used everywhere else.
apps/sim/app/api/schedules/execute/route.ts Passes workspaceId in job metadata for schedule executions so tags can be derived by buildTags.
apps/sim/lib/webhooks/processor.ts Passes foundWorkflow.workspaceId in job metadata for webhook executions — straightforward addition matching other call sites.
apps/sim/lib/logs/events.ts Tags workspaceNotificationDeliveryTask trigger with workspaceId, workflowId, and notificationType — clean and consistent with the new convention.
apps/sim/lib/notifications/inactivity-polling.ts Tags the inactivity polling notification trigger identically to events.ts, keeping the two notification paths consistent.
apps/sim/lib/a2a/push-notifications.ts Adds a taskId tag to the A2A push-notification trigger — minimal, correct change.
apps/sim/app/workspace/[workspaceId]/knowledge/components/edit-knowledge-base-modal/edit-knowledge-base-modal.tsx Minor Tailwind class ordering cleanup (font-size before text-color); no functional change.
apps/sim/app/api/workflows/[id]/execute/route.ts Adds workspaceId to the workflow execution job metadata, completing the metadata set for all three execution types.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Execution Call Site] --> B{Backend?}
    B -->|TriggerDev| C[TriggerDevJobQueue.enqueue]
    B -->|Direct tasks.trigger| D[Direct trigger call]

    C --> E[buildTags - type, options]
    E --> F[workspaceId tag]
    E --> G[workflowId tag]
    E --> H[userId tag]
    E --> I[source / webhookId / scheduleId / provider tags]
    E --> J[explicit options.tags - deduped]
    F & G & H & I & J --> K[slice to 10 tags max]
    K --> L[tasks.trigger - taskId, payload, tags]

    D --> M[Inline tag array]
    M --> L

    subgraph Call Sites
        N[workflow execute route] --> A
        O[schedule execute route] --> A
        P[webhook processor] --> A
        Q[agentmail route] --> D
        R[a2a push-notifications] --> D
        S[logs/events] --> D
        T[inactivity-polling] --> D
        U[documents/service] --> D
        V[sync-engine - DB lookup] --> D
    end
Loading

Comments Outside Diff (1)

  1. apps/sim/lib/core/async-jobs/backends/trigger-dev.ts, line 81-88 (link)

    P2 getJob doesn't populate the new workspaceId field

    workspaceId was added to JobMetadata in this PR, but getJob's metadata reconstruction block wasn't updated to extract it from the payload. Any caller that calls getJob and then reads metadata.workspaceId will always get undefined, even though the value was written into the enriched payload at enqueue time.

Reviews (1): Last reviewed commit: "improvement(triggers): add tags to all t..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit dcebe3a into staging Apr 1, 2026
6 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/trigger-task-tags branch April 1, 2026 02:52
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