Skip to content

Fix issue #3642 - #3643

Merged
integry merged 1 commit into
3642-epic-0-9-y57from
3642/claude-opus-5-5-ultrafix-the-loop-ends-as-20261117-0428-tl8
Nov 17, 2026
Merged

integry merged 1 commit into
3642-epic-0-9-y57from
3642/claude-opus-5-5-ultrafix-the-loop-ends-as-20261117-0428-tl8

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #3642

PR created via retry mechanism

…whose next review was just enqueued. When a loop ends without reaching its goal, it now posts the reason in plain words and removes the `ultrafix` label.

Why the sweep saw a "stranded" loop. The sweep decided a loop was stranded with a single queue scan. That scan looked only at `waiting`, `active` and `delayed` jobs, and nothing recorded that a step had just been enqueued. So any scan that missed the review meant the loop looked idle and got re-armed under a new epoch, which supersedes that review. A miss can happen while the job moves between queue states during a capacity or PR-lock wait, or when the job sits in a state the scan didn't list, such as `prioritized`. An existing test (`a re-arm that misses a pending review in the queue scan supersedes it`) had pinned this as intended behaviour; I replaced it. I couldn't prove from the logs which of these happened in the three stalled loops.

What changed
- New `src/jobs/ultrafixStepEnqueueMarker.ts`: every enqueued step now records its job ID, epoch, time and delay in Redis.
- Re-arm check (`ultrafixStrandedLoopRearm.ts`): before re-arming, the sweep looks that job up directly. If it is in any live state, or it can't be found and less than its delay plus 10 minutes has passed, the loop is left alone. The sweep then schedules a later check instead of acting. A job that `failed` or `completed` is not held, so a step that really failed is still recovered at once (failed jobs are kept for 7 days, so they stay visible).
- Queue scan: it now covers all live states, including `prioritized`, `waiting-children` and `paused`.
- Failure count: re-arming never added to the "failed N times in a row" count; only jobs that exhaust their attempts do. Since the sweep no longer supersedes live jobs, that count can no longer grow without real failures. I didn't change the counting itself.
- Stop notice: for the recovery limit it used to say "Max cycles were exhausted". It now says the steps failed 3 times in a row and to restart with `/ultrafix`.
- Label: it is now removed on every failed finish, including the "CI did not settle" stop. This reverses the documented behaviour, which left the label on the PR. Removing the label clears the loop state, so the PR status stops showing Ultrafix as in progress.
- Docs: `docs/docs/features/pr-commands.md` is updated to match.

Tests. The three regression tests are in `test/ultrafixCiFailureRecovery.test.ts`:
1. A delayed review was just enqueued, the sweep runs before it starts, and the scan misses it: no re-arm, same epoch, the review then runs, and nothing is counted as failed.
2. The review is waiting for agent capacity (moved back to delayed): no re-arm. A `prioritized` job is also seen by the scan.
3. The recovery-limit test now checks that one stop notice is posted with the failure reason and that the label is removed.

I added a fourth test showing a job that has vanished is re-armed only after the grace period, and a label-removal check to the CI-timeout test.

Results. All 24 Ultrafix suites and `checkRunHandler` pass, and so does the docs manifest test. Root typecheck and lint with `--max-warnings 0` on the changed files are clean. The four new or changed tests fail when the fix is temporarily disabled. The real-Redis integration suite didn't run because there's no Redis in this container.

The scenario with about seven loops running at once was tested only through these simulated queue states, not under real load. The change touches the stop-notice code that #3593 also edits, though only with a few added lines.

There are no visual previews because nothing visible in the UI changed.
@propr-dev propr-dev Bot changed the title 🔨 Fix issue #3642 ✅ Fix issue #3642 Nov 17, 2026

