From aeb74eb00b2ba35aa02eee687bd446e28a96ce44 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Tue, 17 Nov 2026 21:13:19 +0800 Subject: [PATCH] /ship's test step says when it hits its time limit, and long test file lists no longer overflow the remote command (GST-2958) (#4429) * Say when /ship's test step hit its time limit, and keep long file lists off the remote test command line gstack-ship-preflight stopped gstack-pregate after a fixed hour and printed 'PREGATE: unreadable (exit 143)'. The whole step's budget is now --step-timeout (default 3600), and a stop at it prints 'PREGATE: time limit hit' with the way out: push and let CI's full run carry the tests, or a larger budget. The test_backend command pregate prints for a small machine put every selected file into one argument, which Linux refuses past 128 KiB. The files now reach the VM in a setup script named by its content. Also adds an arg-limit troubleshooting entry and says the Windows job has eight shards. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Read the small-machine file list from the setup script in the hidden-folder path test The remote command now names a setup script instead of the files, so the test checks that the script lists the ./-prefixed path. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Keep a test path with a newline out of the remote file list A selected test path containing a newline, or equal to the list's end marker, could end the setup script's file list early and run the rest as shell on the test VM. Such paths now keep the quoted inline command. Review-Finding: p1/outside-voice#1 reader=outside-voice Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Mark the preflight half of the Step 5 time limit to-do as done 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> --- TODOS.md | 2 +- ...p-step-time-limit-and-remote-file-lists.md | 2 + docs/pregate.md | 12 ++++-- docs/troubleshooting.md | 19 +++++++++ lib/pregate/checks/lanes.ts | 33 +++++++++++++-- lib/ship-bin-common.ts | 5 ++- lib/ship-preflight.ts | 16 ++++++-- test/pregate-hidden-folder-paths.test.ts | 5 ++- test/pregate-lanes-arg-limit.test.ts | 40 +++++++++++++++++-- test/pregate-remote.test.ts | 12 +++++- test/ship-preflight.test.ts | 20 ++++++++++ 11 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 changelog.d/ship-step-time-limit-and-remote-file-lists.md diff --git a/TODOS.md b/TODOS.md index e47fc855e..3329db324 100644 --- a/TODOS.md +++ b/TODOS.md @@ -46,7 +46,7 @@ ### P2/P3: pregate head-policy follow-ups (filed 2026-10-31, from the GST-419/GST-420 /ship review) - **`finish` fallback drops head-policy lanes (P2)** — `lib/ship-release.ts` reruns pregate on the stamped tree under the base policy, so after a version bump a lane the branch added under `--policy-from head` is gone and `finish` reports `PREGATE: fail (rerun on the stamped tree)`. GSTA-194 owns that file and has the note. **Effort:** S. **Priority:** P2. -- **The 3600 s preflight and `finish` wrapper deadline (P3)** — it caps the whole pregate run, so several runners that each fit `timeout_s` can still be cut off together. Derive the wrapper deadline from `timeout_s` and the lane count, or document the cap. **Effort:** S. **Priority:** P3. +- **The 3600 s `finish` wrapper deadline (P3)** — it caps the whole pregate rerun, so several runners that each fit `timeout_s` can still be cut off together. Derive the wrapper deadline from `timeout_s` and the lane count, or document the cap. Preflight's half is done: `gstack-ship-preflight --step-timeout ` sets that budget and a stop prints `PREGATE: time limit hit` (#4429). **Effort:** S. **Priority:** P3. - **A bootstrap head policy can still certify itself without `--remote` (P3)** — with no trusted policy, the head file may set `remote_gate: null`, or produce an obligation that `gstack-pregate clear --receipt` accepts from the branch's own gate. Decide what a bootstrap `pregate.json` may certify, then enforce it in `verify` from the recorded policy label instead of per entry point. The `--remote` refusal also prints the generic `PREGATE_HEAD_POLICY_LOOSENS` fix line, which does not apply when there is no trusted policy. **Effort:** S. **Priority:** P3. ### P3: `/codex --effort` follow-ups (filed 2026-10-11, from the #3146 autoplan review) diff --git a/changelog.d/ship-step-time-limit-and-remote-file-lists.md b/changelog.d/ship-step-time-limit-and-remote-file-lists.md new file mode 100644 index 000000000..243013fcb --- /dev/null +++ b/changelog.d/ship-step-time-limit-and-remote-file-lists.md @@ -0,0 +1,2 @@ +- **/ship's test step says when it ran out of time, and you can set its budget.** `gstack-ship-preflight` used to stop gstack-pregate after a fixed hour and print `PREGATE: unreadable (exit 143)`, which hid the cause. The whole step's budget is now `--step-timeout ` (default 3600 s), and a stop at that limit prints `PREGATE: time limit hit` with the way out: push and let CI's full run carry the tests, or give the step a larger budget. +- **The remote test command no longer puts every file on one command line.** On a small machine with a remote `test_backend`, the command pregate prints for gstack's Ubicloud runner used to carry every selected test file in one argument, which Linux refuses past 128 KiB (`E2BIG`). The files now go to the VM in a setup script, so the command stays short however many files are selected. docs/troubleshooting.md has a new `arg-limit` entry for this kind of failure. diff --git a/docs/pregate.md b/docs/pregate.md index 7abffb24b..6a51c6ace 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -103,7 +103,7 @@ the byte-pinned `/ship` renders in `test/fixtures/golden/`). | `sealed` | sealed or eval output that must never reach a public destination; read by the pre-push hook and `gstack-pregate sealed` (see [sealed output](#sealed)) | | `price_file` | repo-relative path of the paid gate's call-plan data file (`GSTACK_EVAL_CALLS v1`); `gstack-eval-plan price-gate` prices from it and never executes anything ([docs/eval-calls.md](eval-calls.md)) | | `stall_timeout_s` | seconds a test command may print nothing while using under a tenth of one CPU before its process group is killed and the check is `incomplete` (`PREGATE_STALLED`); default 300, `0` disables; `--stall-timeout` overrides; the `--remote` gate is exempt (see [supervision](#supervision)) | -| `timeout_s` | seconds each runner process may take (the unit-file group, each serial file, each guard without its own `timeout_s`, and the remote gate's deadline) when `--timeout` is not passed; 1 to 3600, default 600. `gstack-ship-preflight` forwards its own `--timeout`; without it, and in the `finish` fallback, this is how a repo with long lanes sets theirs | +| `timeout_s` | seconds each runner process may take (the unit-file group, each serial file, each guard without its own `timeout_s`, and the remote gate's deadline) when `--timeout` is not passed; 1 to 3600, default 600. `gstack-ship-preflight` forwards its own `--timeout`; without it, and in the `finish` fallback, this is how a repo with long lanes sets theirs. The whole pregate under `gstack-ship-preflight` has a separate budget, `--step-timeout ` (1 to 86400, default 3600): a pregate stopped there prints `PREGATE: time limit hit` and a STOP naming the way out, push and let CI's full run at the tree carry the tests ([CI carry](#ci-carry)), or a larger `--step-timeout` | | `remote_gate` | the repo's remote test gate command; under 8 cores the local test tier becomes a `requires-remote` obligation naming it, and `--remote` runs it (see [remote gate](#remote-gate)) | | `run_profiles` | a map from each profile name to `{ workflow, events, jobs, artifact, max_age_hours?, os?, skippable? }`: the GitHub Actions runs `clear --run` verifies as evidence on the identical tree; a profile named after a lane (`free-tests.yml/macos-named-regressions`) clears that lane (see [run evidence](#run-evidence)). `--from-run` and the reuse job verify runs against them too ([from-run](#from-run), [CI reuse](#ci-reuse)) | | `remote_gate_runs` | `{ profiles, inventory, skipped? }`: the run profiles that together clear `pregate.json/remote_gate`, the command that prints the remote gate's test files, one per line, which their runs must cover, and an optional command that prints which selected files the gate itself never runs (see [run evidence](#run-evidence)) | @@ -563,7 +563,11 @@ test_backend` is not `local`, the lanes check runs nothing locally: it records the selected local files as a `requires-remote` obligation with the command to run, `pregate.json/remote_gate` (the declared command) or `test_backend/` (gstack's `scripts/ubicloud/ubi-runner.sh run --src - -- ' '`). Without either, the tier runs locally under + --setup -- ''`, where the setup script, kept under +`/projects//pregate/remote-files/` and named by its content, +writes the selected files to `~/.pregate-files.txt` on the VM and the runner +reads them from there; the list never goes on the command line, which reaches +the VM as one argument, see [arg-limit](troubleshooting.md#arg-limit)). Without either, the tier runs locally under the supervision above. Close the obligation one of four ways: - by default, when the base declares `remote_gate_runs`, let CI clear it: the @@ -1000,7 +1004,7 @@ conclusion. On main the free tier's Windows smoke lane is Two narrower Windows lanes are owed only when a branch selects their own test files: `free-tests.yml/cso-windows-launcher` (cleared by a `free-tests.yml` run) and `windows-setup-e2e.yml/windows-setup` (cleared by a -`windows-setup-e2e.yml` run). The six-shard +`windows-setup-e2e.yml` run). The eight-shard `windows-free-tests.yml/windows-free-shard` job is `manual`, so it is never an obligation. A branch cut before `windows-smoke.yml` landed still owes `windows-free-tests.yml/windows-free-shard` @@ -1862,7 +1866,7 @@ failure the branch caused carries `cause: "diff"` (`PREGATE_LANE_FAILED`, | Kind | Evidence | |---|---| | `missing-binary` | exit 127, `command not found`, a spawn `ENOENT`, a runner tool `not on PATH` (dart, flutter, cargo, a package manager, `python3`, or `pytest` when python3 cannot import it), Playwright's browsers not installed | -| `arg-limit` | `E2BIG`, `Argument list too long`: a command line or environment over the system's limit. gstack splits a lane's file list to stay under it, so this is a gstack bug to report | +| `arg-limit` | `E2BIG`, `Argument list too long`: a command line or environment over the system's limit. gstack splits a lane's file list to stay under it, so this is a gstack bug to report ([troubleshooting](troubleshooting.md#arg-limit)) | | `network` | `ENOTFOUND`, `ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, `EAI_AGAIN`, `Could not resolve host`, `fetch failed`, a TLS handshake or certificate failure | | `quota` | `quota`, `429 Too Many Requests`, `rate limit`, `insufficient_quota` (a vCPU quota on the remote backend) | | `disk` | `ENOSPC`, `No space left on device`, `EDQUOT` | diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 4c7f040cc..8372be81f 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -4360,6 +4360,25 @@ or on the comment line directly above it. The marker waives only that line, and the check lists it as `waived:`. Don't use `warn: ["literals"]` for this, since that turns the check off for every constant. + +### `PREGATE_ENVIRONMENT` with `environment: arg-limit — E2BIG` (or `Argument list too long`) + +**Meaning.** A command gstack started had a command line or environment over +the system's limit, so it never ran and no test was counted. Linux caps one +argument at 128 KiB and a whole command line plus environment at about 2 MiB, +macOS caps the total at 1 MiB, and Windows caps a command line at 32,767 +characters. The usual trigger is a long file list: thousands of selected test +files put into one argument. + +**Fix.** gstack keeps file lists out of single arguments: a local lane splits +its files into runner processes of about 96 KB each (24 KB on Windows), and +the `test_backend` command for the remote gate passes them in a setup script +(docs/pregate.md#remote-gate). So this cause is a gstack bug: report it with +the `environment:` line and the lane or command it names. Until it is fixed, +run the lane remotely (push and let CI's full run carry it, or +`gstack-pregate --remote`), or select fewer files. When the environment, not +the file list, is what's large, unset the big variables before the run. + ### `PREGATE_NO_LANE` diff --git a/lib/pregate/checks/lanes.ts b/lib/pregate/checks/lanes.ts index 075b1bdb2..ee1a0e736 100644 --- a/lib/pregate/checks/lanes.ts +++ b/lib/pregate/checks/lanes.ts @@ -30,7 +30,7 @@ import { spawnSync } from 'node:child_process'; import * as fs from 'node:fs'; import * as path from 'node:path'; -import { baseInputs, sha256 } from '../context'; +import { baseInputs, defaultScratchRoot, sha256 } from '../context'; import { PREGATE_CONFIG_PATH } from '../config'; import { classifyCommandEnvironment, classifyEnvironment, environmentLine, environmentResult, launchCause } from '../environment'; import { checkScratch } from '../run-scratch'; @@ -498,12 +498,39 @@ const GSTACK_ROOT = path.resolve(import.meta.dir, '..', '..', '..'); */ function remoteObligation(ctx: PregateContext, sel: Selection): RemoteObligation { const declared = ctx.config.remote_gate; - const runner = detectRunner(ctx, sel.gateTests); - const command = declared ?? `${GSTACK_ROOT}/scripts/ubicloud/ubi-runner.sh run --src ${quote(ctx.repoRoot)} -- ${quote(runner ? runner.replace('{files}', testFileArgs(runner, sel.gateTests).map(quote).join(' ')) : ' ')}`; + const command = declared ?? backendCommand(ctx, sel.gateTests); const [workflow, job] = declared ? REMOTE_GATE_LANE.split('/') as [string, string] : ['test_backend', ctx.testBackend]; return { lane: `${workflow}/${job}`, platform: 'remote', workflow, job, tests: sel.gateTests, receipt: null, command }; } +/** + * The test backend's command: gstack's Ubicloud runner, with the selected files in a setup script that writes them one per line + * on the VM. The command reaches the VM as one argument and Linux caps one argument at 128 KiB (#4424), so the list never goes in + * it. The script lives under the state root, named by its content, so the same selection prints the same command every run and a + * same-tree clear still matches it; an unwritable state root keeps it in this run's scratch. A path the one-per-line list can't + * hold (a newline, or the list's end marker) keeps the quoted inline form, so no path can end the list early and run as shell. + */ +function backendCommand(ctx: PregateContext, files: readonly string[]): string { + const ubi = `${GSTACK_ROOT}/scripts/ubicloud/ubi-runner.sh run --src ${quote(ctx.repoRoot)}`; + const runner = detectRunner(ctx, files); + if (!runner) return `${ubi} -- ${quote(' ')}`; + const args = testFileArgs(runner, files); + if (args.some(f => f.includes('\n') || f === 'PREGATE_FILES')) return `${ubi} -- ${quote(runner.replace('{files}', () => args.map(quote).join(' ')))}`; + const setup = `cat > ~/.pregate-files.txt <<'PREGATE_FILES'\n${args.map(f => `${f}\n`).join('')}PREGATE_FILES\n`; + const name = `${sha256(setup).slice(0, 16)}.sh`; + let file: string; + try { + const dir = path.join(path.dirname(defaultScratchRoot(ctx.repoRoot, ctx.env)), 'remote-files'); + fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); + file = path.join(dir, name); + fs.writeFileSync(file, setup); + } catch { + file = path.join(checkScratch(ctx.scratch, 'remote'), name); + fs.writeFileSync(file, setup); + } + return `${ubi} --setup ${quote(file)} -- ${quote(`mapfile -t PREGATE_FILES < ~/.pregate-files.txt && ${runner.replace('{files}', () => '"${PREGATE_FILES[@]}"')}`)}`; +} + export const REMOTE_GATE_LANE = 'pregate.json/remote_gate'; /** How many leading lines of a remote gate's output are read for an environment cause: its preamble, before any test output could stream. */ export const REMOTE_PREAMBLE_LINES = 40; diff --git a/lib/ship-bin-common.ts b/lib/ship-bin-common.ts index 94f46da2e..4072a073d 100644 --- a/lib/ship-bin-common.ts +++ b/lib/ship-bin-common.ts @@ -19,9 +19,10 @@ import { ghSpawnSync } from './gh-poll'; import { extractVersion } from './version-source'; import { BIN_DIR, runBashSync, runScriptSync, scriptInvocation } from './script-invocation'; -export interface Run { status: number | null; stdout: string; stderr: string } +/** `timedOut`: the call's own time limit stopped the process (spawnSync's ETIMEDOUT), whatever exit status it then gave. */ +export interface Run { status: number | null; stdout: string; stderr: string; timedOut?: boolean } const done = (r: { status: number | null; stdout?: string | Buffer | null; stderr?: string | Buffer | null; error?: Error }): Run => - ({ status: r.status, stdout: String(r.stdout ?? ''), stderr: String(r.stderr ?? '') + (r.error ? r.error.message : '') }); + ({ status: r.status, stdout: String(r.stdout ?? ''), stderr: String(r.stderr ?? '') + (r.error ? r.error.message : ''), ...((r.error as NodeJS.ErrnoException | undefined)?.code === 'ETIMEDOUT' ? { timedOut: true } : {}) }); export function git(cwd: string, args: string[], timeout = 120_000): Run { return done(spawnSync('git', args, { cwd, encoding: 'utf8', timeout, maxBuffer: 64 * 1024 * 1024, env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } })); diff --git a/lib/ship-preflight.ts b/lib/ship-preflight.ts index d02666477..beedbd4ff 100644 --- a/lib/ship-preflight.ts +++ b/lib/ship-preflight.ts @@ -30,6 +30,8 @@ export const PREFLIGHT_HELP = `gstack-ship-preflight — /ship Steps 1-3 and Ste (a branch that adds the lane for a file it touches); anything else is PREGATE_HEAD_POLICY_LOOSENS --timeout Step 5's pregate --timeout for each runner process, 1 to 3600; unset, the base .gstack/pregate.json timeout_s applies, else 600 s, and a longer lane is PREGATE_INCOMPLETE + --step-timeout the whole Step 5 pregate's budget (every check and lane together), 1 to 86400, default 3600; at the + limit it is stopped and prints PREGATE: time limit hit with the way out (push and let CI's full run carry it) gstack-ship-preflight --tests-only --base --policy-from head --simulate [--allow-repo-commands] --lane