Skip to content

Stop macOS EPERM marking a finished QA capture as incomplete - #4170

Merged
capy-ai[bot] merged 4 commits into
mainfrom
stop-macos-eperm-failing-qa-captures
Nov 8, 2026
Merged

capy-ai[bot] merged 4 commits into
mainfrom
stop-macos-eperm-failing-qa-captures

Conversation

@garrytan

@garrytan garrytan commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

On macOS, gstack-qa-evidence capture no longer records a command that exited 0 as an incomplete capture, so /ship's exploratory QA stops stalling on commands that worked. This serves gstack's goal of a QA loop you can trust unattended: a capture still fails closed whenever the command's process group has a live member.

What changed

Before, any group-kill error except ESRCH failed the capture; after, a macOS EPERM fails it only if the group still has a live member

Before, any group-kill error except ESRCH failed the capture; after, a macOS EPERM fails it only if the group still has a live member.

Before/after as text: Before, any group-kill error except ESRCH failed the capture; after, a macOS EPERM fails it only if the group still has a live member
--- Before · before.txt · captured output
+++ After · after.txt · captured output
+function processGroupEmpty(pgid: number): boolean {
+  try { process.kill(-pgid, 0); } catch (error) { if ((error as NodeJS.ErrnoException).code === 'ESRCH') return true; }
+  const listing = spawnSync('ps', ['-A', '-o', 'pgid=,stat='], { encoding: 'utf8', timeout: 5_000 });
+  if (listing.status !== 0) return false;
+  return !listing.stdout.split('\n').some(line => {
+    const [group, state = ''] = line.trim().split(/\s+/);
+    return Number(group) === pgid && !state.startsWith('Z') && !state.includes('E');
+  });
+}
+
+  ...
-    const kill = () => {
       if (!child.pid) return;
       try {
         if (process.platform === 'win32') child.kill('SIGKILL');
         else process.kill(-child.pid, 'SIGKILL');
       } catch (error) {
+        const code = (error as NodeJS.ErrnoException).code;
+        if (code !== 'ESRCH' && !(code === 'EPERM' && process.platform === 'darwin' && processGroupEmpty(child.pid))) outcome = 2;
-        if ((error as NodeJS.ErrnoException).code !== 'ESRCH') outcome = 2;
       }
     };
 

Before: an EPERM from the cleanup kill of an exited command's process group meant incomplete, exit 2, on every platform.
After, on macOS only: an EPERM makes the capture check the group itself. The group counts as gone when kill(-pgid, 0) returns ESRCH, or when ps -A -o pgid=,stat= lists no member of that group except zombies (state starting with Z) or members that are exiting (the E flag). A live member, a failed ps, or any other error still fails closed. On Linux and every other platform, EPERM fails closed exactly as on main.

The macOS teardown state is inferred from XNU and ps, not measured: this PR was never run on a Mac. If captures on macOS still come back incomplete after a command exits 0, @vilano93, please reopen #4166 or comment here with the capture receipt.

Why

