FORGE-85: bind time cutoffs instead of interval SQL #703

Merged
gmackie merged 1 commit from FORGE-85-time-cutoffs into main 2026-10-12 06:31:08 +00:00
Owner

Part 3 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #701. No behaviour change.

  • msAgo/msFromNow + SECOND_MS…DAY_MS in @forgegraph/db (packages/db/src/time.ts). Cutoffs are computed in JS and compared with drizzle operators so the column mapping picks the stored form.
  • Removed now() - interval / make_interval / ::interval at 8 sites: fg/monitoring/logs, delivery-alert-sweep baseline window, registry /health, registry upgrade-reconcile, node-access-db lease (expiry and the expired-lease check now use one JS clock), registry upstream-tracker, latest-version-resolver.
  • attestation-timeout: created_at + make_interval(timeout) < now() becomes one bound cutoff per distinct timeout_ms value, matched against the joined type row (exactly equivalent; production has 3 timed types with 2 distinct values, read-only check).
  • ISO-string comparisons fixed: events/pipeline/route.ts and agent/events/route.ts (×2) now gt(column, date).
  • Raw-SQL cutoffs (registry /health, upstream-tracker) bind through the column encoder, sql.param(msAgo(…), table.column): postgres-js (fetch_types off) cannot serialise a raw Date once the server infers a timestamp parameter. registry-stale-cutoff.database.test.ts covers it and fails with a raw Date.
  • Pre-existing bug, not fixed here (FORGE-83 owns the file): monitorUpstreamDependencies runs SELECT DISTINCT … ORDER BY latest_checked_at, which Postgres rejects because the ORDER BY column is not selected, so the monitor errors on every call.
  • routers/contract.ts coverage window: FORGE-84 moved that query into loadSloRows on main, so it is no longer changed here.
  • Not touched: health-retention.ts (FORGE-84 removes it), ClickHouse/SigNoz INTERVAL n MINUTE queries (not our DB).

Verification

  • packages/db/src/time.test.ts (3) and apps/web/src/lib/__tests__/time-cutoffs.database.test.ts (3): attestation sweep with per-type timeouts at ms offsets, logs window, Date cursor strictly-after at 1 ms. Green on PGlite and Postgres 16.
  • Existing: node-access concurrency (PG16), registry-proposal-churn, realtime-deployments, node-access/cron/monitoring/events route tests.
  • tsc clean for db, api, web, registry.

🤖 Generated with Claude Code

Part 3 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #701. No behaviour change. - `msAgo`/`msFromNow` + `SECOND_MS…DAY_MS` in `@forgegraph/db` (packages/db/src/time.ts). Cutoffs are computed in JS and compared with drizzle operators so the column mapping picks the stored form. - Removed `now() - interval` / `make_interval` / `::interval` at 8 sites: fg/monitoring/logs, delivery-alert-sweep baseline window, registry `/health`, registry upgrade-reconcile, node-access-db lease (expiry and the expired-lease check now use one JS clock), registry upstream-tracker, latest-version-resolver. - attestation-timeout: `created_at + make_interval(timeout) < now()` becomes one bound cutoff per distinct `timeout_ms` value, matched against the joined type row (exactly equivalent; production has 3 timed types with 2 distinct values, read-only check). - ISO-string comparisons fixed: events/pipeline/route.ts and agent/events/route.ts (×2) now `gt(column, date)`. - Raw-SQL cutoffs (registry `/health`, upstream-tracker) bind through the column encoder, `sql.param(msAgo(…), table.column)`: postgres-js (fetch_types off) cannot serialise a raw Date once the server infers a timestamp parameter. `registry-stale-cutoff.database.test.ts` covers it and fails with a raw Date. - Pre-existing bug, not fixed here (FORGE-83 owns the file): `monitorUpstreamDependencies` runs `SELECT DISTINCT … ORDER BY latest_checked_at`, which Postgres rejects because the ORDER BY column is not selected, so the monitor errors on every call. - routers/contract.ts coverage window: FORGE-84 moved that query into loadSloRows on main, so it is no longer changed here. - Not touched: health-retention.ts (FORGE-84 removes it), ClickHouse/SigNoz `INTERVAL n MINUTE` queries (not our DB). Verification - `packages/db/src/time.test.ts` (3) and `apps/web/src/lib/__tests__/time-cutoffs.database.test.ts` (3): attestation sweep with per-type timeouts at ms offsets, logs window, Date cursor strictly-after at 1 ms. Green on PGlite and Postgres 16. - Existing: node-access concurrency (PG16), registry-proposal-churn, realtime-deployments, node-access/cron/monitoring/events route tests. - tsc clean for db, api, web, registry. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FORGE-85: bind time cutoffs instead of interval SQL
Some checks failed
CI / gitleaks (pull_request) Successful in 11s
CI / go (pull_request) Successful in 1m1s
CI / storybook (pull_request) Successful in 1m50s
CI / checks (pull_request) Successful in 2m11s
CI / unit-web (pull_request) Successful in 1m57s
CI / database (pull_request) Successful in 2m10s
CI / unit-api (pull_request) Successful in 2m39s
CI / web-build (pull_request) Successful in 3m59s
CI / ci (pull_request) Has been cancelled
134f3fba86
Add msAgo/msFromNow and unit constants to @forgegraph/db. Cutoffs are
computed in JS and compared through drizzle operators, so the column
mapping decides the stored form (Date on Postgres, epoch ms on D1).

