Skip to content

fix(cli): Reuse a debug ID that a bundle only registers at runtime - #2270

Open
esetnik wants to merge 1 commit into
getsentry:mainfrom
esetnik:fix/reuse-registered-debug-id
Open

esetnik wants to merge 1 commit into
getsentry:mainfrom
esetnik:fix/reuse-registered-debug-id

Conversation

@esetnik

@esetnik esetnik commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2269.

A bundler plugin leaves its runtime snippet in each output file, but adds the //# debugId= comment and the map's ID only to the copies it uploads. Given that output, sentry sourcemap inject and sentry sourcemap upload found no ID, minted one, and prepended a second snippet. The bundle then registered two different IDs. getFilenameToDebugIdMap in @sentry/core keeps the one registered last, which is the original, so events carried an ID that no uploaded sourcemap had.

When a file has no comment and no map ID but registers exactly one ID at runtime, that ID is now reused: the comment and the map ID are written, and no snippet is added.

Changes

  • readRegisteredDebugId in debug-id.ts returns the ID a file registers through DEBUGID_REGISTRATION_RE, when it registers exactly one. Several different IDs do not identify one bundle, so it returns nothing and the file gets its own ID and snippet as before.
  • injectDebugId and injectInlineDebugId fall back to it after the comment and the map. With a reused ID they skip the snippet and leave mappings unshifted. Binary bundles are not read.
  • The dry run in injectDirectory reports the reused ID in place of (pending). It still reports injected: true, since the file changes.
  • Two tests in inject.test.ts, each for external and inline maps: the ID is reused (file still starts with its own snippet, comment and map ID written, mappings unchanged, one ID registered at runtime, second run a no-op), and a file registering two different IDs is still given its own.

Not changed: a file whose comment carries one ID while its snippet registers another still gets a snippet for the comment's ID. Which of the two should win is a separate decision.

Relation to #2268

This is independent of #2268 and based on main. They touch nearby lines but merge cleanly. The ID is read with the same registration regex, so until #2268 lands a snippet that Oxc has rewritten to a template literal is not read here either, and such a file is handled as before.

Verification

Run locally on macOS, on 39cc4d4:

  • pnpm run tsc: passes.
  • pnpm run lint at the repo root: passes.
  • inject.test.ts: 58 passed. With the source change reverted, the two "reuses an ID" cases fail.
  • pnpm run test in packages/cli: 13,160 passed, 28 failed, 57 skipped. The same 28, in the same six files, fail on unmodified main on this machine: debug-files/upload, build/car-extract.integration, build/zip-writer, delta-upgrade.mocked, install-script and time-range.
  • pnpm run test:e2e in packages/cli: 206 passed, 1 failed, 3 skipped. The failure is telemetry-exit, a timing assertion that passes when run on its own, on this branch and on main.
  • The minimal files from sourcemap inject/upload mints a second debug ID for a file that registers one but has no //# debugId= comment #2269, through the CLI run from source: one ID in the comment, the map and the runtime registry, no added line, mappings unchanged.
  • This branch merged locally with fix(cli): Recognize debug ID snippets from Oxc and React Native Metro #2268, on a real chunk built by Vite 8.3.8 with @sentry/vite-plugin 11.12.0 (2,050 lines, snippet minified by Oxc): the plugin's ID was written to the comment and the map, the file still starts with the plugin's snippet, and mappings is unchanged.

Not done: no event was sent to Sentry to observe symbolication end to end.

🤖 Generated with Claude Code

A bundler plugin leaves its snippet in each output file, but adds the
`//# debugId=` comment and the map's ID only to the copies it uploads.
Given that output, `sourcemap inject` and `sourcemap upload` found no
ID, minted one and prepended a second snippet. The bundle then
registered two IDs, and the SDK reports the one registered last, which
is the original and not the one the sourcemap was uploaded under.

When a file has no comment and no map ID but registers exactly one ID
at runtime, reuse it: write the comment and the map ID, and add no
snippet. A file that registers several different IDs still gets its
own, as before.

Fixes getsentry#2269

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 14, 2026 4:20pm UTC

Request Review

This branch was previously deployed

1 inactive deployment
Preview — 39cc4d4c Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sourcemap inject/upload mints a second debug ID for a file that registers one but has no //# debugId= comment

1 participant