Repository navigation
Conversation
Check type(obj) is not self.owner at the start of InstanceRepair.record() and reject with restart_required before writing repair metadata or recording constructor fields on derived instances. Also check type(obj) is not self.owner in InstanceRepair.revert() before reading _instance_dict() and raise in_doubt when a repaired instance changed its class. Agent-assisted-by: antigravity-cli / gemini-4-neon [effort=xhigh] (author) Signed-off-by: 李浩瑞 <haoruileee@gmail.com>
Insert an exact-owner check at self.prefix_length in InstanceRepair.instrument() so derived subclasses reject with restart_required after the original constructor prefix and before evaluating any added field RHS expression, while preserving index-0 docstrings and keeping defensive exact-owner guards in InstanceRepair.record() and InstanceRepair.revert(). Strengthen conformance tests in test_instance_repair.py to verify added RHS expressions are not called on derived construction, custom setter writes distinguish original-constructor writes from patch-added writes, and post-install __class__ reassignment isolates with in_doubt with zero attribute-hook or _instance_dict accesses. Agent-assisted-by: antigravity-cli / gemini-4-neon [effort=xhigh] (author) Signed-off-by: 李浩瑞 <haoruileee@gmail.com>
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.
Governing Issue and delivery slice
Refs #1048
src/inferrsi/box/kernel/repair.py:self.afterandself.prefix_length = len(before.body)inInstanceRepair.__init__()and inserts a pre-RHS exact-owner check (self.hook_name(self.receiver)) atself.prefix_lengthinInstanceRepair.instrument()— right after the original constructor prefix and before the first added field statement begins evaluating (preserving index-0 docstrings before witness injection).InstanceRepair.record(self, obj, name=MISSING, value=MISSING)to rejectif type(obj) is not self.owner:viasyntax.reject("repair of a class with live derived instances requires restart")on both the 1-arg pre-RHS guard (name is MISSING-> returnsNone) and the defensive 3-arg per-field path before_state(),_history(),_remember(), orSTORE_ATTR.InstanceRepair.revert(), checksif type(obj) is not self.owner:before_instance_dict(obj)or journaling mutations and raisesBoxError("in_doubt", "repaired instance changed its class"), isolating safely on bothuninstall()and failed-install()rollback paths if a repaired instance had its__class__reassigned.tests/box/conformance/test_instance_repair.py:test_derived_instance_constructed_during_repair_is_rejected_cleanlyverifying that both plain (PlainDerived) and custom-__setattr__(CustomDerived) subclasses raiseBoxErrorwithcode == "restart_required"before a computed added field RHS helper (compute_extra) is invoked (rhs_calls == []), while preserving original-constructor writes (derived.writes == ["config"],derived.registry == {"config": config}), leavinghook_nameand repaired fields unwritten, and verifying exactmod.Layerconstruction andbox.uninstall()succeed cleanly (code == "ok",not box.isolated).test_repaired_instance_reassigned_to_derived_class_isolates_on_uninstallverifying that reassigning a repaired instance's__class__toGuardedDerived(tracing__getattribute__,__setattr__,__delattr__, plus wrappingrepair._instance_dict) isolates onbox.uninstall()withcode == "in_doubt"andbox.isolated, with zero attribute-hook calls, zero_instance_dictreads on the reassigned instance, and an unchanged instance dictionary.src/inferrsi/box/kernel/repair.py, or Issue closure.Knowledge authorship declaration
No path protected by
docs/knowledge-model-policy.mdis changed. The declaration is filled for completeness against the current head.Changed artifacts and evidence
src/inferrsi/box/kernel/repair.py:InstanceRepair.instrument()inserts pre-RHS exact-owner check atself.prefix_length;InstanceRepair.record()checksif type(obj) is not self.owner:on both pre-RHS guard and per-field paths (restart_required)9f6cbb01):install=ok uninstall=ok has_extra=False registry={'cfg': {'k': 2}, 'extra': 42}; after (761adf72):BoxError("restart_required")raised withrhs_calls == [], original-constructor write intact (derived.writes == ["config"]), nohook_nameor added fields written, and cleanuninstall() == "ok"; verified bytest_derived_instance_constructed_during_repair_is_rejected_cleanly+ 4-mutant kill checks + docstring/positional-only/mid-constructor flip probes on Py3.10 & Py3.11761adf72, Windows, macOS, and live NPU verification pendingin_doubtinInstanceRepair.revert()when a repaired instance changed its class without reading or mutating the reassigned class's attribute dictsrc/inferrsi/box/kernel/repair.py:InstanceRepair.revert()checksif type(obj) is not self.owner:before_instance_dict(obj)and raisesBoxError("in_doubt", "repaired instance changed its class")test_repaired_instance_reassigned_to_derived_class_isolates_on_uninstall(code == "in_doubt",box.isolated,attr_hooks == [], zero_instance_dictreads onfresh, unchanged__dict__) + mutant kill check + hostile__dict__/__setattr__/__getattribute__probes on Py3.10 & Py3.11761adf72pendingChecks and dependencies
761adf72bbd4c250635ce36cf6d0f3aee76afa30(underenv -u PYTHONPATH):ruff check src tests tools(Python 3.10.20 & 3.11.14): passed (All checks passed!).git diff origin/main..HEAD --check: passed.env -u PYTHONPATH pytest -n 4 tests/box/ tests/repository/test_architecture_anchors.py:302 passedon both Python 3.10.20 (8.35s) and Python 3.11.14 (8.74s).9f6cbb01-> 2 failed; missing pre-RHS AST insert -> 1 failed; missingrecord()guard -> 1 failed; missingrevert()guard -> 1 failed) plus 5 adversarial probes (docstring-only prefix, positional-only custom receiver +AnnAssign, mid-constructor__class__flips in field 1 and field 2 RHS, and hostileEvilDerivedwith exploding__dict__/__class__/__getattribute__/__setattr__and spoofing metaclass__eq__) passed on both Python 3.10.20 and Python 3.11.14.tools/check_pr_references.py,tools/check_knowledge_model_policy.py, andgit merge-tree --write-tree origin/main HEAD(9f6cbb01): passed.git 2.43.0 < 2.45), Windows/macOS advisoryhost-compatibility,installed-package,dashboard-browser, live NPU runtime tests, and upstream GitHub Actions CI for761adf72(triggered on push; prior headb7d984b2passed 10/10 checks in run47256992078).origin/main9f6cbb013839384a032a27e103318b30de35d56c. Zero file overlap with open PRs; pre-install_instancesandBoxErrorprotocol contracts are unchanged.Remaining work and Issue closure
761adf72, and independent review.