Skip to content

fix(gate-diff): read a bare base as origin/<base> in gate-diff and diff-scope (#3650) - #3809

Closed
garrytan wants to merge 4 commits into
mainfrom
gsta246/gate-diff-origin-base
Closed

garrytan wants to merge 4 commits into
mainfrom
gsta246/gate-diff-origin-base

Conversation

@garrytan

@garrytan garrytan commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3809,
  "head": "3675e472744b9b7d2848798fb55a0737447dbd89",
  "version": "1.92.34.0",
  "base": "main",
  "gate": {
    "focused": {
      "pass": 116,
      "fail": 0,
      "skip": 0
    }
  },
  "session_kind": "unattended",
  "head_tree": "74f198448591481e0ca7c743ec3ba7d731621e37",
  "product_patch_id": "c12703860f21208fa034a268b68727beb39ad728",
  "gstack_version": "1.92.33.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 49,
    "rules": "150435b0a543019a",
    "base": "4f5b043b3ea02f4fa9887c0122452856c045bb82",
    "registry": "4f5b043b3ea02f4fa9887c0122452856c045bb82",
    "gate_scan": {
      "tagged": 0,
      "head": "3675e472744b9b7d2848798fb55a0737447dbd89"
    },
    "reasons": [
      "gate-class",
      "runtime=49<=50"
    ]
  },
  "pregate": "requires-remote cleared @74f198448591 (1 checks, current for 3675e472744b)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/41329268039",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/41329268102",
    "pregate.json/remote_gate: remote-gate tree=74f198448591 tests=4014"
  ],
  "issues": {
    "fixes": [
      3650
    ],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CONTRIBUTING.md (grep for gate-diff and diff-scope; troubleshooting no_base and ship-policy receipt sections read)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 3,
    "fixed": 1,
    "scope": "frozen",
    "fix_checks": 2,
    "dispatches": {
      "specialist": 3,
      "red-team": 1
    }
  }
}

What changed

On a Capy clone whose local main is 2 commits behind origin/main, the gate scan and scope now read from the PR's real merge base

On a Capy clone whose local main is 2 commits behind origin/main, the gate scan and scope now read from the PR's real merge base.

Before/after as text: On a Capy clone whose local main is 2 commits behind origin/main, the gate scan and scope now read from the PR's real merge base
--- Before · before.txt · captured output
+++ After · after.txt · captured output
 # local main 1cac25c, origin/main 4f5b043, merge base 6954a8c
 $ gstack-gate-diff main
+listed=2
+unmatched=4
+gstack-gate-diff: local main is not origin/main; base is origin/main
-listed=8
-unmatched=10
 $ gstack-diff-scope main
 SCOPE_BACKEND=true
 SCOPE_TESTS=true
 SCOPE_DOCS=true
+SCOPE_CONFIG=false
-SCOPE_CONFIG=true
 

Proof

Failing tests written first, on main 6954a8c:

(fail) gstack-gate-diff ... > a related local main that is behind origin/main yields to origin/main (#3650)
Expected: "6afb970914d6+6b88a51f97cb"   (candidate for origin/main)
Received: "388cf8b7bd64+6b88a51f97cb"   (candidate for the stale local main)
(fail) a bare base name reads origin/<base> when it exists (#3650) > a local main behind origin/main does not widen the scope to upstream commits
 0 pass, 2 fail

With the fix: test/gate-diff-cli.test.ts, test/diff-scope.test.ts and test/frontend-scope.test.ts are 113 pass and 0 fail. The existing missing-main, unrelated-main and upstream-only-remote cases still pass unchanged.

Blast radius

The change touches resolveBase in lib/gate-diff/git.ts, which only bin/gstack-gate-diff calls, and the base line of bin/gstack-diff-scope, which gstack-review-plan, the ship skills and gstack-ship-receipt call. It's safe because an explicit origin/main, a remote-qualified name, a commit or HEAD is used as given. The receipt and queue paths already pass a resolved origin sha, so they read the same base as before (traced by the red-team reader through ship-receipt-depth and ship-queue). No network calls, environment reads, permission changes, workflow, setup or install edits, and no new dependency.

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-11-01 Ship #3650 as one PR “Ship #3650 only, as one PR from your parked patch” (GStack Minder) approved PR #3809 (#3650 gate-diff and diff-scope base) none

Source: gstack-approvals record for gsta246/gate-diff-origin-base (display only; not an approval citation).

Why

#3650: "one invocation reviewed and gate-scanned against two different bases." /ship fetches and merges origin/<base>, but gstack-gate-diff and gstack-diff-scope read the local main, which never moves in a linked worktree or on a Capy machine. Now both helpers read origin's tracking branch for a bare base name. So the gate scan and the specialist plan cover the PR's own changes, not upstream commits too.

Summary

A stale local main gave /ship two merge bases in one run: the gate scan and specialist scope came from local main, while the review depth and the merge used origin/main. Both helpers now resolve a bare base as refs/remotes/origin/<base> when it exists and shares history with HEAD. Review then hardened that rule. A remote-qualified name is never rewritten, so a fork's origin/upstream/main can't replace an explicit upstream/main. The twin is read by its full ref, so a tag named origin/main can't stand in for it. Only origin's twin beats a related local base. Slash-named bases such as release/x follow the same rule in both helpers. The reporter, @exGeni, proposed resolving a bare name through origin and is credited in the first commit.

Test Coverage

All new code paths have test coverage. The tests were written first and failed on main 6954a8c (gate-diff candidate 388cf8b7bd64 against the expected 6afb970914d6; diff-scope read upstream files). The review-round cases also failed before their fixes: gate-diff tagged nothing for upstream/main with a fork branch, and diff-scope read a tag named origin/main.
Tests ran: focused 116
Tests ran: typecheck count unavailable

Pre-Landing Review

Pre-Landing Review: 9 issues. 5 fixed, 4 noted, 0 deferred (adversarial #2 and outside-voice #2 are the same tag-shadowing finding, counted once). Round 1 was the full panel: batched specialists (testing, security, state machines), the red team, a native adversarial pass and an outside voice on openai/gpt-6.1-sol. Round 2 was a fix-check on the fix. R51 allows two rounds.
REVIEW_LOOP: passes=1 blocking_found=0 deferred=0 noted=3 fixed=1 scope=frozen fix_checks=2 dispatches=4
Gate edits: none detected (2 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Outside review: issues_found (openai/gpt-6.1-sol, completed). It found two gate-bypass paths (a fork branch over an explicit remote base, a tag shadowing origin/main). Both are fixed in 2a1f123 with tests that failed first.

Review notes

  • lib/gate-diff/git.ts:101 and bin/gstack-diff-scope:45 (fix-check, informational): a remote-qualified base the caller types, like origin/main, is still resolved by its short name, so a tag named origin/main would win there. This was already true on main. /ship passes a bare base, which this PR now reads by full ref.
  • bin/gstack-diff-scope:50 (fix-check, advisory): in a shallow clone where origin/<base> has no merge base with HEAD, diff-scope now keeps the bare name, as main did, and exits with SCOPE_ERROR=no_base when there's no local branch. That's fail-closed.
  • Adversarial Fix project-local /browse installs and harden setup #4 (low): a stale origin/<base> now beats a fresher local branch. That's intended: it matches the base /ship merges against, and it can only over-report.

Exploratory QA

Smoke on this checkout (.gstack/tmp/before.txt and after.txt): local main is 2 commits behind origin/main. The installed helpers, from main's code, scanned from 1cac25c (8 gate hunks listed, SCOPE_CONFIG=true from upstream). This branch scans from the PR's merge base 6954a8c (2 listed, SCOPE_CONFIG=false), the same as gstack-gate-diff origin/main. No required plan checks.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). Fix: add "Plan: " to the PR body, or run /autoplan.

Issues

Fixes #3650

TODOS

No TODO items completed in this PR.

Documentation

Status: current. No documentation edits were needed.

Scope: Base 6954a8c, head 3675e47, committed changes only (6 files: bin/gstack-diff-scope, bin/gstack-gate-diff, lib/gate-diff/git.ts, two tests and one changelog fragment). Nothing staged, unstaged or untracked. Docs discovered through git ls-files were grepped for gate-diff and diff-scope references. Read in part: docs/troubleshooting.md (the GATE_ERROR=no_base section) and docs/ship-policy.md (receipt range section).

Documentation health:

  • changelog.d/gsta246-gate-diff-origin-base.md: Current
  • docs/troubleshooting.md: Current
  • docs/ship-policy.md: Current
  • README.md, CONTRIBUTING.md, docs/PROJECT_STRUCTURE.md: Current
  • CHANGELOG.md, TODOS.md: Untouched (protected in ship-owned mode)

Coverage debt: Common gap: the origin-tracking-branch rule and the new local <base> is not origin/<base> stderr message are covered only in the changelog fragment (reference-only). A short note in docs/troubleshooting.md would help. Run /document-generate if wanted. Diagram drift: none. Banned terms: none.

Test plan

  • bun test test/gate-diff-cli.test.ts test/diff-scope.test.ts test/frontend-scope.test.ts: 116 pass, 0 fail
  • bun run typecheck: clean
  • Remote pregate on Ubicloud at tree 74f198448591: 4014 tests, 0 failed ($0.05); macOS and Windows lanes cleared from PR CI runs 41329268039 and 41329268102

…ff-scope (#3650)

gstack-gate-diff and gstack-diff-scope resolved a bare base such as main to
the local branch whenever it shared history with HEAD. A local main that is
behind origin/main (a linked worktree, or a Capy clone, where local main
never moves) then set the merge base, so /ship's gate scan and specialist
scope also read commits already upstream. Both now prefer origin/<base>
when it resolves, the base /ship fetches and merges against.

Fixes #3650

Co-authored-by: exGeni <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 1, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan and others added 3 commits November 1, 2026 16:45
…ough origin too)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…remote never replaces the base)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Frozen in wave review-e7b551ebd865 (branch wave/review-e7b551ebd865) at 3675e47. Push nothing here: a moved head drops this PR from the wave. Fixes go on the wave branch through its integrator.

capy-ai Bot added a commit that referenced this pull request Nov 2, 2026
* fix(retro): keep retro history in the state root, shared across worktrees (#3749)

/retro saved snapshots under .context/retros inside the working tree, so a run
in a linked worktree saw none of the main checkout's history, reported "First
retro recorded", and wrote a snapshot that git worktree remove deletes.

gstack-retro-metrics --history [--next <date>] now resolves the history
directory as <state root>/projects/<slug>/retros (the slug is keyed on the git
common dir, so every worktree shares it), moves any legacy .context/retros from
this worktree and the main checkout into it, lists prior snapshots and prints
the next snapshot path. Step 12/13 and the gbrain prior-retros query use it.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(gate-diff): read a bare base as origin/<base> in gate-diff and diff-scope (#3650)

gstack-gate-diff and gstack-diff-scope resolved a bare base such as main to
the local branch whenever it shared history with HEAD. A local main that is
behind origin/main (a linked worktree, or a Capy clone, where local main
never moves) then set the merge base, so /ship's gate scan and specialist
scope also read commits already upstream. Both now prefer origin/<base>
when it resolves, the base /ship fetches and merges against.

Fixes #3650

Co-authored-by: exGeni <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(retro): make history migration safe against symlinks and concurrent runs (#3749 review)

Review pass 1 findings: a .context/retros that resolves outside its worktree
(or to the shared history itself) is left alone, so migration can no longer
delete the history it points at; moves are no-clobber with retry; a copy
identical to any same-date snapshot collapses; RETRO_FILE is reserved as {}
so overlapping runs in two worktrees never share a path; --next must be a
YYYY-MM-DD date; a missing option value no longer loops forever. Step 12
names RETRO_HISTORY_ERROR instead of reading it as a stale helper.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(changelog): fragment for the #3749 retro history fix

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (diff-scope reads slash-named bases through origin too)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(retro): trim Step 12/13 prose back under the parity skeleton cap

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: Step 11 review fixes (a fork branch, a colliding tag or another remote never replaces the base)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(retro): keep today="<today>" in Step 12 so the judge excerpt keeps both date inputs

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(changelog): describe the fork, tag and remote guards (#3650)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(retro): compare #3749 history paths with forward slashes so the Windows shard passes

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review): review-plan and gate-diff plan the same with a stale local main or a shadowing tag (GST-883, failing first)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): gate-diff and review-plan resolve a branch base to origin/<base> by full ref name; review-plan scans the merge base its own diff used (GST-883)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(changelog): GST-883 fragment

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review-risk): hostile-input time bounds for every risk pattern; the R51 rm and rmSync rules fail (GST-898)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review-risk): the R51 rm and rmSync rules run in linear time (GST-898)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review-packets-removed): repin lib/review-risk.ts on the GST-898 verdict-identity replay

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review-risk): padding cannot push recursive: true out of the rmSync window; repin on the GST-898 no-loss replay

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(changelog): GST-898 fragment wording

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review): planner misreads: SVG chart as runtime, session data as auth, bare base in diff-scope and receipt depth (GST-911, GST-884, failing first)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): a drawing-only SVG is data and a scripted one is security; session data files are not auth; diff-scope and the receipt depth read origin/<base> by full ref name (GST-911, GST-884)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): the SVG drawing check refuses CSS escapes and reads zero-padded character references; the security class reads a file's changed SVG lines joined (GST-911 review pass 1)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review): a stray quote cannot hide an external href in a drawing SVG (GST-911 review pass 2, failing first)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): the SVG drawing check reads every name= without consuming its value, so a stray quote cannot hide an external href (GST-911 review pass 2)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review): CSS in a drawing SVG holds only declarations and url(#id): image-set(), image(), element() keep it code (GST-911 Step 11, failing first)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): a drawing SVG's CSS holds declarations only, no @ rule and no function but url(#id), which closes image-set(), image(), element() and every other CSS load (GST-911 Step 11)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(review): a style element's CSS is read past comments and CDATA, unclosed style tags are refused in linear time, and every drawing verdict holds at 1 MB and 8 MB (GST-911, failing first)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review): walk a style element's CSS with indexOf, dropping comments and reading CDATA, so no hidden </style> ends it early and unclosed style tags refuse in linear time (GST-911)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(review-policy): the linear-time claim covers R51's rm and rmSync rules (GST-898)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(review-policy): state the rmSync padding rule exactly (GST-898)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(review-depth): linear url() refusal in svgDrawing (wave review-2, red-team CRITICAL)

SVG_REFUSED's url() entry backtracked quadratically on url( followed by a
long whitespace run (80k spaces: 820 ms; 1 MB: over 230 s), and
svgDrawing runs in collectLive and in collectCommit, which ship-queue
ready, train build and land call with no timeout. The rewritten entry
refuses exactly what #3838's pattern refused.

Repin lib/review-depth.ts under no-loss replay GST-911-redos
(verdict identity: 60,000 seeded strings, the edges and every SVG blob
in history, zero differences).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes (wave review-2, pass 1)

- bin/gstack-diff-scope: _resolve_base takes a related local <base> before
  another remote's twin, the order resolveBase uses, so the two tools pick
  the same base for a bare name when origin/<base> is unrelated.
- lib/review-depth.ts: a drawing's DOCTYPE names no document but W3C's SVG
  DTD; SYSTEM and other PUBLIC identifiers keep the SVG code.

Repin lib/review-depth.ts under no-loss replay GST-911-redos (the DOCTYPE
change only keeps more SVGs code, so it drops no reviewer).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: freeze the exported SVG_REFUSED list (wave review-2, Step 11)

Exported only so test/review-risk-redos.test.ts can reach the url() entry;
a frozen readonly copy keeps any importer from changing verdicts while
DEPTH_RULES still reports the original rules.

Repin lib/review-depth.ts under no-loss replay GST-911-redos (no pattern
changed).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Revert "fix: freeze the exported SVG_REFUSED list (wave review-2, Step 11)"

The fix-check (wave review-2) showed Object.freeze is shallow: each RegExp
can still be changed in place, so the freeze did not close
adversarial-native#1, and it moved the tree past the one the Step 11
voices reviewed. The finding ships as an open note (its reviewer rated it
Low, not blocking; no production caller mutates the list).

Restores the lib/review-depth.ts pin under no-loss replay GST-911-redos.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(changelog): wave review-2 entry for the integrator fixes

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(review-policy): a drawing's DOCTYPE names no outside document (wave review-2 docs audit)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: exGeni <[email protected]>
@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Landed in wave #3848 as v1.92.76.0 (3d99c22), merged from this PR's pin 3675e47. Integrator changes touching this PR's files: 6789cb4 (merge of #3826, resolved by hand: bin/gstack-gate-diff, lib/gate-diff/git.ts), 86d0414.

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.

/ship helpers resolve the same bare <base> to different commits when the local base branch is behind origin

1 participant