Repository navigation
Snapshot constructor receivers generally without invoking application getters - #157
Merged
Merged
Conversation
This was referenced Oct 26, 2026
Essoz
marked this pull request as ready for review
October 26, 2026 19:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TrainCheck serializes selected API arguments before calling the wrapped function. For a class's
__init__, ordinary introspection can execute properties or dynamic lookup on a partially initialized receiver. This caused the reproducedOpOverloadPacketrecursion, but the unsafe assumption applies to other constructors too.This PR now handles constructor receivers generally. Class traversal explicitly identifies initializers; there is no operator-type special case or function-name heuristic. Before the initializer runs, record receiver identity and native stored state without invoking application properties, custom descriptors, dynamic lookup, or custom metaclass lookup. Preserve the other arguments, receiver identity, application exceptions, and PRE/POST pairs.
Representation and compatibility
_TRAINCHECK_CONSTRUCTOR_SNAPSHOTexplicitly recordsbefore_init/stored_attributes_only, unavailable dictionary storage, unset slots, and requested-but-unavailable fields.The full contract is in docs/constructor-snapshots.md.
Validation at
98fed5058bfc0c712c0e9a717a52c1bc1c22466686cbfc297cb27bac4a99359224cf21d48ecdf581by executing a property before the ordinary class initializer runs; the same test passes after this change. It does not depend on calling a new wrapper interface.test_traincheck_internal_attr_hiddenandtest_inject_eval_loop.--check-untyped-defs --disallow-untyped-defs --disallow-any-generics --follow-imports=silent). The legacy tracer has 28 → 21 errors under those stronger options, with none added; dependency bodies are not fully checked.config/config.py,instrumentor/proxy_wrapper/hash.py, andinstrumentor/proxy_wrapper/subclass.pyundertraincheck/. These unrelated formatting changes are not included.Rechecked the real two-step tiny Transformer CLI using the prior signed #154–#157 composition
035f7f1976c5d84bd01f5d96bb095fb07c9cc059with this commit's two production files overlaid and SHA-256 verified:All three instrumented runs exactly match plain losses, parameters, gradients, cached mask, and Torch CPU RNG; cover all 12 parameter paths; and complete two active, passing invariant decisions each. No incomplete/duplicate API pairs or duplicate raw records. Every observed initializer PRE receiver has exactly one explicit snapshot. API/VAR counts match the prior composition; the snapshot counts reflect the generalized representation. This is correctness validation, not a tracing-speed improvement claim, and was CPU-only.
Reproduce local checks with
python -m pytest -q tests/test_constructor_snapshot.py,python -m pytest -q tests, and the pinned hooks for the five changed files. Exact commands, raw traces, harnesses, source hashes, before/after failures, and coverage reports are retained at/Users/matt/gitrepos/traincheck/outputs/constructor-generalization-20261027/, especiallyvalidation.jsonandcli/validation.json.All commits are signed. Targets main directly; production changes are independent of #154, while the composed Transformer check uses its subclass assignment fix. No PR has been merged.