Replaced now() - interval / make_interval / ::interval at: monitoring
logs, delivery-alert-sweep baseline window, registry /health, registry
upgrade-reconcile, contract coverage window, node-access lease expiry,
registry upstream tracker and latest-version resolver. The column-dependent
attestation-timeout check (created_at + timeout < now) becomes one bound
cutoff per distinct timeout value. health-retention.ts is left to FORGE-84.

The ISO-string cursor comparisons in events/pipeline and agent/events now
bind Date objects through gt().

Tests: msAgo/msFromNow unit tests; a web DB test with millisecond-offset
fixtures for the attestation sweep, the logs window and Date cursors.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
gmackie force-pushed FORGE-85-time-cutoffs from 134f3fba86
Some checks failed
CI / gitleaks (pull_request) Successful in 11s
CI / go (pull_request) Successful in 1m1s
CI / storybook (pull_request) Successful in 1m50s
CI / checks (pull_request) Successful in 2m11s
CI / unit-web (pull_request) Successful in 1m57s
CI / database (pull_request) Successful in 2m10s
CI / unit-api (pull_request) Successful in 2m39s
CI / web-build (pull_request) Successful in 3m59s
CI / ci (pull_request) Has been cancelled
to e2794bc3e8
All checks were successful
CI / gitleaks (pull_request) Successful in 11s
CI / storybook (pull_request) Successful in 1m28s
CI / go (pull_request) Successful in 1m1s
CI / web-build (pull_request) Successful in 2m2s
CI / unit-api (pull_request) Successful in 2m6s
CI / unit-web (pull_request) Successful in 2m6s
CI / database (pull_request) Successful in 2m9s
CI / checks (pull_request) Successful in 4m16s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 36s
2026-10-12 04:48:27 +00:00
Compare
gmackie changed target branch from FORGE-85-latest-per-group to main 2026-10-12 05:22:47 +00:00
gmackie force-pushed FORGE-85-time-cutoffs from e2794bc3e8
All checks were successful
CI / gitleaks (pull_request) Successful in 11s
CI / storybook (pull_request) Successful in 1m28s
CI / go (pull_request) Successful in 1m1s
CI / web-build (pull_request) Successful in 2m2s
CI / unit-api (pull_request) Successful in 2m6s
CI / unit-web (pull_request) Successful in 2m6s
CI / database (pull_request) Successful in 2m9s
CI / checks (pull_request) Successful in 4m16s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 36s
to 3599cd0939
All checks were successful
CF executor smoke / smoke (pull_request) Successful in 18s
CI / gitleaks (pull_request) Successful in 17s
CI / unit-api (pull_request) Successful in 3m59s
CI / unit-web (pull_request) Successful in 4m14s
CI / storybook (pull_request) Successful in 1m31s
CI / go (pull_request) Successful in 1m16s
CI / web-build (pull_request) Successful in 2m57s
CI / database (pull_request) Successful in 3m56s
CI / checks (pull_request) Successful in 4m17s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 38s
2026-10-12 05:26:40 +00:00
Compare
Author
Owner

Preview environment is live: https://pr-703-forgegraph.forgegraf.com

Deployed 3599cd09 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-703-forgegraph.forgegraf.com Deployed `3599cd09` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Preview environment is live: https://pr-703-forgegraph.forgegraf.com

Deployed 3599cd09 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-703-forgegraph.forgegraf.com Deployed `3599cd09` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Preview environment is live: https://pr-703-forgegraph.forgegraf.com

Deployed 3599cd09 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-703-forgegraph.forgegraf.com Deployed `3599cd09` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Preview environment is live: https://pr-703-forgegraph.forgegraf.com

Deployed 3599cd09 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-703-forgegraph.forgegraf.com Deployed `3599cd09` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
gmackie changed target branch from main to FORGE-85-latest-per-group 2026-10-12 05:54:35 +00:00
gmackie changed target branch from FORGE-85-latest-per-group to main 2026-10-12 05:54:39 +00:00
gmackie force-pushed FORGE-85-time-cutoffs from 3599cd0939
All checks were successful
CF executor smoke / smoke (pull_request) Successful in 18s
CI / gitleaks (pull_request) Successful in 17s
CI / unit-api (pull_request) Successful in 3m59s
CI / unit-web (pull_request) Successful in 4m14s
CI / storybook (pull_request) Successful in 1m31s
CI / go (pull_request) Successful in 1m16s
CI / web-build (pull_request) Successful in 2m57s
CI / database (pull_request) Successful in 3m56s
CI / checks (pull_request) Successful in 4m17s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 38s
to cec284a054
All checks were successful
CF executor smoke / smoke (pull_request) Successful in 20s
CI / gitleaks (pull_request) Successful in 17s
CI / unit-api (pull_request) Successful in 2m16s
CI / unit-web (pull_request) Successful in 2m59s
CI / storybook (pull_request) Successful in 2m8s
CI / go (pull_request) Successful in 1m10s
CI / database (pull_request) Successful in 2m55s
CI / web-build (pull_request) Successful in 4m18s
CI / checks (pull_request) Successful in 4m26s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 38s
2026-10-12 06:15:42 +00:00
Compare
Sign in to join this conversation.
No description provided.