Skip to content

fix: make introspection JSON output deterministic#6076

Merged
Tpt merged 1 commit into
PyO3:mainfrom
jelmer:fix-introspection-reproducibility
May 27, 2026
Merged

fix: make introspection JSON output deterministic#6076
Tpt merged 1 commit into
PyO3:mainfrom
jelmer:fix-introspection-reproducibility

Conversation

@jelmer
Copy link
Copy Markdown
Contributor

@jelmer jelmer commented May 26, 2026

The introspection proc macros (used by the experimental-inspect feature) accumulated each JSON object's fields in a HashMap before serializing them in iteration order. Because std's default hasher is seeded randomly per process, the emitted JSON key order varied between otherwise identical builds, leaving the embedded introspection chunks non-reproducible.

Switch to BTreeMap so the keys come out in a stable (alphabetical) order. JSON objects are unordered by spec, so downstream parsers are unaffected.

Caught via Debian's reproducible-builds rebuild of pysequoia 0.1.34-2, which fails with diffs like:
{"name","parent","type","annotation"}
vs
{"annotation","parent","type","name"}

The introspection proc macros (used by the `experimental-inspect`
feature) accumulated each JSON object's fields in a `HashMap` before
serializing them in iteration order. Because `std`'s default hasher is
seeded randomly per process, the emitted JSON key order varied between
otherwise identical builds, leaving the embedded introspection chunks
non-reproducible.

Switch to `BTreeMap` so the keys come out in a stable (alphabetical)
order. JSON objects are unordered by spec, so downstream parsers are
unaffected.

Caught via Debian's reproducible-builds rebuild of pysequoia 0.1.34-2,
which fails with diffs like:
  {"name","parent","type","annotation"}
vs
  {"annotation","parent","type","name"}
Copy link
Copy Markdown
Contributor

@Tpt Tpt left a comment

Choose a reason for hiding this comment

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

Thank you!

@Tpt Tpt added this pull request to the merge queue May 27, 2026
Merged via the queue into PyO3:main with commit 8b1960e May 27, 2026
48 checks passed
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.

2 participants