Skip to content

Detect changepoints on each line a changepoint model watches - #1589

Draft
epompeii wants to merge 1 commit into
u/ep/changepoint/tablefrom
u/ep/changepoint/detector
Draft

epompeii wants to merge 1 commit into
u/ep/changepoint/tablefrom
u/ep/changepoint/detector

Conversation

@epompeii

Copy link
Copy Markdown
Member

The changepoint detector runs Otava over each line a threshold's changepoint model watches, after every report that adds to the line, and keeps the changepoint table in step with what it finds. A step is held as a candidate until as many consecutive scans as the model's confirmations find it, then it is active and its numbers are frozen. A step that later moves or vanishes is withdrawn. Changepoint detection is a Bencher Plus feature.

What changes

  • The task. The API server owns one background task for changepoints, as it owns the commit title task: it takes the server's shutdown signal and keeps its handle, and nothing is detached. After a report's metrics commit, the request hands the task every line it wrote to that a changepoint model watches, without waiting on the scan. A line is the head, testbed, spec, benchmark, variant, measure, and metric name, and a threshold watches it when its parameters filter matches the variant and the report wrote the metric the threshold names, value when it names none.
  • The queue lives in memory. A line is scanned once however many reports queue it before its scan starts, and a report that queues it during its own scan has it scanned again. A full queue drops a report's lines with a warning, and a restart loses the queue; either way, each line is scanned again at its next report.
  • A scan reads and analyses its line on a blocking thread with a connection from the read pool, then reconciles the line's changepoints in one short write transaction. It never holds the writer across a read or an analysis. A scan that panics is logged, and the next line is scanned.
  • The points of a line. One point per version native to the head (above its start point), ordered by version number, valued at the median of every metric the line has on that version: every iteration of every report, a second run of the same commit included. Only reports under the line's spec count, and a version with no metric on the line has no point. The read starts from the head's versions when the head has a start point, as a pull request's does, and from the variant's rows when it has none; both orders read the same points.
  • The analysis. The window is the model's max_sample_size and the p value threshold its significance. A line with fewer points than min_sample_size is not analysed. Each side the model guards runs its own pass, with that side's boundary as the minimum magnitude, and keeps only the steps in its own direction: an upper boundary keeps increases, a lower one decreases. A side with no boundary runs no pass.
  • Statistics that cannot be stored. A changepoint with a NaN or non-finite mean, standard deviation, or p value, or a NaN t statistic, is refused and logged before any write. An infinite t statistic, as between 2 constant sides, is stored as none.
  • Confirmation. A step at a version with no changepoint is inserted as a candidate with its first scan. A candidate found again at the same version, on the same side, counts a scan, and the scan that reaches the model's confirmations makes it active with that scan's numbers. A model that takes 1 confirmation inserts an active changepoint at once.
  • The reconcile. A candidate that a scan does not find is deleted. An active changepoint that a scan does not find is withdrawn, and when the step moved, its new version starts as a candidate. A withdrawn changepoint is history, so a step that returns to its version is a new candidate. A dismissed or silenced changepoint is never changed and keeps its version, so a step a user dismissed does not come back. A candidate judged against a model the threshold no longer holds is deleted, and confirmation starts again under the current model. A scan reconciles only its own threshold's changepoints.
  • Replaced heads and changed models. A line whose head was replaced, or whose threshold no longer holds a changepoint model, is not scanned. The write checks both again. If the head was replaced after the read, or the threshold no longer holds the model the scan read, the scan writes nothing.
  • Shutdown. The task stops at the shutdown signal, at its next wait or before the next pass of a scan, and a scan cut short writes nothing. The server drains the task after the rate limit save.
  • Docs. The glossary defines a Changepoint and a Changepoint Model and adds what a Line is for changepoint detection. The changelog announces changepoints for Bencher Plus.

Tests

lib/bencher_schema/src/model/project/threshold/changepoint_scan.rs covers, on seeded lines: a step that is a candidate for 4 scans and active at the 5th, and confirmation at the model's own count; a newest point that jumps, held as a candidate; a candidate that vanishes; a confirmed step that moves, vanishes, or moves away and returns; a dismissed or silenced step found again; a step below and above a start point; a head replaced while its line is queued; a rerun of an old commit; a threshold that no longer holds the model during the analysis; each guarded side and its own boundary; the median, the spec, and the head a point reads; both read orders; min_sample_size; and the refusal and log of statistics that cannot be stored. lib/bencher_schema/src/context/changepoints.rs covers the task: a report that hands its lines over without waiting, a line queued twice scanned once, a slow scan that leaves the runtime to its other tasks, a panic, and shutdown at each step with nothing written. lib/api_projects/tests/changepoints.rs covers a report that hands its watched lines to the scan through the API.

This change and the two below it merge together.

@epompeii
epompeii added this pull request to stack #1536 November 27, 2026 02:09
@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectBencher
Branchu/ep/changepoint/detector
Testbedintel-v1
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
Adapter::Json📈 view plot
🚷 view threshold
5.34 µs
(+2.57%)Baseline: 5.20 µs
5.50 µs
(97.02%)
Adapter::Magic (JSON)📈 view plot
🚷 view threshold
5.21 µs
(+3.32%)Baseline: 5.04 µs
5.33 µs
(97.66%)
Adapter::Magic (Rust)📈 view plot
🚷 view threshold
26.66 µs
(-0.62%)Baseline: 26.83 µs
28.63 µs
(93.15%)
Adapter::Rust📈 view plot
🚷 view threshold
4.58 µs
(+2.39%)Baseline: 4.47 µs
4.69 µs
(97.65%)
Adapter::RustBench📈 view plot
🚷 view threshold
4.56 µs
(+2.12%)Baseline: 4.46 µs
4.69 µs
(97.25%)
🐰 View full continuous benchmarking report in Bencher

@bencher-cloud

bencher-cloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

🐰 Bencher Report

ProjectBencher
Branchu/ep/changepoint/detector
Testbedintel-v1
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
Adapter::Json📈 view plot
🚷 view threshold
5.46 µs
(+4.84%)Baseline: 5.20 µs
5.50 µs
(99.17%)
Adapter::Magic (JSON)📈 view plot
🚷 view threshold
5.32 µs
(+5.58%)Baseline: 5.04 µs
5.33 µs
(99.79%)
Adapter::Magic (Rust)📈 view plot
🚷 view threshold
7.81 µs
(-70.89%)Baseline: 26.83 µs
28.63 µs
(27.28%)
Adapter::Rust📈 view plot
🚷 view threshold
4.58 µs
(+2.39%)Baseline: 4.47 µs
4.69 µs
(97.65%)
Adapter::RustBench📈 view plot
🚷 view threshold
4.57 µs
(+2.40%)Baseline: 4.46 µs
4.69 µs
(97.51%)
🐰 View full continuous benchmarking report in Bencher

This branch was previously deployed

1 inactive (outdated) deployment
Cloudflare — 1eac85d7 Deployed Dec 1, 2026 by epompeii via Build / Build API Docker #3725
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