Skip to content

fix(cli): sort bundle output files for deterministic task-to-file attribution - #4504

Closed
okxint wants to merge 1 commit into
triggerdotdev:mainfrom
okxint:fix/bundle-deterministic-file-order
Closed

fix(cli): sort bundle output files for deterministic task-to-file attribution#4504
okxint wants to merge 1 commit into
triggerdotdev:mainfrom
okxint:fix/bundle-deterministic-file-order

Conversation

@okxint

@okxint okxint commented Aug 5, 2026

Copy link
Copy Markdown

Summary

When getBundleResultFromBuild iterates Object.entries(result.metafile.outputs), the order is not guaranteed by the spec. On some Node versions and esbuild configurations, task files appear in arbitrary order. When registerResources then iterates files to attribute tasks to their source, a task defined in child.ts (imported by parent.ts) can end up attributed to parent.ts if its output appears first — breaking per-file grouping in the dashboard.

Fixes #4495.

Change

Sort files by entry path (alphabetically) after the loop, before returning, so attribution is deterministic regardless of Object.entries order.

+  files.sort((a, b) => a.entry.localeCompare(b.entry));
+
   if (!configPath) {
     return undefined;
   }

How to test

Deploy a project that has a parent task importing a child task in a separate file. Confirm both tasks appear under their correct source files in the dashboard across multiple deploys.

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5e1f25f

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

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

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

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

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Hi @okxint, thanks for your interest in contributing!

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

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

@github-actions github-actions Bot closed this Aug 5, 2026

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Open in Devin Review

"trigger.dev": patch
---

Fix non-deterministic task-to-file attribution when multiple tasks share an output bundle. `Object.entries` iteration order is not guaranteed, so tasks defined in imported files could be attributed to the wrong source file. Files are now sorted by entry path before registration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Release note text describes internals instead of user impact

The release note for this change is written in implementation terms, naming internal mechanics (Object.entries in .changeset/bundle-deterministic-file-order.md:5) instead of a plain user-facing sentence, so shipped release notes will violate the repository's changeset writing rules.
Impact: Users reading the release notes see internal jargon rather than a clear description of what changed for them.

Rule from AGENTS.md on changeset wording

AGENTS.md states: "Write the description for users, not maintainers. Both changesets and .server-changes/ notes ship verbatim in user-visible release notes. Lead with what changed for the user - one plain sentence describing behavior, not implementation, and never naming internal tools or infra." The current note leads with "non-deterministic task-to-file attribution" and cites Object.entries iteration order and internal registration order.

Suggested change
Fix non-deterministic task-to-file attribution when multiple tasks share an output bundle. `Object.entries` iteration order is not guaranteed, so tasks defined in imported files could be attributed to the wrong source file. Files are now sorted by entry path before registration.
Tasks now consistently appear under the file they are defined in, instead of sometimes being grouped under a file that imports them.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}
}

files.sort((a, b) => a.entry.localeCompare(b.entry));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Alphabetical sort makes attribution deterministic but not necessarily correct

Sorting files by entry path only guarantees a stable order; it does not guarantee that a file defining a task is imported before a file that imports it. registerResources (packages/cli-v3/src/indexing/registerResources.ts:11-14) attributes every task registered during an import to the currently-imported entry, so a parent file that sorts earlier than its child (e.g. trigger/a-parent.ts importing trigger/z-child.ts) will still claim the child's tasks. The PR makes the misattribution consistent rather than eliminating it; a real fix would need to attribute tasks by the source file recorded at registration time (or import leaf modules first based on the metafile import graph).

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6020acfd-9d27-4b4f-baa3-ae41f7742bb7

📥 Commits

Reviewing files that changed from the base of the PR and between ca9a74e and 5e1f25f.

📒 Files selected for processing (2)
  • .changeset/bundle-deterministic-file-order.md
  • packages/cli-v3/src/build/bundle.ts

Walkthrough

Bundle entry files are now sorted alphabetically by their entry path before the bundle result is returned. A patch changeset documents the deterministic ordering and task-to-file attribution behavior.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: dashboard File column mis-attributes a task that is imported by another task file

1 participant