Repository navigation
fix(skills): make /fixer loop until the backlog is drained and park on stall, not fixed counts - #2169
Conversation
…n stall, not fixed counts Two changes: - /fixer previously stopped after one batch of --count issues even when more qualifying open issues remained. It now loops across batches by default (Phase 3), re-fetching a fresh queue and continuing until no qualifying open issues remain or a 15-batch safety cap is hit. --once restores the old single-batch behavior. An empty queue is now reported as a clean stop (exit 0), with an explicit rule against wandering to other repos or inventing unrelated work to fill a batch. - Convergence rounds (2f) and drain passes (Phase 4) were capped at a fixed 3, parking/reporting a PR regardless of whether it was still making real progress. Both now track a per-round/per-pass progress signature and park only after 3 consecutive rounds/passes with zero measurable change (genuinely blocked), backed by a 15-round/15-pass safety cap for runaway cases. Fixes 2 bugs Greptile found on the first attempt at this change (#2165, reverted in #2167, Confidence Score 2/5): - The drain phase never actually removed a merged PR's number from parked.txt, so its length never shrank and a pass that successfully merged a PR was still recorded as making no progress — the drain could wrongly report the remaining PRs as blocked after 3 passes even though each pass was merging something. Step 3 (merge the lowest-ready PR) now explicitly removes it from parked.txt as part of the same step. - Phase 0's resume handling only checked whether state.json existed, so a fresh invocation after a fully-completed prior run inherited that run's stale batches-done count and empty queue.json, causing new issues to be silently skipped or the 15-batch cap to trigger prematurely. Resume now requires queue.json to be non-empty (real unfinished work); otherwise every run-scoped artifact is reset before starting.
| if [ "$PARKED_AFTER" -gt 0 ] && { [ "$DRAIN_STALL" -ge 3 ] || [ "$DRAIN_PASS" -ge 15 ]; }; then | ||
| echo "fixer: stopping drain — $([ "$DRAIN_STALL" -ge 3 ] && echo "3 consecutive passes with no merges (blocked)" || echo "15-pass safety cap reached"). $PARKED_AFTER PR(s) remain: report each as needing human review." | ||
| elif [ "$PARKED_AFTER" -gt 0 ]; then | ||
| echo "fixer: running another pass ($((DRAIN_PASS + 1)))" |
There was a problem hiding this comment.
Fixed in 66125b6 — the merge-lowest-ready-PR step in Phase 4 now also flips that issue's state.json entry from parked to merged (matched by PR number), in the same step that removes the PR from parked.txt. Traced through the logic to confirm: previously only parked.txt shrank, so Phase 5's final report kept listing a successfully-merged issue as parked and undercounted the merged total, exactly as described. (Note: this comment's diff anchor landed on the drain-stall stopping-condition block a few lines below the actual removal snippet — the concern described in the prose is what's fixed.)
| printf '%s\n' "score=${SCORE:-none};unanswered=$UNANSWERED;g3=$(git merge-base --is-ancestor origin/main HEAD && echo ok || echo behind);mergeable=$MERGEABLE;failed=$FAILED_CHECKS" \ | ||
| > .codegraph/fixer/gate-signature |
There was a problem hiding this comment.
There was a problem hiding this comment.
Fixed in b56330b — the gate signature now also folds in the current commit SHA (git rev-parse HEAD), a hash of the full concatenated Greptile review/comment text (not just the extracted N/5 digit), and the specific set of currently-unanswered comment ids (not just their count). Traced through it: a push landing before the score/checks catch up, a re-review that restates the same score for different underlying reasons, or a CI rerun that fails the same named check for a new cause will now all change the signature, so genuine activity between rounds is never misread as zero measurable progress.
| If `.codegraph/fixer/loop-decision` is `loop`, go back to Phase 1 and process another batch — do **not** re-run Phase 0 (the repo slug, test/lint commands, and `state.json` are already established for this run, and re-running Phase 0's resume-detection would misread the mid-run `state.json` as a crash to resume from). If it is `stop`, proceed to Phase: Drain Parked PRs. | ||
|
|
||
| **Exit condition:** `.codegraph/fixer/loop-decision` is `loop` (with a fresh `start-from` persisted and per-batch scratch state cleared) or `stop`. Every batch processed this run is recorded cumulatively in `state.json` — nothing from an earlier batch is lost or overwritten by a later one. |
There was a problem hiding this comment.
Fixed in af322d0 — both the queue-build (Phase 1) and the batch-completion check (Phase 3) now pass --author to 'gh issue list' so the author filter runs server-side instead of being applied client-side after a flat --limit 400 fetch, and the limit is raised to 1000 as a generous safety bound on one author's own backlog rather than a cap on the repo's total open-issue count. Confirmed this was a real gap: with the old client-side filter, issues by other authors interspersed in the 400-issue window could crowd out this author's own qualifying issues, letting REMAINING read 0 while qualifying issues still existed.
Greptile SummaryUpdates
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[Invoke /fixer] --> Resume{Unfinished queue or unreported parked PRs?}
Resume -->|No| Fresh[Reset run-scoped state]
Resume -->|Mid-batch| Batch[Process current batch]
Resume -->|Mid-drain| Drain[Drain parked PRs]
Fresh --> Queue[Build repository-scoped issue queue]
Queue -->|Empty| Done[Exit successfully]
Queue --> Batch
Batch --> More{More qualifying issues and below batch cap?}
More -->|Yes| Queue
More -->|No or --once| Drain
Drain -->|Progress| Drain
Drain -->|Empty or stalled/capped| Report[Produce final report]
Report --> Marker[Write run-complete marker]
Marker --> Done
Reviews (12): Last reviewed commit: "fix: use an explicit run-complete marker..." | Re-trigger Greptile |
Merging a parked PR during the drain phase only removed its number from parked.txt; the corresponding state.json entry stayed status="parked", so Phase 5's final report undercounted merged issues and reported completed work as unfinished. Flip the entry to "merged" (matched by PR number) in the same step that removes it from parked.txt.
Merging a parked PR during the drain phase only removed its number from parked.txt; the corresponding state.json entry stayed status="parked", so Phase 5's final report undercounted merged issues and reported completed work as unfinished. Flip the entry to "merged" (matched by PR number) in the same step that removes it from parked.txt.
…#2169) The stall signature relied on aggregates (score, unanswered count, mergeable, failing check names) that can read identical across two rounds even when real activity happened: a push landing before the score/checks catch up, a re-review restating the same score for different reasons, or a rerun failing the same named check for a new cause. Fold in the current commit SHA, a hash of the full Greptile review text, and the specific set of unanswered comment ids so genuine progress is never misread as a stall.
…ation (#2169) Both the queue-build and the batch-completion check fetched --limit 400 open issues repo-wide and filtered by author client-side. In a repo with more than 400 open issues, entries belonging to the target author could fall outside that window, under-reporting the remaining backlog as drained. Pass --author to gh issue list so filtering happens server-side and raise the limit to a generous safety bound on one author's own queue.
|
Addressed all three findings from the Greptile review (Confidence Score 2/5):
All three were traced through standalone before fixing, per the review guidance. Lint and the full test suite (260 files / 4178 tests) pass locally. Ready for re-review. |
…ure (#2169) A same-commit CI rerun (manual "Re-run failed jobs" or a flaky-test retry) leaves the commit SHA, check names, and every other gate-signature field unchanged, so the stall detector could not distinguish it from genuine inactivity and would park an actively-progressing PR. The signature now folds in each non-green check's completedAt/startedAt timestamp alongside its name, so a rerun always changes the fingerprint even when nothing else does.
|
Addressed the Confidence Score 3/5 gap named in the summary prose (no inline comment existed for it): CI reruns of the same named check are indistinguishable from inactivity — fixed in a067c87. Verified the concern was real: the prior round's fix (commit SHA + Greptile-text hash in the signature) only covers new commits and new review activity, but a manual "Re-run failed jobs" or a flaky-test retry on the same commit changes neither the SHA nor the check name list, so the signature stayed identical and an actively-rerunning PR could still be parked as blocked. The gate signature now also captures each non-green check's Lint clean; bash syntax of all embedded script blocks validated. Full local |
| grep -vxF "$MERGED_PR" .codegraph/fixer/parked.txt > .codegraph/fixer/parked.txt.tmp \ | ||
| && mv .codegraph/fixer/parked.txt.tmp .codegraph/fixer/parked.txt |
There was a problem hiding this comment.
When the drain merges the only PR remaining in parked.txt, grep -vxF writes the desired empty temporary file but exits 1, so the chained mv does not run. The merged PR remains queued, causing subsequent passes to count the merge as no progress and eventually report an already-merged PR as blocked.
There was a problem hiding this comment.
Fixed in 07b0721 — split the chained grep -vxF ... && mv ... into grep -vxF ... || true followed by an unconditional mv. Confirmed the bug was real by reproducing it standalone: with a single-entry parked.txt equal to $MERGED_PR, grep -v excludes that only line, writes a correctly-empty temp file, but exits 1 (its exit status reflects the inverted match count, not redirect success) — so the old &&-chained mv never ran and the "merged" PR stayed in parked.txt forever, exactly on the case that matters most (draining the last parked PR). The new pattern moves the temp file into place regardless of grep's exit code; also verified normal multi-entry removal still behaves correctly.
#2169) grep -v's exit status reflects whether any line passed the inverted filter, not whether the redirect succeeded. When the merged PR is the only entry in parked.txt, every line is excluded and grep exits 1 even though the empty result is exactly what's wanted -- so the chained `&& mv` never ran, silently leaving the just-merged PR's number in parked.txt forever. Decoupled the mv from grep's match-count exit code with `|| true`. Verified against both the last-entry case and a normal multi-entry removal.
| # server-side author filter, which previously meant issues by other authors could crowd | ||
| # this author's own low-numbered issues out of the fetched window). 1000 is a deliberately | ||
| # generous safety bound on one author's queue, not a realistic ceiling to ever hit. | ||
| gh issue list --state open --author "$AUTHOR" --limit 1000 \ |
There was a problem hiding this comment.
There was a problem hiding this comment.
Fixed in 072b185 — correct that 1000 was still the same class of bug at a bigger size, not a fix. Rather than guess a third "generous enough" constant, both fetches (Phase 1's queue build and Phase 3's completion check) now use an effectively-unbounded ISSUE_FETCH_LIMIT (100000) and explicitly detect truncation: if the raw returned count ever equals that limit, the skill fails loudly rather than silently trusting an incomplete result. This closes the whole class of bug instead of moving the ceiling again. Verified gh issue list --limit 100000 behaves correctly (fast, no truncation) against this repo, and the truncation-detection branch itself with mocked data at a small limit.
400, then 1000: any fixed --limit on gh issue list is the same silent truncation point at a different size, and it will keep recurring as an author's backlog grows. Both the Phase 1 queue build and the Phase 3 batch-completion check now fetch against an effectively-unbounded limit (100000) and fail loudly if that limit is ever actually returned in full, instead of guessing at a bigger "generous" constant that could still be exceeded and silently misreport an incomplete queue or a falsely-drained backlog.
…codegraph-tool into fix/2169-fixer-drain-review
| fi | ||
| printf '%s\n' "$PARKED_AFTER" > .codegraph/fixer/drain-parked-count |
There was a problem hiding this comment.
Drain reconciliation is interruption-unsafe
When the process stops after replacing parked.txt but before the separate state.json update completes, the merged PR disappears from the drain queue while its status remains parked. Because queue.json is already empty, the next invocation resets the run instead of resuming it, so the completed merge is lost from the final accounting.
There was a problem hiding this comment.
Fixed in 32c043c — this is a real gap: since queue.json is already empty by the time draining starts, a crash between the parked.txt removal and the separate state.json update would look like a genuinely fresh run to the next invocation, which would then wipe state.json (and parked.txt) instead of resuming, losing that merge from the final accounting entirely. Rather than try to make the two writes atomic or teach Phase 0 to treat drain-phase state as resumable (which has its own false-positive risk — a legitimately completed-but-blocked drain can end with a non-empty parked.txt too, so "parked.txt non-empty" alone isn't a safe resume signal), the drain phase now self-heals at the top of every pass: any state.json entry still marked "parked" whose PR is no longer listed in parked.txt is corrected to "merged" before anything else runs. Verified against both the interrupted case (reconciles correctly) and a normal still-parked case (correctly left untouched).
There was a problem hiding this comment.
Follow-up: the Fixed-in-32c043c7 reply above was necessary but not sufficient — Greptile's re-review of that commit (Confidence Score 3/5) correctly pointed out that Phase 0's resume-detection only ever looked at queue.json, which is legitimately already empty by the time draining starts. So an interruption anywhere during Phase 4 (not just the exact two-write window 32c043c targeted) would make the next invocation's Phase 0 read queue.json as empty, conclude the run had finished, and rm -f parked.txt plus reset state.json to {"issues":[]} before the self-heal step added in 32c043c ever got a chance to run — deleting the very evidence that step exists to recover.
Fixed in a26f43c: Phase 0 now also treats a non-empty parked.txt as evidence of a resumable (mid-drain) run, alongside queue.json, and only resets state when both are empty/absent. It also routes straight to Phase: Drain Parked PRs when queue.json is empty but parked.txt is not, instead of re-running the batch loop.
…#2169) The drain-merge step's two-write reconciliation (parked.txt removal, then a separate state.json parked->merged update) is not atomic: an interruption landing between the two writes leaves parked.txt correctly missing the merged PR while state.json still records it as parked. Since queue.json is already empty once draining starts, a later invocation reads that as a genuinely fresh run and would silently wipe the stale-but-recoverable record, losing the completed merge from the final accounting. The drain phase now reconciles any state.json "parked" entry whose PR is absent from parked.txt (evidence it already merged) back to "merged" before doing anything else that pass. Verified against both an interrupted-drain case (reconciles) and a normal still-parked case (leaves untouched).
…#2169) Phase 0 decided fresh-run vs. resume from queue.json alone. queue.json is legitimately already empty by the time Phase: Drain Parked PRs starts, so an interruption anywhere during the drain (including the exact split-brain window the prior commit's self-heal step was added to recover) looked identical to a fully-completed run: the next invocation would delete parked.txt and reset state.json before that self-heal step ever got a chance to run, silently erasing every still-parked PR along with the evidence needed to recover the interrupted merge. Phase 0 now also treats a non-empty parked.txt as evidence of a resumable (mid-drain) run, alongside queue.json, and routes straight to Phase: Drain Parked PRs when queue.json is empty but parked.txt is not.
|
Addressed the Confidence Score 3/5 gap from the latest summary re-review of 32c043c: Interrupted drain reconciliation could still be erased before the new recovery logic runs — the summary correctly identified that 32c043c's self-heal step (reconciling a Fixed in a26f43c: Phase 0 now also treats a non-empty |
| PARKED_LEN=0 | ||
| [ -s .codegraph/fixer/parked.txt ] && PARKED_LEN=$(wc -l < .codegraph/fixer/parked.txt) | ||
| if { [ -f .codegraph/fixer/queue.json ] && [ "$QUEUE_LEN" -gt 0 ]; } || [ "$PARKED_LEN" -gt 0 ]; then | ||
| echo "fixer: resuming an interrupted run — previous state:" | ||
| jq -r '.issues[] | " #\(.issue) \(.status) \(if .pr then "PR #\(.pr)" else "no PR" end)"' .codegraph/fixer/state.json 2>/dev/null | ||
| if [ "$QUEUE_LEN" -eq 0 ] && [ "$PARKED_LEN" -gt 0 ]; then | ||
| echo "fixer: queue.json is empty but parked.txt has $PARKED_LEN PR(s) — the batch loop had already finished and this run was mid-drain. Skip Phase 1-3 entirely and go straight to Phase: Drain Parked PRs." |
There was a problem hiding this comment.
When Phase 4 terminates normally after three stalled passes or the 15-pass cap, it leaves the blocked PRs in parked.txt. The next invocation therefore classifies the completed run as interrupted and skips Phases 1-3, preventing newly qualifying issues from being queued until every old parked PR merges.
There was a problem hiding this comment.
Fixed in 994896d — this was a real regression risk in the previous fix (a26f43c). Phase: Drain Parked PRs' own exit condition is "merged, or reported as needing human review" — once a drain stops because 3 consecutive passes merged nothing, or the 15-pass cap was hit, the remaining parked.txt entries are a closed, already-reported matter for that run, not an interruption. a26f43c's blanket "non-empty parked.txt = resume" rule didn't distinguish that from a genuine mid-drain interruption, so it would have made every future invocation skip Phase 1-3 forever, re-attempting the same permanently-stuck PRs and starving newly opened issues.
Phase 0 now also reads drain-stall/drain-pass (already maintained by Phase: Drain Parked PRs) to tell the two cases apart: a non-empty parked.txt is only treated as a resume signal when the drain that left it there had not yet reached its own stall (>=3) or cap (>=15) threshold. Verified all six relevant state combinations (no state, fully-merged, mid-batch, mid-drain interrupted, drain stalled-out, drain capped-out) standalone before landing it.
…mable one (#2169) The previous commit made Phase 0 treat any non-empty parked.txt as evidence of a resumable mid-drain run, since queue.json is legitimately already empty for the whole duration of Phase: Drain Parked PRs. But that phase's own exit condition is "every PR merged, or reported as needing human review" — once a drain stops because 3 consecutive passes merged nothing, or the 15-pass cap was hit, the remaining parked.txt entries are a closed, already-reported matter for that run, not an interruption. Treating them the same made every subsequent invocation skip Phase 1-3 forever, re-attempting the same permanently-stuck PRs and never queuing newly opened issues. Phase 0 now also reads drain-stall/drain-pass (already maintained by Phase: Drain Parked PRs) to tell the two cases apart: parked.txt is only a resume signal when the drain that left it there had not yet reached its own stall/cap threshold. Verified the fresh/resume decision against all six relevant combinations (no state, fully-merged, mid-batch, mid-drain interrupted, drain stalled-out, drain capped-out) standalone before landing it.
|
Addressed the Confidence Score 3/5 finding from the review of a26f43c ("a normally completed blocked drain can make every subsequent invocation skip new backlog work"): Phase 0's non-empty- |
| if [ "$PARKED_LEN" -gt 0 ] && { [ "$DRAIN_STALL" -ge 3 ] || [ "$DRAIN_PASS_COUNT" -ge 15 ]; }; then | ||
| DRAIN_ALREADY_REPORTED=1 |
There was a problem hiding this comment.
Threshold state precedes reporting
When the process stops after Phase 4 persists drain-stall=3 or drain-pass=15 but before the terminal report and Phase 5 complete, this branch treats the drain as already reported and deletes parked.txt and state.json, causing the unfinished parked PRs and final accounting to be lost.
There was a problem hiding this comment.
Fixed in ebfd3b7 — this was exactly right, and a real gap in 994896d. drain-stall/drain-pass are written mid-Phase-4, before Phase: Final Report ever runs, so a process stopping in the window after a counter crosses its threshold but before the report is actually produced would have been misclassified as "already reported."
Replaced the counter-based check with an explicit .codegraph/fixer/run-complete marker that Phase: Final Report touches as its last action, strictly after the report has been produced. Phase 0 now uses only that marker's presence to decide whether a non-empty parked.txt is a closed/reported matter (fresh run) or still needs draining (resume) — fully decoupled from the internal stall/cap counters. Verified all six relevant state combinations standalone, including this exact race, before landing it.
…rs (#2169) The previous commit distinguished a genuinely-interrupted drain from an already-reported blocked one by checking whether drain-stall/drain-pass had crossed their stall/cap threshold. That check is itself racy: those counters are written mid-Phase-4, before Phase: Final Report ever runs. A process stopping in the narrow window after a counter crosses its threshold but before the report is actually produced would be misclassified as "already reported," deleting parked.txt and state.json before anyone ever saw the blocked-PR report. Phase: Final Report now touches .codegraph/fixer/run-complete as its last action, strictly after producing the report. Phase 0 uses only this marker's presence to decide whether a non-empty parked.txt is a closed, reported matter (fresh run) or still needs draining (resume) — decoupling the fresh-vs-resume decision from Phase 4's internal stall-detection counters entirely. Resuming into an already-thresholded-but-unreported drain runs one extra (cheap) pass before Phase: Drain Parked PRs' own bookkeeping stops it again, which is what finally lets the report happen and the marker get written. Verified all six relevant state combinations standalone, including the exact race the previous commit missed, before landing this.
|
Addressed the Confidence Score 3/5 finding from the review of 994896d ("an interruption at the drain threshold can cause the next invocation to discard unfinished parked-PR state"): Phase 0's stall/cap-counter check (994896d) was itself racy — |
Summary
--countissues and stopped, even if more qualifying open issues remained. It now loops across batches by default (new Phase 3 — Continue the Batch Loop, or Proceed to Drain), re-fetching a fresh queue and continuing until no qualifying open issues remain or a 15-batch safety cap is hit.--oncerestores the old single-batch behavior.exit 0, not an error) — with an explicit rule against searching other repos or inventing unrelated work to fill a batch.This replaces #2165, reverted in #2167. Fixes the 2 issues Greptile found on #2165 (Confidence Score 2/5):
parked.txtshrinking, but nothing removed a PR's number from it after merging — so a pass that successfully merged a PR still looked stalled, and the drain could wrongly report the remaining PRs as blocked after 3 passes. Fixed: the "merge lowest-ready PR" step now explicitly removes that PR fromparked.txt.state.jsonexisted to decide "resume", so a fresh invocation after a fully-completed prior run inherited its stalebatches-donecount and emptyqueue.json— causing new issues to be silently skipped or the 15-batch cap to trigger early. Fixed: resume now requiresqueue.jsonto be non-empty (real unfinished work); otherwise every run-scoped artifact is reset before starting.Test plan
npm run lintclean (skill file is outsidesrc//tests/scope)/fixer --dry-runon a future run to confirm batch/round bookkeeping behaves as designed