Repository navigation
Record the RelP policy in R-lens checkpoints and repair mislabelled ones - #58
Merged
Merged
Conversation
save_lens_checkpoint_accumulator took backward_rules but never passed it to _save_lens_components, whose default was "standard". Every checkpoint of a RelP fit, and every final promoted from one, therefore recorded the standard estimator policy. The math was RelP throughout, but the session's resume and reuse checks compare the requested policy for equality: an interrupted R-lens fit restarted from zero, and rerunning a finished one refitted and overwrote it. - Forward the rules, and drop the default from the private writers so a dropped argument is a TypeError rather than a silent mislabel. - save_lens and save_lens_checkpoint_accumulator reject a name/rules mismatch: only a RelP fit writes local/relp. - That makes a standard label under local/relp proof of the pre-fix bug. The sidecar loader relabels such a pointer with the RelP policy (rules pinned to the set every pre-fix fit ran) and rewrites it in place once it validates, under the artifact lock every pointer writer holds. Stored R-lenses and their checkpoints heal on first load, with no repair command to remember. - CLI progress lines flush, so a detached fit logging to a file shows progress.
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.
Bug
save_lens_checkpoint_accumulatortookbackward_rulesbut never passed it to_save_lens_components, whose default was"standard". So every checkpoint of a--relpfit (the CLI default), and every final lens promoted from one bypromote_lens_checkpoint, recorded the standard estimator policy. The math was RelP throughout:fit_jlenswraps the estimator inrelp_backward_rules, and therelpname comes from the same variable. The resume and reuse checks in_fit_jlens_transactionand the CLI no-op preflight compare the requested policy for equality, which caused two failures:drowse lens fit <model>on a finished R-lens refitted it and overwrote it.The bug has been present since RelP landed in 70a0226 (2026-09-07). It surfaced on a 2.3-hour Qwen3-8B R-lens whose
local/relp/manifest.jsoncarries{"method": "jlens_cotangent_sum", …}with nobackward_rules.Fix
_save_lens_atand_save_lens_componentsnow takebackward_ruleswith no default, so a dropped argument raises aTypeErrorinstead of silently mislabelling the artifact. I audited every save, promote, top-up and reuse path. Only this one call dropped the rules; promotion copies the checkpoint's own sidecar, so it inherited the error.save_lensandsave_lens_checkpoint_accumulatorraise when(name == "relp") != (backward_rules == "relp"), so only a RelP fit can writelocal/relp.local/relppointer with the standard label can only be a pre-fix RelP fit._load_sidecar_atrelabels it with the RelP policy, using_PRE_FIX_RELP_RULES. That is a pinned copy of the rule set every pre-fix fit ran, so the relabel stays exact ifRELP_RULESchanges later. Once the pointer passes full validation, the loader rewrites it atomically in place. Every caller of_load_sidecar_atalready holds the pointer's artifact lock, which every pointer writer also takes. The new pointer names the same immutable shards, so the swap is safe against concurrent fits and generation GC. A failed write only logs a warning, and the caller still gets the relabelled view.on_progressprinters in the lens, sae, manifold and shared runners now useflush=True. A detached fit logging to a file had shown no progress for over 2 hours.Tests (
tests/test_relp.py)local/defaultare left unchanged.With the forward reverted and the relabel disabled, 7 of the new tests fail.
Locally,
pytest testspasses 4002 tests. Three tests fail, and they fail identically on cleanmainon this Mac: the browser affine-fisher fixture, browser sampling fixture case2, andTestPrefixCache::test_cache_hit_matches_no_cache_output. They test Mac numerics and the prefix cache, and none of them touch lens code.