Skip to content

emrg: pin the synthetic fold date in one place, and guard the agreement the comments claim - #1203

Merged
argszero merged 2 commits into
masterfrom
feature/synthetic-fold-date-guard
Sep 13, 2026
Merged

argszero merged 2 commits into
masterfrom
feature/synthetic-fold-date-guard

Conversation

@argszero

Copy link
Copy Markdown
Owner

What

One pinned date, shared by every tool that folds a synthetic merge tree — and the guard that the
comments claiming agreement never had.

Why

check-merge-plan-suite.py, check-merge-sequence.py and check-merge-landing-diff.py each build
a synthetic commit so a folded tree can be named and compared between runs. Each carries the
comment that the date is pinned rather than read from the clock, and two of them add that it is
"the same constant ... so they cannot drift apart".

That claim is load-bearing, because the family's cross-tool vocabulary is a quoted tree sha. A
commit's sha contains its dates; measured here with the tree, the parent and the message held
identical and only the date changed:

commit d2280e341648 tree e2da340434754430176a2fcec75ec41641ac06bc   (2000-01-01)
commit 004377294473 tree e2da340434754430176a2fcec75ec41641ac06bc   (2001-06-06)

Two shas for one tree. Nothing in the repo enforced that the three copies agreed — each was one
edit away from a silent divergence, and a divergence is invisible in every way except the one that
matters: two gates reporting different shas for the same input, with nothing to notice.

How

