fix(scheduler): default started_at on cron-fire run insert#55
Merged
Conversation
PR #49 made insertRunV2's started_at param optional and set it to null when status='pending'. The scheduled_task_runs.started_at column is NOT NULL, so every cron fire was failing with a constraint violation. - insertRunV2: always default started_at to new Date() when omitted. - schema.sql: idempotent ALTER to ensure column DEFAULT now() is set in prod (belt-and-suspenders against drifted instances). - regression test asserting started_at is always non-null in the INSERT.
1 task
finedesignz
added a commit
that referenced
this pull request
May 26, 2026
PR #55 fixed insertRunV2's JS-side default, but the registry→dispatcher cron-fire path was STILL surfacing "null value in column started_at" in prod logs. Hardens two remaining gaps: 1. hub/src/db/dal.ts insertDeploymentRun — was inserting NULL into started_at when status='pending' (coolify-webhook deployment-marker rows). Now always now(). started_at is "row created"; that's correct for pending too. 2. hub/src/db/scheduled-tasks-dal.ts insertRunV2 — SQL now wraps the bound started_at in COALESCE(_, now()), so even an accidentally-null bind from a future caller resolves server-side. JS-side default (input.started_at ?? new Date()) stays as the primary guard. Schema.sql already has ALTER COLUMN started_at SET DEFAULT now() from PR #55 — that runs on every boot via migrate.ts (verified). Regression tests cover explicit null + the deployment-run path.
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.
Root cause
PR #49 made
insertRunV2'sstarted_atparam optional and set it tonullwhenstatus='pending'. Thescheduled_task_runs.started_atcolumn isNOT NULL, so every cron fire (incl. midnight0 */4 * * *) was failing in prod with:null value in column "started_at" of relation "scheduled_task_runs" violates not-null constraintFix (belt-and-suspenders)
insertRunV2always defaultsstarted_attonew Date()when omitted/null.ALTER COLUMN started_at SET DEFAULT now()so drifted prod instances are also safe.hub/test/insert-run-started-at.test.ts— mocks the postgres tagged-template and asserts the INSERT values include a non-null Date forstarted_atin pending/success paths.Verification
bun test hub/test/insert-run-started-at.test.ts→ 3 pass / 0 fail.0 */4 * * *fire should insert + dispatch without the NOT NULL violation.