integry commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Issue #3642 was corrected after this run started: read its "Correction" section. The review steps on #3615, #3629 and #3637 were refused at admission because the worker's worktree filesystem was below its free-space reserve (WorktreeDiskPressureError in packages/core/src/storage/lifecycle.ts; the refusal comment is built in src/jobs/prCommentUnstartedFailure.ts). Two refusals 19 seconds apart reached the recovery limit and ended the loop; space returned five minutes later.

Keep the sweep change already made, and add:

  1. A step that could not start because of disk pressure (a "could not start, nothing was changed" refusal) is transient for Ultrafix: retry the same step with backoff (about 2, 5, 10, 20 minutes, up to roughly an hour), without counting it toward the consecutive-failure limit, and post one "waiting for disk space on the worker" notice instead of one refusal comment per attempt.
  2. If space does not return in that time, stop with a stop notice that gives the real reason (no free disk space on the worker), the real last score and the real cycle number. On [3598 by Claude Opus 5.5] MCP: contradictory state fields and mixed timestamp formats in results #3637 the notice said "Last score: unknown. Max cycles were exhausted" at cycle 1 of 6 with a last score of 6/10; on [3602 by Claude Opus 5.5] Settings → Maintenance: held follow-ups show only what needs a decision, in plain words, and Resume works for cancelled work #3615 no notice was posted.
  3. Regression tests: two consecutive disk-pressure refusals followed by a successful admission continue the loop; persistent refusals end it with the correct notice and remove the ultrafix label.

Also set this PR's title from the issue title (post-processing of the first run failed on a GitHub rate limit, so the title is still "Fix issue #3642").

integry commented Nov 17, 2026

Copy link
Copy Markdown
Owner

/ultrafix goal=8 max=6

@propr-dev propr-dev Bot added the ultrafix label Nov 17, 2026
@propr-dev propr-dev Bot changed the title ✅ Fix issue #3642 🔨 Fix issue #3642 Nov 17, 2026
@propr-dev

propr-dev Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Ultrafix loop started (goal: 8/10, max cycles: 6)

First action: /review

💡 Tip: Remove the ultrafix label from this PR to stop further ultrafix cycles.

@propr-dev

propr-dev Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @integry

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

Ready to merge based on the supplied diff and surrounding code. The change adds targeted protection against premature loop re-arming and makes terminal stop behavior clearer. Current-head checks report 16 passed, 28 neutral/skipped, and no failures or pending checks. This review was static; no commands were run.

✅ Epoch-scoped protection — The enqueue marker protects only the current work epoch, and explicitly completed or failed jobs do not prevent recovery.

✅ Regression coverage — Added tests exercise missed queue scans, capacity delays, prioritized jobs, and recovery after a missing job’s grace period expires.

✅ Consistent stop handling — Timeout and unsuccessful completion paths remove the label inside the existing label-transition guard; repeated-failure notices now explain the actual stop reason.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S1: 🟢 Test marker decision boundaries

Consider focused tests for findLiveCurrentEpochStep covering epoch mismatch, completed and failed jobs, queue-read errors, and a live job beyond the grace period. The added integration tests cover the primary recovery scenario well; these optional cases would help preserve the helper’s distinction between confirmed live work and temporary uncertainty.

Score

The implementation is focused, includes relevant regression coverage, and has no verified merge blocker. Passing current-head checks support merge readiness within the reviewed scope.

Score: 9/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 1m 17s
  • Tokens: 48,860 (48,415 in / 445 out)
  • Cost: $0.40

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S1

🤖 Review by ProPR

@propr-dev

propr-dev Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-6-astra

Overall Evaluation

The PR adds a current-epoch enqueue marker to prevent unnecessary loop recovery, improves stop explanations, and removes the ultrafix label when a loop stops. It is ready to merge based on the supplied diff and static review.

✅ Epoch-scoped recovery guard — The marker only protects the current epoch, releases completed or failed jobs immediately, and bounds protection for missing jobs.

✅ Targeted regression coverage — Added tests exercise delayed reviews, capacity waits, prioritized jobs, and recovery after the missing-job grace period.