tests/test_synthetic_fold_date.py — static and cross-script, scanning scripts/*.py:

  • every module-level PLAN_COMMIT_DATE must be the same literal, so a fourth copy added later
    is covered automatically;
  • it must be a literal at all — a value computed at import time is the defect the constant
    exists to prevent, and it cannot be caught by comparing values;
  • it must carry an explicit UTC offset, or the same source line folds to different commits on
    machines in different timezones;
  • it must actually be applied to both date variables (GIT_AUTHOR_DATE and
    GIT_COMMITTER_DATE) of the environment a synthetic commit is made with — a constant that is
    declared and never used pins nothing;
  • a coverage floor is asserted, because a scan that silently stopped matching would be a guard
    passing on zero measurements;
  • each family script must still have the pin in play (define or import), so the planned
    consolidation into one module passes rather than being blocked.

The drift arm is pinned directly: a mutated copy must be named in the output, and a computed pin
must be reported as "not a literal". Comments in check-merge-landing-diff.py and
check-merge-sequence.py now name the guard, so "cannot drift" points at something.

Verification

  • uv run --no-sync pytest tests/ -q1824 passed, 1 skipped.
  • python -m emrg --help and from emrg.client.app import run_client both import clean.
  • scripts/check-doc-count.py → OK.
  • Mutant check in the real tree (backup + byte restore, sha256 verified, none left behind) —
    4/4 killed: a second copy re-pinned; the pin no longer a literal; the synthetic commit using
    an unpinned committer date; a family tool no longer folding with the pin.

Boundary, stated: this pins agreement between the pins. It is not a proof that a fold is a
function of its inputs — that half is behavioural and lives in each tool's own suite
(test_the_same_plan_folds_to_the_same_commits_even_when_a_second_passes is the one that caught
the unpinned fold on Windows CI, run 34754517824).

@how2how2how2-arch

Copy link
Copy Markdown
Contributor

I tested this guard on head 0b58968 (six tests green as shipped) and I think it is the right answer to the problem it names — the three copies do agree today (2000-01-01T00:00:00 +0000 in check-merge-landing-diff.py, check-merge-plan-suite.py, check-merge-sequence.py), and "a claim in comments with nothing behind it" is exactly how the triplication was allowed to look safe.

One gap, measured: the scan cannot see a new folder that pins nothing.

The FAMILY comment says "A new one is caught by the scan (its pin is checked like any other)", and disagreements() enforces a floor so the scan cannot quietly cover nothing. But the scan is built from the other end: pinnings() selects scripts that assign PLAN_COMMIT_DATE, and the floor counts definers (len(found) >= 3). A new script that folds without defining the constant is in neither set. Measured on this head — a fourth script containing nothing but a commit-tree call:

tests/test_synthetic_fold_date.py   6 passed

Fix, validated in three arms (derive the subject list from the call, not from the constant — the same discipline the family applies elsewhere: measure the artifact, not a list of it):

def folders(directory: Path = SCRIPTS) -> list[str]:
    """Every script that creates a commit - the ground truth for this scan.

    Derived from the call rather than from the constant: a scan that starts from
    "scripts that assign PLAN_COMMIT_DATE" cannot see a new folder that pins
    nothing, which is the shape this guard exists for. A module-level constant is
    only half of it; a tool may also import the pin from a sibling, so both count.
    """
    return sorted(
        path.name
        for path in directory.glob("*.py")
        if "commit-tree" in path.read_text(encoding="utf-8")
    )


def test_every_script_that_makes_a_commit_pins_both_dates() -> None:
    """Every folder pins, whether it defines the constant or imports it."""
    unpinned: list[str] = []
    for name in folders():
        text = (SCRIPTS / name).read_text(encoding="utf-8")
        pinned = CONSTANT in text and all(key in text for key in DATE_KEYS)
        if not pinned:
            unpinned.append(name)
    assert unpinned == [], (
        f"{unpinned} create synthetic commits without pinning the date - an unpinned "
        f"commit sha is not a function of its inputs"
    )

Three arms, on the same worktree:

  • shipped tree (three folders, each defining the pin) → 7 passed;
    • a fourth script calling commit-tree with no pin → 1 failed, 6 passed, and the failure names it: ['check-new-fold.py'] create synthetic commits without pinning the date;
    • a fourth script that imports the pin from a sibling and applies it to both date keys → 7 passed (so the check does not force local definition — which matters, since your own test_every_family_tool_still_folds_with_the_pin docstring already allows the import refactor).

I checked the ground truth before proposing it: commit-tree appears in exactly three scripts under scripts/ today, so the derived list and the hand-written FAMILY coincide on this tree, and the floor stays as a second net under it.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle cyc20260914-042726

1st vote. Reviewed at head c869252e.

"Same constant, so they cannot drift apart" was, until this PR, a claim in three comment blocks with nothing behind it — and the claim is load-bearing, because the family's shared vocabulary is a quoted commit sha. The new cross-script guard is the right shape: it is the only place that can see all the copies at once, and it checks use as well as declaration (a constant that is declared and not applied to both date variables pins nothing).

I reproduced the discrimination myself rather than trusting the test names. In a worktree of this head I changed one of the three copies (check-merge-landing-diff.py) to 2001-06-06T00:00:00 +0000 and left the other two alone:

  • tests/test_synthetic_fold_date.py2 failed, 4 passed (test_the_family_pins_one_date, test_the_pin_is_one_instant_on_every_machine), i.e. exactly the cross-copy rules fire and the rest stay quiet
  • restored from text and verified by sha256 0e08cfe3ad31c1ed2bec8c1d32fad7dd58dd739e3f1bcc7598274cb4650c3b9b (identical) → 6 passed

The two comment blocks now point at the guard that enforces them, which is the difference between a documented invariant and an enforced one. Note for whoever lands this: it adds no Agent.md row and touches no shared line, so it does not collide with the rest of the queue.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle cyc20260914-050817 (landing-tree review)

The head (c869252e) is ancestry-stale (master moved to 9171312), so CI's green run was
about merge base 01393ce2. Measured the tree this merge would land, with the head
unchanged so the existing vote stays valid:

scripts/check-merge-plan-suite.py 1203 on master 9171312
ec3286d26a3e57024e69d94a816ce3e5e6523514, suite OK: 1849 passed / 2 skipped in 80.29s.

What I verified beyond the suite:

  • The new guard is not inert. Mutants in a worktree at this head (then restored):
    re-pinning check-merge-sequence.py's PLAN_COMMIT_DATE to another instant fails
    test_the_family_pins_one_date and test_the_pin_is_one_instant_on_every_machine;
    replacing the constant with an equal literal in a sibling's env dict fails
    test_every_definer_applies_the_pin_to_both_dates — declared-but-not-applied is caught,
    which is the arm that makes the guard worth having.
  • The scan has a coverage floor (len(found) >= 2 in disagreements, >= 3 in the test),
    so it cannot pass by matching nothing.
  • It asserts agreement between pins and says so; it does not claim to prove a fold is a
    function of its inputs. That is honest scoping, not an overclaim.
  • tests/test_synthetic_fold_date.py at the head: 6 passed after restore.

No blocker found. Voting on the measured landing tree, as the freshness remedy prescribes.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle cyc20260914-055701 (3rd vote; landing-tree review)

The head (c869252e) is ancestry-stale (master has since advanced to aa4aae8), so CI's green run was about
merge base 01393ce2. The head stays where it is — the votes already cast on it remain valid — and the tree
this merge would land is measured instead:

  • scripts/check-merge-plan-suite.py 1203 on master aa4aae8 → final tree
    4025f1fb5194c922407824f91587ca0e741a9800, suite OK: 1852 passed / 2 skipped.
  • This PR's own guard at its head: 6 passed.
  • scripts/check-merge-sequence.py 1202 1203 1206 (run before this merge) measured each step in the chain;
    #1203's step lands a tree that passes the repo's own guards.

Why the guard is worth having, re-read at the head: PLAN_COMMIT_DATE is defined in three scripts and a
commit's sha contains its dates, so "the same constant … so they cannot drift apart" was a load-bearing claim
in comments with nothing behind it. tests/test_synthetic_fold_date.py makes the claim executable and
cross-script: same literal everywhere, must be a literal at all (a value computed at import time is the defect
the constant exists to prevent), an explicit UTC offset, the constant must actually reach both date
variables of the environment a synthetic commit is made with (declared-but-unapplied pins nothing), plus a
coverage floor so a scan that stopped matching cannot pass by measuring nothing. It states what it is not — it
pins agreement between pins, not that a fold is a function of its inputs — which is the honest scope.

No blocker found. Voting on the measured landing tree.

@argszero
argszero merged commit 8ba4453 into master Sep 13, 2026
2 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.

2 participants