Skip to content

Four tests and two tools stop failing at random: gate-ahead worktrees and the gbrain MCP probe (GST-3543) - #4710

Merged
capy-ai[bot] merged 6 commits into
mainfrom
flaky-fixes-2026-11-22
Nov 22, 2026
Merged

capy-ai[bot] merged 6 commits into
mainfrom
flaky-fixes-2026-11-22

Conversation

@garrytan

@garrytan garrytan commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Two gate-ahead preparations for one PR no longer fail each other, and gstack-gbrain-mcp-verify no longer misreads a valid SSE reply as broken.
Both turned up in the daily flaky-test pass from CI runs that failed once and passed on retry. Two test fixtures that raced on timing are fixed too.
Nothing to do for users; the version is written at merge.

What changed
  • Gate-ahead and version-stamping worktrees take one lock per repository (lib/git-worktree-lock.ts). While git adds a worktree it reads every sibling's commondir, and a concurrent add leaves its own empty for an instant, so the other add died with failed to read .git/worktrees/worktree/commondir: Success (Trunk e3ed3abf, Free Tests 44999855570; the 4th time since 2026-10-29). Plain git failed 1 of 480 concurrent adds with that exact message, and 0 of 480 failed through the lock. The lock is best effort. When it can't be taken (a filesystem without hard links, an unwritable git directory, or six minutes of waiting), the command runs unlocked, as it does on main today, instead of failing.
  • gstack-gbrain-mcp-verify reads the SSE reply without early-exit pipes. Under pipefail, echo | head -1 | grep -q fails with SIGPIPE when the reader exits first. A valid SSE body was then parsed as plain JSON, and jq's exit 5 ended the probe (Trunk 1afdd260). Locally 7 of 400 runs failed before the fix and 0 of 400 after. A new test with a reply larger than a pipe buffer fails 5 of 5 on main and passes with the fix.
  • The git fixture template test turns off auto-maintenance. git commit and the receiving end of git push start a detached git maintenance run --auto, which created and deleted objects/maintenance.lock while the template was being copied (ENOENT in cpSync, Trunk 3a4e1509). A new test traces the build and fails on main.
  • The late-SDK-completion overlay test gives both arms 250 ms to start instead of 15 ms. A 20 ms stall in the first trial's setup reproduces the CI failure (Expected 3, Received 2, Trunk 5a3199f2).
Why

Each of these failed a CI run at random and cost a rerun. Two of them are real bugs that users of /ship's merge queue and /setup-gbrain could hit, not just test noise.

Blast radius

The lock wraps only the worktree add and remove calls in lib/restamp.ts and crew/lib/ship-queue-gate.ts. When it can't be taken, those calls behave exactly as on main (8 lock tests, including the unlocked fallback, which is red on the version that threw). The verify script's output classes and JSON are unchanged (its existing test file plus the new large-body test). The other two changes touch tests only.

Pre-Landing Review

The full review panel and a second-model review ran on this PR. Every finding was fixed except two edge cases in the new lock, which ship as notes: a takeover that stalls for more than 10 seconds, or a killed parent whose git child is still running, can let two worktree commands overlap. Both are no worse than main, which has no lock at all. A third second-model finding, that a lock error could fail a command main ran fine, is fixed by making the lock best effort, and a scoped re-check of that fix found nothing.

Documentation

Status: current. The docs already match this branch, so nothing was edited and nothing is blocked.

Scope audited: a88cc7c1..dfb1a663 on flaky-fixes-2026-11-22: 9 committed files (bin/gstack-gbrain-mcp-verify, crew/lib/ship-queue-gate.ts, lib/git-worktree-lock.ts, lib/restamp.ts, a changelog fragment and 4 test files), with nothing staged, unstaged or untracked. All 157 candidate docs were checked for the changed surfaces, and every doc that mentions them was read at the affected sections.

