Repository navigation
fix(tasks): freeze the timeout budget while a task is paused - #2
Merged
Merged
Conversation
deadline_at is a wall-clock timestamp, so pause time counted against the task timeout: pausing overnight (or shutting the machine down while paused) made the deadline ring while parked, and resuming landed straight into the settle sequence and a timeout terminal state. ApplyTaskPause now stamps paused_at, and ApplyTaskAdmission credits the paused interval back onto deadline_at in the same atomic UPDATE that ends the pause (paused_at is cleared there too). The shifted deadline flows to the live handle via the existing RETURNING mirror, so the engine clock context picks it up. Matches the re-basing the archive-restore path already did for paused tasks. Migration is an idempotent ADD COLUMN; tasks paused before the upgrade have no paused_at and keep the old behavior. Fixes #1
murilosoave
pushed a commit
to murilosoave/ARTEX
that referenced
this pull request
Oct 25, 2026
murilosoave
pushed a commit
to murilosoave/ARTEX
that referenced
this pull request
Oct 25, 2026
…udget fix(tasks): freeze the timeout budget while a task is paused
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.
Fixes #1
What was wrong
deadline_at(=first_run_at + timeout_seconds) is a wall-clock timestamp, and pausing a task did nothing to it. So the timeout kept burning while the task was parked: pause overnight (or shut the machine down while paused, which is the same thing once the deadline is persisted), and the deadline rings while parked. On resume the engine immediately runs the settle sequence and the task ends intimeoutwith almost no budget actually spent running.This bit in practice on the very first real run here: a 3h task ran ~2h, was paused overnight, and settled into
timeouton resume the next morning.The archive-restore path already re-based deadlines for paused tasks, so the pause/resume path was inconsistent with it.
The fix
ApplyTaskPausestampspaused_at = now()in the same atomic UPDATE that records the user pauseApplyTaskAdmissioncredits the paused interval back:deadline_at = deadline_at + (now() - paused_at)in the same atomic UPDATE that ends the pause, and clearspaused_at. The shifted value flows to the live task handle through the existingRETURNINGmirror, so the engine clock context picks it up with no extra plumbingALTER TABLE tasks ADD COLUMN IF NOT EXISTS paused_at TIMESTAMPTZin schema.sqlMultiple pause/resume cycles each credit their own interval. Tasks paused before the upgrade have
paused_at = NULLand keep the old behavior (documented in the commit).Known limitation, kept out of scope on purpose: time spent waiting in the concurrency queue after resume still counts, exactly like today. Only the paused interval is credited.
Testing
New
TestPauseShiftsTaskDeadlineOnResume(server package, DB-backed): stamps a 1h deadline, pauses, waits ~1.1s, admits out of the paused state, and asserts the deadline shifted by at least the paused interval,paused_atwas cleared, and the live handle mirrors the shifted deadline.Full suite with a live Postgres: only pre-existing failure is
TestInterceptFilterHTTP, which fails identically onmainwithout this change (verified by re-running it on the stashed base).go build ./...clean, gofmt clean.