Skip to content

Improve recording accuracy#20

Merged
craigpotter merged 1 commit into
mainfrom
fix/recording-accuracy
Jul 18, 2026
Merged

Improve recording accuracy#20
craigpotter merged 1 commit into
mainfrom
fix/recording-accuracy

Conversation

@craigpotter

Copy link
Copy Markdown
Collaborator

Overview of change

Last of the three follow-ups from the review pass behind #17 (feature / schema / accuracy fixes).

keep_successful_responses=false no longer makes successful requests look failed

Previously the response recording was skipped entirely, leaving rows at the request-time default of successful = false with no status — so filtering for failures returned every successful request too. Now the status, outcome, and duration are always recorded; only the body and headers are omitted for successful responses. Failed responses are still kept in full. Config comment and README updated to describe the corrected behaviour.

Byte-accurate max_response_size

The size check used mb_strlen (characters), so multibyte bodies could exceed the configured kilobyte limit by 2–4× on disk (a 100k-character CJK/emoji body is 300–400KB). The limit is about storage, and storage is measured in bytes, so the check now uses strlen. No string slicing is involved, so there is no multibyte-corruption risk.

Correct duration rounding — still whole milliseconds

The old code truncated each timestamp to whole ms before subtracting, introducing up to ±1ms of error — a sub-millisecond request could record as 0ms. Timestamps are now subtracted as raw floats and rounded once at the end. Durations remain clean whole-millisecond integers; no schema, signature, or display changes.

Testing

Four new tests: successful-outcome recording and failed-response fullness under keep_successful_responses=false, byte-vs-character sizing with a multibyte body, and duration rounding across truncation-error cases. Full suite: 47 passed (185 assertions), PHPStan level 8 clean, Pint clean.

- keep_successful_responses=false now still records the status, outcome
  and duration of successful responses - only the body and headers are
  omitted, so rows no longer read as failures
- Measure the max_response_size limit in bytes rather than characters,
  so multibyte bodies cannot exceed the configured limit on disk
- Subtract raw float timestamps before rounding durations, removing the
  +-1ms truncation error; still stored as whole milliseconds
@craigpotter
craigpotter merged commit dfd168d into main Jul 18, 2026
10 checks passed
@craigpotter
craigpotter deleted the fix/recording-accuracy branch July 18, 2026 08:42
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