Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/incidents/da_finished_run_ships.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# da. `da_finished_run_ships`

**What happened:** Two runs on one ticket finished every planned task, opened their draft pull requests, and were then stopped with "CoderHelm stopped this run and handed it to you: its tasks were done and it had continued 4 more times without finishing". Of the four continuations, two were steps that ran out of time inside fix rounds that were closing findings, one was a step the run asked for by design so the changed tests could run with and without the change, and one was the fix round that check started. A fixed count of continuations after the work stopped runs that were still making progress. The stop also stayed on the run, so when the pull request's preview check went red with a readable error, the CI fix round hit the stop on its first pass and the run ended failed instead of fixed.

**The guarantee:** There is no count of continuations after the work. Each continuation names what it is for: the checks not yet run and the items they left open (`run_guard::Target`). The run goes on while each continuation closes something, and a step the run asks for by design is never counted. Once continuing closes nothing, or nothing is left, the run ships the pull request with what is open listed, and the stop is taken back at once (`run_guard::lift_shipped_stop`), so a red check with its error or a comment starts the next round. Finished work is never handed back and never failed because of a stop; runs stopped the older way are taken back the same way when their CI goes red.
5 changes: 5 additions & 0 deletions docs/incidents/db_test_runs_in_its_own_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# db. `db_test_runs_in_its_own_package`

**What happened:** A web change added a unit test in the web app and an end-to-end spec in the repository's end-to-end folder. The check that runs each changed test with and without the change chose its sandbox's install from the end-to-end job, because one of the files was that job's spec, and that job installs only its own folder. The unit test printed `sh: 1: vitest: not found` both ways. The check read that as "fails with the change in place" and "no changed test fails without the change", spent a fix round rewriting a test that had never run, and listed two findings that weren't true.

**The guarantee:** The sandbox's install is chosen only by the files the sandbox runs (an end-to-end spec runs against a preview, never there), and a recorded job is kept only when its folder covers every file (`TestEnv::misses`). A test whose runner isn't installed didn't run: it is recorded as not run because the install failed, never as a failure of the change and never as proof of it. A test that did run and fails with the change, passes without it, or proves nothing is a check the change didn't pass: it holds the draft (`proof::holds_blocked_on`), even with CI green, so the run can't be done with it open.
5 changes: 5 additions & 0 deletions docs/incidents/dc_one_run_per_ticket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# dc. `dc_one_run_per_ticket`

**What happened:** A tracker ticket started a run. Seconds later a person approved a plan written for that same ticket, and the plan's task opened a GitHub issue for it, labelled for CoderHelm. The issue started a second run. The two runs carried different ticket ids (the tracker key and `GH-<n>`), so every guard keyed by ticket id saw two tickets. One ticket got two runs, two branches and two pull requests, and both runs spent their budget on the same change.

**The guarantee:** Every fresh run takes one claim on its ticket's canonical key before it writes anything, at the run start that every trigger goes through (`common::one_run`, `passes::one_run::claim`). The key is the ticket the run is for, not the event that carried it in. An issue CoderHelm opens for another ticket names that ticket twice: in a marker in its body and in the stored link from the issue to its plan task. Its run therefore resolves to the ticket's own key. A second trigger for a ticket that a live run holds starts nothing, from any source and in either order, and the live run's page says the ticket arrived again. A run that has ended hands the claim to the ticket's next run. A plan task written for a ticket that a live run already works opens no issue: it is linked to that ticket and run.
5 changes: 5 additions & 0 deletions docs/incidents/dd_criterion_on_the_preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# dd. `dd_criterion_on_the_preview`

**What happened:** A ticket asked that a page's answers be in the HTML the server sends, so they show with scripts turned off and crawlers read them. The run rewrote the block as markup that needs no script, wrote unit tests that render the component on its own, and pushed. Nothing it ran fetched the preview's page as the server sends it. The page loads the block on the client only, so the served HTML still had none of the answers, and the preview's own check found it after the push ("the text is not in the server HTML"). The run that opened that pull request had started from an issue with an empty body, so the two-way proof had no criterion to prove, and the ready decision read "nothing to prove".