Documentation health:
README.md Current (no feature or install claims touched)
CLAUDE.md Current (changelog-fragment pointer still accurate)
docs/ship-policy.md Current (staging and gate-ahead worktree descriptions still hold; the new lock is internal and falls back to running unlocked)
docs/troubleshooting.md Current (RESTAMP_* and gate-ahead entries unchanged by this diff)
setup-gbrain/memory.md Current (gstack-gbrain-mcp-verify still sorts failures into NETWORK, AUTH and MALFORMED)
setup-gbrain/sections/brain-init.md.tmpl Current (step 4c verify contract and JSON fields unchanged)
docs/evals/detector-inventory.md Current (bin/gstack-gbrain-mcp-verify:64 still points at error_class)
CHANGELOG.md Skipped (ship-owned audit; top entry 1.102.2.0 matches VERSION)
TODOS.md Skipped (ship-owned audit)

Documentation coverage:
[entity] [reference] [how-to] [tutorial] [explanation]
lib/git-worktree-lock.ts (internal) ❌ ❌ ❌ ✅ source header comment
gstack-worktree.lock file ❌ ❌ ❌ ✅ source header comment

Documentation debt (low priority, no user-facing surface): the per-repository worktree lock (gstack-worktree.lock in the git common dir, stale after 120 s, removed automatically) and the failed to read .git/worktrees/<name>/commondir: Success race it narrows are explained only in lib/git-worktree-lock.ts. A troubleshooting entry would fill the how-to gap if the error is still reported after this fix. /document-generate can draft it.

Diagram drift: none. No architecture diagram names the changed modules.

Note for the author: changelog.d/flaky-fixes-2026-11-22.md says the worktree calls now take one lock per repository. It doesn't mention that they run unlocked when the lock can't be taken. It was left unedited because this audit doesn't change changelog files.

Tests
  • CI Free Tests run 45038130756 at dfb1a66: 1,769 test files passed, including macos-named-regressions; windows-smoke run 45038130811 passed.
  • bun test test/git-worktree-lock.test.ts: 8 pass, 0 fail.
  • New regression tests fail without their fix and pass here: the large SSE reply (5 of 5 red on main), the fixture maintenance trace (red on main), and the unlocked fallback (red on the lock as it stood at f857c25, before the fallback).
Agent notes

Flaky pass GSTA-809 for 2026-11-22 (GST-3543). Ledger: the crew drive's handoffs/flaky-ledger.md. Not in this PR: the cso-snapshot-state REPEAT (lib/cso lock code, its own PR with the security panel).

REVIEW_LOOP: passes=2 blocking_found=3 deferred=0 noted=10 fixed=12 scope=frozen open=2 fix_checks=3 dispatches=6
Ruled note: lib/git-worktree-lock.ts:60:outside-voice at f857c25 ruled by GSTA-36 (relayed from GSTA-36:2026-11-22T15:24:33.060Z) at 2026-11-22T15:24:44.564Z: a takeover stalled past 10 s can let two worktree commands run at once, no worse than main, which has no lock (approval a-8d75c3223ccb)
Ruled note: lib/git-worktree-lock.ts:47:outside-voice at f857c25 ruled by GSTA-36 (relayed from GSTA-36:2026-11-22T15:24:33.060Z) at 2026-11-22T15:24:44.667Z: a takeover while a killed parent's git child still runs lets two worktree commands overlap, no worse than main, which has no lock (approval a-3e273d76901e)
Review round exception: one scoped fix-check of dfb1a66 after round 2, granted by GSTA-36 (approval a-3f3ac0fc408c): "A flaky-fix lock must fall back to main's unlocked behaviour on any failure; edges no worse than main are notes."

Approvals

Approved: yes (record r-c5165d4bb000). The full approval record stays private.
Plan: exempt: bug fixes for flaky tests (repro or failing-first test per fix)
Plan check: exempt bug fix

