Skip to content

fix(cron): compare order timestamps as instants, not text - #125

Merged
ralyodio merged 1 commit into
mainfrom
fix/text-date-pg-wt-nc7
Oct 21, 2026
Merged

ralyodio merged 1 commit into
mainfrom
fix/text-date-pg-wt-nc7

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

What broke

orders.created_at / updated_at are TEXT. The column default writes YYYY-MM-DD HH:MM:SS, while the services write ISO-8601 (...T...Z) on update. expire-orders and reconcile-payments compared them with an ISO cutoff using drizzle lt(), which is a text comparison. ' ' sorts before 'T', so any order from later the same UTC day counted as older than the cutoff.

On the prod data, both orders created at 2026-10-21 12:18 test as older than a 2026-10-21T10:00:00Z cutoff:

created_at          | text <  cutoff | fixed
2026-10-21 12:18:08 | t              | f

So expire-orders could expire a CREATED order hours after it was made instead of after EXPIRE_AFTER_HOURS, and reconciliation picked up orders before RECONCILE_AFTER_MINUTES.

Fix

olderThan(column, cutoffIso) compares (column::timestamp at time zone 'utc') < cutoff::timestamptz. Both stored spellings parse, both are UTC, and the result does not depend on the session time zone. No schema change.

tsc clean for services/cron, vitest run: 506 pass.

🤖 Generated with Claude Code

orders.created_at defaults to 'YYYY-MM-DD HH:MM:SS' and updated_at is
rewritten as ISO-8601 by the services. Against an ISO cutoff the text
comparison sorts ' ' before 'T', so an order created later the same UTC
day already looked older than the cutoff: expire-orders could expire a
fresh CREATED order and reconcile-payments polled orders too early.
Read both spellings as UTC timestamps and compare instants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

1 finding(s)

MEDIUM: 1

Severity Rule Location
MEDIUM js-unescaped-html-sink apps/site/app/_components/pit-footer.tsx:17

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit d34bebc into main Oct 21, 2026
7 checks passed
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