Repository navigation
Re-run failed completions from their scheduled args - #280
ianmacartney wants to merge 2 commits into
Conversation
A mutation job whose scheduled `complete` failed held its pool slot forever (#276): recovery only checked the wrapper, which had succeeded. The wrapper now records the scheduled completion on the work in the same transaction as the work. Recovery checks that completion instead of the wrapper: it waits while it is pending, and re-runs a failed or canceled one from its stored args, since `complete` is guarded by the attempt number. Committed work is never re-run. After five re-runs it frees the slot and leaves the work in place. Completions for work canceled before it started are tracked the same way, as `completing` entries in running that hold no slot. Scheduling the completion now happens outside the wrapper's try, so a scheduling error fails the wrapper and rolls back the work instead of recording a failure for committed work.
|
@cubic-dev-ai review |
@ianmacartney I have started the AI code review. It will take a few minutes to complete. |
commit: |
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Each canceled-before-start job now waits in the running list as a `completing` entry until the loop sees its completion. Completions were read at most maxParallelism per iteration while cancelations arrive 64 at a time, so a mass cancel grew the list by thousands of entries. Read up to 64 completions regardless of maxParallelism, and stop taking cancelations while 256 canceled jobs are waiting on their completions. Reports, diagnostics and the running query count only entries that hold a slot.
|
@cubic-dev-ai review |
@ianmacartney I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
2 issues found across 11 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/component/lostCompletion.test.ts">
<violation number="1" location="src/component/lostCompletion.test.ts:137">
P2: `drive` performs roughly 24,500 scheduler drains and database queries across this file, which makes the new suite unnecessarily slow and likely to hit the default test timeout. Advance in coarser intervals or target the recovery boundaries instead of polling every two seconds.</violation>
</file>
<file name="src/component/loop.ts">
<violation number="1" location="src/component/loop.ts:389">
P2: The `MAX_COMPLETING` bound is bypassed when it is already full: the start lane can still select a due `pendingStart` whose cancellation was not in the limited cancellation batch, and `handleStart` then adds another `completing` entry. Under a stuck completion and a mass cancel, the running list can exceed the advertised bound and continue growing; enforce the cap in every path that calls `scheduleCanceledCompletion` or exclude these canceled starts before selecting the start lane.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| * that no more than maxParallelism entries hold a slot. | ||
| */ | ||
| async function drive(t: T, ms: number) { | ||
| for (let elapsed = 0; elapsed < ms; elapsed += 2 * SECOND) { |
There was a problem hiding this comment.
P2: drive performs roughly 24,500 scheduler drains and database queries across this file, which makes the new suite unnecessarily slow and likely to hit the default test timeout. Advance in coarser intervals or target the recovery boundaries instead of polling every two seconds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/component/lostCompletion.test.ts, line 137:
<comment>`drive` performs roughly 24,500 scheduler drains and database queries across this file, which makes the new suite unnecessarily slow and likely to hit the default test timeout. Advance in coarser intervals or target the recovery boundaries instead of polling every two seconds.</comment>
<file context>
@@ -0,0 +1,346 @@
+ * that no more than maxParallelism entries hold a slot.
+ */
+async function drive(t: T, ms: number) {
+ for (let elapsed = 0; elapsed < ms; elapsed += 2 * SECOND) {
+ vi.advanceTimersByTime(2 * SECOND);
+ await t.finishInProgressScheduledFunctions();
</file context>
| .take(CANCELLATION_BATCH_SIZE); | ||
| .take(MAIN_BATCH_SIZE); | ||
| const completing = running.length - countRunning(running); | ||
| const cancelLimit = Math.min( |
There was a problem hiding this comment.
P2: The MAX_COMPLETING bound is bypassed when it is already full: the start lane can still select a due pendingStart whose cancellation was not in the limited cancellation batch, and handleStart then adds another completing entry. Under a stuck completion and a mass cancel, the running list can exceed the advertised bound and continue growing; enforce the cap in every path that calls scheduleCanceledCompletion or exclude these canceled starts before selecting the start lane.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/component/loop.ts, line 389:
<comment>The `MAX_COMPLETING` bound is bypassed when it is already full: the start lane can still select a due `pendingStart` whose cancellation was not in the limited cancellation batch, and `handleStart` then adds another `completing` entry. Under a stuck completion and a mass cancel, the running list can exceed the advertised bound and continue growing; enforce the cap in every path that calls `scheduleCanceledCompletion` or exclude these canceled starts before selecting the start lane.</comment>
<file context>
@@ -371,19 +380,28 @@ async function queryPending(
- .take(CANCELLATION_BATCH_SIZE);
+ .take(MAIN_BATCH_SIZE);
+ const completing = running.length - countRunning(running);
+ const cancelLimit = Math.min(
+ CANCELLATION_BATCH_SIZE,
+ Math.max(0, MAX_COMPLETING - completing),
</file context>
Fixes #276 for mutation jobs and canceled jobs.
A mutation job whose scheduled
completefailed stayedrunningand held its pool slot forever: recovery only checked the wrapper, which had succeeded.completeon the work (completionId) in the same transaction as the work. Scheduling now happens outside the wrapper'stry, so a scheduling error fails the wrapper and rolls back the work.completeis guarded by the attempt number, so committed work is never re-run. After 5 re-runs it frees the slot and leaves the work doc in place.completeclearscompletionIdwhen it bumps attempts, and points jobs it forwards to a split batch at the new completion.completingentries inrunning, which don't count towardmaxParallelism.completenow writes apendingCompletionfor canceled jobs so the loop can release them.maxParallelism, and stops taking cancelations while 256 canceled jobs are waiting on their completions, so a mass cancel can't growrunningwithout bound.stats.runningcount only entries that hold a slot.lostCompletion.test.ts, which injects failures intocomplete.Not covered: action jobs whose inline and fallback completions both fail, and mutations stuck pending in the scheduler (#240).