Skip to content

v1.91.250.0 fix(tests): remove three free-tier fixture races (GSTA-107 daily flaky pass) - #3474

Merged
capy-ai[bot] merged 4 commits into
mainfrom
capy/gsta-107-free-fixtures
Oct 26, 2026
Merged

capy-ai[bot] merged 4 commits into
mainfrom
capy/gsta-107-free-fixtures

Conversation

@garrytan

@garrytan garrytan commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3474,
  "head": "895219f14d1c59cd948edcdee805a3f52093cf62",
  "version": "1.91.246.0",
  "base": "main",
  "gate": {
    "free (ubicloud remote pregate)": {
      "pass": 9236,
      "fail": 0,
      "skip": 0
    },
    "focused local bun test (3 changed files + 2 ratchets)": {
      "pass": 49,
      "fail": 0,
      "skip": 0
    }
  },
  "spend_usd": 0.11,
  "session_kind": "unattended",
  "pregate": "requires-remote cleared @31f7ad6f291e (7 checks, current for 895219f14d1c)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/40342993374",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/40342998678",
    "pregate.json/remote_gate: remote-gate tree=31f7ad6f291e tests=9236"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  }
}

What changed

The probe publishes its result by rename and waitForFile waits for content, not existence, so a 50 ms poll can no longer read an empty agent-env.json (Free Tests shard 2, twice)

The probe publishes its result by rename and waitForFile waits for content, not existence, so a 50 ms poll can no longer read an empty agent-env.json (Free Tests shard 2, twice)

Before/after as text: The probe publishes its result by rename and waitForFile waits for content, not existence, so a 50 ms poll can no longer read an empty agent-env.json (Free Tests shard 2, twice)
--- Before · dotenv-before.txt · captured output
+++ After · dotenv-after.txt · captured output
+// The probe publishes its result by rename, so a poller never sees the file
+// empty file writeFileSync had just created, "JSON Parse error: Unexpected EOF").
 function probeSource(out: string): string {
+  return `const fs = require('node:fs'); const tmp = ${JSON.stringify(out)} + '.tmp'; fs.writeFileSync(tmp, JSON.stringify({ sandbox: process.env.GSTACK_CHROMIUM_NO_SANDBOX ?? null })); fs.renameSync(tmp, ${JSON.stringify(out)});\n`;
-  return `require('node:fs').writeFileSync(${JSON.stringify(out)}, JSON.stringify({ sandbox: process.env.GSTACK_CHROMIUM_NO_SANDBOX ?? null }));\n`;
 }
 
+/** The probe's complete result: waits for the file to exist and to hold content, not only to exist. */
 async function waitForFile(file: string): Promise<string> {
   const deadline = Date.now() + 20_000;
+  let content = '';
+  while (Date.now() < deadline) {
+    try { content = fs.readFileSync(file, 'utf-8'); } catch {}
+    if (content) return content;
+    await Bun.sleep(50);
+  }
-  while (!fs.existsSync(file) && Date.now() < deadline) await Bun.sleep(50);
   return fs.readFileSync(file, 'utf-8');
 }