**The guarantee:** The criteria to prove come from the ticket, else from the plan's criteria map (`common::e2e_proof::criteria_or_map`), so an empty ticket body never means nothing to prove. A criterion about what the server sends (the page source, the page with scripts off, what a crawler reads: `Criterion::about_served`) is also proven on the served page itself. CoderHelm fetches the criterion's page as the server sends it, on the preview and on staging, with a plain request and no script run (`e2e_proof::served_legs`, through `web_check::fetch_page`), and judges each side against the criterion. Not shown on the preview is coder work whatever the browser test says: it goes back as a fix round and the ready decision waits for it (`common::e2e_proof::outcome`, `standing_of`). Shown on the preview and missing on staging is proven. A side that couldn't be fetched or judged is labelled unverified with why, never a pass.
5 changes: 5 additions & 0 deletions docs/incidents/de_plan_check_gaps_once.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# de. `de_plan_check_gaps_once`

**What happened:** A ticket asked for a page block to work without JavaScript, with its structured data (`FAQPage`) in the server HTML. The plan's `## Out of scope` held one item decided with its default, and under it two indented lines recording what a lookup showed ("Looked up: ... `FAQPage` was not in the server HTML", "No lookup settles ..."). The plan check read each indented line as an item left out, so `FAQPage` became the mark of an out-of-scope item called "Looked up", and each of the five task lines naming it added the same gap. The run note and the decision's open gaps carried "A task names `FAQPage`, which `## Out of scope` leaves out" five times, telling the run to take the ticket's own ask out of its tasks. A second plan for the same ticket was told that an item about one script per page was asked for by the criterion "No layout shift when the page loads or when items toggle": the two shared only "when" (counted twice) and "page".

**The guarantee:** An out-of-scope section's items are its top-level bullets; an indented line under one, and any line recording a lookup, is that item's evidence and never an item (`common::scope_ledger`). Bold markers are no part of an item's name. What the ticket itself names (its title and body) is in scope: it is no mark of an out-of-scope item, and an item the ticket says in full moves in, both in the plan check and in the ledger kept on the run. A criterion asks for an item only on distinct words that tell items apart, never on common words or a word counted twice. Every plan-check gap is said once, in the run note and on the decision's open gaps (`scope_ledger::unique`, `FixDecision::add_gaps`), whichever check found it and on however many task lines.
5 changes: 5 additions & 0 deletions docs/incidents/df_working_alternative_is_code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# df. `df_working_alternative_is_code`

**What happened:** A ticket said a camp card showed a broken image: the page used an older image address that returned an error, while the address the reporter expected was already stored in our database. The trace found the whole path: the class's own record in the source system held the broken address, a second source record of the same kind (its league) held a working one, and our pipeline gave the class's own image priority, so the broken one was stored and rendered. A thousand other classes carried addresses of the same kind. The run decided the fix was outside the code (edit the one source record), and a later run of the unchanged ticket stopped on that earlier verdict without planning again: "the ticket is unchanged since CoderHelm learned the fix is outside the code". A careful engineer makes the pipeline fall back to the working image, for every record.

**The guarantee:** A broken source value that our code chooses over a working one in its reach is a code fix. When a decision says `outside_code` and its own trace shows a layer holding a working value of the same kind as a wrong layer, and a layer that is code in one of our repositories, the plan check sends it back to fix that code (prefer, or fall back to, the working value, with a test), and the planner's guidance says so from the start (`fix_location::working_alternative`). `outside_code` stays right when no layer our code reads holds a working value. An earlier "outside the code" verdict is judged again under the same rule before it may stop a new plan on an unchanged ticket (`TicketHistory::guard`).
2 changes: 1 addition & 1 deletion docs/incidents/p_finished_work_loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

**What happened:** A small ticket finished its 11 tasks, then spent 2.5 hours and $41.96 with no pull request: each 15-minute step re-ran the checks before the pull request from nothing and started fresh fix rounds.

**The guarantee:** The draft pull request opens before the proof check, the rules and the review, which then can't block it. A check runs once on a head and keeps its rounds across steps. A run with no real progress (tasks, the pull request, CI green, fewer findings) ends one way: a draft with Open items, waiting on a person.
**The guarantee:** The draft pull request opens before the proof check, the rules and the review, which then can't block it. A check runs once on a head and keeps its rounds across steps. A run with no real progress (tasks, the pull request, CI green, fewer findings) ends its steps one way: a draft with Open items. Once its tasks are done that draft is shipped, not handed back: CI's errors and comments still start rounds on it (see `da_finished_run_ships`).
251 changes: 251 additions & 0 deletions services/common/src/e2e_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,89 @@ impl Criterion {
pub fn needs_e2e(&self) -> bool {
self.visible || self.page.is_some()
}

/// Whether it is about what the server sends, before any script runs
/// in the browser: the page's source, its server HTML, the page with
/// scripts turned off, what a crawler reads. A browser test runs the
/// page's scripts and can pass while the server sends none of it, so
/// such a criterion is also proven on the served page itself
/// ([`Served`]).
pub fn about_served(&self) -> bool {
let t = self.text.to_ascii_lowercase();
SERVED_WORDS.iter().any(|w| t.contains(w))
}
}

