Skip to content

Stop counting a finished command as a failed QA capture on macOS - #4166

Closed
vilano93 wants to merge 2 commits into
garrytan:mainfrom
vilano93:fix/qa-deadline-macos-group-kill
Closed

vilano93 wants to merge 2 commits into
garrytan:mainfrom
vilano93:fix/qa-deadline-macos-group-kill

Conversation

@vilano93

@vilano93 vilano93 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Why (in your own words)

On macOS, 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. The cause is the cleanup kill in runQaDeadlineCommand: after the child exits, it signals the process group and treats everything except ESRCH as a containment failure. While an exited group is still being torn down, macOS can answer EPERM. This change treats EPERM on macOS the same as ESRCH for that kill. Every other error, and EPERM on other platforms, still fails closed.

Live evidence

The kill error, measured directly: 14 runs of a multi-threaded Rust CLI that exits 0, with the same detached spawn and process.kill(-pid, 'SIGKILL') on the exit event:

darwin v26.3.0 {"exit0:ESRCH":1,"exit0:EPERM":3,"exit0:ok":10}

The same program through gstack-qa-evidence capture --public --deadline ... (the program itself exits 0 when run directly):

# upstream main 6042f6ad4, 12 runs
   9 "status":"complete" "exitCode":0
   3 "status":"incomplete" "exitCode":2

# this branch, 16 runs
  16 "status":"complete" "exitCode":0

The new test was red first (processGroupAlreadyGone in place, still only accepting ESRCH), then green:

# before the fix
(fail) a process group that already exited on macOS is not a containment failure

# test/qa-deadline.test.ts on this Mac
upstream main: 39-40 pass, 4-5 fail (two runs)
this branch:   46 pass, 0 fail

The 4-5 failures on main are existing qa-deadline tests (timeout and interruption closing the owned process tree). They pass with this change, so they appear to hit the same EPERM.

Scope

  • Changed:
    • lib/qa-deadline.ts: new processGroupAlreadyGone(code, platform), used by the group kill.
    • test/qa-deadline.test.ts: EPERM is tolerated on macOS only; other errors and other platforms still fail closed.
    • changelog.d/fix-qa-deadline-macos-group-kill.md: the changelog fragment.
  • Verified live by: the capture runs above on macOS 26 (Apple Silicon, Bun 1.x); bun run typecheck clean; bun run typecheck:test "812 known diagnostics, none new"; bun run build passes.
  • Did NOT test:
    • Linux or Windows behaviour (the new branch is macOS-only).
    • The full free suite: gstack-checks reported the selection as too broad (1711 files), so I ran the qa-deadline and qa-evidence tests.
    • test/qa-evidence*.test.ts still has 5 failures on this Mac. All 5 also fail on clean main, which has 7 there.
  • Known trade-off: on macOS, a group member owned by another user that survives the child's exit is now not reported, since EPERM cannot be told apart from teardown.
  • Not changed: lib/claude-code.ts:100 has a similar group kill with the same ESRCH check. I did not reproduce a failure there.

Liveness proof (required for external contributors)

SCR-20261108-mckz

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above

🤖 Generated with Claude Code

@trunk-io

trunk-io Bot commented Nov 8, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@vilano93
vilano93 marked this pull request as ready for review November 8, 2026 12:33
@vilano93 vilano93 changed the title fix(qa): a macOS EPERM from an exited process group is not a failed capture Stop counting a finished command as a failed QA capture on macOS Nov 8, 2026
@capy-ai

capy-ai Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the macOS measurements and the red-first test. This is on the crew's pick-up list: a crew lane will rebuild it on current main and credit you as co-author when it lands, then close this PR.

@capy-ai

capy-ai Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks @vilano93. Your report and measurements led to the fix in #4170, which merged as 1e25057 and credits you as co-author.

#4170 takes a slightly different approach from this PR. It doesn't treat EPERM on macOS as "gone" outright. Instead, after an EPERM it checks the process group itself: kill(-pgid, 0) returning ESRCH, or else a ps listing where every remaining member is a zombie or is exiting (STAT starts with Z or carries the E flag). A live member, which includes one owned by another user, still fails closed. That covers the trade-off you noted. Linux is unchanged.

We couldn't run macOS on our side. The teardown state is inferred from XNU and ps, not measured. If captures still come back incomplete on your Mac after updating, please reopen this or comment with the capture receipt. Closing this PR in favor of #4170.

@capy-ai capy-ai Bot closed this Nov 8, 2026
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