Skip to content

Pull requests overview: every signal recorded at the source, trends from history, and the opt-in digest and nudges - #995

Open
nambok wants to merge 2 commits into
mainfrom
prs-overview-signals
Open

nambok wants to merge 2 commits into
mainfrom
prs-overview-signals

Conversation

@nambok

@nambok nambok commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

This replaces #991, which GitHub closed when #985 merged and deleted its base branch. It's the same work, now on main. The org overview no longer says "not recorded yet". Each signal is now recorded where it happens, for every pull request and repository, whoever wrote it. The weekly digest and per-pull-request nudges exist too, and both are off until a team turns them on.

Changes

  • Main red time, and pull requests blocked by a red main (common::pr_ci): every check_run, status and workflow_job webhook on the default branch updates one record per repository. The record holds the head's checks and the red episodes, each with its start, its end and the commit that fixed it. A pull request is blocked by main when a check failing on it is failing on main now.
  • Runner queue p95: each job's started_at minus created_at, from workflow_job (newly routed to the overview) and from check runs.
  • Findings funnel and verified-fixed rate (common::pr_findings): the reviewer writes it each time it stores a review. Findings go raised, then acknowledged, then changed, then verified, or else dismissed. A finding counts as verified only when the reviewer finds it gone at a later head; resolving the thread isn't enough.
  • Run end states (common::pr_runs): each run maps to one of first_try, after_fixes, rerun_only, gave_up, blocked or stopped, using the ending the run's end gate recorded. The state goes on History as run_outcome, with stop_reason, when the pull request closes. A nightly reconcile covers runs that end after the pull request closed. A test walks every run status and every ending kind and reason, and checks each maps to exactly one state.
  • Cost per merged pull request: the runs' recorded cost_usd, summed onto History as cost_micro_usd.
  • Single-reviewer paths and sensitive-path merges: History now keeps the pull request's files, up to 300.
  • Sensitive paths per repo (common::pr_settings, GET/PUT /api/prs/settings; changing them needs agent settings): the defaults are **/auth/**, **/payments/**, **/secrets/**, **/infra/** and **/migrations/**. For example, acme/checkout can list cart/rounding/** and *.pem instead. The SLA days are saved here as well.
  • Security alerts with no pull request: open Dependabot findings that no pull request addresses yet, read from the security findings CoderHelm already keeps. Code scanning says it needs the security events permission.
  • Trends from history (common::pr_trends): no snapshots needed, so they show on the first day after the backfill.
    • Every merged PR's cycle time over 90 days, one point each.
    • Open PRs per stage per day over 12 weeks, rebuilt from each PR's opened and closed times and its stage change log. Days the log doesn't reach count in the total only, and split_from says from which day the split is complete.
    • When no snapshot is a week old, the strip's week-over-week change and its 8-week sparkline come from the same flow, and the review flow comes from the request and review logs.
    • "Not enough history yet" is now kept for data CoderHelm records going forward, and says which. Numbers that are recorded but have too few events say "too few yet" (reason few).
  • Shared reader: the overview read moves into common::pr_overview_read, so the page and the digest read it the same way.
  • Digest and nudges (worker::passes::pr_notify, run on the 20-minute tick):
    • The digest goes Monday from 13:00 UTC, once a week. It goes to the team's Slack or Teams update channels, or by email to listed addresses that belong to team members.
    • Nudges are private emails to the person whose turn it is. They go at the stage's p85, then two and four working days later, then never again for that stage. A pull request with a person's activity in the last working day is skipped.
  • Incident case ya_overview_signals_recorded: pins the recording points, the six end states, the permission wording and the opt-in defaults. xz follows the reader to common.
  • Docs: docs/pull-requests/api_contract.md covers the new records.

Verification

  • cargo fmt --all --check, rustfmt --check on the incidents, and cargo clippy -p common -p worker -p gateway --all-targets -D warnings are clean.
  • The full cargo test -p common -p worker -p gateway passes.
  • text_guard.py, domain_examples.py and brand_spelling.py pass.
  • New unit tests cover the trends (open per stage from the change log, unknown before it, one cycle point per merge), main CI episodes and blocked-by-main, the findings funnel, every run ending, sensitive-path globs and validation, nudge timing (three a stage, weekends skipped, none while moving), and the digest's content.

The dashboard side is CoderHelm/coderhelm#548 (settings, merged) and CoderHelm/coderhelm#549 (the overview design and the trend charts).

…t-in digest and nudges

The overview no longer says "not recorded yet". Each signal is recorded
where it happens, for every pull request and repository:

- default-branch check runs, statuses and job waits from the webhook,
  into one record per repository with red episodes and runner waits
  (common::pr_ci); pull requests blocked by a red main
- CoderHelm's findings, each time the reviewer stores a review, from
  raised to verified fixed at a later head (common::pr_findings)
- every run's end state, stop reason and cost on the pull request's
  history, at close and nightly (common::pr_runs), with a test that every
  ending maps to exactly one of six states
- closed pull requests' files, for single-reviewer paths and
  sensitive-path merges against each repository's list, defaulting to
  auth, payments, secrets, infra and migrations (common::pr_settings,
  GET/PUT /api/prs/settings)
- open Dependabot alerts with no pull request; code scanning says it
  needs the security events permission

The overview read moves into common::pr_overview_read so the page and the
weekly digest share it. The digest (Monday, to the team's channels or its
members by email) and private nudges (at the stage's p85, then two and
four working days later, then never) are both off until a team turns
them on. Incident case ya_overview_signals_recorded pins it.
…ot snapshots

The overview answers what the backfilled history can answer, from the
first day after the backfill: every merged pull request's cycle time over
90 days, and open pull requests per stage per day over 12 weeks, rebuilt
from each one's opened and closed times and its stage change log (days the
log doesn't reach count in the total, and split_from says where the split
is complete). With no snapshot a week old, the strip's change and its 8
weeks, and the review flow, come from the same history. "Not enough
history yet" is kept for what CoderHelm records going forward; a recorded
number with too few events says "too few yet" (reason "few").
@nambok nambok added the ch-review CoderHelm reviews this pull request label Dec 6, 2026

@coderhelm coderhelm Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Changes requested: 3 required items (required rules, failing checks or unproven critical paths).

Holding the merge:

  • services/common/src/pr_ci.rs:204 Episode closes as soon as the checks reported so far are all done, before the whole head has reported (a critical-path change with no test or proof)
  • services/common/src/pr_ci.rs:246 Runner queue samples from check runs measure from suite creation and double-count jobs also seen as workflow_job (a possible break of the change's main path that nothing has checked)
  • services/common/src/pr_runs.rs:72 ci_flaky read as a string, but stored as a boolean; rerun_only is never produced (a critical-path change with no test or proof)

Why changes requested: services/common/src/pr_ci.rs:204 Episode closes as soon as the checks reported so far are all done, before the whole head has reported (a critical-path change with no test or proof); services/common/src/pr_ci.rs:246 Runner queue samples from check runs measure from suite creation and double-count jobs also seen as workflow_job (a possible break of the change's main path that nothing has checked); services/common/src/pr_runs.rs:72 ci_flaky read as a string, but stored as a boolean; rerun_only is never produced (a critical-path change with no test or proof).

Details: PR Overview · 🎯 Risk

PR Overview

The PR records the pull request overview signals at their source (main CI, findings, run end states, cost, files).

Changes

  • New common modules: pr_ci, pr_findings, pr_runs, pr_settings, pr_trends, pr_notify and pr_overview_read
  • Webhook recording of check_run, status and workflow_job events into per-repository main CI records
  • Findings funnel written by the reviewer, and run end states stored on History
  • GET and PUT /api/prs/settings for sensitive paths and SLA days
  • A worker pass for the digest and nudges, both off by default
  • An incident case and API contract docs
  • New common::pr_ci keeps one versioned record per repository: the default branch's head checks, red episodes and runner queue samples.
  • MainCi::apply_event turns check_run, status and workflow_job webhooks into episodes and queue samples.

Reviewed Changes

25 changed files.

Show a summary per file
File Description
docs/incidents/ya_overview_signals_recorded.md Incident write-up for the overview signals now recorded at the source, with the guarantee they pin.
docs/pull-requests/api_contract.md Documents the new history fields, the records written at the source, the settings, and the digest and nudge behaviour.
services/common/src/lib.rs Declares the new pr_ci, pr_findings, pr_notify, pr_overview_read, pr_runs, pr_settings and pr_trends modules.
services/common/src/pr_ci.rs New default-branch CI record: red episodes, queue samples, blocked-by-main and the versioned DynamoDB update.
services/common/src/pr_findings.rs New findings-funnel record: state machine, funnel counts, and an optimistic-version DynamoDB update.
services/common/src/pr_history.rs History gains files (up to 300) and cost_micro_usd, both defaulted when a row is built from a record.
services/common/src/pr_notify.rs New pure digest and nudge logic: digest builder and renderers, due-time rules, working-day math, nudge text, tests.
services/common/src/pr_overview.rs Reads the new records (main CI, findings, settings, alerts, trends) into the overview and reclassifies the missing-data reasons.
services/common/src/pr_overview_read.rs New shared reader: loads the team's PR records with their run and reviewer joins, history, snapshots, backfill, main CI, findings…
services/common/src/pr_runs.rs New module: reads a run's facts from its table item and maps them to one of six end states, a stop reason and a summed cost.
services/common/src/pr_settings.rs New settings struct, validation, glob matcher, DynamoDB load/save and unit tests
services/common/src/pr_trends.rs Pure functions for the cycle-time points, the open-by-stage flow per day, and the split_from day, with two unit tests
services/gateway/src/main.rs Registers the GET and PUT /prs/settings route
services/gateway/src/permissions.rs Adds get_settings to the read capability and put_settings to the agent-settings write capability
services/gateway/src/routes/github_webhook.rs Sends workflow_job events to the pull requests writer
services/gateway/src/routes/prs.rs Writes the default-branch CI record on check_run, status and workflow_job events. Computes the run outcome and cost when a PR closes.…
services/gateway/src/routes/prs_overview.rs The overview handler delegates to the shared reader; adds the get_settings and put_settings handlers.
services/worker/src/main.rs Runs the digest and nudge sweeps on the 20-minute tick and logs the counts.
services/worker/src/passes/incidents/xw_every_open_pr_has_one_state.rs The team-key assertion now checks the shared reader's run join.
services/worker/src/passes/incidents/xz_org_overview_facts_only.rs Input gets the new fields; the per-read team-keying checks now target pr_overview_read.rs.
services/worker/src/passes/incidents/ya_overview_signals_recorded.rs New incident test for the recording points, run end states, permission wording, opt-in defaults and trends from history.
services/worker/src/passes/mod.rs Registers the new pr_notify pass module.
services/worker/src/passes/pr_notify.rs New worker pass. digest_sweep sends the weekly digest once per ISO week per team. nudge_sweep emails the person whose turn it is at the…
services/worker/src/passes/pr_records.rs Nightly reconcile: for closed rows with runs but no outcome, reads the runs and writes run_outcome, stop_reason and cost_micro_usd to…
services/worker/src/passes/review_pr.rs After a review is stored, records the findings raised on this head and what the earlier threads' judgments did to prior findings.

This part only changes services/common/src/lib.rs, which adds seven pub mod declarations. I listed services/common/src and every declared module has its file. Nothing in the declarations breaks anything. The logic sits in the other parts of the review.

🎯 Risk: HIGH (77/100)

  • ██████████ blast radius 100 — ~183 dependent refs; hottest: lib.rs (~25), main.rs (~25), permissions.rs (~25)
  • ███░░░░░░░ sensitive area 30 — sensitive-adjacent additions
  • ████████░░ test coverage 80 — 25 source / 0 test file(s) changed
  • ██████████ size/spread 94 — 4202 lines across 25 file(s), spread 80%

FYI: apart from what blocks by rule, nothing here holds the merge. Assumed: The review's many findings are real correctness/data issues that belong as open items on the PR, but none require stopping the ship; the confirmed defects can be fixed within this delivery and the unconfirmed ones noted for a person.


Was this review right? Rate it 👍 / 👎 so the reviewer learns · reply @coderhelm re-review or @coderhelm <question>

Comment on lines +204 to +209
"green" => {
if let Some(open) = self.episodes.last_mut().filter(|e| e.to == 0) {
open.to = at.max(open.from);
open.fixed_sha = self.sha.clone();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Blocking (critical path, no proof): Episode closes as soon as the checks reported so far are all done, before the whole head has reported (correctness, not verified)

rollup returns green when the map is non-empty and every tracked check is completed. A new head's checks map is cleared in note_check and holds only the checks reported so far. Jobs that depend on others (needs:) have no check_run yet, and a late-created check isn't in the map. Suppose a fast job such as lint completes with success while the test job hasn't been created. The map is then {lint: success}, which rolls up green. settle then sets open.to and fixed_sha on the red episode, even though the head isn't green. When the slow check later fails, settle opens a new episode starting at that later time. The result is understated red time, episodes split in two, and a wrong fixed_sha. This hits the main-red-time signal and the 'fixed by' commit the PR introduces. The tests only use a single check per head, so they don't catch it. Consider closing an episode only when the head has no pending or running check, for example by learning the head's expected checks from the suite or workflow_run events, or by waiting for a settle window with nothing in progress. Also decide how a green head with only a subset of checks should be treated.

Comment on lines +246 to +255
// Capacity: queued (its suite created) to started, any branch.
let started = ts(&run["started_at"]);
let created = ts(&run["check_suite"]["created_at"]);
if started > 0 && created > 0 && payload["action"] == "created" {
changed |= self.note_queue(QueueSample {
at: started,
secs: started - created,
label: String::new(),
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Blocking (needs a check): Runner queue samples from check runs measure from suite creation and double-count jobs also seen as workflow_job (correctness, needs a check)

The check_run branch computes started_at - check_suite.created_at. check_suite.created_at is when the whole workflow run was created, not when this job was queued. A job that waits on needs: or on an environment approval therefore reports the dependency wait as 'runner queue' time. That inflates the p95 the overview shows as capacity. Jobs in the same workflow are also recorded by the workflow_job branch, with a different secs and a non-empty label. The dedupe only drops samples equal on (at, secs, label), so the same job is counted twice in the p95 input. The module doc says queue samples are 'queued to started'. Use workflow_job.created_at to started_at as the single source. Drop the check_run sample, or keep it only for non-Actions apps and key the dedupe on the job or check id.

This needs a check before merge: make one real call on that path (runner queue p95 signal) and paste the result in the PR. This is on runner queue p95 signal, and nothing in the review or the PR's own verification exercises it yet. If the check passes, say so here and this becomes a note; if it fails, it is a defect to fix.

kind: field("kind"),
reason: field("reason"),
fix_commits: n(item, "ci_fix_commits").max(0.0) as u32,
flaky: matches!(s(item, "ci_flaky").as_str(), "yes" | "true"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Blocking (critical path, no proof): ci_flaky read as a string, but stored as a boolean; rerun_only is never produced (bug)

facts_of computes flaky: matches!(s(item, "ci_flaky").as_str(), "yes" | "true"), and s uses as_s(). The existing reader of this attribute, RunRow::from_item in services/gateway/src/routes/analytics.rs:189, uses b(i, "ci_flaky"). That helper is built on as_bool() (analytics.rs:52). So the attribute is a DynamoDB BOOL, and as_s() returns an error on a BOOL, so s yields an empty string. flaky is therefore always false. A run that went green only after a re-run, with no fix, is then counted as first_try instead of rerun_only. That breaks the PR's stated goal that each run maps to one of the six states with reruns told apart from fixes. Whose failure this is isn't shown: the failing test doesn't fail the same way on the base branch's head. I could not find the code that writes ci_flaky (the large passes/mod.rs isn't indexed), so the BOOL type is inferred from the reader. Please check the writer's type.

Suggested change
flaky: matches!(s(item, "ci_flaky").as_str(), "yes" | "true"),
flaky: item
.get("ci_flaky")
.map(|v| {
v.as_bool().map(|b| *b).unwrap_or(false)
|| v.as_s().map(|x| matches!(x.as_str(), "yes" | "true")).unwrap_or(false)
})
.unwrap_or(false),

self.findings
.values_mut()
.filter(|f| f.path == p.path.trim())
.find(|f| !f.title.is_empty() && body.contains(&f.title))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 Suggestion: Thread-to-finding match is a substring test on the joined words (correctness, not verified)

matching returns the first finding on the path whose title words are a substring of the thread's first-line words. The substring is not checked at word boundaries. When one title is contained in another on the same file ("missing index" and "missing index on orders"), or a short title sits inside a longer word, the thread can move the wrong finding. BTreeMap order decides which one wins. That would skew the acknowledged, changed and verified counts in the funnel. A word-boundary check (pad both sides with a space) and a preference for the longest matching title would remove this.

This blocks: Substring matching without word boundaries can move the wrong finding, skewing funnel counts (data correctness) on the change's main path

Suggested change
.find(|f| !f.title.is_empty() && body.contains(&f.title))
.find(|f| !f.title.is_empty() && format!(" {body} ").contains(&format!(" {} ", f.title)))

"exempt": ch_merged_w.iter().filter(|h| h.merged_by_type == "coderhelm" && h.bypass.is_some()).count(),
},
"cost_per_merged": Value::Null,
"cost_per_merged": (!ch_merged_w.is_empty() && ch_merged_w.iter().any(|h| h.cost_micro_usd > 0)).then(|| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 FYI: Cost per merged PR is averaged over PRs that have no recorded cost (correctness, not verified)

cost_per_merged sums cost_micro_usd and divides by ch_merged_w.len(), which counts every merged CoderHelm pull request in the window. The same block shows that cost is only recorded going forward. A cost_micro_usd of 0 means 'never recorded', and the miss entry says as much. During rollout, and for any pull request merged without recorded runs, the zeros stay in the denominator. The average comes out too low and looks like a real figure. The check any(|h| h.cost_micro_usd > 0) only decides whether to show the number. It does not stop the zeros from diluting it. Averaging over the pull requests that have a recorded cost avoids this.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

Comment on lines +141 to +149
if !super::review_pr::claim_once_ttl(state, &team, &claim, 14 * 86_400).await {
continue;
}
let overview = match pr_overview_read::read(&t, &team, None, None, 7, now, None).await {
Ok(o) => o,
Err(e) => {
warn!(team_id = %team, error = %e, "Digest: overview not read");
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 FYI: The digest is lost for the week if the overview read or the send fails (correctness, not verified)

The PRDIGEST#<week> claim is held for 14 days (line 141). It is taken before the overview is read and before anything is sent. If pr_overview_read::read errors (line 144), or every email or channel delivery fails (ok is false at line 194), the code continues or falls through with the claim kept. digest_due is true all Monday afternoon and every tick would retry, but each one stops at the claim. The team gets no digest that week even though it turned the digest on. Release the claim on the read-error path and when ok is false. For the email channel, if no listed address belongs to a team member, nothing is sent and the claim is spent. That case should at least log a warning.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

facts.push(common::pr_runs::facts_of(item));
}
}
Err(e) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 Suggestion: Reconcile can settle a row while one of its runs is still working (correctness, not verified)

of_runs ignores runs that haven't ended and returns the last run that did, and its cost is the sum so far. The row is then written with a non-empty run_outcome, and the filter h.run_outcome.is_empty() never picks it up again. If a run on a closed PR is still working when the nightly runs, the stored end state and cost stay at that earlier snapshot. Separately, rows whose runs have not ended are re-read every night for 30 days, at up to 10 get_item calls per row and 200 rows per team. Both are edge cases. A cheap guard is to skip the row while any of its runs is not ended and not retried, and to let it be picked up on a later night.

This blocks: Reconcile settles a closed-PR row with a non-empty run_outcome while a run is still working, freezing stale end-state and cost that never get corrected (data loss)

/// Nudges per stage: at p85, two working days later, four working days later.
pub const NUDGES_PER_STAGE: u8 = 3;

pub fn nudge_sk(repo: &str, number: u64) -> String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 FYI: Near-identical helpers added together (scope, not verified)

services/common/src/pr_notify.rs adds nudge_sk next to findings_sk (in services/common/src/pr_findings.rs), added in the same change. Keep one helper with the shared logic (a parameter for what differs) and call it from both places. If the ticket truly needs it, say why on a line Wider than the ticket: services/common/src/pr_notify.rs: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

}
}

fn day_of(t: i64) -> String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 FYI: Near-identical helpers added together (scope, not verified)

services/common/src/pr_trends.rs adds day_of next to day (in services/common/src/pr_overview_read.rs), added in the same change. Keep one helper with the shared logic (a parameter for what differs) and call it from both places. If the ticket truly needs it, say why on a line Wider than the ticket: services/common/src/pr_trends.rs: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

}

#[test]
fn a_signal_without_its_permission_says_which() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 FYI: Near-identical helpers added together (scope, not verified)

services/worker/src/passes/incidents/ya_overview_signals_recorded.rs adds a_signal_without_its_permission_says_which next to every_review_records_its_findings_and_moves_the_earlier_ones_on, added in the same change. Keep one helper with the shared logic (a parameter for what differs) and call it from both places. If the ticket truly needs it, say why on a line Wider than the ticket: services/worker/src/passes/incidents/ya_overview_signals_recorded.rs: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ch-review CoderHelm reviews this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant