fix(orchestration): hold queue claims until startup completes, tweak limiter limits and Reclaim stale jobs from running to pending without needing a process restart - #45
Merged
Conversation
The limiter throttled background work to a fixed 2 as soon as half the HTTP pool was busy. On the hosted default profile (6 HTTP / 8 BG) routine API-client traffic tripped that for hours, holding scheduled cache runs at 2 concurrent. - BackgroundHttpPressureThreshold now defaults to two thirds of HttpPoolSize (4 of 6) instead of half. - New BackgroundHttpPressureConcurrency sets the throttled BG level; defaults to half the ceiling (4 of 8), clamped to [min(2, ceiling), ceiling].
ResolveTaskWorkAsync dropped any task whose status was Running, on the assumption that a worker in this process held it. But Running also reaches the live graph from storage: it is the pre-invoke durable marker another process writes. That happens when a run is rehydrated from storage (e.g. an old container outliving the new one's startup recovery during an App Service swap) or when the pump's rehydrated copy wins the _activeRuns race against recovery at startup. The dropped job was marked Skipped, its queue row deleted, and nothing re-drives Running, so the run never finalized until the next restart (observed: a 508-task planner stuck at 505/508 for ~31h). Track ownership with a non-persisted OwnedHere flag set wherever this process marks a task Running. A Running task not owned here is an interrupted attempt from a dead owner: count it and run it, or fail it terminally on the third attempt, exactly as crash recovery does.
JobQueuePump started claiming at host start, while SchedulerService only ran ResumeInterruptedRunsAsync once the worker pool and storage were ready. A claim in that window rehydrated its run (with the previous process's stale Running markers) into _activeRuns, and recovery's reset then landed on a copy that lost the TryAdd race. OrchestratorService now exposes a RecoveryDone gate, opened from a finally around SchedulerService's startup sequence so it opens whether recovery succeeds, throws, is skipped, or the host stops mid-startup. The pump awaits it before its first claim. HTTP, health and row enqueueing are unaffected; rows written meanwhile are claimed on the first cycle after.
JohnDuprey
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.