"gstack-qa-evidence capture sometimes records a successful command as status: incomplete, exitCode: 2. The QA chain then refuses --after on that capture, so /ship's exploratory QA stalls on a command that worked" (#4166, which measured 3 of 12 captures failing on main and 0 of 16 with a fix). Finished commands now record as complete on macOS, and a group that still has a live member is still reported.

Blast radius

runQaDeadlineCommand's group-kill error path is shared by lib/qa-evidence.ts:232 (QA captures) and lib/dx-error-capture.ts:405. Only the EPERM-on-macOS branch changed, and it can only turn a failure into a pass after ps shows no live member, so Linux and Windows behave as on main (read at lib/qa-deadline.ts:160-168; the off-macOS test fails without the platform check). The check spawns ps (found through PATH) synchronously with a 5 s timeout, only on that path. No network, secrets, permissions, workflows, install scripts or dependencies change.

Summary

The QA capture recorded finished macOS commands as incomplete because it treated a teardown EPERM like a containment failure. The fix checks the group directly on macOS. Review then narrowed it twice. The check runs only on macOS, so a Linux member hidden from ps can't turn a failure into a pass, and the ps state parsing now matches macOS, where E (exiting) is a trailing flag and X means traced. The QA deadline reference now documents the exception.

Test Coverage

All new code paths have test coverage. Coverage: deterministic (the one changed runtime file has a changed test naming it).
Tests: 11 new cases in test/qa-evidence.test.ts. Three stub process.kill to throw EPERM: an empty group as macOS records complete, a live member as macOS fails closed, and an empty group as Linux fails closed. Six put a fake ps first on PATH: RE and UE members count as gone; R, S, X and RX stay live.
Regression proof: the empty-group case is red on main 15a35ff; the Linux case is red against f89e2c3's lib; RE, UE and X are red against bd0f126's lib; all pass at 7b0717c.
Tests ran: qa-evidence 43

Pre-Landing Review

Pre-Landing Review: 10 issues — 0 auto-fixed, 2 fixed in granted fix rounds, 8 noted, 0 deferred.

  • Fixed (red-team, confirmed by the native adversarial reader): the ps fallback ran on Linux too, where a member hidden from ps (hidepid /proc, another user's process) read as gone. Now macOS-only.
  • Fixed (outside voice): on macOS, E and X are trailing ps flags, so only a leading Z counted as gone. Now Z first or E anywhere counts as gone; X (traced) stays live.
  • Fix-checks on both fix ranges returned no findings.

Gate edits: none detected (1 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: unavailable as Codex (not installed); the outside-voice brief ran on a Claude subagent and completed.

Review notes

  • ps resolves through PATH rather than /bin/ps (low; anyone who controls the parent's PATH already controls the run).
  • The synchronous ps can block the event loop up to 5 s, at most twice, on the macOS EPERM path only (low).
  • Predates this PR: a later kill error can overwrite a timeout outcome (outcome ??= 2 would fix it) (low).
  • No test reaches a real macOS EPERM or real macOS ps output; both are stubbed (low).
  • lib/claude-code.ts:100 has the same ESRCH-only group kill; left alone, no reproduction there.

Exploratory QA

Functional smoke, 4 probes at 7b0717c on Linux with a preload stub for macOS behavior, verdict pass: a finished command records complete; as macOS, a refused group kill with a live member fails closed (incomplete, exit 2); as macOS, a refused group kill after the group emptied records complete; as Linux, the same refused kill fails closed. Not run: real macOS. Earlier runs at f89e2c3 and bd0f126 are superseded.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

Review bot comments

No review bot comments.

Scope Drift

Scope Check: CLEAN

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). This is a bug fix, exempt from plan review.

Issues

Refs p1/red-team#1

Verification Results

No plan verification items (bug fix, plan exempt). Exploratory QA: 4 PASS, 0 FAIL, 0 BLOCKED, 0 NOT RUN.

TODOS

No TODO items completed in this PR.

Documentation

Status: updated.
Scope: the branch diff from 15a35ff (lib/qa-deadline.ts, test/qa-evidence.test.ts, changelog.d fragment) plus the docs that cover QA capture cleanup (docs/reference-qa-deadlines.md, docs/troubleshooting.md). Result: docs/reference-qa-deadlines.md now documents that a failed cleanup kill is a guard error (exit 2) except a macOS EPERM where every remaining group member is a zombie or exiting; the changelog fragment already matched the code. Debt: none.

Test plan

  • bun test test/qa-evidence.test.ts: 43 pass, 1 skip, 0 fail at 7b0717c
  • CI free-tests at 7b0717c (run 42502128064): green, carried

Rewritten on main from #4166 by @vilano93, credited as co-author.

Agent notes

Refs GST-1917

Approvals

Approved: yes (record r-3a10cb75530b). The full approval record stays private: this repository is public or its visibility is unknown.
Plan: exempt: bug fix
Plan check: exempt bug fix

  • Bug fix lane GST-1917 under GStack Minder. Failing-first test written before the fix; red on main 15a35ff with exit 2, green after.

  • Review loop: pass 1 full (4 readers), fix-check 1 on f89e2c3..bd0f126, then fix-check 2 on bd0f126..402f230 under the owner's grant a-665a5edc68e7 (review_loop_grant at bd0f126); both clean.
    REVIEW_LOOP: passes=1 blocking_found=0 deferred=0 noted=0 fixed=2 scope=frozen unbound=2 ledgers_read=4 fix_checks=2 dispatches=4

  • Gate edits: none detected (1 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)

{
  "schema_version": 1,
  "pr": 4170,
  "head": "7b0717c393c06bf758da02d9b9c9989aede22add",
  "version": "1.98.0.0",
  "base": "main",
  "gate": {
    "qa-evidence": {
      "pass": 43,
      "fail": 0,
      "skip": 1
    }
  },
  "session_kind": "unattended",
  "head_tree": "fdcb1eb7361c8e02592ddeab55a64c25d658f9c8",
  "product_patch_id": "2669bf10de7eafadf64df468efd6cbec325157f8",
  "gstack_version": "1.98.0.0",
  "review_depth": {
    "depth": "full",
    "class": "code",
    "runtime_lines": 15,
    "rules": "66e5174161eecc2c",
    "base": "15a35ff1fd365b4e92a09510cf69cfe8b31fdfaf",
    "registry": "15a35ff1fd365b4e92a09510cf69cfe8b31fdfaf",
    "gate_scan": {
      "tagged": 0,
      "head": "7b0717c393c06bf758da02d9b9c9989aede22add"
    },
    "reasons": [
      "risk:security",
      "runtime=15"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @fdcb1eb7361c (8 checks, current for 7b0717c393c0)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42502128064/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=fdcb1eb7361c tests=36558 skipped=68 runs=42502128064/1 profiles=ci-reuse/free-tests heads=7b0717c393c0 verified=2026-11-08T17:00:12.702Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "updated",
    "scope": "README.md and docs/; updated docs/reference-qa-deadlines.md (cleanup-kill EPERM exception on macOS)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 0,
    "fixed": 2,
    "scope": "frozen",
    "fix_checks": 2,
    "rounds": 3,
    "ledgers_read": 4,
    "unbound": 2,
    "dispatches": {
      "specialist": 3,
      "red-team": 1
    }
  }
}

Open in Capy

On macOS the cleanup kill of an exited command's process group can get
EPERM while the group is being torn down, and the capture then recorded a
successful command as incomplete with exit code 2. On EPERM, check the group
directly (kill with signal 0, then a ps listing that ignores zombie and
exiting entries) and treat it as gone only when no live member remains.
A live member or a failed check keeps the fail-closed result.

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

trunk-io Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 3 commits November 8, 2026 16:29
Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
On macOS, ps shows a process that is exiting with a trailing E flag
(for example RE or UE), so a check on the leading letter alone read a
mid-exit member as live and kept the capture incomplete. Count a member
as gone when its state starts with Z or carries E; X means traced on
macOS, so it stays live. Linux is unchanged and still fails closed.

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 merged commit 1e25057 into main Nov 8, 2026
49 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