✅ Consistent stop behavior — Both ordinary unsuccessful completion and CI timeout remove the label within the existing label-transition guard.

Current checks report 16 passed, 28 neutral/skipped, and no failures or pending checks. No commands or tests were run during this review.

Merge blockers

No merge blockers.

Suggestions

These are optional follow-ups and are not sent to /fix.

S2: 🟢 Cover marker boundary cases

Consider direct tests for findLiveCurrentEpochStep covering an old-epoch marker, completed and failed jobs within grace, and queue-read failures before and after grace expires. These branches govern when recovery becomes permissible; focused tests would complement the integration scenarios. This is optional coverage, with no verified defect in those branches.

Score

The change is focused, includes relevant regression coverage, and has no verified merge blockers or current-head check failures. Validation here was limited to static inspection of the supplied code.

Score: 9/10


🤖 Review Details

  • Model: GPT-6 Astra
  • Time: 2m 45s
  • Tokens: 49,604 (49,199 in / 405 out)
  • Cost: $0.40

View Task


💡 Next step: Comment /fix to address every F# merge blocker, /fix all for every pending blocker and suggestion, or name records explicitly, as in /fix F3 S5.
F# and S# IDs increment across review comments and remain permanent, so selectors such as /fix F3 F5 stay unambiguous across cycles. S# suggestions stay optional: they are implemented only when you name them or request /fix all, and they never relax a merge blocker.

Copy and edit to choose records from this review:

/fix S2

🤖 Review by ProPR

@propr-dev propr-dev Bot removed the ultrafix label Nov 17, 2026
@propr-dev propr-dev Bot changed the title 🔨 Fix issue #3642 ✅⑨ Fix issue #3642 Nov 17, 2026

