fix(cli): hash the injected snippet variant in event mode - #92250
Conversation
The release snippet is longer than the chunk-id snippet, so a chunk that gains a release ships a map with shifted generated columns. Both uploads hashed the same, so the server kept the first map and later frames resolved to wrong source positions. The hash still ignores the release id, so a new release does not re-upload every chunk. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jg6r6rFUBnowrXssZyU7yR
|
😎 Merged successfully - details. |
🤖 CI report✅ Trunk lane — non-backend laneThis PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes. |
|
Reviews (1): Last reviewed commit: "fix(cli): hash the injected snippet vari..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue in the posthog-cli “event” release mode content hashing: previously, the content hash did not differentiate between the two injected snippet variants (chunk-id-only vs with-release), which can produce different uploaded sourcemaps for the same chunk id and lead to incorrect stack frame resolution.
Changes:
- Include the injected snippet variant (but not the specific release id) in the event-mode
content_hashcomputation. - Add a helper to detect whether a minified source contains the release-bearing snippet variant.
- Update/rename the regression test to assert the new expected hashing behavior, and add a changeset entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cli/tests/sourcemap.rs |
Updates the event-mode content-hash test to require snippet-variant sensitivity while remaining stable across different release ids. |
cli/src/sourcemaps/source_pairs.rs |
Extends event-mode content hashing to include a stable marker for the snippet variant. |
cli/src/sourcemaps/content.rs |
Adds has_release_snippet to detect the release-bearing injected snippet in the source. |
cli/.sampo/changesets/event-mode-hash-snippet-variant.md |
Records the patch-level change and rationale for release notes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Merge this before #91823, which makes event mode the default.
Problem
Changes
How did you test this code?
cargo testincli/.test_event_mode_content_hash_tracks_the_snippet_variantcovers both directions. It fails against the previous hash.error-tracking-examples/web-raw. The old code returns one hash for both snippet variants. The new code returns two.sourcemap processagainst a local PostHog with both binaries. Both uploaded the second build. That run does not separate them, so it is evidence of no regression rather than evidence of the fix.Hash measured on the esbuild bundle
Same pristine
index.jsandindex.js.map, injected twice.uuid_stableis the property the hash has to keep. A second release id leaves the map identical, so the hash must not move.posthog-cli sourcemap process against a local PostHog
One chunk, uploaded three times. Step 2 repeats step 1 and confirms the server stores and compares the hash.
Both binaries upload at s3. Through
sourcemap processthe restored map already differs between the two variants, which separates the hashes without this change. The collision needs the restored map to match, which the measurement above shows it does.Automatic notifications
Docs update
None.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Written with Claude Code (Opus 5). Skills invoked:
/writing-pr-descriptions.A review on #91823 reported this. The test named above asserted the old behavior, so this PR changes what it claims.
The end-to-end run does not reproduce the stale map. The fix makes the hash depend on the snippet variant by construction, rather than through a difference in the restored map that happens to fall the right way.