/// Words that say a criterion is about the served page ([`Criterion::about_served`]).
const SERVED_WORDS: &[&str] = &[
"server html",
"server-rendered",
"server rendered",
"server-side render",
"server side render",
"rendered on the server",
"page source",
"view source",
"view-source",
"raw html",
"initial html",
"html response",
"curl",
"wget",
"without javascript",
"without js",
"javascript off",
"javascript turned off",
"javascript disabled",
"javascript is off",
"javascript is disabled",
"js off",
"js disabled",
"js turned off",
"no-js",
"no javascript",
"noscript",
"crawler",
"search engine",
"seo",
"json-ld",
"structured data",
];

/// The criteria to prove: the ticket's own ([`criteria`]), else the lines
/// of the plan's criteria map. A run whose ticket text gives no criteria
/// (an empty issue body, a ticket whose criteria only the plan wrote down)
/// is still proven on what the plan said it would do, never waved through
/// with nothing to prove.
pub fn criteria_or_map(
title: &str,
body: &str,
acceptance: &[String],
map: &[MapLine],
) -> Vec<Criterion> {
let from_ticket = criteria(title, body, acceptance);
if from_ticket.iter().any(Criterion::needs_e2e) {
return from_ticket;
}
let from_map: Vec<Criterion> = map
.iter()
.filter(|m| !m.criterion.trim().is_empty())
.map(|m| {
let page = Some(m.page.trim())
.filter(|p| !p.is_empty())
.map(|p| pages(p).into_iter().next().unwrap_or_else(|| p.to_string()));
Criterion {
text: m.criterion.trim().to_string(),
visible: page.is_some() || is_visible(&m.criterion),
page,
}
})
.collect();
if from_map.is_empty() {
from_ticket
} else {
from_map
}
}

/// Section names plain ticket text uses without any mark.
Expand Down Expand Up @@ -470,6 +553,167 @@ pub struct Proof {
pub test: String,
/// The two runs: `base` on staging, `change` on the preview.
pub record: Record,
/// The criterion's page as the server sends it, no script run: on
/// staging (`served_base`) and on the preview (`served_change`), for a
/// criterion about the served page ([`Criterion::about_served`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub served_base: Option<Served>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub served_change: Option<Served>,
}

/// One fetch of a criterion's page as the server sends it (a plain GET, no
/// cookies, no script run), and what the judgment read in it.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Served {
/// The address fetched.
#[serde(default)]
pub url: String,
/// The fetch got an answer.
#[serde(default)]
pub fetched: bool,
#[serde(default)]
pub status: u16,
/// Whether the served page shows what the criterion asks: `None` when
/// nothing could judge it.
#[serde(default)]
pub shown: Option<bool>,
/// What in the served page settles it, quoted, or what is missing.
#[serde(default)]
pub quote: String,
/// Why it wasn't fetched or judged.
#[serde(default)]
pub note: String,
}

impl Served {
/// The server answered with a page.
pub fn ok(&self) -> bool {
self.fetched && (200..300).contains(&self.status)
}

fn why(&self) -> String {
let q = self.quote.trim();
let n = self.note.trim();
let w = if !q.is_empty() { q } else { n };
if w.is_empty() {
"no result".to_string()
} else {
crate::truncate_str(w, 200).to_string()
}
}

fn at(&self) -> String {
if self.url.is_empty() {
String::new()
} else {
format!(" ({})", self.url)
}
}
}

