1111# 2. If the agent produced a cleanup patch, apply it onto
1212# module-cleanup-wip and push.
1313# 3. If wip diff vs origin/main has reached FLUSH_THRESHOLD files OR
14- # the queue is empty, cut a batch branch from wip, open the PR,
15- # and reset wip back to origin/main.
14+ # the queue is empty, cut a batch branch from wip and open the PR.
15+ # Wip is NOT reset — each chain has its own wip branch, so the next
16+ # chain starts fresh on a different wip.
1617# 4. Self-dispatch the workflow unless we just opened a PR or the
17- # queue is empty (cron will pick up later).
18+ # queue is empty (cron will pick up later). Threads WIP_BRANCH so
19+ # the next run in the chain reuses the same wip.
1820#
1921# No rebase-retry loops on push: the workflow uses
2022# concurrency.group=module-cleanup with cancel-in-progress=false, so this
3537# FLUSH_THRESHOLD - file count that triggers a PR (default 10)
3638# WORKFLOW_FILE - workflow file name for self-dispatch
3739# MEMORY_BRANCH - default: memory/module-cleanup
38- # WIP_BRANCH - default: module-cleanup-wip
40+ # WIP_BRANCH - per-chain wip branch (passed in by the workflow;
41+ # defaults to module-cleanup-wip-<GITHUB_RUN_ID>)
3942
4043set -euo pipefail
4144
4245MEMORY_BRANCH=" ${MEMORY_BRANCH:- memory/ module-cleanup} "
43- WIP_BRANCH=" ${WIP_BRANCH:- module-cleanup-wip} "
46+ WIP_BRANCH=" ${WIP_BRANCH:- module-cleanup-wip- ${GITHUB_RUN_ID :- manual} } "
4447THRESHOLD=" ${FLUSH_THRESHOLD:- 10} "
4548QUEUE_REMAINING=" ${QUEUE_REMAINING:- 0} "
4649REPO=" ${GITHUB_REPOSITORY:? GITHUB_REPOSITORY required} "
@@ -183,20 +186,13 @@ if [ "$SHOULD_FLUSH" = "true" ]; then
183186 --reverse --format=' ## %s%n%n%b%n'
184187 } > " $BODY_FILE "
185188
186- # Don't let a transient `gh pr create` failure (e.g. label not found,
187- # rate limiting) abort before we reset wip and self-dispatch — the batch
188- # branch is already pushed and a PR can be opened manually.
189- if ! gh pr create \
189+ gh pr create \
190190 --repo " $REPO " \
191191 --base main \
192192 --head " $BATCH_BRANCH " \
193193 --title " Module cleanup: batch (run $RUN_ID )" \
194194 --body-file " $BODY_FILE " \
195- --label " module cleanup" ; then
196- echo " WARNING: gh pr create failed; batch branch $BATCH_BRANCH still pushed."
197- fi
198-
199- git push --force origin " origin/main:refs/heads/$WIP_BRANCH "
195+ --label " module cleanup"
200196
201197 OPENED_PR=true
202198fi
@@ -208,8 +204,9 @@ if [ "$OPENED_PR" = "true" ]; then
208204elif [ " $QUEUE_REMAINING " -le 0 ]; then
209205 echo " Queue empty; nothing to dispatch."
210206else
211- echo " Self-dispatching workflow for next module."
212- gh workflow run " $WORKFLOW_FILE " --repo " $REPO " --ref main
207+ echo " Self-dispatching workflow for next module on $WIP_BRANCH ."
208+ gh workflow run " $WORKFLOW_FILE " --repo " $REPO " --ref main \
209+ --field " wip_branch=$WIP_BRANCH "
213210fi
214211
215212git worktree remove --force " $MEM_WT " 2> /dev/null || true
0 commit comments