fix(dispatcher): add process-group signal to review_near_success (#132, INV-24) - #133
Merged
Conversation
… INV-24)
Adds a fifth signal to `review_near_success`: walk the review wrapper's
process group (PGID == content of `review-${ISSUE}.pid`, because
`_run_with_timeout`'s `setsid` makes session-leader PID == PGID) via
`pgrep -g <pgid>` + `ps -o comm= -p <pid>` and treat as ALIVE/skip-
crash if any group member's `comm` matches `AGENT_CMD`.
Reproduced on a downstream consumer's #209 (2026-05-15 16:00:39Z): a
14-min review wrapper hit `pid_alive` triple miss (kill -0 / PID-file
mtime / heartbeat sibling mtime all stale), and the four legacy PR-state
signals (PR.mergedAt / APPROVED / verdict comment / defensive kill -0)
were all negative because the wrapper hadn't yet emitted any of those
artifacts. Dispatcher declared crashed → `reviewing → pending-dev`,
which 4 minutes later created a phantom dev-resume one second before
the same wrapper successfully merged the PR.
The new signal is additive — never replaces an existing positive
signal — and runs LAST in the cost-ordered chain (1+2: shared fetch_pr
call, 3: gh-api call, 4: kill -0, 5: pgrep+ps). Substring match against
AGENT_CMD tolerates Linux's 15-char `comm` truncation. Three defensive
guards (numeric PGID, pgrep on PATH, ps on PATH) keep the signal a
silent skip rather than fail-closed when prereqs aren't met.
Pipeline doc (CLAUDE.md authority rule): INV-24 enumerates 5 signals
with a dated 2026-05-16 note explaining the gap signal 5 closes.
Tests: extends `tests/unit/test-dispatcher-review-near-success.sh` from
6 cases to 11 (TC-RNS-007..011): new positive path alone, all-five-
negative crash path, legacy-positive-short-circuits-before-pgrep
ordering pin, strict-knob-overrides-pgrep, empty-PID-skips-pgrep-
silently. Full suite (61 files) green; lib-dispatch.sh + test file
shellcheck-clean.
Closes #132
There was a problem hiding this comment.
This PR successfully addresses the gap identified in issue #132 where long-running review wrappers could be falsely declared crashed during the window between "review wrapper is processing" and "review wrapper has emitted its first artifact."
The implementation is solid:
- Adds a fifth signal (process-group walk) to
review_near_successthat checks if any descendant process in the review wrapper's process group has acommmatchingAGENT_CMD - Properly ordered as the last (most expensive) signal, with TC-RNS-009 pinning this ordering
- Defensive guards ensure it never fails closed (skips silently on empty PID, missing tools, etc.)
- Comprehensive test coverage: 5 new test cases (TC-RNS-007..011) bringing total from 6 to 11
- Thorough documentation updates in both
invariants.mdand dedicated test case doc
The fix closes the production gap reproduced in #209 while maintaining backward compatibility through the REVIEW_NEAR_SUCCESS_WINDOW_SECONDS=0 strict knob.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
review_near_success(skills/autonomous-dispatcher/scripts/lib-dispatch.sh): walk the review wrapper's process group viapgrep -g <pgid>+ps -o comm= -p <pid>and treat as ALIVE/skip-crash if any group member'scommmatchesAGENT_CMD. PGID == content ofreview-${ISSUE}.pidbecause_run_with_timeout'ssetsidmakes session-leader PID == PGID.pid_alivetriple miss (kill -0 / PID-file mtime / heartbeat sibling mtime all stale) AND four legacy PR-state signals all negative (PR not merged, no APPROVED, no verdict comment, defensive kill -0 missed) — dispatcher declared crashed, label flipped to pending-dev, and 4 minutes later a phantom dev-resume fired one second before the same wrapper successfully merged the PR.docs/pipeline/invariants.mdenumerates all 5 signals with a dated 2026-05-16 note explaining the gap signal 5 closes.Why "additive, last in chain"
Signal ordering is cost-cheapest first: 1+2 share one
fetch_pr_for_issuecall, 3 is one gh-api call, 4 is a singlekill -0, 5 hits the kernel proc table. Earlier signals short-circuit before signal 5 runs (regression-pinned by TC-RNS-009). The new signal never replaces a positive earlier signal — only augments the all-negative path.REVIEW_NEAR_SUCCESS_WINDOW_SECONDS=0strict-knob override fires at the early numeric guard before any signal runs (TC-RNS-010 pins).Defensive guards (all silent skips, never fail-closed)
pgrep -g 0which returns kernel processes).pgrepmust be on PATH.psmust be on PATH.Substring match
*${AGENT_CMD}*tolerates Linux's 15-charcommtruncation. Over-match is preferred here because the signal only runs after 4 others already failed; a false positive defers crash declaration by one tick at most, while a false negative reproduces #209.Test Plan
docs/test-cases/review-near-success-pgrp-signal.md)tests/unit/test-dispatcher-review-near-success.shextended from 6 cases to 11 (TC-RNS-007..011: positive-alone / all-five-negative / legacy-positive-short-circuits-before-pgrep / strict-knob-overrides-pgrep / empty-PID-skips-pgrep-silently)shellcheck -S errorclean onlib-dispatch.sh+ extended test fileChecklist
Closes #132