Skip to content

fix(skills/copilot-review-loop): stop review waits that never exit - #98

Merged
sourcehawk merged 3 commits into
mainfrom
fix/97-background-wait
Oct 16, 2026
Merged

sourcehawk merged 3 commits into
mainfrom
fix/97-background-wait

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Description

Fixes #97

Subagents in a review loop started a background until ! pgrep -f "await-copilot-review.sh <pr>" loop to learn when the wait script ended, and that loop never exits because pgrep -f matches its own command line. Step 3 of copilot-review-loop now says exactly how to wait: the one background shell is the whole wait, a wake means read its exit code and then its output file, and a harness with no wake runs the same script in the foreground with a bounded timeout. It also says that no background shell may still run when the agent reports back, so a finished subagent does not stay alive.

Changes

  • copilot-review-loop Step 3: a recipe for the wait, for a top-level session and a subagent alike. On each wake the exit code decides: 0 goes to triage, 124 goes to the timeout rule, and any other exit is reported as a failure, with no new wait. It has a foreground fallback when the harness gives no wake on a background exit, or the agent cannot tell that it does.
  • copilot-review-loop Step 3: forbids a second command that watches the wait script, and names the pgrep -f / ps | grep self-match.
  • copilot-review-loop Step 3: before it reports back, the agent lists its background tasks and stops any that is still live.
  • Two new Red Flags rows: the "background a second loop" thought, and the "round is done, so report back" thought.
  • fanning-out-with-worktrees ripening step 1: the dispatch prompt for a review-loop subagent names the skill and adds no wait instructions of its own. The prompt in the incident told subagents to "poll yourself with a backgrounded command", and that advice led them to the pgrep loop.

Related

  • Follow-up, not in this PR: Step 3 passes "$SINCE", but each shell call runs in a new shell, so the variable from Step 1 is empty there unless the agent writes the literal timestamp. All ten test agents noticed this and wrote the literal value. The skill does not say to.

Testing

I tested with the RED → GREEN loop from superpowers:writing-skills. Each run was an isolated subagent that read only the skill file and the reproduction from #97: a background subagent at Step 3 that is not sure it gets a wake, with the dispatch prompt from the issue ("poll yourself with a backgrounded command").

  • RED, the skill on main, 5 runs: 2 runs started a second background loop to watch the wait script, and one of them said that the loop would still run when it reported. 2 runs read the output file again and again in the foreground. All 5 said that nothing told them to check for live background shells before they report.
  • GREEN, this branch, 5 runs: 5 of 5 passed the predicate in copilot-review-loop: subagents wait on the background review script with a pgrep loop that never exits #97. No run started a second watcher or a pgrep / ps | grep command, and no run left a shell running when it reported. Each run took the bounded foreground wait (30 540) and said why it did not follow the dispatch prompt's poll advice.
  • REFACTOR: two GREEN runs asked whether "not sure about the wake" counts as "no wake". The fallback bullet now says "or you cannot tell that it does".

The JSON in .claude-plugin/ parses. No script changed, so no script tests apply.

🤖 Generated with Claude Code

sourcehawk and others added 2 commits October 16, 2026 10:07
Step 3 said only that the harness re-invokes the session when the wait
script exits. A subagent that did not trust the wake made up its own
wait, often a background `until ! pgrep -f "await-copilot-review.sh"`
loop. That loop matches its own command line and never ends, so
finished subagents stayed alive for hours.

Step 3 now says that the one background shell is the whole wait, to
read its output file on each wake, and to run the script in the
foreground with a bounded timeout when no wake comes. It forbids a
second watcher, and it says that no background shell may still run
when the agent reports back.

Towards #97

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…loop skill

The orchestrator wrote its own wait instructions into the dispatch
prompt of each review-loop subagent ("poll yourself with a backgrounded
command"). That advice led subagents to the self-matching pgrep wait.
The ripening step now says that the prompt names the review-loop skill
and adds no wait instructions of its own.

Towards #97

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new wait instructions can mistake an exited task for a running one and stall indefinitely.

1 open finding
What changed in this PR

This PR addresses #97 by clarifying how review-loop agents wait for Copilot and clean up background tasks.

Changes:

  • Defines background waiting and a bounded foreground fallback.
  • Forbids secondary watchers and requires cleanup before reporting.
  • Keeps subagent dispatch prompts from overriding wait instructions.
File Description
skills/​fanning-out-with-worktrees/​SKILL.md Delegates subagent wait instructions to the review-loop skill.
skills/​copilot-review-loop/​SKILL.md Adds wait handling, cleanup requirements, and related Red Flags.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread skills/copilot-review-loop/SKILL.md Outdated
… its output

An empty output file does not show that the wait script still runs.
The script can exit early without output, for example when
`gh repo view` fails under `set -e`. The agent then ends its turn
again and waits for a wake that already came. Step 3 now reads the
task's exit code first, and on an exit other than 0 or 124 it reports
the failure and does not wait again.

Towards #97

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round 1. Review base: 6857e9b. Review effort: Balanced (from the review's **Review effort:** line).

Suppressed findings: none. The review body has no Suppressed comments block.

Posted findings: 1, applied in 76c6f2a (the exit code of the wait decides, not the output file). The thread has a reply and is resolved.

Comment gate (comment_growth.py 6857e9b): 0 flagged, 0 listed, 0 removed, 0 not checked. The round changed no code comment, so no verdict table applies.

Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused guidance addresses the reported failure modes and prior feedback, with no unresolved blocking issues identified.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@sourcehawk
sourcehawk merged commit 7ead34c into main Oct 16, 2026
6 checks passed
@sourcehawk
sourcehawk deleted the fix/97-background-wait branch October 16, 2026 10:03
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.

copilot-review-loop: subagents wait on the background review script with a pgrep loop that never exits

2 participants