Skip to content

fix(protocols): Info field order follows PyPy's attribute layout, not the declared fields #2003

Closed

Description

@JarryShaw

On PyPy, Info field order depends on earlier instances of the same class. PyPy reorders an instance's attribute storage to match the first instance it saw, and Info reads its field order from those attributes. So to_dict(), and anything rebuilt from it, can list fields in a different order from CPython.

  • Found on PyPy 8.0.1 (pypy3.11), while wiring PyPy into the ALL tier for ci: categorise the tests into tiers and run each tier where it belongs #1958 phase 3. A plain-Python reproduction shows the same reordering.
  • Fails:
    • test_to_dict_repeated_exthdr_1453_unit
    • test_multiinfo_1484_unit::test_to_dict_returns_a_plain_ordered_multi_dict_at_every_level
    • test_frame_layer_limit_1610_unit::test_a_cut_frame_rebuilds_byte_exact
  • Fix: take Info's field order from the class's declared fields, not from the instance's attribute order.

Activity

  1. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    fixPull requests that fix a defect (fix: subject prefix)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 20, 2026
  2. moved this to Pending in PyPCAPKiton Oct 20, 2026
  3. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 20, 2026
  4. moved this from Pending to WIP in PyPCAPKiton Oct 20, 2026
  5. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 20, 2026
  6. moved this from WIP to Needs decision in PyPCAPKiton Oct 20, 2026
  7. JarryShaw commented on Oct 21, 2026

    @JarryShaw
    OwnerAuthor

    i think the order is not required to preserve? Info and Schema construction are keywords only.

  8. JarryShaw commented on Oct 21, 2026

    @JarryShaw
    OwnerAuthor

    Construction is keyword-only, yes. The order still matters on the way back, when a protocol is rebuilt from its to_dict(). Two lookups infer structure from key order:

    • Protocol._lookup_payload treats the last nested key as the payload (keys[-1]);
    • IPv6._lookup_exthdr rebuilds the extension-header chain by walking items(multi=True) in order.

    On PyPy, with main's Info, a cut frame rebuilds at 902 octets against 14273 on the wire, and an IPv6 hop-dst-dst chain at 56 against 76. Details are in #2009.

    If order shouldn't matter, the fix belongs in those two lookups (option 2 on #2009). The payload and header chain would come from the protocol's declared structure, so Info needs no recorded order and #2009 closes. Shall I go that way?

  9. JarryShaw commented on Oct 21, 2026

    @JarryShaw
    OwnerAuthor

    so Protocol should look up payload by the protocol name, not the last key; IPv6 extension header chain is ordered using the OrderedMultiInfo and that one is specifically ordered.

  10. JarryShaw commented on Oct 21, 2026

    @JarryShaw
    OwnerAuthor

    Understood: Protocol._lookup_payload will find the payload by the protocol's name rather than by the last key. A worker has started. It will also check, on PyPy, why the repeated-extension-header rebuild still fails when the chain sits in an OrderedMultiInfo. #2009 closes as superseded.

  11. removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 21, 2026
  12. moved this from Needs decision to WIP in PyPCAPKiton Oct 21, 2026
  13. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 21, 2026
  14. added this to the PyPCAPKit v1.5 milestone on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions