Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gstack/ship-policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"bun run typecheck",
"bun run gen:skill-docs --host all && test -z \"$(git status --porcelain -- . ':(exclude)node_modules')\"",
"bun run scripts/test-free-shards.ts --files-from test/land-merged-checks.txt --wall-timeout 600"
]
],
"merged_ci": { "workflow": "free-tests.yml", "profile": "ci-reuse/free-tests" }
},
"release_gate": { "cadence_hours": 8, "gate_workflow": "evals.yml", "branch": "main", "stable_ref": "stable", "check_name": "main-backstop", "on_red": "hold-release", "bisect_spend_cap_usd": 80 },
"min_gstack_version": "1.96.0.0"
Expand Down
6 changes: 6 additions & 0 deletions changelog.d/capy-keep-lands-merged-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: minor
important: security
---
- **`gstack-ship-queue land` runs `land.merged_checks` in a fresh clone and stops when a check touches anything land's later git or gh calls read.** The merged-tree checks now run in a clone outside the checkout, with its own `.git` and a copy of `node_modules`, so what a check writes to its hooks, config or modules is thrown away with the clone. Before the checks, land pins the absolute `git` and `gh` it runs and puts their directories first on its own `PATH`, and it records the checkout's git config, hooks, `commondir` and `gitdir` files and `.git`, every config file git loads there (includes and the global file among them), gh's config and hosts files, the pinned binaries, and every symlink hop among them. When a check changed any of them, land refuses with `QUEUE_LAND_MERGED_CHECKS` naming each path and a hold-and-inspect fix, makes no further git or gh call and leaves the land lock held; after restoring the named paths, `gstack-ship-queue land --pr <n> --pin <sha>` without `--allow-repo-commands` releases the lock without running the checks. Every git call `gstack-ship-queue land` makes runs with `core.hooksPath=/dev/null` and `core.fsmonitor=false`; other queue commands keep the checkout's hooks. (GST-1747, GST-1766)
- **`gstack-ship-queue land` can run full CI on the merged tree before it lands a PR whose base moved.** A new `land.merged_ci` key (`{ workflow, profile }`) makes land push the PR merged onto main's tip to a scratch branch, dispatch that workflow there, wait, and land only when the run passes the named run profile with the merged tree as its tested tree; a red run refuses with `QUEUE_LAND_MERGED_CHECKS`. gstack's own policy now runs the whole free suite this way, so no PR reaches main on a base its tests never saw. (GST-3303)
10 changes: 9 additions & 1 deletion crew/lib/ship-queue-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { mergeChangelogs } from '../../lib/changelog-check';
import { ensureTmpExcluded, restamp, versionFiles } from '../../lib/restamp';
import type { ResultCodeName } from '../../lib/result-codes';
import type { ShipPolicy } from '../../lib/ship-policy';
import { toolPath } from '../../lib/tool-path';

export const QUEUE_DIR_REL = '.gstack/tmp/ship-queue';
export const GATE_AHEAD_DIR_REL = `${QUEUE_DIR_REL}/gate-ahead`;
Expand All @@ -39,8 +40,15 @@ export interface QueueFailure { code: ResultCodeName; message: string; fix?: str

export function sha256(buf: Buffer | string): string { return createHash('sha256').update(buf).digest('hex'); }

let hooksOff = false;
/** land calls this first: none of its git calls runs a hook or fsmonitor, because land.merged_checks are repo commands that can write where the checkout's hooks live (lib/land-merged-checks.ts). Other queue commands keep the checkout's hooks, the managed pre-push guard among them. */
export function queueHooksOff(): void { hooksOff = true; }

export function git(cwd: string, args: string[], env?: NodeJS.ProcessEnv, input?: string | Buffer): { ok: boolean; out: string; err: string; status: number | null } {
const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 120_000, env: env ?? process.env, input, maxBuffer: 64 * 1024 * 1024 });
const base = env ?? process.env;
const n = Number(base.GIT_CONFIG_COUNT) || 0;
const noHooks = hooksOff ? { GIT_CONFIG_COUNT: String(n + 2), [`GIT_CONFIG_KEY_${n}`]: 'core.hooksPath', [`GIT_CONFIG_VALUE_${n}`]: '/dev/null', [`GIT_CONFIG_KEY_${n + 1}`]: 'core.fsmonitor', [`GIT_CONFIG_VALUE_${n + 1}`]: 'false' } : {};
const r = spawnSync(toolPath('git', base.PATH), args, { cwd, encoding: 'utf8', timeout: 120_000, env: { ...base, ...noHooks }, input, maxBuffer: 64 * 1024 * 1024 });
return { ok: r.status === 0, out: (r.stdout ?? '').replace(/\n$/, ''), err: (r.stderr ?? '').trim(), status: r.status };
}

Expand Down
62 changes: 52 additions & 10 deletions docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ branch that changes the policy.
| `docs` | `{ caps: [{ path, max_bytes }] }` or `null` | `null` | Documentation files with a byte cap. `/ship` Step 14.5 runs `gstack-ship-receipt docs-caps --base <base>` (the caps come from `origin/<base>`'s policy, never the branch's copy; `--policy <file>` is for a repository bootstrapping its policy) before the verification gate and prints one `DOCS_CAP: <path> <bytes>/<max> ok\|over` line per cap; any `over` (an absent file counts) exits 1 and blocks the ship until the file is trimmed or the cap raised on the base branch (`DOCS_AUDIT_BLOCKED`). At most 64 caps, each path contained. See [the ship receipt](#ship-receipt). Needs `min_gstack_version`. |
| `train` | `{ gate_workflow, free_workflow, full_gate_check, record_artifact, max_size, fill_hours, screen_selection, trial_reservation_usd, land? }`, `{ gates, land, max_size, fill_hours }` or `null` | `null` | Turns on [merge trains](#run-a-merge-train), read from the base revision only. Every field is required and an unknown field is `POLICY_INVALID`: `max_size` 1 to 6, `fill_hours` above 0 and at most 24, `screen_selection` `gstack-paid` \| `none`, `trial_reservation_usd` above 0 and at most 100. A block with `gates` ([any repository](#train-gates)) takes `max_size` 1 to 5 and needs `min_gstack_version` at least `TRAIN_GATES_KEY_VERSION`. `null` keeps the per-PR queue exactly as it is. Needs `min_gstack_version`. |
| `merge` | `train` \| `direct` | `train` | `direct` lands each READY PR at its own green head with [`land --pr <n> --pin <sha>`](#land-direct): no train and no stamp commit, and `train build` refuses. A PR then leaves VERSION, the `package.json` version and the CHANGELOG at its merge base, and the release sets them. Needs `changelog_fragments`, and the stamping `land --pr <n>` refuses under it. `train` keeps merge trains. Read from the base revision only. Needs `min_gstack_version`. |
| `land` | `{ merged_checks?, docs_only_skip?, merge_commit_paths? }` or `null` | `null` | Under `merge: direct`, the shell commands (1 to 16, one line of at most 512 characters each, 15 minutes each) [`land --pin`](#land-direct) runs on the pin merged onto the base tip when the base moved past the pin's merge base; it lands only when every one exits 0. They are repo commands, so land runs them only with `--allow-repo-commands`, never under `--dry-run`. `null` lands a stale base untested with a `STALE_BASE: warn` line. `docs_only_skip` lists `merged_checks` commands to skip for a docs-only pin ([pregate.md](pregate.md#docs-only)) and needs `min_gstack_version` at its own release (`LAND_DOCS_ONLY_SKIP_KEY_VERSION`), because older releases refuse it. `merge_commit_paths` (1 to 64 git glob pathspecs, no `..`) makes every land form keep a merge commit, with the plain subject and body, for a PR that changes a matching path, such as an eval results PR whose run records point to its own commits; with it, `merged_checks` may be left out, and it needs `min_gstack_version` at its own release (`LAND_MERGE_COMMIT_PATHS_KEY_VERSION`). Any other key under `land` is a warning, ignored. Read from the base revision only. Needs `min_gstack_version`. |
| `land` | `{ merged_checks?, docs_only_skip?, merge_commit_paths?, merged_ci? }` or `null` | `null` | Under `merge: direct`, the shell commands (1 to 16, one line of at most 512 characters each, 15 minutes each) [`land --pin`](#land-direct) runs on the pin merged onto the base tip when the base moved past the pin's merge base; it lands only when every one exits 0. They are repo commands, so land runs them only with `--allow-repo-commands`, never under `--dry-run`. `null` lands a stale base untested with a `STALE_BASE: warn` line. `docs_only_skip` lists `merged_checks` commands to skip for a docs-only pin ([pregate.md](pregate.md#docs-only)) and needs `min_gstack_version` at its own release (`LAND_DOCS_ONLY_SKIP_KEY_VERSION`), because older releases refuse it. `merge_commit_paths` (1 to 64 git glob pathspecs, no `..`) makes every land form keep a merge commit, with the plain subject and body, for a PR that changes a matching path, such as an eval results PR whose run records point to its own commits; with it, `merged_checks` may be left out, and it needs `min_gstack_version` at its own release (`LAND_MERGE_COMMIT_PATHS_KEY_VERSION`). `merged_ci` (`{ workflow, profile }`) dispatches that workflow on the merged commit after any `merged_checks` pass and lands only when its run passes the named run profile of `.gstack/pregate.json` ([land --pin](#land-direct)); with it, `merged_checks` may be left out, and an older gstack ignores it with a warning. Any other key under `land` is a warning, ignored. Read from the base revision only. Needs `min_gstack_version`. |
| `docs_only` | `{ allow, deny?, tests? }` or `null` | `null` | Human-docs paths beyond `README.md`, `docs/**.md` and `changelog.d/*.md` for the [docs-only class](pregate.md#repo-docs-paths) (`{ "allow": ["wiki/board/**.md"] }`). `allow` (1 to 16) takes narrow Markdown globs: each ends in `.md`, starts with a literal directory or file name, and passes through no hidden, code, test or agent directory; `**`, `*`, `*.md` and patterns naming agent files are `POLICY_INVALID` with an example of a narrow one. `deny` (up to 64 globs) removes paths, built-in ones included. `tests` (up to 16 test files) are the repository's checks for those directories: the docs lane runs them, and a non-prose file that reads an allowed directory refuses the class unless it is tied to one; a listed test missing from the branch refuses it too. The built-in deny list always wins. Any other key under `docs_only` is a warning, and the classifier then ignores `allow`. Read from the base revision only; a pull request that edits this file is never docs-only. Needs `min_gstack_version`. |
| `release_gate` | `{ cadence_hours, gate_workflow, branch, stable_ref, check_name, on_red, bisect_spend_cap_usd }` or `null` | `null` | One full paid gate on main every `cadence_hours` (8 to 168) instead of the per-push main backstop, feeding the stable release; see [release_gate](#release-gate). Every field is required: `on_red` is `hold-release`, `bisect_spend_cap_usd` 0 to 500 (0 skips the bisect). `null` keeps the per-push backstop. Needs `min_gstack_version`. |
| `bookkeeping` | glob list | `[]` | <a id="bookkeeping"></a>Root-anchored globs of bookkeeping tables a verify or ratchet step rewrites (size baselines, serial lists, limits), each ending in `.tsv`, `.csv` or `.txt` and never under `.gstack/` or `.github/` (`["scripts/*-baseline.tsv"]`). A matching file changed at most 20 lines after review binds, first touched or not, takes finish's [one scoped reader](review-policy.md#bounded-post-review-edits) instead of Steps 5–11.5; the reader still reads every changed row. Read from the base revision only. Needs `min_gstack_version`. |
Expand Down Expand Up @@ -2965,14 +2965,15 @@ release-file rows):
| GitHub reports the PR `MERGEABLE` and `CLEAN` | [`QUEUE_LAND_NOT_CLEAN`](troubleshooting.md#queue-land-not-clean) |
| land takes the land lock (`land-pin:<pin>` journal, phase `merging`) and re-fetches `origin/main`; it takes over a lock an earlier `land --pin` run of the same PR left, and `--break-lock` breaks another lander's stale lock under the usual rules | `QUEUE_LAND_LOCKED`, `QUEUE_NOT_READY` |
| when the base moved past the pin's merge base and the base policy lists `land.merged_checks`: `--allow-repo-commands` was passed, the pin merges onto the tip without a conflict, and every command passes on that merged tree | [`REPO_COMMANDS_NOT_ALLOWED`](troubleshooting.md#repo-commands-not-allowed), [`QUEUE_LAND_NOT_CLEAN`](troubleshooting.md#queue-land-not-clean), [`QUEUE_LAND_MERGED_CHECKS`](troubleshooting.md#queue-land-merged-checks) |
| when the base moved past the pin's merge base and the base policy sets `land.merged_ci`: the workflow's run on the merged commit is green, and `lib/run-evidence.ts` accepts it under the named run profile with the merged tree as its tested tree | [`QUEUE_LAND_MERGED_CHECKS`](troubleshooting.md#queue-land-merged-checks) (a red run), `QUEUE_NOT_READY` |

Release outputs (the agents digest) are checked by the Version Gate, which must
be green at the pin: it accepts an output only when it equals what the release
tool generates at the merge base's VERSION. A green PR merged onto newer
commits can still break main (#3886 pushed ship/DRIVER.md past its size cap
that way). So when the base moved, land builds the pin merged onto the tip of
`origin/main` in a throwaway worktree (the checkout's `node_modules` linked
in), runs each `land.merged_checks` command there in order, and prints
`origin/main` in a fresh clone outside the checkout, with its own `.git` and a
copy of the checkout's `node_modules`, runs each `land.merged_checks` command there in order, and prints
`MERGED_CHECKS: pass tree=<tree> base=<tip> pin=<pin> checks: …`. The
commands are repo commands: the merged tree's `package.json` decides what
`bun run` does, so the PR controls them. Land runs them only with
Expand All @@ -2992,12 +2993,35 @@ land's starting environment to a same-user process. A check that moves HEAD
off the merged commit fails. Land re-reads the base policy after the locked
fetch, so a `land.merged_checks` that main gained meanwhile applies. When the
merged tree's lockfile or `package.json` dependencies differ from the
checkout's, the linked `node_modules` can't vouch for it: land refuses with
`QUEUE_NOT_READY` before any check runs, and the lane merges main and re-ships. It doesn't sandbox
the filesystem: a command can still write the checkout's `.git` (the worktree
shares it) and the linked `node_modules`, and read anything the user can (other
processes' environments, credential files), so pass the flag only for a base
policy and PRs you trust to run. A list such
checkout's, the copied `node_modules` can't vouch for it: land refuses with
`QUEUE_NOT_READY` before any check runs, and the lane merges main and re-ships.
What a check writes in the clone (its `.git`, hooks, config or `node_modules`)
stays there, and land deletes the clone afterward. A check still runs as
land's user, so it can write outside the clone by absolute path, to files
land's later git and gh calls read with land's full environment. So before the
checks land pins the absolute paths of `git` and `gh` (`lib/tool-path.ts`) and puts
their directories first on its own `PATH`, so a `git` a check drops earlier on
`PATH` never runs, and it records the config and hooks of the checkout's git
directories, the `commondir` and `gitdir` files and the checkout's `.git` that say
where git finds them, every config file git loads in the checkout (includes
and the global file among them, plus the global and XDG files when absent),
gh's `config.yml` and `hosts.yml`, the pinned `git` and `gh` files, and every hop of
a symlink among them. When a check changed or added any of them, land
restores nothing: it refuses with `QUEUE_LAND_MERGED_CHECKS` naming each path,
makes no further git or gh call and leaves the land lock held. Inspect each
named path and restore it from a trusted copy (delete a hook the checks
added), then release the lock without running the checks with
`gstack-ship-queue land --pr <n> --pin <sha>` (no `--allow-repo-commands`: it
refuses with `REPO_COMMANDS_NOT_ALLOWED` and releases the lock). Land's own git
calls in the clone run with the checks' environment, and no git call
`gstack-ship-queue land` makes runs a hook or fsmonitor. That includes the managed
pre-push guard: land pushes only the lock and notes it writes and, under
`land.merged_ci`, the merged commit of commits that were already pushed, and a
hook run after the checks is the opening this closes. It doesn't otherwise
sandbox the filesystem: a command can still write the checkout's other files
and read anything the user can (other processes' environments, credential
files), so pass the flag only for a base policy and PRs you trust to
run. A list such
as typecheck plus the size ratchets takes about two minutes, against a main
merge, a CI round and a new receipt per PR. gstack's own policy runs
typecheck, the generated-docs freshness check, and the size and budget guards
Expand All @@ -3008,7 +3032,25 @@ plus the core files of `test:quick` through the strict free runner on
doesn't run `test:quick` itself, because its browser tests find no Chromium
under the throwaway `HOME`. Without the key, land prints
`STALE_BASE: warn … no land.merged_checks configured` and merges the stale
base untested, as it did before the key. Then land runs `gh pr merge
base untested, as it did before the key.

When the base policy sets `land.merged_ci` (`{ workflow, profile }`), land then runs CI
on the same merged tree: it pushes the merged commit to the scratch branch
`gstack-land/<n>`, dispatches the workflow there, waits up to 45 minutes, and
prints `MERGED_CI: pass <workflow> run <url> on the merged tree <tree> (profile
<profile>)` only when `lib/run-evidence.ts` accepts the run under that run profile
of the base's `.gstack/pregate.json`, with the merged commit as its head and the
merged tree as its tested tree. A red run refuses with
`QUEUE_LAND_MERGED_CHECKS`; a run that can't be pushed, dispatched, finished in
time or proved refuses with `QUEUE_NOT_READY`; the branch is deleted either way.
The run is on CI runners, so it needs no `--allow-repo-commands`, and
`--dry-run` dispatches nothing. gstack's own policy dispatches `free-tests.yml`
under `ci-reuse/free-tests`, so the whole free suite has run on a stale-base tree
before it lands (about 5 minutes); its `merged_checks` still run first and fail
fast. A rerun after the merge checks the landed tree with `merged_checks` only,
and main's own push run tests it in CI.

Then land runs `gh pr merge
--squash --match-head-commit <pin>` (`--merge` under `history: merge-only`),
reads the merge commit, and checks that its tree is the pin merged onto the
merge commit's parent. The land lock keeps other gstack landers off main
Expand Down
Loading
Loading