Skip to content

Give probe_result duration sub-second precision#96

Merged
lewispb merged 1 commit into
mainfrom
fix-probe-result-duration-precision
Jun 29, 2026
Merged

Give probe_result duration sub-second precision#96
lewispb merged 1 commit into
mainfrom
fix-probe-result-duration-precision

Conversation

@lewispb

@lewispb lewispb commented Jun 29, 2026

Copy link
Copy Markdown
Member

Problem

After the SQLite → MySQL migration, the duration of most probe results renders as 0.00s in production.

The duration column is declared as t.decimal :duration with no precision (db/migrate/20250114000001_create_upright_probe_results.rb). Duration is computed from a monotonic clock and is almost always sub-second:

# app/models/concerns/upright/probeable.rb
def measure
  start_time = monotonic_now
  result = yield
  [ result, monotonic_now - start_time ]   # float seconds, e.g. 0.043
end

On SQLite, NUMERIC affinity stored the full float (0.043). On MySQL, DECIMAL with no scale defaults to DECIMAL(10,0) — zero digits after the point — so every value is rounded to a whole second on write:

  • 0.043s0
  • 0.6s1

Most checks finish well under a second, so they store 0 and display as 0.00s.

Fix

New migration altering the column to DECIMAL(10,6) (microsecond precision; max ~9999s). Dummy schema dump updated to match.

Caveats

  • Rows already written as 0 were rounded on insert and cannot be recovered; only probe results recorded after the migration runs will be correct.
  • This is the engine migration that runs in host apps (e.g. 37upright) via the appended migration path, so deploying the bumped gem fixes production. Host bump: basecamp/37upright (companion PR).

🤖 Generated with Claude Code

`t.decimal :duration` with no precision becomes DECIMAL(10,0) on MySQL,
which rounds every value to a whole second on write. Probe durations are
sub-second floats from a monotonic clock, so post-MySQL-migration they
were all stored as 0 and rendered as 0.00s. SQLite preserved the
fractional value, which is why this only surfaced after the migration.

Alter the column to DECIMAL(10,6) (microsecond precision). Existing rows
already rounded to 0 can't be recovered; new probe results record their
true duration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 29, 2026 15:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lewispb lewispb merged commit 8788ea9 into main Jun 29, 2026
8 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.

2 participants