Skip to content

Record the RelP policy in R-lens checkpoints and repair mislabelled ones - #58

Merged
a9lim merged 1 commit into
mainfrom
fix/relp-checkpoint-policy
Oct 28, 2026
Merged

a9lim merged 1 commit into
mainfrom
fix/relp-checkpoint-policy

Conversation

@a9lim

@a9lim a9lim commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Bug

save_lens_checkpoint_accumulator took backward_rules but never passed it to _save_lens_components, whose default was "standard". So every checkpoint of a --relp fit (the CLI default), and every final lens promoted from one by promote_lens_checkpoint, recorded the standard estimator policy. The math was RelP throughout: fit_jlens wraps the estimator in relp_backward_rules, and the relp name comes from the same variable. The resume and reuse checks in _fit_jlens_transaction and the CLI no-op preflight compare the requested policy for equality, which caused two failures:

  • an interrupted R-lens fit could never resume and restarted from zero;
  • rerunning 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.json carries {"method": "jlens_cotangent_sum", …} with no backward_rules.

Fix

  • Forward the rules. _save_lens_at and _save_lens_components now take backward_rules with no default, so a dropped argument raises a TypeError instead 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.
  • Bind the name to the rules. save_lens and save_lens_checkpoint_accumulator raise when (name == "relp") != (backward_rules == "relp"), so only a RelP fit can write local/relp.
  • Repair stored artifacts on load. Given that invariant, a local/relp pointer with the standard label can only be a pre-fix RelP fit. _load_sidecar_at relabels 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 if RELP_RULES changes later. Once the pointer passes full validation, the loader rewrites it atomically in place. Every caller of _load_sidecar_at already 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.
    • I chose this over a one-off repair command. R-lenses fitted elsewhere, including any on Jobe, and interrupted pre-fix checkpoints heal the first time anything loads them. Nobody has to remember to run a repair first, and a stale label can't trigger the overwrite this bug caused.
  • Flush CLI progress lines. The on_progress printers in the lens, sae, manifold and shared runners now use flush=True. A detached fit logging to a file had shown no progress for over 2 hours.

Tests (tests/test_relp.py)

  • A RelP checkpoint records the RelP policy. The test reads the raw pointer before any loader touches it.
  • An interrupted RelP fit resumes from its checkpoint: the estimator sees only the remaining prompts, and the result matches a full fit.
  • A promoted final carries the RelP policy, and the checkpoint is reaped.
  • Rerunning a finished RelP fit is a no-op: no estimator call and no tensor write. This holds both for the session and for the CLI's model-free preflight.
  • These four post-fix tests also assert that the loader never had to relabel anything.
  • A pre-fix final is relabelled and persisted, and a rerun then no-ops. A pre-fix checkpoint resumes. Standard labels under local/default are left unchanged.
  • The writers reject a name/rules mismatch.

With the forward reverted and the relabel disabled, 7 of the new tests fail.

Locally, pytest tests passes 4002 tests. Three tests fail, and they fail identically on clean main on this Mac: the browser affine-fisher fixture, browser sampling fixture case2, and TestPrefixCache::test_cache_hit_matches_no_cache_output. They test Mac numerics and the prefix cache, and none of them touch lens code.

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.
@a9lim
a9lim enabled auto-merge October 28, 2026 19:16
@a9lim
a9lim merged commit 29b5203 into main Oct 28, 2026
18 of 21 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.

1 participant