Skip to content

Conversation

@smudge
Copy link
Member

@smudge smudge commented Feb 10, 2026

Stacked PRs:


fix: clamp max_age metrics at 0

After the change in #89 to have delayed surface DB-accurate max_age
metrics, it appears that PostgreSQL will occasionally report a run_at
that is milliseconds after the current NOW() in UTC time.

This is more than just clock drift between the DB and the server that
inserted the row -- in READ COMMITTED mode, statements can see rows
committed after the start of the transaction, while NOW() is frozen to
the transaction start time. (Even without an explicit BEGIN, bare
statements are wrapped in an implicit transaction.)

This PR:

  • Switches PostgreSQL to STATEMENT_TIMESTAMP() to get even closer to
    the time at which the SELECT actually began.
  • Clamps at 0 anyways because clock drift is still a possibility.

/no-platform

After the change in #89 to have `delayed` surface DB-accurate max_age
metrics, it appears that PostgreSQL will occasionally report a `run_at`
that is milliseconds _after_ the current NOW() in UTC time.

This is more than just clock drift between the DB and the server that
inserted the row -- in READ COMMITTED mode, statements can see rows
committed after the start of the transaction, while NOW() is frozen to
the transaction start time. (Even without an explicit `BEGIN`, bare
statements are wrapped in an implicit transaction.)

This PR:
- Switches PostgreSQL to `STATEMENT_TIMESTAMP()` to get even closer to
  the time at which the `SELECT` actually began.
- Clamps at 0 anyways because clock drift is still a possibility.

/no-platform

stack-info: PR: #94, branch: smudge/stack/5
@smudge smudge marked this pull request as draft February 10, 2026 17:26
@smudge smudge changed the base branch from smudge/stack/4 to main February 10, 2026 17:26
@smudge smudge changed the base branch from main to smudge/stack/4 February 10, 2026 17:27
@smudge smudge marked this pull request as ready for review February 10, 2026 17:27
@smudge smudge marked this pull request as draft February 10, 2026 17:28
@smudge smudge changed the base branch from smudge/stack/4 to main February 10, 2026 17:28
@smudge smudge changed the base branch from main to smudge/stack/4 February 10, 2026 17:29
@smudge smudge mentioned this pull request Feb 10, 2026
@smudge smudge marked this pull request as ready for review February 10, 2026 17:29
@smudge smudge marked this pull request as draft February 10, 2026 17:31
@smudge smudge changed the base branch from smudge/stack/4 to main February 10, 2026 17:31
@smudge smudge changed the base branch from main to smudge/stack/4 February 10, 2026 17:32
@smudge smudge marked this pull request as ready for review February 10, 2026 17:32
@smudge smudge requested a review from effron February 10, 2026 17:37
@smudge smudge marked this pull request as draft February 10, 2026 18:10
@smudge smudge changed the base branch from smudge/stack/4 to main February 10, 2026 18:10
@smudge smudge changed the base branch from main to smudge/stack/4 February 10, 2026 18:10
@smudge smudge marked this pull request as ready for review February 10, 2026 18:11
smudge added a commit that referenced this pull request Feb 10, 2026
After the change in #89 to have `delayed` surface DB-accurate max_age
metrics, it appears that PostgreSQL will occasionally report a `run_at`
that is milliseconds _after_ the current NOW() in UTC time.

This is more than just clock drift between the DB and the server that
inserted the row -- in READ COMMITTED mode, statements can see rows
committed after the start of the transaction, while NOW() is frozen to
the transaction start time. (Even without an explicit `BEGIN`, bare
statements are wrapped in an implicit transaction.)

This PR:
- Switches PostgreSQL to `STATEMENT_TIMESTAMP()` to get even closer to
  the time at which the `SELECT` actually began.
- Clamps at 0 anyways because clock drift is still a possibility.

/no-platform

stack-info: PR: #94, branch: smudge/stack/5
smudge added a commit that referenced this pull request Feb 10, 2026
After the change in #89 to have `delayed` surface DB-accurate max_age
metrics, it appears that PostgreSQL will occasionally report a `run_at`
that is milliseconds _after_ the current NOW() in UTC time.

This is more than just clock drift between the DB and the server that
inserted the row -- in READ COMMITTED mode, statements can see rows
committed after the start of the transaction, while NOW() is frozen to
the transaction start time. (Even without an explicit `BEGIN`, bare
statements are wrapped in an implicit transaction.)

This PR:
- Switches PostgreSQL to `STATEMENT_TIMESTAMP()` to get even closer to
  the time at which the `SELECT` actually began.
- Clamps at 0 anyways because clock drift is still a possibility.

/no-platform

stack-info: PR: #94, branch: smudge/stack/5
"TIMEZONE('UTC', NOW())"
"TIMEZONE('UTC', STATEMENT_TIMESTAMP())"
when 'MySQL', 'Mysql2'
"UTC_TIMESTAMP()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the behavior of mysql here? is it not impacted by the transaction start timestamp behavior on that platform?

Copy link
Member Author

@smudge smudge Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, MySQL's timestamp is equivalent to pg's statement timestamp -- as in, NOW() is based on statement time already, not transaction start.

Base automatically changed from smudge/stack/4 to main February 11, 2026 14:50
Copy link
Contributor

@effron effron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domainLGTM

@smudge smudge merged commit 2b6c0f6 into main Feb 11, 2026
47 checks passed
@smudge smudge deleted the smudge/stack/5 branch February 11, 2026 15:44
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.

3 participants