feat(supervisor): wide events + warm-start trace propagation#3669
feat(supervisor): wide events + warm-start trace propagation#3669nicktrn wants to merge 9 commits into
Conversation
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR adds a supervisor-wide "wide events" observability system: new wideEvents modules provide types (State/Phase/Error), traceparent parsing, AsyncLocalStorage context, phase timing/recording, JSON serialization to stdout, lifecycle middleware (runWideEvent/emitOneShot) and helpers (setMeta/setExtra). Tests cover parsing, state creation, recording, emission, and middleware. Environment flags TRIGGER_WIDE_EVENTS_ENABLED and TRIGGER_WIDE_EVENTS_NOISY_ROUTES gate behavior. Supervisor, ComputeSnapshotService, WorkloadServer, and compute client/manager are wired to create and propagate wide events across dequeue, HTTP routes, socket lifecycle, and outbound compute calls. Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
671b137 to
3330bdc
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
apps/supervisor/src/wideEvents/emit.test.ts (1)
97-102: ⚡ Quick winStrengthen truncation coverage with a UTF-8 multibyte case.
The current check validates character-count truncation only; adding a multibyte message case will prevent byte-limit regressions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/emit.test.ts` around lines 97 - 102, The existing test for truncation only checks character count; add a UTF-8 multibyte case to ensure truncation is done by byte length not characters: create a new test (similar to the "truncates very long error messages" one) that uses newState and captureEmit, sets s.error.message to a long repeated multibyte sequence (e.g., emoji or non-ASCII characters) whose character count is less than but byte length exceeds 512, then assert that (out["error.message"] as string).length in bytes (or Buffer.byteLength of the emitted string) is 512; reference the same helpers newState and captureEmit and the s.error structure to implement this check.apps/supervisor/src/wideEvents/record.test.ts (1)
34-40: ⚡ Quick winAdd a multibyte truncation test to match the byte-limit contract.
Current truncation coverage only uses ASCII; add a UTF-8 multibyte case so byte-capped behavior is protected.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/record.test.ts` around lines 34 - 40, Add a new test that verifies recordPhase's truncation enforces a 512-byte limit for multibyte (UTF-8) characters: create a state with makeState(), call recordPhase(s, "x", performance.now(), new Error("<multibyte string>")) where the error message is a repeated multibyte character (e.g. "あ") long enough to exceed 512 bytes, then read phase = s.phases[0] and assert that Buffer.byteLength(phase.errorMsg!, "utf8") === 512 and that phase.errorMsg!.length is less than the original string length; reference the existing test pattern around makeState and recordPhase to add this case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/supervisor/src/wideEvents/emit.ts`:
- Around line 36-40: The current truncation uses code units and can exceed
MAX_ERROR_MSG_BYTES for multibyte UTF‑8 characters; change the logic to truncate
by bytes: create a UTF‑8 buffer from state.error.message
(Buffer.from(state.error.message, 'utf8')), if buffer.length <=
MAX_ERROR_MSG_BYTES use the original message, otherwise slice the buffer to
MAX_ERROR_MSG_BYTES (buffer.slice(0, MAX_ERROR_MSG_BYTES)) and convert back to a
string via toString('utf8') so you get a byte-safe truncated msg before calling
appendIfSet("error.message", msg); update the code around state.error.message,
MAX_ERROR_MSG_BYTES, and msg in emit.ts accordingly.
In `@apps/supervisor/src/wideEvents/middleware.ts`:
- Line 72: Wrap each call to emit(state) in a non-throwing try/catch so
wide-event emission is best-effort: for the three occurrences of emit(state)
(the calls in this file), catch any error and log it via the module's logger (or
console.error if no logger is available) but do not rethrow or change the
returned result/flow; ensure the catch only handles emission failures and does
not swallow or override any existing error the surrounding operation may be
propagating.
In `@apps/supervisor/src/wideEvents/record.ts`:
- Around line 35-37: The code currently truncates p.errorMsg by JS string length
(msg.slice) which can exceed MAX_ERROR_MSG_BYTES when characters are multi-byte;
instead compute UTF-8 bytes via Buffer.from(msg, 'utf8'), if buf.length >
MAX_ERROR_MSG_BYTES slice the buffer to MAX_ERROR_MSG_BYTES and then trim any
trailing continuation bytes (drop bytes while (buf[last] >> 6) === 2) to avoid
cutting a multi-byte sequence, finally set p.errorMsg = buf.toString('utf8');
use the existing symbols msg, MAX_ERROR_MSG_BYTES, and p.errorMsg to locate and
replace the current truncation logic.
---
Nitpick comments:
In `@apps/supervisor/src/wideEvents/emit.test.ts`:
- Around line 97-102: The existing test for truncation only checks character
count; add a UTF-8 multibyte case to ensure truncation is done by byte length
not characters: create a new test (similar to the "truncates very long error
messages" one) that uses newState and captureEmit, sets s.error.message to a
long repeated multibyte sequence (e.g., emoji or non-ASCII characters) whose
character count is less than but byte length exceeds 512, then assert that
(out["error.message"] as string).length in bytes (or Buffer.byteLength of the
emitted string) is 512; reference the same helpers newState and captureEmit and
the s.error structure to implement this check.
In `@apps/supervisor/src/wideEvents/record.test.ts`:
- Around line 34-40: Add a new test that verifies recordPhase's truncation
enforces a 512-byte limit for multibyte (UTF-8) characters: create a state with
makeState(), call recordPhase(s, "x", performance.now(), new Error("<multibyte
string>")) where the error message is a repeated multibyte character (e.g. "あ")
long enough to exceed 512 bytes, then read phase = s.phases[0] and assert that
Buffer.byteLength(phase.errorMsg!, "utf8") === 512 and that
phase.errorMsg!.length is less than the original string length; reference the
existing test pattern around makeState and recordPhase to add this case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a20c1096-8c6a-468a-9621-0a1eb47e4bfd
📒 Files selected for processing (23)
.server-changes/README.md.server-changes/supervisor-compute-traceparent-forwarding.md.server-changes/supervisor-snapshot-lifecycle-events.md.server-changes/supervisor-wide-events.mdapps/supervisor/src/env.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/workloadServer/index.tsinternal-packages/compute/src/client.ts
✅ Files skipped from review due to trivial changes (6)
- .server-changes/supervisor-wide-events.md
- .server-changes/README.md
- .server-changes/supervisor-snapshot-lifecycle-events.md
- .server-changes/supervisor-compute-traceparent-forwarding.md
- apps/supervisor/src/wideEvents/context.ts
- apps/supervisor/src/wideEvents/state.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (38)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: typecheck / typecheck
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: units / e2e-webapp / 🧪 E2E Tests: Webapp
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
- GitHub Check: typecheck / typecheck
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects insteadAlways import tasks from
@trigger.dev/sdk. Never use@trigger.dev/sdk/v3or deprecatedclient.defineJob.
Files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use function declarations instead of default exports
**/*.{ts,tsx,js,jsx}: Inpackages/core(@trigger.dev/core), import subpaths only, never import from root.
Add crumbs as you write code using//@Crumbscomments or `// `#region` `@crumbsblocks for debug tracing. They should be stripped byagentcrumbs stripbefore merge.
Files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries
Files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (AGENTS.md)
Code formatting must be enforced using Prettier before committing
Files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
apps/supervisor/src/workloadManager/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Container orchestration abstraction (Docker or Kubernetes) should be implemented in
src/workloadManager/
Files:
apps/supervisor/src/workloadManager/compute.ts
apps/supervisor/src/env.ts
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Environment configuration should be defined in
src/env.ts
Files:
apps/supervisor/src/env.ts
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use vitest for all tests in the Trigger.dev repository
Files:
apps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/new.test.ts
**/*.test.ts
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts: Use vitest exclusively for testing. Never mock anything - use testcontainers instead.
Place test files next to source files with the naming conventionSourceFile.ts->SourceFile.test.ts
Files:
apps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/new.test.ts
**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.test.{ts,tsx,js,jsx}: Test files should live beside the files under test and use descriptive describe and it blocks
Unit tests should use vitest framework
Tests should avoid mocks or stubs and use helpers from@internal/testcontainerswhen Redis or Postgres are needed
Files:
apps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/new.test.ts
apps/supervisor/src/services/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Core service logic should be organized in the
src/services/directory
Files:
apps/supervisor/src/services/computeSnapshotService.ts
apps/supervisor/src/workloadServer/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
HTTP server for workload communication (heartbeats, snapshots) should be implemented in
src/workloadServer/
Files:
apps/supervisor/src/workloadServer/index.ts
🧠 Learnings (5)
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).
Applied to files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.
Applied to files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.
Applied to files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.
Applied to files:
apps/supervisor/src/wideEvents/index.tsinternal-packages/compute/src/client.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/index.ts
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.
Applied to files:
apps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/new.test.ts
🔇 Additional comments (30)
apps/supervisor/src/env.ts (1)
260-267: LGTM!apps/supervisor/src/index.ts (6)
31-38: LGTM!Also applies to: 61-66, 257-276
286-304: LGTM!
306-386: LGTM!
388-452: LGTM!
475-476: LGTM!
493-547: LGTM!apps/supervisor/src/services/computeSnapshotService.ts (5)
9-17: LGTM!Also applies to: 36-36, 50-50, 56-56
75-108: LGTM!
110-131: LGTM!
148-205: LGTM!
244-269: LGTM!apps/supervisor/src/workloadServer/index.ts (9)
34-41: LGTM!Also applies to: 78-80, 88-89, 119-120, 127-127
161-209: LGTM!
225-258: LGTM!
260-332: LGTM!
334-427: LGTM!
429-503: LGTM!
505-589: LGTM!
661-679: LGTM!
681-707: LGTM!Also applies to: 716-726, 759-776
apps/supervisor/src/workloadManager/compute.ts (1)
13-13: LGTM!Also applies to: 46-64
internal-packages/compute/src/client.ts (1)
10-21: LGTM!Also applies to: 45-59
apps/supervisor/src/wideEvents/traceparent.ts (1)
11-39: LGTM!apps/supervisor/src/wideEvents/traceparent.test.ts (1)
1-44: LGTM!apps/supervisor/src/wideEvents/new.ts (1)
13-76: LGTM!apps/supervisor/src/wideEvents/new.test.ts (1)
1-82: LGTM!apps/supervisor/src/wideEvents/middleware.ts (1)
1-71: LGTM!Also applies to: 86-108, 110-123
apps/supervisor/src/wideEvents/middleware.test.ts (1)
1-208: LGTM!apps/supervisor/src/wideEvents/index.ts (1)
1-29: LGTM!
| const msg = | ||
| state.error.message.length > MAX_ERROR_MSG_BYTES | ||
| ? state.error.message.slice(0, MAX_ERROR_MSG_BYTES) | ||
| : state.error.message; | ||
| appendIfSet(out, "error.message", msg); |
There was a problem hiding this comment.
error.message truncation should be byte-safe.
Line 37 currently truncates by code units, so UTF-8 multibyte messages can exceed the intended 512-byte cap.
Proposed fix
- const msg =
- state.error.message.length > MAX_ERROR_MSG_BYTES
- ? state.error.message.slice(0, MAX_ERROR_MSG_BYTES)
- : state.error.message;
+ const msg = truncateUtf8(state.error.message, MAX_ERROR_MSG_BYTES);
appendIfSet(out, "error.message", msg);+function truncateUtf8(value: string, maxBytes: number): string {
+ if (Buffer.byteLength(value, "utf8") <= maxBytes) return value;
+ let out = value;
+ while (Buffer.byteLength(out, "utf8") > maxBytes) {
+ out = out.slice(0, -1);
+ }
+ return out;
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const msg = | |
| state.error.message.length > MAX_ERROR_MSG_BYTES | |
| ? state.error.message.slice(0, MAX_ERROR_MSG_BYTES) | |
| : state.error.message; | |
| appendIfSet(out, "error.message", msg); | |
| function truncateUtf8(value: string, maxBytes: number): string { | |
| if (Buffer.byteLength(value, "utf8") <= maxBytes) return value; | |
| let out = value; | |
| while (Buffer.byteLength(out, "utf8") > maxBytes) { | |
| out = out.slice(0, -1); | |
| } | |
| return out; | |
| } | |
| const msg = truncateUtf8(state.error.message, MAX_ERROR_MSG_BYTES); | |
| appendIfSet(out, "error.message", msg); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/supervisor/src/wideEvents/emit.ts` around lines 36 - 40, The current
truncation uses code units and can exceed MAX_ERROR_MSG_BYTES for multibyte
UTF‑8 characters; change the logic to truncate by bytes: create a UTF‑8 buffer
from state.error.message (Buffer.from(state.error.message, 'utf8')), if
buffer.length <= MAX_ERROR_MSG_BYTES use the original message, otherwise slice
the buffer to MAX_ERROR_MSG_BYTES (buffer.slice(0, MAX_ERROR_MSG_BYTES)) and
convert back to a string via toString('utf8') so you get a byte-safe truncated
msg before calling appendIfSet("error.message", msg); update the code around
state.error.message, MAX_ERROR_MSG_BYTES, and msg in emit.ts accordingly.
| } else { | ||
| state.ok = true; | ||
| } | ||
| emit(state); |
There was a problem hiding this comment.
Make wide-event emission best-effort (non-fatal).
emit(state) is currently allowed to throw on Line 72, Line 84, and Line 109. That can fail a successful operation (or mask the original thrown error), making observability impact business flow.
Suggested fix
import { emit } from "./emit.js";
import { newState, type Env } from "./new.js";
import { wideEventStorage } from "./context.js";
import type { State } from "./state.js";
+function emitSafely(state: State): void {
+ try {
+ emit(state);
+ } catch {
+ // best-effort observability: never break request flow
+ }
+}
+
/**
* Runs `fn` inside an AsyncLocalStorage state and emits one wide event on
@@
- emit(state);
+ emitSafely(state);
return result;
} catch (err) {
@@
- emit(state);
+ emitSafely(state);
throw err;
}
}
@@
- emit(state);
+ emitSafely(state);
}Also applies to: 84-85, 109-109
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/supervisor/src/wideEvents/middleware.ts` at line 72, Wrap each call to
emit(state) in a non-throwing try/catch so wide-event emission is best-effort:
for the three occurrences of emit(state) (the calls in this file), catch any
error and log it via the module's logger (or console.error if no logger is
available) but do not rethrow or change the returned result/flow; ensure the
catch only handles emission failures and does not swallow or override any
existing error the surrounding operation may be propagating.
| const msg = err.message; | ||
| p.errorMsg = msg.length > MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg; | ||
| } |
There was a problem hiding this comment.
Enforce the 512-byte cap using UTF-8 bytes, not string length.
Line 36 truncates by code units, so multibyte messages can exceed MAX_ERROR_MSG_BYTES despite the byte-limit contract.
Proposed fix
- const msg = err.message;
- p.errorMsg = msg.length > MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg;
+ const msg = err.message;
+ p.errorMsg = truncateUtf8(msg, MAX_ERROR_MSG_BYTES);
}+function truncateUtf8(value: string, maxBytes: number): string {
+ if (Buffer.byteLength(value, "utf8") <= maxBytes) return value;
+ let out = value;
+ while (Buffer.byteLength(out, "utf8") > maxBytes) {
+ out = out.slice(0, -1);
+ }
+ return out;
+}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/supervisor/src/wideEvents/record.ts` around lines 35 - 37, The code
currently truncates p.errorMsg by JS string length (msg.slice) which can exceed
MAX_ERROR_MSG_BYTES when characters are multi-byte; instead compute UTF-8 bytes
via Buffer.from(msg, 'utf8'), if buf.length > MAX_ERROR_MSG_BYTES slice the
buffer to MAX_ERROR_MSG_BYTES and then trim any trailing continuation bytes
(drop bytes while (buf[last] >> 6) === 2) to avoid cutting a multi-byte
sequence, finally set p.errorMsg = buf.toString('utf8'); use the existing
symbols msg, MAX_ERROR_MSG_BYTES, and p.errorMsg to locate and replace the
current truncation logic.
3330bdc to
1e1ff9e
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (2)
apps/supervisor/src/wideEvents/record.ts (1)
35-37:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse UTF-8 byte truncation for
errorMsg.Line 36 truncates by string length, not bytes. Multibyte messages can exceed the documented 512-byte cap.
Proposed fix
if (err) { p.errorCode = err.name || "Error"; const msg = err.message; - p.errorMsg = msg.length > MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg; + p.errorMsg = truncateUtf8(msg, MAX_ERROR_MSG_BYTES); } @@ function asError(e: unknown): Error { return e instanceof Error ? e : new Error(String(e)); } + +function truncateUtf8(value: string, maxBytes: number): string { + if (Buffer.byteLength(value, "utf8") <= maxBytes) return value; + let out = value; + while (Buffer.byteLength(out, "utf8") > maxBytes) { + out = out.slice(0, -1); + } + return out; +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/record.ts` around lines 35 - 37, p.errorMsg is being truncated by character count instead of UTF-8 bytes. Replace the current truncation (using msg.length and msg.slice) with a byte-aware approach: create a UTF-8 Buffer from msg (e.g., Buffer.from(msg, 'utf8')), slice it to MAX_ERROR_MSG_BYTES, then decode with toString('utf8') and trim any trailing replacement character (�) that indicates a cut multibyte sequence; assign that result to p.errorMsg. Use the existing symbols msg, MAX_ERROR_MSG_BYTES, and p.errorMsg to locate and update the logic.apps/supervisor/src/wideEvents/middleware.ts (1)
78-78:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMake wide-event emission non-fatal.
On Line 78, Line 90, and Line 119,
emit(state)can throw and either fail a successful operation or mask the original exception. Emission should be best-effort.Suggested fix
import { emit } from "./emit.js"; import { newState, type Env } from "./new.js"; import { wideEventStorage } from "./context.js"; import type { State } from "./state.js"; +function emitSafely(state: State): void { + try { + emit(state); + } catch { + // Observability must not alter business flow + } +} + @@ - emit(state); + emitSafely(state); return result; } catch (err) { @@ - emit(state); + emitSafely(state); throw err; } } @@ - emit(state); + emitSafely(state); }Also applies to: 90-90, 119-119
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/middleware.ts` at line 78, emit(state) calls in the wideEvents middleware are currently allowed to throw and make the whole operation fail; wrap each emit(state) invocation (the three occurrences in this file) in a try/catch so emission is best-effort, swallow the error (do not rethrow) and log the failure via the module's logger (or console.error) with context including the state and a short message; ensure the surrounding function names (the middleware handling functions that call emit) remain unchanged and that the catch only prevents the emit error from propagating.
🧹 Nitpick comments (1)
apps/supervisor/src/wideEvents/record.test.ts (1)
34-40: ⚡ Quick winAdd a multibyte regression case for truncation.
This test only validates ASCII truncation length. Add a UTF-8 multibyte case to assert the 512-byte cap behavior.
Suggested test addition
it("truncates very long error messages", () => { const s = makeState(); recordPhase(s, "x", performance.now(), new Error("y".repeat(2000))); const phase = s.phases[0]; if (!phase) throw new Error("missing phase"); expect(phase.errorMsg?.length).toBe(512); }); + + it("truncates by UTF-8 bytes for multibyte messages", () => { + const s = makeState(); + recordPhase(s, "x", performance.now(), new Error("🙂".repeat(2000))); + const phase = s.phases[0]; + if (!phase?.errorMsg) throw new Error("missing errorMsg"); + expect(Buffer.byteLength(phase.errorMsg, "utf8")).toBeLessThanOrEqual(512); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/record.test.ts` around lines 34 - 40, Add a UTF-8 multibyte regression to the truncation test: create a state with makeState(), call recordPhase(s, "x", performance.now(), new Error(/* string with multibyte chars repeated to exceed 512 bytes, e.g. "💩" or "𐍈" */)), then assert the resulting s.phases[0] exists and that phase.errorMsg?.length is 512 bytes (not characters) to verify the 512-byte cap; reuse the existing test pattern and functions (makeState, recordPhase, phase.errorMsg) so the new case sits alongside the ASCII test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@apps/supervisor/src/wideEvents/middleware.ts`:
- Line 78: emit(state) calls in the wideEvents middleware are currently allowed
to throw and make the whole operation fail; wrap each emit(state) invocation
(the three occurrences in this file) in a try/catch so emission is best-effort,
swallow the error (do not rethrow) and log the failure via the module's logger
(or console.error) with context including the state and a short message; ensure
the surrounding function names (the middleware handling functions that call
emit) remain unchanged and that the catch only prevents the emit error from
propagating.
In `@apps/supervisor/src/wideEvents/record.ts`:
- Around line 35-37: p.errorMsg is being truncated by character count instead of
UTF-8 bytes. Replace the current truncation (using msg.length and msg.slice)
with a byte-aware approach: create a UTF-8 Buffer from msg (e.g.,
Buffer.from(msg, 'utf8')), slice it to MAX_ERROR_MSG_BYTES, then decode with
toString('utf8') and trim any trailing replacement character (�) that indicates
a cut multibyte sequence; assign that result to p.errorMsg. Use the existing
symbols msg, MAX_ERROR_MSG_BYTES, and p.errorMsg to locate and update the logic.
---
Nitpick comments:
In `@apps/supervisor/src/wideEvents/record.test.ts`:
- Around line 34-40: Add a UTF-8 multibyte regression to the truncation test:
create a state with makeState(), call recordPhase(s, "x", performance.now(), new
Error(/* string with multibyte chars repeated to exceed 512 bytes, e.g. "💩" or
"𐍈" */)), then assert the resulting s.phases[0] exists and that
phase.errorMsg?.length is 512 bytes (not characters) to verify the 512-byte cap;
reuse the existing test pattern and functions (makeState, recordPhase,
phase.errorMsg) so the new case sits alongside the ASCII test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 692d4405-9351-448e-9daa-d186cef7e6a1
📒 Files selected for processing (24)
.server-changes/README.md.server-changes/supervisor-compute-traceparent-forwarding.md.server-changes/supervisor-op-field-coverage.md.server-changes/supervisor-snapshot-lifecycle-events.md.server-changes/supervisor-wide-events.mdapps/supervisor/src/env.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/workloadServer/index.tsinternal-packages/compute/src/client.ts
✅ Files skipped from review due to trivial changes (3)
- .server-changes/supervisor-compute-traceparent-forwarding.md
- .server-changes/README.md
- .server-changes/supervisor-wide-events.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (37)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: typecheck / typecheck
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: units / e2e-webapp / 🧪 E2E Tests: Webapp
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: typecheck / typecheck
- GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects insteadAlways import tasks from
@trigger.dev/sdk. Never use@trigger.dev/sdk/v3or deprecatedclient.defineJob.
Files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use function declarations instead of default exports
**/*.{ts,tsx,js,jsx}: Inpackages/core(@trigger.dev/core), import subpaths only, never import from root.
Add crumbs as you write code using//@Crumbscomments or `// `#region` `@crumbsblocks for debug tracing. They should be stripped byagentcrumbs stripbefore merge.
Files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries
Files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (AGENTS.md)
Code formatting must be enforced using Prettier before committing
Files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use vitest for all tests in the Trigger.dev repository
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.test.ts
**/*.test.ts
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts: Use vitest exclusively for testing. Never mock anything - use testcontainers instead.
Place test files next to source files with the naming conventionSourceFile.ts->SourceFile.test.ts
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.test.ts
**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.test.{ts,tsx,js,jsx}: Test files should live beside the files under test and use descriptive describe and it blocks
Unit tests should use vitest framework
Tests should avoid mocks or stubs and use helpers from@internal/testcontainerswhen Redis or Postgres are needed
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.test.ts
apps/supervisor/src/workloadManager/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Container orchestration abstraction (Docker or Kubernetes) should be implemented in
src/workloadManager/
Files:
apps/supervisor/src/workloadManager/compute.ts
apps/supervisor/src/env.ts
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Environment configuration should be defined in
src/env.ts
Files:
apps/supervisor/src/env.ts
apps/supervisor/src/workloadServer/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
HTTP server for workload communication (heartbeats, snapshots) should be implemented in
src/workloadServer/
Files:
apps/supervisor/src/workloadServer/index.ts
apps/supervisor/src/services/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Core service logic should be organized in the
src/services/directory
Files:
apps/supervisor/src/services/computeSnapshotService.ts
🧠 Learnings (6)
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).
Applied to files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/index.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/workloadServer/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/services/computeSnapshotService.ts
📚 Learning: 2026-05-14T14:54:39.095Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3545
File: .server-changes/agent-view-sessions.md:10-10
Timestamp: 2026-05-14T14:54:39.095Z
Learning: In the `trigger.dev` repository, do not flag inconsistent dot vs slash notation in route/path strings inside `.server-changes/*.md` files. These markdown files are consumed verbatim into the changelog, so the mixed notation (e.g., `resources.orgs.../runs.$runParam/...`) is intentional and should be preserved as-is.
Applied to files:
.server-changes/supervisor-snapshot-lifecycle-events.md.server-changes/supervisor-op-field-coverage.md
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/new.test.ts
🪛 LanguageTool
.server-changes/supervisor-op-field-coverage.md
[grammar] ~6-~6: Use a hyphen to join words.
Context: ...e: improvement --- Tag every supervisor structured event with op and kind fi...
(QB_NEW_EN_HYPHEN)
🔇 Additional comments (17)
apps/supervisor/src/wideEvents/state.ts (1)
1-78: LGTM!apps/supervisor/src/wideEvents/traceparent.ts (1)
1-40: LGTM!apps/supervisor/src/wideEvents/traceparent.test.ts (1)
1-44: LGTM!apps/supervisor/src/wideEvents/new.ts (1)
1-83: LGTM!apps/supervisor/src/wideEvents/new.test.ts (1)
1-82: LGTM!apps/supervisor/src/wideEvents/context.ts (1)
1-15: LGTM!apps/supervisor/src/wideEvents/emit.test.ts (1)
1-114: LGTM!apps/supervisor/src/wideEvents/middleware.test.ts (1)
1-208: LGTM!apps/supervisor/src/wideEvents/index.ts (1)
1-29: LGTM!apps/supervisor/src/env.ts (1)
260-267: LGTM!.server-changes/supervisor-snapshot-lifecycle-events.md (1)
1-6: LGTM!.server-changes/supervisor-op-field-coverage.md (1)
1-6: LGTM!apps/supervisor/src/index.ts (1)
31-38: LGTM!Also applies to: 61-67, 257-455, 477-479, 495-520
apps/supervisor/src/services/computeSnapshotService.ts (1)
9-17: LGTM!Also applies to: 36-37, 50-57, 77-107, 115-132, 150-199, 246-270
apps/supervisor/src/workloadServer/index.ts (1)
34-42: LGTM!Also applies to: 78-80, 88-90, 119-128, 161-212, 234-600, 673-783
apps/supervisor/src/workloadManager/compute.ts (1)
13-14: LGTM!Also applies to: 50-63
internal-packages/compute/src/client.ts (1)
14-20: LGTM!Also applies to: 50-57
1e1ff9e to
eba7141
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (2)
apps/supervisor/src/wideEvents/middleware.ts (1)
78-79:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMake wide-event emission best-effort to avoid masking operation outcomes.
Direct
emit(state)calls can throw and either fail a successful operation or hide the original thrown error. Observability failures should not alter control flow.Suggested fix
import { emit } from "./emit.js"; import { newState, type Env } from "./new.js"; import { wideEventStorage } from "./context.js"; import type { State } from "./state.js"; + +function emitSafely(state: State): void { + try { + emit(state); + } catch { + // best-effort observability: never break request flow + } +} @@ - emit(state); + emitSafely(state); return result; @@ - emit(state); + emitSafely(state); throw err; @@ - emit(state); + emitSafely(state); }Also applies to: 90-91, 119-120
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/middleware.ts` around lines 78 - 79, The direct emit(state) calls in middleware.ts (the emit calls at the locations shown) must be made best-effort so they never alter the operation's outcome: wrap each emit(state) invocation in a try/catch that logs the emission error (using the module's logger or processLogger) but does not rethrow, so successful results are returned and original thrown errors are propagated unchanged; update the three occurrences (the emit calls around lines 78–79, 90–91, and 119–120) to follow this pattern and ensure the catch only swallows/logs the emit error.apps/supervisor/src/wideEvents/record.ts (1)
35-37:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse UTF-8 byte truncation for
errorMsgcap.
msg.slice(0, MAX_ERROR_MSG_BYTES)truncates by string length, not UTF-8 bytes, so multibyte messages can exceed the 512-byte contract.Proposed fix
if (err) { p.errorCode = err.name || "Error"; const msg = err.message; - p.errorMsg = msg.length > MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg; + p.errorMsg = truncateUtf8(msg, MAX_ERROR_MSG_BYTES); } @@ function asError(e: unknown): Error { return e instanceof Error ? e : new Error(String(e)); } + +function truncateUtf8(value: string, maxBytes: number): string { + if (Buffer.byteLength(value, "utf8") <= maxBytes) return value; + let end = value.length; + while (end > 0 && Buffer.byteLength(value.slice(0, end), "utf8") > maxBytes) { + end--; + } + return value.slice(0, end); +}#!/bin/bash # Verify the byte-cap mismatch in implementation and coverage gap in tests. rg -n -C2 'MAX_ERROR_MSG_BYTES|msg\.length|slice\(0, MAX_ERROR_MSG_BYTES\)' apps/supervisor/src/wideEvents/record.ts rg -n -C2 'truncates very long error messages|errorMsg\?\.length' apps/supervisor/src/wideEvents/record.test.tsExpected result:
record.tsshows code-unit truncation (msg.length/slice) while tests assert char length only, not UTF-8 byte length.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/supervisor/src/wideEvents/record.ts` around lines 35 - 37, The code currently truncates error messages by JavaScript string length (msg.slice) which can exceed MAX_ERROR_MSG_BYTES in UTF-8; change to UTF-8 byte-aware truncation: create a Buffer from msg (Buffer.from(msg, 'utf8')), if buf.length <= MAX_ERROR_MSG_BYTES set p.errorMsg = msg, otherwise slice the buffer to MAX_ERROR_MSG_BYTES and then trim any trailing UTF-8 continuation bytes (while lastByte & 0xC0 === 0x80 remove one byte) so you don't cut a multi-byte character, then set p.errorMsg = slicedBuffer.toString('utf8'); update the logic around MAX_ERROR_MSG_BYTES, msg and p.errorMsg in the record.ts function that currently does const msg = err.message; p.errorMsg = msg.length > MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg.
🧹 Nitpick comments (1)
internal-packages/compute/src/client.ts (1)
45-59: 💤 Low valueConsider applying propagation headers before fixed headers to prevent accidental override.
Propagation entries are merged after
Content-TypeandAuthorization, so a caller returning either key fromgetPropagationHeaders()would silently overwrite them and break auth or content negotiation. With the current supervisor caller this is safe, but sinceComputeClientis consumed via@internal/compute, it's cheap to make the contract robust against future callers.♻️ Proposed reorder so caller propagation cannot clobber fixed headers
private get headers(): Record<string, string> { - const h: Record<string, string> = { "Content-Type": "application/json" }; - if (this.opts.authToken) { - h["Authorization"] = `Bearer ${this.opts.authToken}`; - } + const h: Record<string, string> = {}; const propagation = this.opts.getPropagationHeaders?.(); if (propagation) { for (const [key, value] of Object.entries(propagation)) { if (value) { h[key] = value; } } } + h["Content-Type"] = "application/json"; + if (this.opts.authToken) { + h["Authorization"] = `Bearer ${this.opts.authToken}`; + } return h; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal-packages/compute/src/client.ts` around lines 45 - 59, The headers getter builds request headers but applies caller-provided propagation headers after the fixed headers ("Content-Type" and "Authorization"), allowing propagation to accidentally override them; change the merge order in the headers getter (private get headers) to first copy propagation from this.opts.getPropagationHeaders(), then set/overwrite Content-Type and Authorization from this.opts.authToken so the client-enforced headers cannot be clobbered, referencing the headers getter, this.opts.getPropagationHeaders, "Content-Type" and "Authorization" in your edits.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/supervisor/src/services/computeSnapshotService.ts`:
- Around line 115-131: The code mixes direct state.extras assignments with calls
to null-safe helpers; replace the direct mutations inside the fromContext()
block with the null-safe helper (e.g., use setExtra for "snapshot.status",
"snapshot.instance_id", "snapshot.duration_ms", "snapshot.id", and
"snapshot.error") and keep the setMeta("run_id", ...) and setMeta("snapshot_id",
...) calls consistent by either moving them into the same if (state) block or
leaving them as-is (they are null-safe); in short, stop writing to state.extras
directly and use the existing setExtra/setMeta helpers alongside
fromContext()/state to keep style and null-safety consistent.
In `@apps/supervisor/src/wideEvents/baggage.ts`:
- Around line 39-40: The current truncation uses UTF-16 code units (raw.length /
raw.slice) so multibyte UTF-8 values can still exceed MAX_BAGGAGE_VALUE_BYTES;
change the logic around raw/v to truncate by UTF-8 bytes: convert raw to a
Buffer with utf8 encoding, if Buffer.byteLength(raw, "utf8") >
MAX_BAGGAGE_VALUE_BYTES slice the buffer to MAX_BAGGAGE_VALUE_BYTES and convert
back to a UTF-8 string for v (ensuring toString('utf8') will drop any incomplete
trailing byte sequence), then push `${k}=${v}` as before; also add a unit test
that constructs a non-ASCII value and asserts Buffer.byteLength(v, "utf8") <=
MAX_BAGGAGE_VALUE_BYTES after processing.
---
Duplicate comments:
In `@apps/supervisor/src/wideEvents/middleware.ts`:
- Around line 78-79: The direct emit(state) calls in middleware.ts (the emit
calls at the locations shown) must be made best-effort so they never alter the
operation's outcome: wrap each emit(state) invocation in a try/catch that logs
the emission error (using the module's logger or processLogger) but does not
rethrow, so successful results are returned and original thrown errors are
propagated unchanged; update the three occurrences (the emit calls around lines
78–79, 90–91, and 119–120) to follow this pattern and ensure the catch only
swallows/logs the emit error.
In `@apps/supervisor/src/wideEvents/record.ts`:
- Around line 35-37: The code currently truncates error messages by JavaScript
string length (msg.slice) which can exceed MAX_ERROR_MSG_BYTES in UTF-8; change
to UTF-8 byte-aware truncation: create a Buffer from msg (Buffer.from(msg,
'utf8')), if buf.length <= MAX_ERROR_MSG_BYTES set p.errorMsg = msg, otherwise
slice the buffer to MAX_ERROR_MSG_BYTES and then trim any trailing UTF-8
continuation bytes (while lastByte & 0xC0 === 0x80 remove one byte) so you don't
cut a multi-byte character, then set p.errorMsg = slicedBuffer.toString('utf8');
update the logic around MAX_ERROR_MSG_BYTES, msg and p.errorMsg in the record.ts
function that currently does const msg = err.message; p.errorMsg = msg.length >
MAX_ERROR_MSG_BYTES ? msg.slice(0, MAX_ERROR_MSG_BYTES) : msg.
---
Nitpick comments:
In `@internal-packages/compute/src/client.ts`:
- Around line 45-59: The headers getter builds request headers but applies
caller-provided propagation headers after the fixed headers ("Content-Type" and
"Authorization"), allowing propagation to accidentally override them; change the
merge order in the headers getter (private get headers) to first copy
propagation from this.opts.getPropagationHeaders(), then set/overwrite
Content-Type and Authorization from this.opts.authToken so the client-enforced
headers cannot be clobbered, referencing the headers getter,
this.opts.getPropagationHeaders, "Content-Type" and "Authorization" in your
edits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bddd7e63-8a49-4f36-ae0e-69ab511ab848
📒 Files selected for processing (26)
.server-changes/README.md.server-changes/supervisor-compute-traceparent-forwarding.md.server-changes/supervisor-op-field-coverage.md.server-changes/supervisor-snapshot-lifecycle-events.md.server-changes/supervisor-wide-events.mdapps/supervisor/src/env.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/workloadServer/index.tsinternal-packages/compute/src/client.ts
✅ Files skipped from review due to trivial changes (4)
- .server-changes/supervisor-wide-events.md
- .server-changes/supervisor-compute-traceparent-forwarding.md
- .server-changes/supervisor-snapshot-lifecycle-events.md
- .server-changes/README.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: typecheck / typecheck
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects insteadAlways import tasks from
@trigger.dev/sdk. Never use@trigger.dev/sdk/v3or deprecatedclient.defineJob.
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use function declarations instead of default exports
**/*.{ts,tsx,js,jsx}: Inpackages/core(@trigger.dev/core), import subpaths only, never import from root.
Add crumbs as you write code using//@Crumbscomments or `// `#region` `@crumbsblocks for debug tracing. They should be stripped byagentcrumbs stripbefore merge.
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use vitest for all tests in the Trigger.dev repository
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/record.test.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
**/*.test.ts
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.test.ts: Use vitest exclusively for testing. Never mock anything - use testcontainers instead.
Place test files next to source files with the naming conventionSourceFile.ts->SourceFile.test.ts
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/record.test.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (AGENTS.md)
Code formatting must be enforced using Prettier before committing
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.test.{ts,tsx,js,jsx}: Test files should live beside the files under test and use descriptive describe and it blocks
Unit tests should use vitest framework
Tests should avoid mocks or stubs and use helpers from@internal/testcontainerswhen Redis or Postgres are needed
Files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/record.test.ts
apps/supervisor/src/workloadManager/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Container orchestration abstraction (Docker or Kubernetes) should be implemented in
src/workloadManager/
Files:
apps/supervisor/src/workloadManager/compute.ts
apps/supervisor/src/env.ts
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Environment configuration should be defined in
src/env.ts
Files:
apps/supervisor/src/env.ts
apps/supervisor/src/services/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
Core service logic should be organized in the
src/services/directory
Files:
apps/supervisor/src/services/computeSnapshotService.ts
apps/supervisor/src/workloadServer/**/*.{js,ts}
📄 CodeRabbit inference engine (apps/supervisor/CLAUDE.md)
HTTP server for workload communication (heartbeats, snapshots) should be implemented in
src/workloadServer/
Files:
apps/supervisor/src/workloadServer/index.ts
🧠 Learnings (6)
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.tsapps/supervisor/src/workloadManager/compute.tsapps/supervisor/src/wideEvents/index.tsapps/supervisor/src/wideEvents/context.tsapps/supervisor/src/env.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/new.tsapps/supervisor/src/wideEvents/traceparent.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/emit.tsapps/supervisor/src/wideEvents/record.test.tsapps/supervisor/src/index.tsapps/supervisor/src/services/computeSnapshotService.tsinternal-packages/compute/src/client.tsapps/supervisor/src/wideEvents/state.tsapps/supervisor/src/wideEvents/record.tsapps/supervisor/src/wideEvents/middleware.tsapps/supervisor/src/workloadServer/index.ts
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.
Applied to files:
apps/supervisor/src/wideEvents/traceparent.test.tsapps/supervisor/src/wideEvents/baggage.test.tsapps/supervisor/src/wideEvents/emit.test.tsapps/supervisor/src/wideEvents/middleware.test.tsapps/supervisor/src/wideEvents/new.test.tsapps/supervisor/src/wideEvents/record.test.ts
📚 Learning: 2026-05-14T14:54:39.095Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3545
File: .server-changes/agent-view-sessions.md:10-10
Timestamp: 2026-05-14T14:54:39.095Z
Learning: In the `trigger.dev` repository, do not flag inconsistent dot vs slash notation in route/path strings inside `.server-changes/*.md` files. These markdown files are consumed verbatim into the changelog, so the mixed notation (e.g., `resources.orgs.../runs.$runParam/...`) is intentional and should be preserved as-is.
Applied to files:
.server-changes/supervisor-op-field-coverage.md
🪛 LanguageTool
.server-changes/supervisor-op-field-coverage.md
[grammar] ~6-~6: Use a hyphen to join words.
Context: ...e: improvement --- Tag every supervisor structured event with op and kind fi...
(QB_NEW_EN_HYPHEN)
🔇 Additional comments (32)
apps/supervisor/src/wideEvents/middleware.test.ts (1)
1-208: LGTM!apps/supervisor/src/wideEvents/index.ts (1)
1-30: LGTM!apps/supervisor/src/wideEvents/state.ts (1)
1-78: LGTM!apps/supervisor/src/wideEvents/traceparent.ts (1)
1-40: LGTM!apps/supervisor/src/wideEvents/traceparent.test.ts (1)
1-44: LGTM!apps/supervisor/src/wideEvents/new.ts (1)
1-83: LGTM!apps/supervisor/src/wideEvents/new.test.ts (1)
1-82: LGTM!apps/supervisor/src/wideEvents/context.ts (1)
1-15: LGTM!apps/supervisor/src/wideEvents/record.ts (1)
1-34: LGTM!Also applies to: 38-83
apps/supervisor/src/wideEvents/record.test.ts (1)
1-113: LGTM!apps/supervisor/src/wideEvents/emit.ts (1)
39-42:error.messagetruncation is still code-unit based, not byte-safe.This matches the earlier finding on this file; multibyte UTF-8 content can exceed the intended byte cap.
apps/supervisor/src/wideEvents/baggage.test.ts (1)
1-38: LGTM!apps/supervisor/src/wideEvents/emit.test.ts (1)
1-115: LGTM!apps/supervisor/src/env.ts (1)
260-267: LGTM!.server-changes/supervisor-op-field-coverage.md (1)
1-6: LGTM!apps/supervisor/src/index.ts (6)
31-67: LGTM!
257-307: LGTM!
308-388: LGTM!
390-453: LGTM!
477-478: LGTM!
495-549: LGTM!apps/supervisor/src/services/computeSnapshotService.ts (4)
9-17: LGTM!Also applies to: 32-37, 50-56
75-110: LGTM!
147-209: LGTM!
245-271: LGTM!apps/supervisor/src/workloadServer/index.ts (5)
34-41: LGTM!Also applies to: 78-80, 88-89, 119-120, 127-127
161-212: LGTM!
234-261: LGTM!Also applies to: 270-299, 308-337, 345-433, 441-475, 483-511, 519-544, 551-568, 573-583, 590-600
673-693: LGTM!
695-721: LGTM!Also applies to: 738-738, 783-783
apps/supervisor/src/workloadManager/compute.ts (1)
13-13: LGTM!Also applies to: 50-69
internal-packages/compute/src/client.ts (1)
14-20: LGTM!
| const runId = body.metadata?.runId; | ||
| const snapshotFriendlyId = body.metadata?.snapshotFriendlyId; | ||
|
|
||
| // Enrich the wrapping route's wide event with snapshot metadata. The | ||
| // `/api/v1/compute/snapshot-complete` route is registered with `wideRoute`, | ||
| // so `fromContext()` returns the State of that route and these calls | ||
| // become extras/meta on the same wide event - no nested emission. | ||
| const state = fromContext(); | ||
| if (state) { | ||
| state.extras["snapshot.status"] = body.status; | ||
| if (body.instance_id) state.extras["snapshot.instance_id"] = body.instance_id; | ||
| if (body.duration_ms !== undefined) state.extras["snapshot.duration_ms"] = body.duration_ms; | ||
| if (snapshotId) state.extras["snapshot.id"] = snapshotId; | ||
| if (body.status === "failed" && body.error) state.extras["snapshot.error"] = body.error; | ||
| } | ||
| if (runId) setMeta(state, "run_id", runId); | ||
| if (snapshotFriendlyId) setMeta(state, "snapshot_id", snapshotFriendlyId); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm setMeta/setExtra accept undefined state, and inspect fromContext's return type.
fd -t f 'index.ts' apps/supervisor/src/wideEvents
fd -t f 'context.ts' apps/supervisor/src/wideEvents
fd -t f 'record.ts' apps/supervisor/src/wideEvents
# Show the helper signatures
ast-grep --pattern $'export function setMeta($$$) { $$$ }'
ast-grep --pattern $'export function setExtra($$$) { $$$ }'
ast-grep --pattern $'export function fromContext($$$) { $$$ }'
# Fallback ripgrep with context if ast-grep misses
rg -nP -C3 '\b(setMeta|setExtra|fromContext)\s*[:=]?\s*(function|\()' apps/supervisor/src/wideEventsRepository: triggerdotdev/trigger.dev
Length of output: 6155
Align fromContext() null-guarding with helper usage (helpers are already null-safe).
fromContext() returns State | null, and setMeta/setExtra are explicitly null-safe (if (!state) return). So the unguarded setMeta/setExtra calls won’t crash on the TRIGGER_WIDE_EVENTS_ENABLED=false path; the remaining issue is just mixed style—either move those helper calls into the if (state) block for symmetry, or use helpers consistently instead of direct state.extras[...] assignments.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/supervisor/src/services/computeSnapshotService.ts` around lines 115 -
131, The code mixes direct state.extras assignments with calls to null-safe
helpers; replace the direct mutations inside the fromContext() block with the
null-safe helper (e.g., use setExtra for "snapshot.status",
"snapshot.instance_id", "snapshot.duration_ms", "snapshot.id", and
"snapshot.error") and keep the setMeta("run_id", ...) and setMeta("snapshot_id",
...) calls consistent by either moving them into the same if (state) block or
leaving them as-is (they are null-safe); in short, stop writing to state.extras
directly and use the existing setExtra/setMeta helpers alongside
fromContext()/state to keep style and null-safety consistent.
| const v = raw.length > MAX_BAGGAGE_VALUE_BYTES ? raw.slice(0, MAX_BAGGAGE_VALUE_BYTES) : raw; | ||
| out.push(`${k}=${v}`); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the file and print the relevant section around the cited lines
FILE="apps/supervisor/src/wideEvents/baggage.ts"
if [ ! -f "$FILE" ]; then
echo "Missing file: $FILE"
exit 1
fi
echo "---- $FILE (lines 1-120) ----"
nl -ba "$FILE" | sed -n '1,120p'
echo "---- $FILE (lines 120-240) ----"
nl -ba "$FILE" | sed -n '120,240p'
# Search for MAX_BAGGAGE_VALUE_BYTES and any existing UTF-8 truncation helpers
rg -n "MAX_BAGGAGE_VALUE_BYTES|truncateUtf8|byteLength|utf8|baggage" "$FILE"
# Check for Node Buffer usage elsewhere in the module directory
rg -n "Buffer\.byteLength|TextEncoder\(|utf8" apps/supervisor/src/wideEvents || trueRepository: triggerdotdev/trigger.dev
Length of output: 197
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="apps/supervisor/src/wideEvents/baggage.ts"
[ -f "$FILE" ] || { echo "Missing file: $FILE"; exit 1; }
echo "---- $FILE (lines 1-140) ----"
cat -n "$FILE" | sed -n '1,140p'
echo "---- $FILE (lines 140-260) ----"
cat -n "$FILE" | sed -n '140,260p'
echo "---- Relevant searches ----"
rg -n "MAX_BAGGAGE_VALUE_BYTES|truncateUtf8|byteLength|utf8|baggage" "$FILE" || true
rg -n "Buffer\.byteLength|TextEncoder\(" apps/supervisor/src/wideEvents/baggage.ts || trueRepository: triggerdotdev/trigger.dev
Length of output: 2342
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "encodeBaggage\(" -S . | head -n 50
rg -n "Baggage" apps/supervisor -S | head -n 50
# Show a bit more context around the most likely usages (first matches)
python3 - <<'PY'
import subprocess, re, os, textwrap
out=subprocess.check_output(["bash","-lc","rg -n \"encodeBaggage\\(\" -S . | head -n 50"], text=True)
print(out.strip())
PYRepository: triggerdotdev/trigger.dev
Length of output: 3759
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "---- compute.ts (lines 1-120) ----"
cat -n apps/supervisor/src/workloadManager/compute.ts | sed -n '1,140p'
echo "---- baggage.test.ts (lines 1-200) ----"
cat -n apps/supervisor/src/wideEvents/baggage.test.ts | sed -n '1,220p'Repository: triggerdotdev/trigger.dev
Length of output: 7547
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find where getPropagationHeaders is consumed / sent to an HTTP request
rg -n "getPropagationHeaders" -S apps/supervisor src packages . || true
# Search for "headers.baggage" or "baggage" header usage in supervisor/workload code
rg -n "\"baggage\"|headers\.baggage|Baggage" apps/supervisor -S || true
# Inspect the internal compute client if it's in-repo (avoid node_modules)
fd -t f -a ComputeClient -E node_modules . || true
fd -t f -a "computeClient" . || true
# Broad search for "x-request-id" usage in repo
rg -n "x-request-id" -S . | head -n 50Repository: triggerdotdev/trigger.dev
Length of output: 3348
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show internal compute client code around getPropagationHeaders and request construction
cat -n internal-packages/compute/src/client.ts | sed -n '1,220p'
# Also inspect any helper that constructs fetch/undici requests for propagation headers
rg -n "propagation|getPropagationHeaders|baggage|traceparent|x-request-id" internal-packages/compute/src -SRepository: triggerdotdev/trigger.dev
Length of output: 6767
Enforce a true UTF-8 byte cap for baggage values.
MAX_BAGGAGE_VALUE_BYTES is a byte limit, but raw.length/raw.slice(...) truncate by UTF-16 code units; multibyte UTF-8 values can still exceed 256 bytes in the baggage header. Add a test that asserts Buffer.byteLength(..., "utf8") <= 256 for a non-ASCII value.
Suggested fix
const MAX_BAGGAGE_VALUE_BYTES = 256;
+
+function truncateUtf8(value: string, maxBytes: number): string {
+ if (Buffer.byteLength(value, "utf8") <= maxBytes) return value;
+ let out = value;
+ while (Buffer.byteLength(out, "utf8") > maxBytes) {
+ out = out.slice(0, -1);
+ }
+ return out;
+}
@@
- const v = raw.length > MAX_BAGGAGE_VALUE_BYTES ? raw.slice(0, MAX_BAGGAGE_VALUE_BYTES) : raw;
+ const v = truncateUtf8(raw, MAX_BAGGAGE_VALUE_BYTES);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/supervisor/src/wideEvents/baggage.ts` around lines 39 - 40, The current
truncation uses UTF-16 code units (raw.length / raw.slice) so multibyte UTF-8
values can still exceed MAX_BAGGAGE_VALUE_BYTES; change the logic around raw/v
to truncate by UTF-8 bytes: convert raw to a Buffer with utf8 encoding, if
Buffer.byteLength(raw, "utf8") > MAX_BAGGAGE_VALUE_BYTES slice the buffer to
MAX_BAGGAGE_VALUE_BYTES and convert back to a UTF-8 string for v (ensuring
toString('utf8') will drop any incomplete trailing byte sequence), then push
`${k}=${v}` as before; also add a unit test that constructs a non-ASCII value
and asserts Buffer.byteLength(v, "utf8") <= MAX_BAGGAGE_VALUE_BYTES after
processing.
Adds wide-event observability for the supervisor: one flat-keyed JSON line per dequeue iteration, workload-server route, and run socket lifecycle event. Events carry
trace_idsourced from the inbound W3C traceparent plusmeta.run_idand related identifiers, so they join across services by run.The outbound warm-start POST also forwards the inbound traceparent so the upstream receiver continues the same trace instead of minting a new one.
Off by default behind
TRIGGER_WIDE_EVENTS_ENABLED. With the flag off, no events are emitted, no ALS state is allocated, and the outbound warm-start request is unchanged — every call site was audited to confirm the off path is byte-identical to current behavior.Dequeue-path phase timings recorded under
phase.<name>.duration_ms:restore,warm_start,workload_create. Apath_takenextra distinguishesrestore/warm_start/cold_create/skipped_no_image.Refs TRI-9480.