integry commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Please implement the "Correction" section of issue #3642, which this PR does not cover yet. Keep everything already in the PR and add:

  1. When an Ultrafix step cannot start because the worker refuses it for disk pressure (WorktreeDiskPressureError from packages/core/src/storage/lifecycle.ts; the refusal comment comes from src/jobs/prCommentUnstartedFailure.ts), treat it as transient: retry the same step with backoff (about 2, 5, 10, 20 minutes, roughly an hour in total), do not count it toward the consecutive-failure limit, and post a single "Ultrafix is waiting for free disk space on the worker" notice instead of one refusal comment per attempt.
  2. If space does not return within that time, stop the loop with a stop notice that names the real reason, the real last score and the real cycle number (on [3598 by Claude Opus 5.5] MCP: contradictory state fields and mixed timestamp formats in results #3637 the notice said "Last score: unknown. Max cycles were exhausted" at cycle 1 of 6 with a last score of 6/10).
  3. Regression tests: two consecutive disk-pressure refusals followed by a successful admission continue the loop; persistent refusals end it with the correct notice and without the ultrafix label.

@integry
integry merged commit d8e73b5 into 3642-epic-0-9-y57 Nov 17, 2026
47 checks passed
@propr-dev propr-dev Bot changed the title ✅⑨ Fix issue #3642 Fix issue #3642 Nov 17, 2026
propr-dev Bot pushed a commit that referenced this pull request Nov 18, 2026
…melines. The second is my best reading of the evidence: I had no worker logs, so I couldn't watch it happen. There is no UI change, so no previews.

Cause 1: PRs opened by the retry fallback never got the `AI` label (#3643, propr-site#222, #226)

Evidence:
- All three PR bodies read `Resolves #N\n\n_PR created via retry mechanism_`.
- Their timelines have no `labeled AI` event. #3643's only label was `ultrafix`; #222's only label was `ultrafix`; #226 had none.
- For comparison, #3667 was created normally and has `labeled AI` and `labeled llm-claude-opus55` 2 s after it was opened.

What happened: when post-processing doesn't leave a PR, `retryPRCreationViaAPI` (`src/jobs/issueJobPRRetry.ts`) opens one, but it never added the labels that normal creation adds. The webhook then treats the PR as not opted in, so every plain follow-up was dropped as `no_comment_trigger` with only a debug log. `/ultrafix` still worked on #3643 and #222 because slash commands don't need the label, which is why these PRs looked half-alive. A PR found during final validation had the same gap.

Fix: new `src/jobs/pullRequestProcessingLabels.ts` adds the processing and model labels, with retries. It never throws, and it can't block the PR retry itself. It is called on the three recovery routes: a PR the retry creates, an existing PR it finds after a 422, and a PR found during final validation. `PR_LABEL` and `modelName` are passed in from `processGitHubIssueJob.ts`.

PRs that already exist without the label are not fixed by this. They need the `AI` label added by hand before follow-ups on them are accepted.

Cause 2: a follow-up stored behind a running job could be left with no job to pick it up (#3667)

Evidence:
- The first request (comment 6945632909, 10:37) never got a run.
- The re-sent text (6947331935, 11:56:00) got a brand-new job, `…-1794916564247`, created at 11:56:04. So nothing was queued for the PR at that point.
- That run's receipt lists only `trigger-comment-ids=6947331935`, so the first comment was not waiting anywhere.
- The two comments are 79 minutes apart, more than the pending list's 1-hour expiry.

What happened: when any job for the PR exists, intake only appends the comment to the `pending-pr-comments` Redis list and calls it accepted. An active job has already read that list when it started. It looks once more near the end of its cleanup, and some early-exit paths never look at all. A comment stored after that last look had nothing to read it, and the list expired an hour later: no run, no comment. Which job was running for #3667 at 10:37 is the part I couldn't confirm without logs.

Fix:
- New `packages/core/src/webhook/pendingCommentDrain.ts`: after storing a comment, if no waiting or delayed job exists for the PR, intake queues a drain job. That job waits for the PR lock and then picks up the stored comments. If queuing it fails, the webhook delivery fails and is redelivered instead of being lost.
- `cleanupJob` no longer queues a second follow-up when a job is already queued for the PR. The queue check lives in the new `src/jobs/prCommentQueuedPickup.ts`.

On a labelled PR, a matching follow-up now always ends as a queued run, or as one of the existing outcomes (a held follow-up, or the assignment-gate refusal comment). A PR whose first run failed in post-processing now gets its label, so later follow-ups are accepted.

Tests
- New `test/recoveredPullRequestLabels.test.ts` (6 tests): the retry route, the 422 route and the found-during-validation route all add the labels; transient label failures are retried and a lasting one is logged. 4 of these fail against the old code.
- `test/commentEventHandler.switch-use.test.ts`: 3 new tests (active job → drain queued; delayed job → no drain; a job for a different PR doesn't count). Four existing tests that asserted "nothing queued" behind an active job now expect the drain job. With the drain call disabled, 6 tests fail.
- `test/prCommentCleanupOrder.test.ts`: 3 new tests for the cleanup dedupe.
- 57 related suites (root, core and api tests that touch these files) pass. Lint passes with zero warnings and typecheck is clean for root and core. The Redis integration suite ran 0 tests here because there is no Redis in this container.
integry pushed a commit that referenced this pull request Nov 18, 2026
… is sometimes never picked up (#3700)

* I found two causes and fixed both. The first is proven from the PR timelines. The second is my best reading of the evidence: I had no worker logs, so I couldn't watch it happen. There is no UI change, so no previews.

Cause 1: PRs opened by the retry fallback never got the `AI` label (#3643, propr-site#222, #226)

Evidence:
- All three PR bodies read `Resolves #N\n\n_PR created via retry mechanism_`.
- Their timelines have no `labeled AI` event. #3643's only label was `ultrafix`; #222's only label was `ultrafix`; #226 had none.
- For comparison, #3667 was created normally and has `labeled AI` and `labeled llm-claude-opus55` 2 s after it was opened.

What happened: when post-processing doesn't leave a PR, `retryPRCreationViaAPI` (`src/jobs/issueJobPRRetry.ts`) opens one, but it never added the labels that normal creation adds. The webhook then treats the PR as not opted in, so every plain follow-up was dropped as `no_comment_trigger` with only a debug log. `/ultrafix` still worked on #3643 and #222 because slash commands don't need the label, which is why these PRs looked half-alive. A PR found during final validation had the same gap.

Fix: new `src/jobs/pullRequestProcessingLabels.ts` adds the processing and model labels, with retries. It never throws, and it can't block the PR retry itself. It is called on the three recovery routes: a PR the retry creates, an existing PR it finds after a 422, and a PR found during final validation. `PR_LABEL` and `modelName` are passed in from `processGitHubIssueJob.ts`.

PRs that already exist without the label are not fixed by this. They need the `AI` label added by hand before follow-ups on them are accepted.

Cause 2: a follow-up stored behind a running job could be left with no job to pick it up (#3667)

Evidence:
- The first request (comment 6945632909, 10:37) never got a run.
- The re-sent text (6947331935, 11:56:00) got a brand-new job, `…-1794916564247`, created at 11:56:04. So nothing was queued for the PR at that point.
- That run's receipt lists only `trigger-comment-ids=6947331935`, so the first comment was not waiting anywhere.
- The two comments are 79 minutes apart, more than the pending list's 1-hour expiry.

What happened: when any job for the PR exists, intake only appends the comment to the `pending-pr-comments` Redis list and calls it accepted. An active job has already read that list when it started. It looks once more near the end of its cleanup, and some early-exit paths never look at all. A comment stored after that last look had nothing to read it, and the list expired an hour later: no run, no comment. Which job was running for #3667 at 10:37 is the part I couldn't confirm without logs.

Fix:
- New `packages/core/src/webhook/pendingCommentDrain.ts`: after storing a comment, if no waiting or delayed job exists for the PR, intake queues a drain job. That job waits for the PR lock and then picks up the stored comments. If queuing it fails, the webhook delivery fails and is redelivered instead of being lost.
- `cleanupJob` no longer queues a second follow-up when a job is already queued for the PR. The queue check lives in the new `src/jobs/prCommentQueuedPickup.ts`.

On a labelled PR, a matching follow-up now always ends as a queued run, or as one of the existing outcomes (a held follow-up, or the assignment-gate refusal comment). A PR whose first run failed in post-processing now gets its label, so later follow-ups are accepted.

Tests
- New `test/recoveredPullRequestLabels.test.ts` (6 tests): the retry route, the 422 route and the found-during-validation route all add the labels; transient label failures are retried and a lasting one is logged. 4 of these fail against the old code.
- `test/commentEventHandler.switch-use.test.ts`: 3 new tests (active job → drain queued; delayed job → no drain; a job for a different PR doesn't count). Four existing tests that asserted "nothing queued" behind an active job now expect the drain job. With the drain call disabled, 6 tests fail.
- `test/prCommentCleanupOrder.test.ts`: 3 new tests for the cleanup dedupe.
- 57 related suites (root, core and api tests that touch these files) pass. Lint passes with zero warnings and typecheck is clean for root and core. The Redis integration suite ran 0 tests here because there is no Redis in this container.

* feat(ai): I've fixed F1. A delayed PR comment job no longer counts as the pickup for a stored follow-up if it runs after that follow-up's pending list expires. This applies to both intake and cleanup, so the usage-limit retry an hour away no longer blocks the timely drain or follow-up job.

I've fixed F1. A delayed PR comment job no longer counts as the pickup for a stored follow-up if it runs after that follow-up's pending list expires. This applies to both intake and cleanup, so the usage-limit retry an hour away no longer blocks the timely drain or follow-up job.

**The fix**
- **Run time comes from BullMQ's delayed set.** Both checks read the delayed job's score with `zscore` (the run timestamp shifted left 12 bits). I didn't use the job's `timestamp + delay` fields, because PR-lock waits move the job back to delayed: that rewrites `delay` relative to the move but keeps the original creation timestamp, so the sum would be too early.
- **Expiry comes from the list itself.** Both checks read the list's remaining TTL with `pttl`, instead of assuming 3,600 s. In cleanup the list may have been written up to an hour earlier.
- **The rule:** a waiting job always counts. A delayed job counts only if it runs at least 60 s before the list expires. If either the run time or the TTL can't be read, the code queues the drain rather than suppressing it; the cost is at most one extra job that claims an empty list.
- **Where it lives:**
  - Intake: `packages/core/src/webhook/pendingCommentDrain.ts`, with `storeCommentForBatch` in `commentEventHandler.ts` passing in the list's TTL.
  - Cleanup: `src/jobs/prCommentQueuedPickup.ts`, which `cleanupJob` now calls with the Redis client and the list key.
  - The check is duplicated in the two packages on purpose. Exporting a new helper from `@propr/core` would break the test suites that mock that module by listing its exports one by one.

I checked the sibling paths. Every intake route, including slash commands and `/switch`, goes through `storeCommentForBatch`, so the one intake change covers them all. The other jobs that sit delayed (lock waits) put their claimed comments back on the list with a fresh TTL, and they are now judged by their real run time too.

**Tests**
- New in `test/commentEventHandler.switch-use.test.ts`:
  - A comment arrives behind an active job while a usage-limit retry is queued 65 minutes out; intake queues a drain.
  - A delayed job whose run time can't be read; intake queues a drain.
  - The existing "delayed job, no drain" test now gives that job a run time 3 s away.
- New in `test/prCommentCleanupOrder.test.ts`, each showing cleanup still queues the follow-up:
  - behind a distant usage-limit retry.
  - behind a job due in 5 minutes when the list has only 2 minutes left.
  - behind a delayed job whose run time can't be read.
- All 5 new regressions fail against the previous source and pass now.
- All 32 related root and core suites pass, each run on its own. `ultrafixRecoveryRedisIntegration` ran 0 tests because there is no Redis in this container.
- Root lint passes with zero warnings, core lint is clean on the changed files, and typecheck is clean for root and core.

There is no UI change, so there are no previews.

PR: #3700
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

* feat(ai): I fixed the failure. It was caused by this PR, and two shards hit it, not just Shard 3. In both, an older test still assumed that no job is queued while another job for the PR is running. The drain job this PR added now queues one in that case, which is the intended behaviour.

I fixed the failure. It was caused by this PR, and two shards hit it, not just Shard 3. In both, an older test still assumed that no job is queued while another job for the PR is running. The drain job this PR added now queues one in that case, which is the intended behaviour.

- **Shard 3/4:** `packages/api/test/taskFollowupRoutes.test.ts`, "review batched behind manual work preserves command metadata", failed with `1 !== 0` on the queued-job count.
- **Shard 1/4:** `packages/api/test/taskReviewRoutes.test.ts`, "dedicated review batched behind manual work retains review metadata and its idempotent receipt", failed the same way.

In both tests the only existing job for the PR is a running one. The command is still stored on the pending list and reported as `batched`, and the new code then queues a drain job to pick it up. That's the same change the earlier commit made to the four core tests in `commentEventHandler.switch-use.test.ts`.

**Fix:** I only changed the two tests, not the product code. They now expect exactly one drain job:
- In the follow-up test, the job is a delayed `processPullRequestComment` with empty `comments` and no `commandMode`. The command itself still goes only to the pending list.
- In the review test, the repeated request still adds nothing, so the count stays at one.

**Verification:** both suites pass locally (62 of 62 tests), and lint passes with zero warnings on the two files.

PR: #3700
Comment by: @propr-dev[bot] (ID: 6977156358)
Model: Claude Opus 5.5

---------

Co-authored-by: propr-dev[bot] <1316198+propr-dev[bot]@users.noreply.github.com>
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