+
+beforeEach(() => {
 

Each fixture builds its own Git repository with auto-maintenance off instead of copying a shared template with fs.cpSync, so no directory walk races a detached git maintenance run (Free Tests shard 17)

Each fixture builds its own Git repository with auto-maintenance off instead of copying a shared template with fs.cpSync, so no directory walk races a detached git maintenance run (Free Tests shard 17)

Before/after as text: Each fixture builds its own Git repository with auto-maintenance off instead of copying a shared template with fs.cpSync, so no directory walk races a detached git maintenance run (Free Tests shard 17)
--- Before · cso-before.txt · captured output
+++ After · cso-after.txt · captured output
+// Each fixture builds its own repository from Git; nothing is copied from a shared
+// its directory walk once and passed on the serial retry). Auto-maintenance is off
+// because `git commit` otherwise starts a detached `git maintenance run --auto` that
+// creates and deletes .git/objects/maintenance.lock after the commit returns, under
+// the tests' own .git reads and the afterEach rmSync (docs/TESTING_INTERNALS.md,
+// Free-suite flake rules); fixtureGit's replacement env never sees the shard backstop.
+function seedRepo(repo:string,home:string){
+  const git=fixtureGit(repo,home);fs.mkdirSync(repo);
+  git('init','-q');git('config','user.email','[email protected]');git('config','user.name','Fixture');
+  git('config','maintenance.auto','false');git('config','gc.auto','0');
+  fs.writeFileSync(path.join(repo,'tracked.ts'),'export const tracked = true\n');git('add','tracked.ts');git('commit','-qm','base');
+  return git;
+}
-let template='';
 // The first /usr/bin/git spawns on a cold macOS runner can eat a test's whole 5 s budget before the code under test runs; pay them once here.
 beforeAll(()=>{
+  const warm=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cso-git-hardening-warm-')));
+  try{seedRepo(path.join(warm,'repo'),warm);}finally{fs.rmSync(warm,{recursive:true,force:true});}
-  template=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cso-git-hardening-template-')));
-  const repo=path.join(template,'repo'),git=fixtureGit(repo,template);fs.mkdirSync(repo);
-  git('init','-q');git('config','user.email','[email protected]');git('config','user.name','Fixture');
-  fs.writeFileSync(path.join(repo,'tracked.ts'),'export const tracked = true\n');git('add','tracked.ts');git('commit','-qm','base');
 },{timeout:30_000});
-afterAll(()=>fs.rmSync(template,{recursive:true,force:true}));
 
 function fixture(){
   const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cso-git-hardening-'))),repo=path.join(root,'repo'),runDir=path.join(root,'state','run');
+  roots.push(root);const git=seedRepo(repo,root);fs.mkdirSync(runDir,{recursive:true,mode:0o700});
+  return{root,repo,runDir,git};
-  roots.push(root);fs.cpSync(path.join(template,'repo'),repo,{recursive:true});fs.mkdirSync(runDir,{recursive:true,mode:0o700});
-  return{root,repo,runDir,git:fixtureGit(repo,root)};
 }
 

The descendant publishes its pid by rename and the timeout case polls publishedPid(), a positive integer, so an empty read no longer becomes pid 0 (Free Tests shard 13)

The descendant publishes its pid by rename and the timeout case polls publishedPid(), a positive integer, so an empty read no longer becomes pid 0 (Free Tests shard 13)

Before/after as text: The descendant publishes its pid by rename and the timeout case polls publishedPid(), a positive integer, so an empty read no longer becomes pid 0 (Free Tests shard 13)
--- Before · runner-before.txt · captured output
+++ After · runner-after.txt · captured output
+writeFileSync(process.env.PID_FILE! + '.tmp', String(process.pid));
+renameSync(process.env.PID_FILE! + '.tmp', process.env.PID_FILE!);
-writeFileSync(process.env.PID_FILE!, String(process.pid));
 record('pid_published');
 ...
+/** The descendant's published pid: a positive integer in the pid file, or undefined while unpublished. */
+function publishedPid(): number | undefined {
+  let text: string;
+  try { text = readFileSync(PID, 'utf8'); } catch { return undefined; }
+  return /^[1-9]\d*$/.test(text) ? Number(text) : undefined;
+}
+...
       const readyBy = Date.now() + 2000;
+      while (publishedPid() === undefined && Date.now() < readyBy) await Bun.sleep(5);
+      const descendantPid = publishedPid();
+      expect(descendantPid, 'descendant never published its pid within the readiness window').toBeDefined();
+      expect(running(descendantPid!)).toBe(true);
-      while (!existsSync(PID) && Date.now() < readyBy) await Bun.sleep(5);
-      expect(running(Number(readFileSync(PID, 'utf8')))).toBe(true);
 

Three free-tier files that failed once in Free Tests and passed on the serial retry each had a self-inflicted race, repaired in the fixture; no assertion, timeout or budget changed.

File Runs Cause Repair
browse/test/dotenv-isolation.test.ts 39902683183 shard 2, 40322888041 shard 2 ("JSON Parse error: Unexpected EOF" at the agent-env.json read) waitForFile returned as soon as the file existed; the probe created it with a plain writeFileSync, so a 50 ms poll between create and write read "" the probe writes a temp file and renames it into place; waitForFile waits for content. The new test spawns Bun with emptyBunConfig() so it also runs on the Windows lane (/ship review fix)
test/claude-code-runner.test.ts 39694715116 shard 13 (running(pid) false at the timeout case) same shape: an existence poll on descendant.pid then Number(readFileSync(...)), so an empty read became pid 0 and /proc/0/stat does not exist the descendant publishes the pid by rename; the test polls publishedPid() (a positive integer) and asserts it was published before asking whether it runs (/ship review fix)
test/cso-git-hardening.test.ts 40288142343 shard 17 (fs.cpSync threw inside copyDir/getStatsSync in fixture(), empty error message, passed on retry) every fixture copied one shared template repository with fs.cpSync; the walk failed once on a stat inside it. /ship's docs audit found the likely file: git commit starts a detached git maintenance run --auto that creates and deletes .git/objects/maintenance.lock after the commit returns, and fixtureGit's replacement env never saw the shard backstop (docs/TESTING_INTERNALS.md, Free-suite flake rules) each fixture builds its own repository with Git, with maintenance.auto=false and gc.auto=0; beforeAll still pays the cold macOS Git spawns once on a throwaway repository

Why

The GSTA-107 daily flaky pass found three free-tier files that each failed once in Free Tests (runs 39902683183, 40322888041, 39694715116, 40288142343) and passed on the serial retry. Each failure came from the fixture racing itself, not from the code under test, so the repairs stay inside the fixtures: nothing a user runs changes, and the free suite stops paying a serial retry for these files. The CHANGELOG entry stays under ## [Unreleased] (stamp-at-merge).

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-10-26 Paid spend for this /ship run: two Ubicloud remote free-tier pregates for #3474 “it's fine run as many $93 paid gates as you want who cares” (Garry (CREW rule 5, 2026-10-15, relayed by GStack Minder)) standing approval Ubicloud remote pregate runs for #3474 ($0.06 each; cap $2 per run, $15 for the /ship run) none
2026-10-26 Fixture-only test fixes in #3474 (no threshold, budget, timeout or trial count moved) “none needed” (GSTA-107 parent (thread rule: fixture-only changes need no approval)) standing approval browse/test/dotenv-isolation.test.ts, test/claude-code-runner.test.ts, test/cso-git-hardening.test.ts none

Source: gstack-approvals record for capy/gsta-107-free-fixtures (display only; not an approval citation).

Summary

Fixture-only repairs for three free-tier races (atomic result files in dotenv-isolation and claude-code-runner, per-fixture Git repositories with auto-maintenance off in cso-git-hardening), plus two /ship review fixes in the same files (Windows-safe Bun config in the new dotenv test; the runner names a missed pid publication). No product code changed.

Test Coverage

Test-only diff: the coverage audit returned a skipped audit (null coverage, zero gaps, "No new application code paths to audit"). Coverage gate: could not determine percentage — skipping.
Tests: 367 → 367 test files (+0 new files; one new test case in browse/test/dotenv-isolation.test.ts feeds the old race and fails on the pre-fix poller with the CI message, see Exploratory QA capture 004).
Tests ran: free (Ubicloud remote pregate, gstack-pregate --stage all --remote --spend-cap 2 --timeout 2700 --allow-repo-commands --base main) 9236 (0 failed, tree 31f7ad6f291e).
Tests ran: focused local bun test of the three changed files 4 + 21 + 11 (0 failed), plus test/bun-entry-isolation.test.ts and test/spawnsync-timeout-tripwire.test.ts 13 (0 failed); bun run typecheck 0 errors; bun run typecheck:test 819 known, none new.

Pre-Landing Review

Review loop: 3 passes (CREW rule 23 cap; pass 1 whole diff, passes 2 and 3 delta only; pass 3 found nothing new).

Pass 1 (whole diff; 3 specialists: testing, maintainability, performance; security, data-migration, api-contract, design, simplification and state-machines skipped by scope; Red Team not activated, 76 lines, no CRITICAL): 9 informational findings, 0 critical. Fixed in 4dcd7f3:

  • [INFORMATIONAL] (confidence 7, adversarial) browse/test/dotenv-isolation.test.ts:63 — the new test spawned Bun with a literal --config=/dev/null; the file runs on the Windows lane, where native Bun cannot open it. Now --config=${emptyBunConfig()} from browse/src/bun-child-config.
  • [INFORMATIONAL] (confidence 7, testing + maintainability + adversarial) test/claude-code-runner.test.ts:309 — running(publishedPid()!) failed as "expected true, got false" when the readiness window expired; the pid is now captured once and asserted defined with a message.

Pass 2 (delta 4dcd7f3): no new findings. The documentation audit then found seedRepo committing without maintenance.auto=false / gc.auto=0 (docs/TESTING_INTERNALS.md, Free-suite flake rules); fixed in 895219f, git 2.55.0 trace2 shows the detached maintenance spawn with the keys unset and none with them set.

Pass 3 (delta 895219f): no new findings.

Named and left as they are (advisory, informational or test-gap items per CREW rule 23):

  • browse/test/dotenv-isolation.test.ts:66 (testing 6, adversarial 8): the new test's second half proves valid JSON and no leftover .tmp, not rename atomicity itself; the first half (empty file filled 150 ms later) is what guards the race.
  • test/cso-git-hardening.test.ts:28 (performance 5, testing 5, adversarial 5, multi-specialist confirmed): fixture() now costs seven Git spawns per test instead of one cpSync; measured 41-216 ms per test on a 4-core Linux box; the macOS lane measures the cold case.
  • browse/test/dotenv-isolation.test.ts:28 [ADVISORY] (maintainability 5): the write-temp-then-rename idiom is now hand-written in three fixtures; a shared test helper is a proposal, not a defect.
  • browse/test/dotenv-isolation.test.ts:56 (maintainability 5): one test covers both the poller and the probe; the 150 ms timer is not cleared.
  • browse/test/dotenv-isolation.test.ts:38, test/cso-git-hardening.test.ts:13 (maintainability 4, appendix): bare catch {} in waitForFile; comments cite CI run ids.

Deferred to #3476 (pre-existing or neighbouring code): fixtureGit treats a null spawn status as success (test/cso-git-hardening.test.ts:12); other browse tests still spawn Bun with a literal --config=/dev/null.

Gate edits: none detected (9 listed, 6 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none). The six read hunks remove lines only to replace an existence poll with a content wait, a plain write with a rename, and a template copy with a per-fixture repository; no assertion, timeout, retry or skip was loosened. Forced probe for the test-only flake fix: the pre-fix poller fed the same empty-then-filled file fails with SyntaxError: JSON Parse error: Unexpected EOF (capture 004); the fixed files passed 20/20 under 24 busy loops on 4 cores before this run and 9236/0 on the remote free tier at the final tree.
Outside review: unavailable (Codex CLI not installed on this machine; codex_reviews unset). Native adversarial passes: Claude (anthropic/claude-sonnet-5-5, high reasoning) on passes 1, 2 and 3; specialists on anthropic/claude-sonnet-5-5. Missing outside coverage is listed, not passed.

Exploratory QA

Functional surface only (bun:test CLI runs), 5-minute smoke budget, report at .gstack/qa-reports/ship-3474-20261026T143047Z/functional/functional-report.md on the ship machine. Captures: 001 dotenv 4/4 pass (pre-fix tree, superseded by 005), 002 runner 21/21 (superseded by 006), 003 cso-git-hardening 11/11 with per-test 41-216 ms, 004 forced probe: the pre-fix waitForFile exits 1 with the CI message, 005 dotenv 4/4 and 006 runner 21/21 after the review fixes. Verdict: pass; no reproduced defect. Limits: Windows and macOS lanes not run locally (covered by the dispatched free-tests.yml and windows-free-tests.yml runs).

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped (bun run scripts/eval-select.ts --base origin/main: behavioral probes none, quality judges none; aside-browse-basic, aside-browse-flow and carve-section-loading-browse remain scheduled/release coverage). Paid eval spend: $0.

Greptile Review

No Greptile comments (no Greptile signal on this repository; the PR has no comments or reviews from a Greptile account).

Scope Drift

Scope Check: CLEAN
Intent: remove three free-tier fixture races found by the GSTA-107 daily flaky pass without changing assertions, timeouts or budgets.
Delivered: fixture-only changes in the three named test files, the CHANGELOG entry, and two review fixes inside the same files.

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.
Acceptance edits: baseline unavailable (no plan file).

Verification Results

No plan-specific verification items (no plan file). Automatic diff-scoped QA: 6 captures, 6 PASS (2 superseded and rerun), 0 FAIL, 0 BLOCKED, 0 NOT RUN.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. No documentation edits were needed or made (audit ship-3474-docs2-20261026T144023Z, the second and last attempt of this /ship invocation; the first, ship-3474-docs-20261026T143542Z, was also current and surfaced the auto-maintenance finding fixed in 895219f).

Scope: the base-to-HEAD diff (ab9a854..895219f: CHANGELOG.md plus three test files), with no staged, unstaged or untracked content. It includes 4dcd7f3 (the new dotenv test spawns Bun with emptyBunConfig(), and the runner asserts the pid was published) and 895219f (cso-git-hardening seedRepo sets maintenance.auto=false and gc.auto=0). Banned-terms check: none (the repo keeps no list). Discovery covered 123 candidate docs. Files read: the changed docs and tests, the test-policy docs, the entry-point docs, and investigate/sections/flake.md.tmpl. Other docs were checked with grep for references to the changed tests, the template-repo copy, cpSync, auto-maintenance, and the atomic-publish or poll patterns.

Documentation health:
CHANGELOG.md Current ([Unreleased] entry matches the final diff, including the maintenance.auto=false / gc.auto=0 wording; protected, not edited)
docs/TESTING_INTERNALS.md Current (the Free-suite flake rules already require fixtures that commit then list, watch or remove .git to turn auto-maintenance off, with the same two keys; the new seedRepo conforms, so the earlier finding is resolved. No mention of the removed shared-template copy)
docs/TEST_PORTFOLIO.md Current (no reference to the three tests)
docs/test-audit-2026-10.md Current (dated record; its "fix wave 2" flake-rate row is a historical measurement and is left alone)
docs/test-value-bar.md Current
docs/triage.md Current
CONTRIBUTING.md Current (test-tier and flake-ledger text unaffected)
AGENTS.md Current (validation discipline unchanged; the diff changes no commands or conventions)
CLAUDE.md Current
README.md Current
VERSION Current (1.91.246.0; the CHANGELOG [Unreleased] heading sits above it by design under stamp-at-merge; protected, not edited)

Documentation coverage:
Entity: atomic publish and content-wait polling for fixture result files (dotenv-isolation probe, claude-code-runner pid)
reference: no, how-to: no, tutorial: no, explanation: partial (CHANGELOG entry only)
Entity: per-fixture Git repositories with auto-maintenance off in cso-git-hardening
reference: yes (TESTING_INTERNALS Free-suite flake rules), how-to: no, tutorial: no, explanation: yes (the rule's own rationale)

Documentation debt:

  • Common gap: the Free-suite flake rules list has no bullet saying a fixture that publishes a result file for a poller writes it by rename and the poller waits for content (a reference/how-to entry). It is left unwritten because adding a new rule to a policy document is a policy change, not a factual correction. The existing rule "handshakes with a runner wait for the runner's own observable effect, not for a fixture side file" is adjacent, and the claude-code-runner fixture still handshakes on a descendant pid file, so the parent may want a one-line bullet.

Diagram drift: none. The diff touches no component named in an ARCHITECTURE diagram, and no doc diagram names these fixtures.

Test plan

  • gstack-pregate --stage all --remote --spend-cap 2 --timeout 2700 --allow-repo-commands --base main (Ubicloud, one VM): 9236 tests, 0 failed, tree 31f7ad6f291e, $0.05 (a first run on the pre-fix tree dcff4de0b4a2 also passed 9236/0, $0.06, and was not certified because the tree changed under it)
  • bun test browse/test/dotenv-isolation.test.ts test/claude-code-runner.test.ts test/cso-git-hardening.test.ts: 4 + 21 + 11 pass, 0 fail
  • bun test test/bun-entry-isolation.test.ts test/spawnsync-timeout-tripwire.test.ts: 13 pass, 0 fail
  • bun run typecheck: 0 errors; bun run typecheck:test: 819 known diagnostics, none new
  • Dispatched on the branch at 895219f (the PR itself gets no pull_request CI while it conflicts with main on CHANGELOG.md only): free-tests.yml run 40342993374 and windows-free-tests.yml run 40342998678

🤖 Generated with Claude Code via gstack /ship under Capy

… in dotenv-isolation and claude-code-runner, per-fixture Git repo in cso-git-hardening (GSTA-107)

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

trunk-io Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

The new dotenv-isolation test spawns Bun with emptyBunConfig() instead of a
literal --config=/dev/null, which the Windows lane cannot open; the runner's
timeout case asserts the descendant published a pid before asking whether it
is running, so a missed readiness window names itself.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan and others added 2 commits October 26, 2026 14:39
seedRepo commits with fixtureGit's replacement env, which never sees the
shard backstop, so each commit started a detached git maintenance run that
creates and deletes .git/objects/maintenance.lock under the tests' own .git
reads and the afterEach rmSync (docs/TESTING_INTERNALS.md, Free-suite flake
rules). Found by /ship's documentation audit; git 2.55.0 trace2 shows the
maintenance spawn with the keys unset and none with them set.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… base=origin/main@3ab7b14 policy=base origin/main@3ab7b149c908:.gstack/ship-policy.json)

STAMP_VERSION: 1.91.250.0
stage version: done (wrote 1.91.250.0)
stage release_tool: done (bun scripts/gen-agents-digest.ts)
stage changelog: done (Unreleased -> 1.91.250.0)
stage stamp_paths: skipped (no stamp_paths in policy)
stage mirror: skipped (no mirror in policy)
stage apply: done (4 file(s))
FILES: CHANGELOG.md VERSION agents-digest/gstack-AGENTS.md package.json
GSTACK_RESULT: skill=restamp status=complete run=/workspace/gstack/.gstack/tmp/restamp-journal.json

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot changed the title fix(tests): remove three free-tier fixture races (GSTA-107 daily flaky pass) v1.91.250.0 fix(tests): remove three free-tier fixture races (GSTA-107 daily flaky pass) Oct 26, 2026
@capy-ai
capy-ai Bot merged commit 39b06e2 into main Oct 26, 2026
75 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.

1 participant