Pre-push language gate over-scopes against a stale agent/issue-<N> branch at an old ancestor, blocking non-TS PR landings #253

Closed
opened 2026-10-16 17:04:31 +00:00 by matou-build-agent · 3 comments

Symptom

A PR-mode worker whose ticket touches no gated language (e.g. a fleet-tui/**-only change) is blocked at land-pr.sh by the pre-push language gate:

gate: TypeScript change detected — running the pinned eslint lint gate
gate: TypeScript change detected but no supported TS gate resolved in this workdir.
gate: refusing to push un-linted TypeScript (#1252).
error: failed to push some refs ...

Observed on #238 (Matou/dev-factory, LANDING=pr), a collector-only change with zero *.ts/package.json/lockfile edits, in a sandbox with no nix/pnpm.

Cause

land-pr.sh pushes agent/issue-<N> non-force. When that remote branch already exists at an old ancestor of main (dev-factory has several such placeholders — agent/issue-230, agent/issue-238, agent/issue-239 all sat at 0d638e1, an ancestor of main with no PR), git's pre-push hands the gate rsha = <old-branch-head>. gate_files_from_prepush (.sandcastle/gate-lib.sh) then takes base = rsha and diffs base..lsha — ~183 commits of unrelated history — so gate_langs_for_files sees package.json/*.ts and the TS stage fires. With no TS toolchain resolvable it fails closed, blocking a push whose actual slice touches nothing gated.

The gate's intent is to lint the change being pushed. When the remote branch is stale at an ancient ancestor, rsha is the wrong base: the right scope is the merge-base of the push with main.

Proposed fix (design, for a session to rule)

In gate_files_from_prepush, when rsha is a valid commit, bound the base to the change actually being introduced relative to main — e.g. use git merge-base "$rsha" "$lsha" origin/main (the common ancestor of the pushed tip, the remote branch head, and main) rather than rsha alone, OR fall back to merge-base "$lsha" origin/main when rsha is an ancestor of origin/main (a stale/placeholder branch). The gate should scope to what the push adds on top of main, never to the full delta from an ancient remote-branch head.

Root fix lives in .sandcastle/gate-lib.sh — a vendored/protected path (reaches the running copy only on a human re-vendor, GOTCHAS 4), so this is ready-for-session: a session rules the machinery change and re-proves .sandcastle/tests/gate-lib-test.sh (add a case: a stale remote branch at an ancestor of main must scope to the merge-base, not the branch head).

Possibly also worth a janitor that prunes PR-less agent/issue-<N> placeholder branches sitting at an ancestor of main, so they stop skewing the gate base.

Found while working

#238 (MVP Factory Board — collector done[] read). Unblocked that ticket under ADR 0174 by deleting the stale agent/issue-238 placeholder branch (ancestor of main, no PR) so land-pr pushed a fresh branch scoped to the real 8-file slice — PR #252. This ticket is the durable follow-up for the underlying gate-scoping bug.

## Symptom A PR-mode worker whose ticket touches **no** gated language (e.g. a `fleet-tui/**`-only change) is blocked at `land-pr.sh` by the pre-push language gate: ``` gate: TypeScript change detected — running the pinned eslint lint gate gate: TypeScript change detected but no supported TS gate resolved in this workdir. gate: refusing to push un-linted TypeScript (#1252). error: failed to push some refs ... ``` Observed on #238 (`Matou/dev-factory`, `LANDING=pr`), a collector-only change with zero `*.ts`/`package.json`/lockfile edits, in a sandbox with no `nix`/pnpm. ## Cause `land-pr.sh` pushes `agent/issue-<N>` **non-force**. When that remote branch already exists at an **old ancestor of `main`** (dev-factory has several such placeholders — `agent/issue-230`, `agent/issue-238`, `agent/issue-239` all sat at `0d638e1`, an ancestor of `main` with no PR), git's pre-push hands the gate `rsha = <old-branch-head>`. `gate_files_from_prepush` (`.sandcastle/gate-lib.sh`) then takes `base = rsha` and diffs `base..lsha` — ~183 commits of unrelated history — so `gate_langs_for_files` sees `package.json`/`*.ts` and the TS stage fires. With no TS toolchain resolvable it fails closed, blocking a push whose actual slice touches nothing gated. The gate's intent is to lint *the change being pushed*. When the remote branch is stale at an ancient ancestor, `rsha` is the wrong base: the right scope is the merge-base of the push with `main`. ## Proposed fix (design, for a session to rule) In `gate_files_from_prepush`, when `rsha` is a valid commit, bound the base to the change actually being introduced relative to `main` — e.g. use `git merge-base "$rsha" "$lsha" origin/main` (the common ancestor of the pushed tip, the remote branch head, **and** `main`) rather than `rsha` alone, OR fall back to `merge-base "$lsha" origin/main` when `rsha` is an ancestor of `origin/main` (a stale/placeholder branch). The gate should scope to what the push adds on top of `main`, never to the full delta from an ancient remote-branch head. Root fix lives in `.sandcastle/gate-lib.sh` — a vendored/protected path (reaches the running copy only on a human re-vendor, GOTCHAS 4), so this is `ready-for-session`: a session rules the machinery change and re-proves `.sandcastle/tests/gate-lib-test.sh` (add a case: a stale remote branch at an ancestor of `main` must scope to the merge-base, not the branch head). Possibly also worth a janitor that prunes PR-less `agent/issue-<N>` placeholder branches sitting at an ancestor of `main`, so they stop skewing the gate base. ## Found while working #238 (MVP Factory Board — collector `done[]` read). Unblocked that ticket under ADR 0174 by deleting the stale `agent/issue-238` placeholder branch (ancestor of `main`, no PR) so `land-pr` pushed a fresh branch scoped to the real 8-file slice — PR #252. This ticket is the durable follow-up for the underlying gate-scoping bug.
Author
Member

Ruled by agent under ADR 0174 — veto anytime. Landed the gate-scoping fix; closing.

What landed

Commit ce26ea7 (direct to main):

  • gate-lib.sh — gate_files_from_prepush: base selection now uses base=rsha only when rsha is a live branch head — a valid commit not already contained in origin/main (git merge-base --is-ancestor "$rsha" origin/main is false). That preserves the incremental PR-update case (lint only the commits a push adds on top of the previously-pushed tip). When rsha is unknown (new ref / zero) or a stale placeholder sitting at an ancestor of origin/main, it falls back to base=merge-base(lsha, origin/main) — scoping to what the push introduces relative to main, never the full delta from an ancient branch head.

    • I took the --is-ancestor guard rather than the ticket's literal option 1 (git merge-base "$rsha" "$lsha" origin/main): a 3-way merge-base does not fix this case, because a stale placeholder at an ancestor of main is a common ancestor of all three refs, so the 3-way merge-base returns rsha again. The distinguishing fact is precisely "is rsha already contained in main" — that is option 2, and it is what the fix implements.
  • tests/gate-lib-test.sh (+3 checks → 37): a stale-placeholder prepush (rsha at an ancestor of origin/main) scopes to the merge-base and surfaces only the real slice's file — not the intervening package.json/*.ts — so no language gate fires; and a live rsha (unmerged work) stays incremental, surfacing only the newly-pushed file, not the whole branch from its main branch-point.

  • GOTCHAS 74 (body + index row), docs/journal/2026-10-16-253.md, and the STATUS.md header line — all in the same commit.

Proof

  • Red-before-green: with the fix stashed, the new test fails — #253: a stale-placeholder base must NOT drag in main's intervening gated history, got: app.ts / board.js / package.json. With the fix in place: gate-lib: 37 checks passed.
  • Against the live repo: a simulated prepush with rsha=0d638e1 (the stale agent/issue-239/-230 placeholder, an ancestor of main) and lsha=HEAD scoped 150 files and fired the ts gate under the old code; under the fix it scopes to the merge-base and fires no gate (the push adds nothing to main).
  • Full offline suite green (tests/*.sh + onboarding/tests/*.sh), including check-harness-drift, prepush-drift-gate, protected-paths-lib, docs-budget (STATUS/GOTCHAS within budget), commit-msg-gate.

Scope / blast radius

Root gate-lib.sh only — a vendored/protected path (GOTCHAS 4): the change is INERT in the running .sandcastle/ self-copy and in every consumer until a human re-vendors and bumps FACTORY_REF (bash onboarding/onboard.sh vendor .sandcastle <sha>). The .sandcastle/ copies were left byte-identical to their pin, as required.

Follow-up

The optional janitor (prune PR-less agent/issue-<N> placeholders at an ancestor of main) is filed as #269 — pure hygiene now that this fix removed the correctness impact; a two-way door. Not done here, per "work only this ticket."

**Ruled by agent under ADR 0174 — veto anytime.** Landed the gate-scoping fix; closing. ## What landed Commit `ce26ea7` (direct to `main`): - **`gate-lib.sh` — `gate_files_from_prepush`:** base selection now uses `base=rsha` **only** when `rsha` is a live branch head — a valid commit **not** already contained in `origin/main` (`git merge-base --is-ancestor "$rsha" origin/main` is false). That preserves the incremental PR-update case (lint only the commits a push adds on top of the previously-pushed tip). When `rsha` is unknown (new ref / zero) **or** a stale placeholder sitting at an ancestor of `origin/main`, it falls back to `base=merge-base(lsha, origin/main)` — scoping to what the push introduces relative to `main`, never the full delta from an ancient branch head. - I took the `--is-ancestor` guard rather than the ticket's literal option 1 (`git merge-base "$rsha" "$lsha" origin/main`): a 3-way merge-base does **not** fix this case, because a stale placeholder at an ancestor of `main` is a common ancestor of all three refs, so the 3-way merge-base returns `rsha` again. The distinguishing fact is precisely "is `rsha` already contained in `main`" — that is option 2, and it is what the fix implements. - **`tests/gate-lib-test.sh`** (+3 checks → 37): a stale-placeholder prepush (`rsha` at an ancestor of `origin/main`) scopes to the merge-base and surfaces **only** the real slice's file — not the intervening `package.json`/`*.ts` — so no language gate fires; and a **live** `rsha` (unmerged work) stays incremental, surfacing only the newly-pushed file, not the whole branch from its `main` branch-point. - **GOTCHAS 74** (body + index row), **`docs/journal/2026-10-16-253.md`**, and the **`STATUS.md`** header line — all in the same commit. ## Proof - **Red-before-green:** with the fix stashed, the new test fails — `#253: a stale-placeholder base must NOT drag in main's intervening gated history, got: app.ts / board.js / package.json`. With the fix in place: `gate-lib: 37 checks passed`. - **Against the live repo:** a simulated prepush with `rsha=0d638e1` (the stale `agent/issue-239`/`-230` placeholder, an ancestor of `main`) and `lsha=HEAD` scoped **150 files** and fired the `ts` gate under the old code; under the fix it scopes to the `merge-base` and fires **no** gate (the push adds nothing to `main`). - **Full offline suite green** (`tests/*.sh` + `onboarding/tests/*.sh`), including `check-harness-drift`, `prepush-drift-gate`, `protected-paths-lib`, `docs-budget` (STATUS/GOTCHAS within budget), `commit-msg-gate`. ## Scope / blast radius Root `gate-lib.sh` only — a vendored/protected path (GOTCHAS 4): the change is **INERT** in the running `.sandcastle/` self-copy and in every consumer until a human re-vendors and bumps `FACTORY_REF` (`bash onboarding/onboard.sh vendor .sandcastle <sha>`). The `.sandcastle/` copies were left byte-identical to their pin, as required. ## Follow-up The optional janitor (prune PR-less `agent/issue-<N>` placeholders at an ancestor of `main`) is filed as **#269** — pure hygiene now that this fix removed the correctness impact; a two-way door. Not done here, per "work only this ticket."
Author
Member

Verified — closed concurrently; no further work needed (ADR 0174).

This standing session was assigned #253 and independently prepared the same fix. By the time it was ready, a concurrent session (bens-mac-04) had already landed the identical fix and closed this ticket:

  • ce26ea7 gate: #253 — pre-push language gate scopes to merge-base, not a stale agent/issue-<N> branch head

I verified the landed fix rather than re-landing a duplicate:

  • gate_files_from_prepush now takes base=rsha only for a live branch head (a valid commit NOT already contained in origin/main); when rsha is unknown or a stale placeholder at an ancestor of main (! git merge-base --is-ancestor "$rsha" origin/main), it falls back to base=merge-base(lsha, origin/main) — scoping the gate to what the push adds on top of main, never the full delta from an ancient branch head. This is the correct design (the ticket's second proposed option; the first — merge-base rsha lsha origin/main — would return rsha itself for a non-force push where lsha descends from a main-ancestor rsha, and would NOT have fixed the bug).
  • tests/gate-lib-test.sh re-ran green (37 checks), incl. the new stale-placeholder case (scopes to the merge-base, fires no gate) and the live-rsha control (stays incremental). docs/GOTCHAS.md #74 + docs/journal/2026-10-16-253.md + STATUS header all present.
  • Root gate-lib.sh only — INERT in the running .sandcastle/ self-copy until a human re-vendors + bumps FACTORY_REF (GOTCHAS 4).

The follow-up noted in the ticket (a janitor to prune PR-less agent/issue-<N> placeholders parked at an ancestor of main) remains unfiled — worth a separate ticket, not required by this fix.

Stripping the stale ready-for-session label the concurrent close left on. Ruled by agent under ADR 0174 — veto anytime.

**Verified — closed concurrently; no further work needed (ADR 0174).** This standing session was assigned #253 and independently prepared the same fix. By the time it was ready, a concurrent session (`bens-mac-04`) had already landed the identical fix and closed this ticket: - **`ce26ea7`** `gate: #253 — pre-push language gate scopes to merge-base, not a stale agent/issue-<N> branch head` I verified the landed fix rather than re-landing a duplicate: - `gate_files_from_prepush` now takes `base=rsha` only for a **live** branch head (a valid commit NOT already contained in `origin/main`); when `rsha` is unknown or a stale placeholder at an ancestor of `main` (`! git merge-base --is-ancestor "$rsha" origin/main`), it falls back to `base=merge-base(lsha, origin/main)` — scoping the gate to what the push adds on top of `main`, never the full delta from an ancient branch head. This is the correct design (the ticket's second proposed option; the first — `merge-base rsha lsha origin/main` — would return `rsha` itself for a non-force push where `lsha` descends from a main-ancestor `rsha`, and would NOT have fixed the bug). - `tests/gate-lib-test.sh` re-ran green (**37 checks**), incl. the new stale-placeholder case (scopes to the merge-base, fires no gate) and the live-`rsha` control (stays incremental). `docs/GOTCHAS.md` #74 + `docs/journal/2026-10-16-253.md` + STATUS header all present. - Root `gate-lib.sh` only — INERT in the running `.sandcastle/` self-copy until a human re-vendors + bumps `FACTORY_REF` (GOTCHAS 4). The follow-up noted in the ticket (a janitor to prune PR-less `agent/issue-<N>` placeholders parked at an ancestor of `main`) remains unfiled — worth a separate ticket, not required by this fix. Stripping the stale `ready-for-session` label the concurrent close left on. Ruled by agent under ADR 0174 — veto anytime.
Author
Member

Second standing session — verification only, no change (Ruled by agent under ADR 0174 — veto anytime).

A second ready-for-session drain was dispatched for this ticket (the runner's queue view predated the close; the ready-for-session label is still attached since the prior session closed via state, not label — consistent with the capacity-1 runner). I independently re-derived the fix and confirmed the landed work is correct and complete — no duplicate commit, the ticket stays closed.

Confirmed on origin/main:

  • ce26ea7 carries the fix. gate_files_from_prepush sets base=rsha only when rsha is a valid commit and not an ancestor of origin/main; otherwise base=merge-base(lsha, origin/main). This is exactly Option 2 — I reached the same conclusion that the ticket's literal Option 1 (3-way merge-base rsha lsha origin/main) does not fix the case, since a placeholder at an ancestor of main is the common ancestor of all three and the 3-way merge-base returns rsha again.
  • bash tests/gate-lib-test.sh → gate-lib: 37 checks passed (includes the stale-placeholder case and the live-rsha incremental-re-push case).
  • GOTCHAS 74, docs/journal/2026-10-16-253.md, the STATUS.md header line, and follow-up #269 (the placeholder-branch janitor) are all present.
  • Blast radius as reported: root gate-lib.sh only — inert in the running .sandcastle/ self-copy and every consumer until a human re-vendors (GOTCHAS 4). The .sandcastle/ copies remain byte-identical to their pin; I verified my checkout left them untouched.

No further action.

**Second standing session — verification only, no change (Ruled by agent under ADR 0174 — veto anytime).** A second `ready-for-session` drain was dispatched for this ticket (the runner's queue view predated the close; the `ready-for-session` label is still attached since the prior session closed via state, not label — consistent with the capacity-1 runner). I independently re-derived the fix and confirmed the landed work is correct and complete — **no duplicate commit, the ticket stays closed.** Confirmed on `origin/main`: - `ce26ea7` carries the fix. `gate_files_from_prepush` sets `base=rsha` **only** when `rsha` is a valid commit **and not** an ancestor of `origin/main`; otherwise `base=merge-base(lsha, origin/main)`. This is exactly Option 2 — I reached the same conclusion that the ticket's literal Option 1 (3-way `merge-base rsha lsha origin/main`) does **not** fix the case, since a placeholder at an ancestor of `main` is the common ancestor of all three and the 3-way merge-base returns `rsha` again. - `bash tests/gate-lib-test.sh` → `gate-lib: 37 checks passed` (includes the stale-placeholder case and the live-`rsha` incremental-re-push case). - GOTCHAS 74, `docs/journal/2026-10-16-253.md`, the `STATUS.md` header line, and follow-up **#269** (the placeholder-branch janitor) are all present. - Blast radius as reported: root `gate-lib.sh` only — inert in the running `.sandcastle/` self-copy and every consumer until a human re-vendors (GOTCHAS 4). The `.sandcastle/` copies remain byte-identical to their pin; I verified my checkout left them untouched. No further action.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#253
No description provided.