Skip to content

fix(notebook-tools,#8057): registry rebaseline writes LF, not os.linesep - #8716

Merged
jsboige merged 1 commit into
mainfrom
fix/twin-registry-lf-write
Jul 28, 2026
Merged

jsboige merged 1 commit into
mainfrom
fix/twin-registry-lf-write

Conversation

@jsboige

@jsboige jsboige commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Grain: MED/tooling — lane myia-ai-01:CoursIA — prev: MED/docs (#8710)

check_twin_parity.py --update promet un diff chirurgical. Il tient cette promesse pendant le calcul et la perd a l'ecriture, sur toutes les machines Windows.

Le defaut

pfile.write_text(new_raw, encoding="utf-8")

Path.write_text ouvre avec newline=None, ce qui traduit chaque \n en os.linesep — donc en \r\n sous Windows. Le fichier entier est reecrit en CRLF, y compris les lignes que surgical_rebaseline venait deliberement de laisser intactes.

La docstring de cette fonction dit, mesure a l'appui, pourquoi elle existe :

Mesure firsthand sur le registre a 116 paires — un rebaseline d'UNE paire produisait 1108 insertions(+), 658 deletions(-) […] Le vrai changement (4 lignes) devenait irreviewable.

C'est exactement ce qui se reproduisait, a une echelle plus petite et par un autre chemin. Constate aujourd'hui sur deux PRs, toutes deux des rebaselines d'une seule paire :

PR Diff affiche Changement reel
#8709 +23/-16 1 SHA + 1 entree known_differences
#8713 +24/-16 sur deux fichiers idem, par fichier

Les -16 sont les lignes inchangees, supprimees puis reajoutees en CRLF. La ligne qu'un relecteur doit reellement examiner — le SHA rebaseline — se retrouve noyee au milieu.

Pourquoi ca n'avait jamais ete vu

Le defaut est invisible la ou core.autocrlf=true (ma machine, entre autres) : git renormalise en LF a l'ajout, le blob reste propre. Il n'apparait que la ou autocrlf est inactif, ou le CRLF part directement dans le blob. Un defaut qui ne se manifeste que sur une partie de la flotte voyage longtemps.

Et la suite de tests ne pouvait pas l'attraper : test_diff_limited_to_target_block et test_noop_is_byte_identical testent surgical_rebaseline, la fonction pure, sur des chaines. Elles passent sur toutes les plateformes meme quand le fichier ecrit sur disque est integralement reecrit. La garantie etait testee la ou elle tient et non appliquee la ou elle casse.

Le correctif, en deux couches

1. L'ecrivain. write_registry_text(path, text) ouvre avec newline="" — aucune traduction, le texte part tel quel. Utilise aux deux sites d'ecriture (file-per-entry et mono-fichier legacy).

2. .gitattributes. scripts/notebook_tools/twin_pairs.d/*.yaml text eol=lf. La premiere couche corrige cet outil ; la seconde tient l'invariant pour n'importe quel ecrivain — un Edit sous Windows, un script ad-hoc, un futur outil. Le fichier documente deja ce motif sous le nom « L268 » (« the Edit tool on Windows flips LF->CRLF intermittently when no explicit eol rule is set »), avec cinq occurrences constatees ; le registre en est la sixieme, et le bloc de commentaire du registre existait deja pour l'accueillir.

Tests

9 passed in 1.23s   (7 existants + 2 nouveaux)
  • test_write_preserves_lf_on_every_platform — ecrit via write_registry_text, relit en octets, exige l'absence de \r\n.
  • test_registry_blobs_are_lf_only — backstop : aucun blob du registre n'est en CRLF.

Ce second test interroge l'index (git ls-files --eol, colonne i/), pas le working tree. C'est le detail qui compte : ma premiere version testait les octets sur disque et echouait sur 130 fichiers parfaitement sains — avec core.autocrlf=true, un working tree en CRLF est correct, seul le blob doit etre en LF. Un test sur le disque aurait echoue sur toute machine Windows normalement configuree, pour un registre irreprochable. C'est la meme confusion de surface qui rend ce defaut difficile a voir.

Effet sur les deux PRs en cours

Une fois cette PR sur main, #8709 et #8713 rebasees verront leurs YAML renormalises en LF au prochain git add — leur diff retombera aux deux lignes reelles sans effort de leur auteur. Je l'ai signale sur les deux.

Perimetre

3 fichiers, +85/-2. Aucun notebook, aucun fichier de registre, catalogue byte-identique a main. Le comportement de surgical_rebaseline est inchange : cette PR corrige ce qu'on fait de son resultat.

See #8057

`Path.write_text(..., encoding="utf-8")` opens with `newline=None`, which
translates every `\n` to `os.linesep` -- CRLF on Windows. Half the fleet runs
on Windows, so a single-pair rebaseline silently rewrote every line of the
pair file, including the ones `surgical_rebaseline` had just left untouched.

The surgical guarantee was tested at the string level and unenforced at the
I/O level: `test_diff_limited_to_target_block` passes on every platform even
when the file written to disk is entirely rewritten.

Two layers:
- `write_registry_text()` opens with `newline=""` (no translation) and is used
  at both write sites;
- `.gitattributes` pins `twin_pairs.d/*.yaml` to `eol=lf`, so the invariant
  holds for any writer, not just this one.

Plus two regression tests: one on the writer, one asserting no registry blob
is CRLF in the index (`git ls-files --eol`, not the working tree -- with
`core.autocrlf=true` a CRLF working tree is correct and a byte test on disk
would fail on healthy Windows checkouts).

Observed on #8709 (+23/-16) and #8713 (+24/-16), both single-pair rebaselines
whose real change was two lines.

See #8057

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jsboige
jsboige merged commit 04f2bdb into main Jul 28, 2026
11 checks passed
jsboige added a commit that referenced this pull request Jul 28, 2026
check_twin_parity.py --update wrote CRLF line endings (Path.write_text translates
\n to os.linesep on Windows), which made the registry YAML diffs show as full-file
churn (+24/-16) instead of the real 8-line change. Fixed at source by #8716; this
branch predates that fix. git --renormalize applies the .gitattributes LF rule to
the tracked YAML without hand-conversion.

Co-Authored-By: Claude <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Jul 28, 2026
…iew fixes

Re-baseline after the cell 28/30 markdown fixes (callout rendering, cell-30
consistency, LaTeX restoration). python_sha -> 0994697; csharp_sha unchanged.
Twin parity OK=136 DRIFT=0. Registry written in LF (post-#8716).

See #8718

Co-Authored-By: Claude <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Jul 28, 2026
…riance factor

Formula verified firsthand against Herbrich-Minka-Graepel 2007, and the committed output re-derived independently:

  c = 13.1762   V(0) = 0.79788   W(0) = 0.63662
  sigma' = sqrt(s^2 (1 - (s^2/c^2) W)) = 7.1945   <- committed output, and the Infer.NET posterior of cell 16
  without the s^2/c^2 factor                = 5.0234   <- what #8709 had

The sigma^2/c^2 factor is present in both the LaTeX and the C# cell. The .NET cell carries execution_count=21 (real local execution), its output reproduces the engine's own N(29.21, 7.19) from section 3, and the notebook is therefore self-consistent rather than merely plausible.

No escape corruption introduced (13 literal \n, all legitimate C# Console.WriteLine, identical count on main). No output leak, no null execution_count. Twin registry YAML is LF post-#8716.

Credit where due: po-2026 caught this by refusing to stand aside on claim priority when the substance was wrong. That is the behaviour the review rules are for.

Closes #8704.
jsboige added a commit that referenced this pull request Jul 28, 2026
…) (#8713)

Renormalisation faite avec le bon outil : `git add --renormalize` sur le repertoire du registre, pas de reecriture manuelle. Le diff affiche desormais le vrai changement (+8 lignes) au lieu du churn CRLF pleine-page — les blobs CRLF dataient d'avant #8716, ils ne venaient pas de cette PR.

Rattachement PyMC-7 / PyMC-13 au chapitre MBML : l'asymetrie relevee dans #8711 est reelle et la correction s'aligne sur le traitement deja applique aux autres entrees du chapitre.

See #8711, #8081.
jsboige added a commit that referenced this pull request Jul 28, 2026
…iew fixes

Re-baseline after the cell 28/30 markdown fixes (callout rendering, cell-30
consistency, LaTeX restoration). python_sha -> 0994697; csharp_sha unchanged.
Twin parity OK=136 DRIFT=0. Registry written in LF (post-#8716).

See #8718

Co-Authored-By: Claude <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Jul 28, 2026
…gma^2/c^2 factor (#8720)

* fix(probas,#8718): PyMC-8 TrueSkill variance closed-form — restore sigma^2/c^2 factor

Cell 29 (executed) and cell 28 (LaTeX prose) of the "7 bis" closed-form EP
section contracted the posterior variance by W(t) alone, instead of the
canonical (sigma_w^2 / c^2) * W(t) factor (Herbrich, Minka & Graepel 2007).

Consequence: the cell printed sigma 8.33 -> 5.02, while the C# twin Infer-8
cell 16 (the real Infer.NET EP engine on the same config) prints N(29.21, 7.19).
A twin pair thus displayed two different std-devs for the same update, and the
Python side deviated from the reference engine.

Fix:
- cell 29 code: sig_new = sqrt(sig**2 * (1 - (sig**2/c**2)*W))  (both w and l)
- cell 28 LaTeX: variance update now shows the sigma^2/c^2 ratio + a callout
- Re-executed cell 29 (Stop & Repair): real captured output sigma -> 7.19 on
  both sides, matching Infer-8 cell 16. Cell is self-contained (scipy + math,
  hardcoded params, no kernel-state deps), so standalone exec reproduces the
  kernel stdout exactly.

This is the Python source of the error propagated into my closed #8709 (Infer-8
C#, superseded by po-2026 #8715 which carries the canonical form + executed
proof). Fixing the root on the PyMC twin.

See #8718
See #8081
See #8704

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(twin-parity,#8718): rebaseline Probas-8 TrueSkill python_sha after variance fix

Records the PyMC-8 cell 28+29 closed-form variance correction (sigma^2/c^2
factor restored) on the Python twin. python_sha rebaselined to the committed
fix; csharp_sha unchanged (Infer-8 carries its own correction in #8715).
known_differences documents the fix provenance (#8718, root of the error
propagated into the closed #8709).

Twin parity: OK=136 DRIFT=0.

See #8718

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(probas,#8718): address review — cell30 consistency + callout rendering + LaTeX

Addresses ai-01's CHANGES_REQUESTED on #8720 (maths correct, 3 rendering/consistency
defects). Markdown-only, no re-exec.

1. cell 30 (interpretation of cell 29) still cited the OLD contraction:
   "sigma: 8,33 -> 5,02, soit -40%" — contradicting cell 29 which now prints 7.19.
   Fixed to "8,33 -> 7,19, soit -13,7%" (matches the executed output). "forte
   contraction" softened to "contraction" since the callout itself establishes
   that sigma^2/c^2 bounds the contraction. ±4.2 points on the skill left intact
   (25 -> 29.21 is still correct).

2. cell 28 callout ("Detail subtil") was double-escaped: a raw-string insertion
   left literal \n and \u00e9/\u2014 in the source, rendering as
   "\n> **D\u00e9tail subtil**" instead of a blockquote. Rewritten with real
   unicode chars + real newline + doubled LaTeX backslashes. Renders as a proper
   blockquote now.

3. Pre-existing LaTeX corruption in cell 30 (same class as #8709): BEL+pprox
   (\approx mangled) and TAB+o (\to mangled) — a write layer interpreted \a and
   \t before JSON serialization. Restored to \approx and \to.

Verified: 0 control characters remain anywhere in the notebook; byte-stable
round-trip; cell 29 (executed, the actual fix) unchanged.

See #8718

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(twin-parity,#8718): re-rebaseline Probas-8 python_sha after review fixes

Re-baseline after the cell 28/30 markdown fixes (callout rendering, cell-30
consistency, LaTeX restoration). python_sha -> 0994697; csharp_sha unchanged.
Twin parity OK=136 DRIFT=0. Registry written in LF (post-#8716).

See #8718

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
@jsboige
jsboige deleted the fix/twin-registry-lf-write branch September 2, 2026 13:18
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