{
  "schema_version": 1,
  "pr": 4710,
  "head": "dfb1a6635fb2e1f95b3a356037fed41d4051e0f3",
  "version": "1.102.2.0",
  "base": "main",
  "gate": {
    "free": {
      "pass": 1769,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "free",
      "run": 45038130756,
      "attempt": 1,
      "tree": "aa3840716cd311f04e53c441ceb125b45af68bba"
    }
  ],
  "session_kind": "unattended",
  "run": "ship-20261122T150551-e6014c",
  "head_tree": "aa3840716cd311f04e53c441ceb125b45af68bba",
  "product_patch_id": "455a7ea01dc4c943a4647334d0d1faedaf94af11",
  "gstack_version": "1.102.2.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 136,
    "rules": "33831f8248a814fd",
    "base": "a88cc7c1bec414b19b72b67c75821e8771fd85a6",
    "registry": "a88cc7c1bec414b19b72b67c75821e8771fd85a6",
    "gate_scan": {
      "tagged": 0,
      "head": "dfb1a6635fb2e1f95b3a356037fed41d4051e0f3"
    },
    "reasons": [
      "gate-class",
      "risk:security",
      "runtime=136"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @aa3840716cd3 (8 checks, current for dfb1a6635fb2)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/45038130756/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/45038130811/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=aa3840716cd3 tests=39161 skipped=71 runs=45038130756/1 profiles=ci-reuse/free-tests heads=dfb1a6635fb2 verified=2026-11-22T15:31:33.310Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md (157 docs) against a88cc7c1..dfb1a663"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 3,
    "deferred": 0,
    "noted": 5,
    "fixed": 5,
    "scope": "frozen",
    "fix_checks": 2,
    "rounds": 1,
    "ledgers_read": 3,
    "dispatches": {
      "specialist": 3
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/git-worktree-lock.ts:60:outside-voice",
      "head": "f857c257c53b97d45a3d06c9acc6597d926ee582",
      "by": "GSTA-36",
      "reason": "a takeover stalled past 10 s can let two worktree commands run at once, no worse than main, which has no lock",
      "at": "2026-11-22T15:24:44.564Z",
      "approval": "a-8d75c3223ccb",
      "relayed": "GSTA-36:2026-11-22T15:24:33.060Z"
    },
    {
      "finding": "lib/git-worktree-lock.ts:47:outside-voice",
      "head": "f857c257c53b97d45a3d06c9acc6597d926ee582",
      "by": "GSTA-36",
      "reason": "a takeover while a killed parent's git child still runs lets two worktree commands overlap, no worse than main, which has no lock",
      "at": "2026-11-22T15:24:44.667Z",
      "approval": "a-3e273d76901e",
      "relayed": "GSTA-36:2026-11-22T15:24:33.060Z"
    }
  ],
  "gate_dispositions": []
}
{"head":"503029b1eb80f641309d69087dac1e8b14314e1c","run":"ship-20261122T144250-0a7bd9","status":"started","review_loop":{"passes":1,"blocking_found":2,"deferred":0,"noted":10,"fixed":9,"scope":"frozen","fix_checks":1,"rounds":1,"dispatches":{"specialist":3}}}

garrytan and others added 3 commits November 22, 2026 14:42
- gstack's own git worktree add and removal take one lock per repository,
  so two gate-ahead preparations no longer fail each other reading a
  half-written commondir.
- gstack-gbrain-mcp-verify reads the SSE first line and data line without
  early-exit pipes, which failed with SIGPIPE under pipefail.
- The git fixture template test's repos turn off auto-maintenance, whose
  detached run removed objects/maintenance.lock mid-copy.
- The late-SDK-completion overlay test gives both arms 250 ms to start.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/specialist-batched#2 reader=testing
Review-Finding: p1/red-team#2 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…time remove a stale one

Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Review-Finding: p1/adversarial-native#1 reader=adversarial-native
Review-Finding: p1/adversarial-native#2 reader=adversarial-native
Review-Finding: p1/adversarial-native#3 reader=adversarial-native
Review-Finding: p1/adversarial-native#5 reader=adversarial-native
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 3 commits November 22, 2026 15:05
Also: the fixture trace test's control looks for the push by name, which the Windows runner spells differently (windows-scoped-shard, run 45036384878).
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p1/red-team#3 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ree lock cannot be taken

A filesystem without hard links, an unwritable git dir or a six-minute wait no longer fails gate-ahead or restamp; they fall back to the unlocked behaviour main had.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot marked this pull request as ready for review November 22, 2026 15:35
@capy-ai
capy-ai Bot merged commit 5962f0d into main Nov 22, 2026
55 of 56 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