Skip to content

fix: restore metrics after waitpoint resume#3840

Closed
RitwijParmar wants to merge 1 commit into
triggerdotdev:mainfrom
RitwijParmar:codex/trigger-waitpoint-metric-attribution
Closed

fix: restore metrics after waitpoint resume#3840
RitwijParmar wants to merge 1 commit into
triggerdotdev:mainfrom
RitwijParmar:codex/trigger-waitpoint-metric-attribution

Conversation

@RitwijParmar

Copy link
Copy Markdown

What changed

Closes #3672.

This restores run-level metric attribution after a task resumes from a waitpoint:

  • adds taskContext.enable() as the explicit inverse of taskContext.disable()
  • calls it from both managed and dev worker RESOLVE_WAITPOINT handlers before resolving runtime waitpoints
  • adds a TaskContextAPI regression test for disable → enable
  • adds TaskContextMetricExporter coverage proving:
    • disabled context still strips run-specific attrs between active execution
    • re-enabled context restores RUN_ID, TASK_SLUG, ATTEMPT_NUMBER, run tags, and worker attrs
  • adds a patch changeset for @trigger.dev/core and trigger.dev

Why

FLUSH { disableContext: true } is used at waitpoints to mark the process as between active run execution. In a warm process, setGlobalTaskContext() is not called again when the same run resumes, so _runDisabled can stay true for the rest of the run. The periodic metric exporter then keeps stripping run-specific attributes, making post-waitpoint CPU/memory/heap metrics hard to query by run.

Re-enabling the task context at waitpoint resolution keeps the existing between-run stripping behavior while restoring attribution when user code resumes.

Validation

  • bun test packages/core/src/v3/taskContext/index.test.ts packages/core/src/v3/taskContext/otelProcessors.test.ts — 8 passed
  • bunx prettier --check .changeset/waitpoint-metric-attribution.md packages/core/src/v3/taskContext/index.ts packages/core/src/v3/taskContext/index.test.ts packages/core/src/v3/taskContext/otelProcessors.test.ts packages/cli-v3/src/entryPoints/managed-run-worker.ts packages/cli-v3/src/entryPoints/dev-run-worker.ts
  • git diff --check

I also ran package typechecks, but this local checkout reports existing unrelated workspace/setup errors, including missing generated workspace package types for @trigger.dev/database / @trigger.dev/schema-to-json and pre-existing assertExhaustive(...string) errors. The new test file type errors found on the first run were fixed, and the focused tests pass.

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1477ad3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@trigger.dev/core Patch
trigger.dev Patch
@trigger.dev/build Patch
@trigger.dev/plugins Patch
@trigger.dev/python Patch
@trigger.dev/redis-worker Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@trigger.dev/rbac Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker Patch
@internal/sdk-compat-tests Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Hi @RitwijParmar, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6e6b9341-6ce1-4b4b-b0e9-8ba63ecb6207

📥 Commits

Reviewing files that changed from the base of the PR and between 8c9fee3 and 1477ad3.

📒 Files selected for processing (6)
  • .changeset/waitpoint-metric-attribution.md
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts
  • packages/core/src/v3/taskContext/index.test.ts
  • packages/core/src/v3/taskContext/index.ts
  • packages/core/src/v3/taskContext/otelProcessors.test.ts

Walkthrough

This PR restores run metric attribution after waitpoint resume by implementing task context re-enablement. A new enable() method was added to TaskContextAPI to complement the existing disable() behavior, allowing task context to be restored after suspension. Both dev and managed run workers now call taskContext.enable() within their RESOLVE_WAITPOINT handlers before resolving waitpoints. Tests validate the enable/disable cycle and verify that run-specific OpenTelemetry metric attributes (run ID, task slug, attempt number) are properly stripped when context is disabled and restored when re-enabled. Release metadata documents the patch version updates.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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.

bug: Metrics emitted after waitpoint resume are unattributed — TaskContextMetricExporter strips RUN_ID because taskContext.disable() is never reversed

1 participant