/// What the served-page legs show, when they settle the proof: `None` when
/// they are absent or couldn't judge it (the end-to-end test decides).
fn served_outcome(p: &Proof) -> Option<Outcome> {
let change = p.served_change.as_ref()?;
let what = format!("\"{}\" in the server HTML (no script run)", p.criterion);
if change.fetched && !change.ok() {
return Some(Outcome::CoderWork(format!(
"{what}: the preview{} answered {}",
change.at(),
change.status
)));
}
match change.shown {
Some(false) => {
return Some(Outcome::CoderWork(format!(
"{what}: not on the preview{}: {}",
change.at(),
change.why()
)))
}
Some(true) => {}
None => {
// Not judged: the test decides; with no test, it is unverified.
return p.test.is_empty().then(|| {
Outcome::Unverified(format!(
"{what}: the preview{} couldn't be judged: {}",
change.at(),
change.why()
))
});
}
}
// Shown on the preview: a failing browser test still sends work back.
if !p.test.is_empty() && p.record.change.ran && p.record.change.red() {
return None;
}
let base = p.served_base.as_ref();
Some(match base.and_then(|b| b.shown.filter(|_| b.ok())) {
Some(false) => Outcome::Proven(format!(
"{what}: missing on staging{} and shown on the preview{}: {}",
base.map(Served::at).unwrap_or_default(),
change.at(),
change.why()
)),
Some(true) => Outcome::Unverified(format!(
"{what}: shown on the preview{} and already on staging{}, so staging doesn't show what the ticket says is wrong",
change.at(),
base.map(Served::at).unwrap_or_default()
)),
None => Outcome::Unverified(format!(
"{what}: shown on the preview{}, staging couldn't be read{}",
change.at(),
base.map(|b| format!(": {}", b.why())).unwrap_or_default()
)),
})
}

/// Characters of a served page a judgment reads.
pub const SERVED_VIEW_CHARS: usize = 60_000;

/// The served page as a judgment reads it: its markup with scripts and
/// styles taken out (structured data, `application/ld+json`, kept: the
/// server sends it for crawlers), whitespace collapsed, bounded.
pub fn served_view(html: &str) -> String {
let mut out = String::with_capacity(html.len().min(SERVED_VIEW_CHARS));
let low = html.to_ascii_lowercase();
let mut i = 0;
while i < html.len() {
let rest = &low[i..];
let skip_tag = ["<script", "<style"]
.iter()
.find(|t| rest.starts_with(**t))
.copied();
if let Some(tag) = skip_tag {
let open_end = rest.find('>').map(|e| i + e + 1).unwrap_or(html.len());
let open = &low[i..open_end];
let close = if tag == "<script" {
"</script>"
} else {
"</style>"
};
let end = low[open_end..]
.find(close)
.map(|e| open_end + e + close.len())
.unwrap_or(html.len());
if tag == "<script" && open.contains("ld+json") {
out.push_str(&html[i..end]);
}
i = end;
continue;
}
let c = html[i..].chars().next().unwrap_or(' ');
if c.is_whitespace() {
if !out.ends_with(' ') {
out.push(' ');
}
} else {
out.push(c);
}
i += c.len_utf8();
}
crate::truncate_str(out.trim(), SERVED_VIEW_CHARS).to_string()
}

/// What a proof shows.
Expand Down Expand Up @@ -516,6 +760,9 @@ fn at(l: &Leg) -> String {

/// What the two runs show (see the module's rules).
pub fn outcome(p: &Proof) -> Outcome {
if let Some(o) = served_outcome(p) {
return o;
}
let (base, change) = (&p.record.base, &p.record.change);
let what = if p.test.is_empty() {
format!("\"{}\"", p.criterion)
Expand Down Expand Up @@ -599,6 +846,9 @@ impl Proof {
"Two-way proof: {w}. Make the test assert what the ticket says is wrong on {page} (\"{}\"), so it fails on staging and passes on this preview.",
self.criterion
)),
Outcome::CoderWork(w) if self.served_change.is_some() => Some(format!(
"Two-way proof: {w}. The criterion is about what the server sends, so a person (or a crawler) without scripts must get it from {page} as served: fix the code (not the test) so the server renders it, then fetch the preview's page source to see it there.",
)),
Outcome::CoderWork(w) => Some(format!(
"Two-way proof: {w}. The change doesn't do \"{}\" on the preview yet; fix the code (not the test) until it passes there.",
self.criterion
Expand Down Expand Up @@ -769,6 +1019,7 @@ mod tests {
source: "sandbox".into(),
at: String::new(),
},
..Default::default()
}
}

Expand Down
Loading
Loading