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

@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 27, 2026 7:40pm UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

This PR has had no activity for 3 days. It closes in 2 days unless someone pushes, comments, or adds the WIP label.

@sentry-junior sentry-junior 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.

Thanks for this, @esetnik. The fix looks right to me, and the write-up made it easy to check.

What I verified:

  • The premise holds. getFilenameToDebugIdMap in @sentry/core assigns filename -> debugId per registry key in insertion order, and _debugIds is processed after _sentryDebugIds. So any registration already in the file beats a prepended snippet, and reusing that ID is the only way the uploaded map matches what events carry.
  • The branch rebases cleanly onto current main (165 commits ahead, including #2268 and the TS 7 move). On the rebased copy, inject.test.ts and the rest of the sourcemap tests pass, and the two "reuses an ID" cases fail with the src/ change reverted. The CLI test typecheck passes, and oxlint and oxfmt are clean on the touched files.
  • Because readRegisteredDebugId reuses DEBUGID_REGISTRATION_RE, it picks up every form #2268 added. I checked it against the plugin snippet, the Oxc template-literal rewrite, Turbopack's (e._debugIds||(e._debugIds={}))[n] and ||= forms, Metro's bare _sentryDebugIds[stack], and the bracketed key. Each returns the ID. Registry reads, the sentry-dbid- marker alone, a //# debugId= comment, and identifiers that only end in _sentryDebugIds return nothing.
  • The comment, debug_id/debugId, and the runtime registry all end up on one ID. mappings is left unshifted on both the external and inline paths, the dry run reports the reused ID, and a second run is a no-op. Ran the #2269 repro through the CLI from source and got the same result. Binary bundles and skipSnippet are not read, which matches the existing guards. react-native gradle goes through injectDebugId too and gets the same behavior.

One small ask, not a blocker: since Vite 8 + Oxc is the case that motivated this, a reuse case with the template-literal snippet would pin that path down. The regex has its own coverage from #2268, but nothing yet checks the reuse end to end for the minified form.

Could you rebase onto main? It merges cleanly. CI on fork PRs needs a maintainer to approve the workflow runs, so the Test/Warden runs on this head never actually ran. A fresh push also resets the stale timer.

Heads-up: #2248 (minified snippet detection, Vite 8 line shift) is being worked on in parallel and touches the same regex area. Your change should pick up anything it widens automatically, but whichever lands second may need a small rebase.

@sentry-junior
sentry-junior Bot requested a review from BYK November 26, 2026 11:09
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>
@esetnik
esetnik force-pushed the fix/reuse-registered-debug-id branch from 39cc4d4 to b511d85 Compare November 27, 2026 19:40
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 27, 2026 19:40 Inactive
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@esetnik is attempting to deploy a commit to the Sentry Team on Vercel.

A member of the Team first needs to authorize it.

@esetnik

esetnik commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (b511d85). The one conflict was the dry run in injectDirectory, where #2524 moved the lookup into readPairDebugId. The dry run now uses it and still falls back to the ID the bundle registers at runtime. The sourcemap tests pass, and the two "reuses an ID" cases fail with the src/ change reverted.

One question: readExistingDebugIds (upload --no-rewrite) still sends no ID for a bundle that only registers one at runtime. Should it send that ID too, here or in a follow-up?

[Written by Claude]

This branch was previously deployed

2 inactive (1 outdated) deployments
Preview – sentry-local — b511d85b Deployed Nov 27, 2026 by vercel[bot]
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 Stale

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