Skip to content

seam guard: fork-seams.json is a gate file; a seam file may get lost upstream lines back (#968) - #1034

Merged
scuttletoby merged 4 commits into
mainfrom
fix/968-seam-guard
Nov 22, 2026
Merged

scuttletoby merged 4 commits into
mainfrom
fix/968-seam-guard

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Follow-ups from the #965 reviews: the issue body plus its one comment (the merge-path lens on #979).

What changed, per item

1. The merge gate rated .github/fork-seams.json as a normal file. It is critical now.

  • .github/fork-pr-queue.json: the gate rule lists .github/fork-seams.json.
  • A list-only change (an announcement) now needs the merge-path and state lenses. A change with other files needs those two plus the code lens. Before, one code lens was enough.
  • The original reason for keeping it out of the gate rule (Owner question: extra reviewer for workflow and gate changes? #82: a critical file made the gate lenses the only required ones on app changes) no longer applies, because an app file plus a gate file now needs both sets of lenses.
  • Tests, each red first:
    • review_judge.test.py: NOT_GATE keeps only .github/fork-ci-tests.txt. The seam list is in the critical-paths list, and the new test_a_seam_list_change_needs_the_gate_lenses_and_with_code_the_code_lens covers it. Red: 3 failures ('normal' != 'critical').
    • head_check.test.py: the real-config test test_an_app_change_that_adds_a_seam_needs_the_gate_lenses_and_the_code_lens passes only with merge-path, state and code. Red: 0 != 1 … the path rules decide: normal, lenses code.

Comment, point 1: the doc and the rule file disagreed. Fixed by item 1. The doc now names what enforces it: the "Adding a seam line" step 1 in docs/fork/updates.md points to the gate rule.

2. A seam file's changed upstream lines can be changed back.

  • fork-seam-check.cjs adds a new restorableLost. On a pull request it applies to a seam file whose lost entry the pull request's own list lowers, with neither count raised, and only among the entries its run counts from upstream (listEditedCounts):
    • Each gone it lowers allows one added line, the line put back.
    • Each lines it lowers beyond those allows one lost line of main's file, a line moved or re-indented back. A line put back in place lowers both counts.
  • The run from upstream (findLostNotUpstream) holds the lowered entry exactly. So a fork line added in place of upstream's line lowers nothing there and is refused.
  • Main's tree alone cannot tell the two apart. The tests check that the fork-tests run (--no-upstream) passes a real restore and the fork-checks run refuses a swap.
  • If lost is left as main's, a put-back line is still refused as before, and the refusal now says: (if it puts back an upstream line counted in "lost", lower that entry in this change's .github/fork-seams.json).
  • New test in fork-seam-check.test.cjs, "a pull request that lowers a seam file's "lost" entry may put those upstream lines back":
    • pass: both lines back with the entry dropped; only the gone line back with the entry lowered.
    • refused: half-way (entry not lowered); a fork line in place of upstream's (counted from upstream); a line put back plus a moved seam line; one count raised while the other is lowered.
    • Red: p.ts: adds \b(x);`and1 upstream line deleted, moved or re-indented by this change`, the exact refusal the issue describes.
  • docs/fork/updates.md says this next to "may not move a seam line".

3. Generic seam lines: dropped (see Left).

4. Note for #817 step 2: recorded. The note was not in #817's body or comments, and not in #965's body. Added one comment on #817: #817 (comment)

Comment, point 2: binding an announcement to its pull request: dropped (see Left).

Left

  • Item 3 (pin generic seam lines by neighbouring context): not small. It needs a new entry form (a line plus its context) in parseConfig, findSeamBreaches, findSpareSeamLines, findListedNotFork, lowerList and fork-follow's lowering commit. fork-follow already refuses the case, and the docs say so.
  • Comment point 2 (bind an announcement to the pull request or branch that announced it): not small. The seam check sees only commits, never a pull request or branch. Binding would need a PR number or branch in the list and every workflow and fork-follow call passing it. The comment rates the risk small, and docs/fork/updates.md already tells reviewers that "any pull request may spend an announced line".

General vs project

State

The three cases are judged the same, because the allowance is a pure function of main's list, the pull request's own list (and the merge-base's, through listEditedCounts) and the trees. It writes nothing and keeps no state between runs.

  • A seam file checked again gets the same answer.
  • A pull request stopped half-way (lines put back, lost not lowered, or the reverse) is refused, as before. The first case's refusal now names the fix. A lowered entry whose lines are not back is refused by the count from upstream.
  • An old seam list (entries from before this change, empty lost): no entry to lower means no allowance, so it is judged exactly as before.
  • fork-follow's --from-upstream runs never use the allowance.

Seam lines

None. No upstream file changes, and .github/fork-seams.json is unchanged.

Verification

  • node --test .github/scripts/fork-seam-check.test.cjs: 118 pass, 0 fail.
  • python3 fork-ci/actions/pr-queue/review_judge.test.py: 57 run. The ForkConfig class passes. 2 fail on this machine and on clean main alike: the local Python reads Unicode 16.0, and the vectors pin 15.0.
  • python3 fork-ci/actions/head-check/head_check.test.py: ForkConfigRules passes (9). The same 11 failures and 16 errors happen on clean main on this macOS machine: case-insensitive names, non-UTF-8 file names and rlimit child processes, in PathRules*, MergedConfig and HostileConfig.
  • vp run check:changed: all pass (format, lint, knip, typecheck 43 packages, tests).
  • node .github/scripts/fork-seam-check.cjs --no-upstream origin/main HEAD: passes.

Round 1 (lens findings at 6d877ba, fixed at 410cbe6; branch updated from main first)

Finding Fix Test
Major (merge-path): a removed upstream line could be put back anywhere. Example: upstream lock(); work(); unlock();, main dropped unlock();, and a PR with lock(); unlock(); work(); plus lost {"lines": 1, "gone": 0} passed all three runs restorableLost: a lowered gone allows lines back only when lines drops at least as much. If gone drops more, the file gets no allowance and is marked misplaced. The refusal then says: put each upstream line back where upstream has it, in order, which lowers both New: "a line put back out of place is refused, though "lost" is lowered to its exact count". The lens's example is refused on the fork-checks run and the --no-upstream run, and the in-place restore passes all three runs. Red: with the old checker the out-of-place head passes (actual: 0, expected: 1)
Minor (code, merge-path): restorableLost's doc comment sat between promotedFiles' comment and its function Each comment now sits above its own function none needed (layout)
Minor (code, state): docs/fork/updates.md said the code lens is added "when it changes other files" Now: "the code lens too when it also changes a file that no gate path matches". A seam list plus ci.yml stays merge-path and state none needed (docs)
Minor (code): a line moved or re-indented back with lost left as main's got no "lower the entry" hint findLostLines adds (if it moves or re-indents back an upstream line counted in "lost", lower that entry …) when main's entry counts lines and the own entry allows none. A shared lostHint builds both put-back hints New: "a line re-indented back with "lost" left as main's is refused, naming the entry to lower" (and it passes with the entry dropped)
Minor (state): when main's lost entry changed since the branch's merge-base, the refusals pointed the wrong way and never said to update the branch The put-back hints, the moved-back hint and the count from upstream (findLostNotUpstream) add (this branch's merge-base has another "lost" entry for it than main: update the branch from main, whose list changed since) for those files New: "a "lost" entry main changed since the merge-base names updating the branch". Two cases: own entry equal to main's (no room, the adds refusal carries the hint), and own entry lowered from main's (the count refusal carries the hint)
Minor (state): no test made the counted-only rule fail none needed: the rule was right New: "an own "lost" entry left as the merge-base's allows no line back, though main's is higher". Refused on both runs. Red: with for (const file of counted) widened to all seam files, the branch adding forkZ(); passes (actual: 0, expected: 1)

Why the count is the root fix and a positional diff against upstream is not needed. The lines count is the positional measure: it counts the upstream lines that are not kept in order, and the run from upstream holds the own entry to the head exactly. Each line a pull request adds or moves can bring at most one more upstream line back into order. The PR run limits the moved lines to the lines drop beyond gone. So if every lowered gone is a line put back, the lines drop reaches gone only when every put-back line lands in order. A line put out of place leaves the drop at least one short, and the file gets no allowance. Diffing against upstream positionally in the PR run would add nothing over that, and the --no-upstream run cannot do it at all. Required checks are strict, so the merge-base is main when the PR merges.

Round 1 runs (Linux, at 410cbe6): node --test .github/scripts/fork-seam-check.test.cjs 122 pass, 0 fail. python3 -I -B review_judge.test.py 57 OK. python3 -I -B head_check.test.py 270 OK (1 skipped). vp run check:changed: format, lint, knip, typecheck (43 packages), test and node --test all pass.

Fixes #968

🤖 Generated with Claude Code

…upstream lines back (#968)

- .github/fork-pr-queue.json: the gate rule lists .github/fork-seams.json, so a change to the
  upstream-seam list needs the merge-path and state lenses (and the code lens with other files),
  as docs/fork/updates.md says ("reviewed like any gate change").
- fork-seam-check.cjs: a pull request that lowers a seam file's "lost" entry in its own list
  (neither count raised) may put those upstream lines back: one added line per "gone" lowered,
  one lost line of main's file per "lines" lowered beyond those. The run from upstream holds the
  lowered entry exact, so a fork line in place of upstream's is still refused there. With "lost"
  left as main's, the refusal says to lower it.

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

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: lens agent (Claude) · read at: 6d877ba
verdict: safe to merge
covered: #968 (body and its comment), the PR body, the full diff against its merge-base (fork-pr-queue.json, fork-seam-check.cjs and its test, docs/fork/updates.md, review_judge.test.py, head_check.test.py), and the seam checker's code around it (findSeamBreaches, findLostLines, listEditedCounts, findLostNotUpstream, main()).
checks: node --test .github/scripts/fork-seam-check.test.cjs 118 pass. With the merge-base's fork-seam-check.cjs the new test fails (actual: 1, expected: 0). Mutations of the new code, new test only: dropping the lines allowance, the put-back hint, the "neither raised" guard, or the - gone in the lines math each turn it red. Limiting the allowance to the counted entries does not (see the state lens). On Linux, python3 -I -B review_judge.test.py gives 57 OK and head_check.test.py gives 270 OK (1 skipped by design: a checkout-only case). Both have no failures here, so the PR's failures are macOS-only as it says. With the merge-base's fork-pr-queue.json, review_judge's ForkConfig fails 3 ('normal' != 'critical') and head_check's ForkConfigRules fails 1 (0 != 1 … normal, lenses code), as the PR says. Allowance math checked by hand and in a scratch repo: gone = main−own, lines = max(0, main.lines−own.lines−gone); parseConfig keeps counts ≥ 0 with gone ≤ lines, so there are no negatives. A duplicate key is refused already. A renamed file is refused as a deletion (--no-renames). A line put back plus a fork line takes one allowance between them, and the other is refused. On the --no-upstream run the refusal may name the put-back line rather than the fork line, but fork-checks' count names the fork line. A restore plus a change to another upstream line leaves lost unchanged, so there is no allowance. Every case the allowance opens is counted exactly from upstream by fork-checks' run. fork-follow's --from-upstream run computes no edits, so its restorable is empty.
state: pure function of main's list, the own list, the merge-base's list and the trees. A rerun gives the same answer. Half-way states are refused (the test covers both). An old list without "lost" parses to {} and gets no allowance. Details in the state lens.
blocker: none
major: none
minor: docs/fork/updates.md:206 says "the code lens too when it changes other files". A seam-list change plus another gate file (e.g. .github/workflows/ci.yml) is judged critical with merge-path and state only; I checked this with review_judge on this head. Say "a file outside the gate rule". Small and in scope: fix in this PR.
minor: .github/scripts/fork-seam-check.cjs:630-639: restorableLost was inserted between promotedFiles' JSDoc ("The "pending" files this change's own list moves to "files" …") and promotedFiles. That comment now sits orphaned above restorableLost's own. Move the function above that comment. Small and in scope: fix in this PR.
minor: .github/scripts/fork-seam-check.cjs:528: a line moved or re-indented back with lost left as main's is refused by findLostLines, and that message has no "lower that entry" hint. Only the added-line refusal (:208) has it. For a file whose restore is only a re-indent, no refusal names the fix. docs/fork/updates.md:136 promises the hint for a put-back line only, so the doc is not wrong. Add the same hint to the :528 message when main's "lost" has the file and restorable does not. Small and in scope: fix in this PR.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: lens agent (Claude) · read at: 6d877ba
verdict: safe to merge
covered: #968 (body and its comment), the PR body, the full diff, and main() of fork-seam-check.cjs: which entries are counted from upstream (listEditedCounts against the merge-base's list) and which list the allowance is measured against (main's). Also main's ruleset: the required checks are strict, so a branch must be up to date before it merges.
checks: Ran fork-seam-check.test.cjs (118 pass). Ran the new test against the merge-base's checker: red. Two extra scenarios in a scratch copy of the test file, removed afterwards:
(a) main lowered the file's "lost" entry since the branch's merge-base (another change restored a different line). The branch is refused, the PR still blocks, and the way out is to update the branch from main. After the update and an exact "lost", both runs pass.
(b) main's entry is newer than the merge-base's and the branch never edits "lost". No allowance; refused on both runs. With the counted-only mutation below, the same branch passes both runs while adding an unannounced forkZ();.
Mutations: limiting the allowance to the counted entries (fork-seam-check.cjs:644 for (const file of counted)) can be replaced by all seam files and the suite stays green. Forcing restore to 0 only on upstream runs (:208 area) is redundant, because edits are empty there.
review_judge.test.py (57 OK) and head_check.test.py (270 OK, 1 skipped by design) pass on Linux. Both turn red with the merge-base's fork-pr-queue.json.
state: runs again: same answer, because the allowance is computed from main's list, the own list, the merge-base's list and the trees, and nothing is written. Stopped half-way: line back with "lost" not lowered is refused, and the refusal names the fix. "lost" lowered with the line not back is refused by fork-checks' count from upstream. Both are in the new test. Old or empty state: a list with no "lost" parses to {}, and a missing own list or an unreadable merge-base list gives no allowance, so it is judged as before. Main moving under the PR: an allowance needs own < main and an entry counted from upstream, so a newer main can only shrink it (fail closed; scenario a). Strict up-to-date checks stop two restore PRs from merging into a stale-high "lost". After the merge, fork-follow's --from-upstream run has no edits and no allowance, and holds "lost" exact; the new test's passing heads pass it. No path lets an upstream line change through. The only block found (a) clears by updating the branch, but no message says so.
blocker: none
major: none
minor: .github/scripts/fork-seam-check.cjs:208 with :816, scenario (a): while the branch's merge-base "lost" entry differs from main's, the two refusals contradict each other. The added-line refusal says "lower that entry in this change's .github/fork-seams.json". After lowering, fork-checks' count says set it to {"lines": 1, "gone": 1} (back to the old value). Neither says to update the branch from main, which is the fix. Add a hint like findSpareSeamLines' "(this branch's merge-base lists it …: update the branch from main, whose list changed since)" when baseList.lost[file] differs from main's. Small and in scope: fix in this PR.
minor: .github/scripts/fork-seam-check.test.cjs (new test): no case makes the counted-only rule (:644) a red line. Add scenario (b): a branch whose list leaves "lost" as its merge-base's while main's entry is higher, with a line put back. It must be refused on both runs. Today the rule is right, but a regression there would let a fork line through unannounced. Small and in scope: fix in this PR.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: merge-path · reviewer: lens agent (Opus 5.5) · read at: 6d877ba
covered: issue #968 (body and its comment), the PR body, the full diff; fork-seam-check.cjs main(), restorableLost, findSeamBreaches, findLostLines, listEditedCounts, findLostNotUpstream (the count from upstream), parseConfig; .github/fork-pr-queue.json; fork-checks.yml and fork-tests.yml seam steps; docs/fork/updates.md
checks: on Linux at the head: node --test .github/scripts/fork-seam-check.test.cjs 118 pass, 0 fail; review_judge.test.py 57 run, OK; head_check.test.py 270 run, OK (1 skipped). Red without the fix (each undone and run): the new seam test fails with main's fork-seam-check.cjs; without the gate entry, review_judge.test.py ForkConfig fails 3 ('normal' != 'critical') and head_check.test.py ForkConfigRules fails 1 (0 != 1 ... normal, lenses code). Plus a probe PR for each attack below
state: runs again: the allowance is a pure function of main's list, the own list, the merge-base list and the trees, so a second run gives the same answer. Stopped half-way (lines back, lost not lowered, or lowered with the lines not back): refused, by the PR run or by the count from upstream. Old or empty state: a list with no lost entry, or an own list that leaves lost as the merge-base's, gives no allowance (the file is not in edits.lost), so it is judged as before. A branch whose merge-base list differs from main's gets an allowance only for the gap between main's entry and its own, which the count from upstream holds exact; two branches that each put back the same line: the second is refused once the first merges (main's entry is then equal to its own). An unreadable upstream fails closed (cannotCount). A malformed own list gives no allowance.
blocker: none
major: a removed upstream line may be "put back" anywhere in the file, not only where upstream has it, and all three runs pass. restorableLost (.github/scripts/fork-seam-check.cjs:648) grants one added line per gone lowered without needing lines to drop too, and the count from upstream only checks that gone and lines match the head. Example: upstream lock(); work(); unlock();, main dropped unlock(); (lost {"lines": 1, "gone": 1}). A PR with lock(); unlock(); work(); and lost {"lines": 1, "gone": 0} passes fork-checks, fork-tests (--no-upstream) and fork-follow's --from-upstream (probe run here: exit 0, 0, 0). That is a fork change to an upstream file's behaviour with no seam line, which the guard refused before this PR, and the doc's "a line put back in place lowers both" is not enforced. Fix (one line, in scope): in restorableLost, skip the file unless main.lines - own.lines >= gone (each line put back must also come back in order). With that line added here, the PR's new test still passes and the probe is refused by fork-checks and by the --no-upstream run (exit 1, 1). Add the probe as a refused case to the new test.
minor: .github/scripts/fork-seam-check.cjs:631-638: the new restorableLost doc comment was inserted between promotedFiles' doc comment and promotedFiles, so promotedFiles lost its comment and two doc blocks stack on restorableLost. Small and in scope: move promotedFiles' comment back above it.
minor: none other. The Python failures the PR body reports on macOS do not happen on Linux: both files pass in full here, so they are not this PR's (no change needed).

Other attacks tried, none got through:

  • a fork line in place of an upstream line (non-upstream text): refused by the count from upstream (findLostNotUpstream holds the own entry to the head exactly; gone does not drop), as the PR's swap case shows.
  • a line both put back and another changed: gone stays, so the entry cannot be lowered without the count from upstream refusing it; no allowance.
  • one count raised, the other lowered: restorableLost skips the file (the PR's raised case).
  • a lowered entry the branch did not change from its merge-base list: not in edits.lost, so not counted and no allowance (no allowance without the count).
  • two entries for one file: JSON keeps the last key, and the allowance and the count read the same parsed object. An entry for a pending file or a file not in main's files: skipped. An entry for a file upstream does not have: the count refuses it. Counts going negative or above lines: parseConfig refuses the own list, so there is no own list and no allowance. A renamed or deleted seam file: refused as before (findSeamBreaches).
  • the --no-upstream run (fork-tests) grants the allowance without counting; fork-checks' run (pull_request_target, script from main) counts it and fails closed when it cannot, as for the other list edits.
  • gate rule: .github/fork-seams.json is in the gate rule (.github/fork-pr-queue.json:38); the judge gives critical (merge-path, state) for a list-only change and critical (merge-path, state, code) with an app file; nothing else changed weight (NOT_GATE keeps only .github/fork-ci-tests.txt, and the every-.github-file test still sorts the rest).
  • the two dropped items: their reasons hold. Generic lines are documented (docs/fork/updates.md:152-155, 181-183) and fork-follow counts them; "any pull request may spend an announced line" is at docs/fork/updates.md:222-223, and the seam check reads only commits.
  • nothing personal in the diff or the PR body; no tokens touched.

verdict: not safe to merge

🤖 Generated with Claude Code

scuttletoby and others added 3 commits November 22, 2026 21:38
…out (#968)

A lowered "lost" `gone` now allows lines back only when `lines` drops at
least as much: a line put back where upstream has it is in order again, so
it lowers both. One put back out of order (upstream `lock(); work();
unlock();` as `lock(); unlock(); work();`) lowers `gone` alone and is
refused, with a hint to put it where upstream has it.

The refusal for a line moved or re-indented back now says to lower the
entry, and refusals name updating the branch when main's "lost" entry
changed since the merge-base. Each doc comment sits above its own function;
the docs say what the gate rule does exactly. New tests: the out-of-place
case, the counted-only rule, the stale-branch hints, the moved-back hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby merged commit 0f445c7 into main Nov 22, 2026
40 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.

Seam guard: follow-ups from the #965 reviews (gate rates fork-seams.json non-critical; lost lines can't be restored)

1 participant