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
96 changes: 95 additions & 1 deletion docs/coder-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,107 @@ The causes were in the loop, not only in prompt wording:
run) is judged again with what it found, even when it wrote no code
(`proof::round_answered`, `incidents::cn_proof_answer_judged`).

7. **Rounds agree.**
7. **Commit and push.**
Each gate runs where the commit is made, not as a line in the prompt
(`common::push_gate`, `passes/push_checks.rs`).

- **The checks come from the repository.** `run_checks` adds the scripts
of each package that owns a touched file: its test script, its type
check (`check-types`, `typecheck`) and its lint. When a non-test file
changed, the package's whole unit suite runs, because a shared helper
breaks callers outside the diff. Only a change to nothing but test
files runs just those files. This step replaces the test line taken
from the first workflow that had one. On one pull request that line was
another package's `npm test --passWithNoTests`: it reported "2 of 2
checks passed" while `vitest` on the touched files exited 1.
- **Checks before every push** (`push_checks::before_push`, in the CI fix
round before `round::land`). If the checks ran on the fix's last edit
and passed, the fix is pushed and the commit records what ran. If they
failed, or never ran on the last edit, the fix is not pushed: the next
attempt continues on the same edits with the failing output. If the
sandbox couldn't run them (the install failed, or there is no sandbox),
the fix is pushed with an `Unverified:` line saying why and what ran.
- **The message matches the diff** (`round::land`,
`push_gate::true_message`). A message is rewritten from the diff when
it says revert, remove or drop while the diff adds test lines or more
than it removes, when it says add while the diff only removes, or when
it names a file the commit doesn't touch.
- **A revert takes its tests with it** (`push_gate::removed_symbols`,
`still_expected`). A commit that removes a definition a test still
names is held until that test is reverted or updated in the same
commit.
- **Two fixes per failing test** (`push_gate::FixLedger`, kept on the run
as `ci_test_fixes`). The failing tests are read from the failure report
or the log (vitest, jest, Playwright, pytest, cargo, go), or, when they
can't be, the failing checks are used. After two pushed fixes a test that
is still red stops the rounds: the pull request and the run name the
test and its error, and nothing more is pushed. The branch is never
rolled back to an older green head, and a planned task is never taken
out to turn CI green. Only a dependency run's newest set of bumps comes
out (`resume::take_out_failing_bumps`). Five of 53 runs had rolled back,
two of them with tests left behind that expected the reverted code.
- **No log is no reason to stop** (`push_gate::logs_unread_brief`,
`hold_no_logs`). When CI's job log can't be read, the fix brief gives
the owning package's commands so the fixer reproduces the failure in the
sandbox. Any sentence that blames the missing log is replaced.
- **Fixtures use looked-up ids, and tests are sized to the behaviour**
(`minimal_change::made_up_ids`, `repeated_cases`, in the habits check).
Ids like `sport-a` or `id-1` are sent back when the run's lookups
returned real ids. Three or more added cases that differ only in their
values are sent back as one case per behaviour. The size check (test
lines against code lines) runs too; it fires on the roughly 415 test
lines one run added for 50 lines of code.

8. **Rounds agree.**
Planned work that a review commit on the pull request took out is not
built again by a planned-work round, and the run says which commit took it
out. When an acceptance criterion of the ticket asks for it, the ticket
wins: it is built, and the reply to the review says why
(`round_agree`, `incidents::co_rounds_agree`).

9. **Scope is decided once.**
The plan writes `## Out of scope` in design.md, one `- <item>: <why>` line
each, naming the code that would show it (backticked names, paths, routes).
A product question the ticket doesn't settle is decided there with its
default; it is never asked in the pull request. The plan goes back when the
section is missing, a question is left open, an item has no reason, an
acceptance criterion asks for an item it leaves out, a task names an
out-of-scope item, or a task is open-ended ("switch any other caller")
(`scope_ledger::plan_gaps`).
When the plan is generated, before any code, the run keeps a scope ledger
(`common::scope_ledger`, run attribute `scope_ledger`): the ticket's
acceptance criteria as read by `stop_judge::acceptance` (the same list the
criteria-to-test mapping reads) are in scope, the plan's out-of-scope lines
are out. A plan revision never rewrites it. Every later round is held to it:
- the tests and scope check reads the diff, tests included, and sends back
each out-of-scope item it brings in (tests are exempt from "inside the
plan", never from the ledger);
- a planned-work round never builds an item the ledger leaves out, next to
`round_agree`'s rule for what a review took out;
- a round that must build one writes `Scope change: <item>: <why>`; it is
accepted only when the why cites an acceptance criterion or a person's
comment on the pull request, and the ledger records who moved it in.
(`incidents::sl_scope_decided_once`)

10. **The description describes the head.**
On every push the description is rebuilt from the head's facts
(`description::build`; Problem, Changes, Risk, Verification). The written
text is held to the head and the ledger (`description_facts::hold_scope`):
- sections about earlier attempts, pushes and waits go; the revert and
"CI is failing" lines stay for `ci_lines`, which drops them once untrue;
- a sentence saying something is out of scope, untouched or put back while
the diff changes it goes (`scope_ledger::contradictions`), and a change
to a file not in the diff goes (`pr_claims`);
- open product questions become out-of-scope defaults;
- the written notes fit a length scaled to the changed lines of code, tests
and generated files left out (150 to 600 words), with the run page for
the rest.
Changes ends with one Out of scope line rendered from the ledger. An item
the diff brings back is never shown as out of scope; it is listed as not
verified until it is taken out or moved in. `pr_body::defects` fails a body
that asks an open product question.
(`incidents::sm_description_of_the_head`)

## What is deterministic

Everything above except the model's own writing: the searches, section checks,
Expand Down
5 changes: 5 additions & 0 deletions docs/incidents/ga_fix_pushed_unchecked.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ga. `ga_fix_pushed_unchecked`

**What happened:** A pull request that removed a duplicated filter chip changed a shared slug helper and added about 415 lines of unit tests for about 50 lines of code, with fixture ids `sport-a` and `sport-b` although the run had looked up the two real records. CI went red on a test outside the diff. Every CI fix round's sandbox said "2 of 2 checks passed": its test step was another package's `npm test` with `--passWithNoTests`, so no touched test ran, while the coder's own `vitest run` of the touched files exited 1 four times. The fixes were pushed anyway. After four attempts the supervisor put a source file back to an older green head in a commit titled "Revert the change that broke CI" and left the tests that expected the reverted helper in place.

**The guarantee:** The sandbox runs the owning package's own scripts: its whole unit suite when a non-test file changed, only the touched test files when nothing but tests changed, and its type check and lint (`common::push_gate::package_steps`). A CI fix is pushed only when those ran on its last edit and passed; one the sandbox couldn't check is pushed with `Unverified:` and what ran (`push_checks::before_push`). A commit message that disagrees with its diff is rewritten from it (`round::land`). A commit that removes a definition a test still names is held until the test goes with it. A failing test gets two pushed fixes; then the rounds stop with the test and its error named, and nothing is rolled back. Invented fixture ids and three or more test cases that differ only in their values go back to the coder (`minimal_change`).
5 changes: 5 additions & 0 deletions docs/incidents/gb_red_ci_stops_named.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# gb. `gb_red_ci_stops_named`

**What happened:** A pull request's end-to-end check failed on "selecting a camp adds it to the cart while registration is open" with `Subtotal$0`. After three fix attempts the supervisor rolled seven of the pull request's files back to an older green head. The test failed the same way on the result: the vendor portal had opened registration, so it was red on every branch. Five of the last 53 runs rolled their branch back the same way.

**The guarantee:** Red checks never roll a ticket run's branch back to an older head or take a planned task out; only a dependency run's newest set of bumps comes out (`resume::take_out_failing_bumps`). A failing test gets at most two pushed fixes (`common::push_gate::FixLedger`, kept on the run as `ci_test_fixes`). Then the rounds stop, nothing more is pushed, and the pull request and the run name the test and its error. When CI's job log can't be read, the fixer reproduces the failure with the owning package's own commands in the sandbox, and a sentence that blames the unreadable log is replaced.
5 changes: 5 additions & 0 deletions docs/incidents/sl_scope_decided_once.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# sl. `sl_scope_decided_once`

**What happened:** A pull request fixed a duplicated filter chip. Its plan put the `/classes/<sport>` path pages out of scope "as an open product question", answered each question with "meanwhile", and still had a task to "switch any other caller". Three days later a round built the path pages; the tests and scope check took the code out but left its tests (that check exempts tests); the automatic revert put the tests back for code that was gone; a person deleted them by hand. The description said the path pages were out of scope while the diff changed them, and asked the team the questions the plan had answered. In the 53 runs audited, 19 of 38 recorded plans left product questions open and 8 branches had a file go in, out and back in.

**The guarantee:** Scope is decided once, from the ticket's acceptance criteria (`stop_judge::acceptance`) and the plan's `## Out of scope` section, when the plan is generated and before any code (`common::scope_ledger`, kept on the run). A plan with no such section, an open question, an item without a reason, an item a criterion asks for, a task that names an out-of-scope item or an open-ended task goes back to the planner. Every round's tests and scope check reads the diff, tests included, against the ledger; a planned-work round never builds an out-of-scope item; a scope change needs a `Scope change:` line that cites a criterion or a person's comment, and the ledger records who moved it in. The description renders one Out of scope line from the ledger, turns question sections into defaults, and drops any sentence the diff refutes.
5 changes: 5 additions & 0 deletions docs/incidents/sm_description_of_the_head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# sm. `sm_description_of_the_head`

**What happened:** A vendor-portal pull request of 8 files went through 16 commits, and its description piled up history: an "Earlier attempts" section, "Deferred: reverted 7 file(s)" and "Waiting on CI" after the work came back, a note that scroll assertions were "dropped from this pull request" while the diff still changed that page object, and notes longer than the change. Another pull request's description grew to about four times its diff and contradicted it in three places.

**The guarantee:** Every build of a description, on every push, holds the written text to the head (`description_facts::hold_scope`, `common::scope_ledger`): sections about earlier attempts, pushes and waits go (the revert and "CI is failing" lines stay for `ci_lines`, which drops them once untrue); a sentence saying a file was reverted, put back or dropped while the diff still changes it goes; open product questions become out-of-scope defaults; the written notes fit a length scaled to the changed lines of code (150 to 600 words), with the run page for the rest. The visible part stays Problem, Changes (with one Out of scope line), Risk and Verification, and `pr_body::defects` fails any body that asks an open product question.
126 changes: 126 additions & 0 deletions services/common/src/fixture_ids.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//! A test fixture uses the ids the run looked up, not made-up ones.
//!
//! A run queried the production database, found the two records behind a
//! duplicated filter and quoted their ids in its evidence, then wrote test
//! fixtures with `sport-a` and `sport-b`. The test passed on data that
//! doesn't exist, and nobody could tell from it which records the bug was
//! about.
//!
//! [`looked_up_ids`] reads the ids out of the run's lookups (UUIDs, their
//! eight-character prefixes, long hex and numeric ids); [`made_up`] finds an
//! id-like value in a test's added lines that looks invented (`sport-a`,
//! `id-1`, `test-id`, `fake_user`) while real ids are on record. The check
//! of the change against the plan (`habits_check`) sends each one back.

/// Ids a run's lookups returned, in order, each once.
pub fn looked_up_ids(lines: &[String]) -> Vec<String> {
let re = regex::Regex::new(
r"\b(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{8}(?:…|\.\.\.)|[0-9a-f]{24,40})",
)
.expect("valid regex");
let mut out: Vec<String> = Vec::new();
for l in lines {
// Only what came back: the question may hold ids typed by hand.
let got = l.split("Came back:").nth(1).unwrap_or("");
for m in re.find_iter(got) {
let id = m.as_str().trim_end_matches('…').trim_end_matches("...");
if id.chars().any(|c| c.is_ascii_digit()) && !out.iter().any(|o| o == id) {
out.push(id.to_string());
}
}
}
out
}

/// Whether a fixture value looks invented rather than read.
pub fn looks_made_up(value: &str) -> bool {
let v = value.to_lowercase();
let letter_or_digit = regex::Regex::new(r"^[a-z]+[-_][a-z0-9]$").expect("valid regex");
let numbered = regex::Regex::new(r"^(?:id|item|row|rec)[-_]?\d{1,3}$").expect("valid regex");
let filler = regex::Regex::new(
r"^(?:test|fake|mock|dummy|placeholder|sample|some|foo|bar)(?:[-_][a-z0-9-_]*)?$",
)
.expect("valid regex");
letter_or_digit.is_match(&v) || numbered.is_match(&v) || filler.is_match(&v)
}

/// One invented fixture id.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MadeUp {
pub path: String,
pub value: String,
}

/// Invented id values on the added lines of test files (`diff`: path,
/// status, patch), when the run looked up real ids (`looked`). An id-like
/// key: `id`, `…Id`, `…_id`, `ids`.
pub fn made_up(diff: &[(String, String, String)], looked: &[String]) -> Vec<MadeUp> {
if looked.is_empty() {
return Vec::new();
}
let key =
regex::Regex::new(r#"(?i)\b[a-z_]*(?:id|ids)\s*[:=]\s*\[?\s*["'`]([^"'`]{1,40})["'`]"#)
.expect("valid regex");
let mut out: Vec<MadeUp> = Vec::new();
for (path, _, patch) in diff
.iter()
.filter(|(p, _, _)| crate::push_gate::is_test_file(p))
{
for line in patch
.lines()
.filter(|l| l.starts_with('+') && !l.starts_with("+++"))
{
for c in key.captures_iter(line) {
let value = c[1].to_string();
if looks_made_up(&value)
&& !looked.iter().any(|l| l == &value)
&& !out.iter().any(|m| m.path == *path && m.value == value)
{
out.push(MadeUp {
path: path.clone(),
value,
});
}
}
}
}
out
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn made_up_ids_are_found_only_when_real_ones_were_looked_up() {
let lines = vec![
"- [L1] Asked Production database: SELECT id FROM sport WHERE ... Came back: 4c2d9e10-1111-4a2b-8c3d-0a2b3c4d5e6f 'Multi-sport'; b7f3a2c8… 'Multi-Sport'".to_string(),
"- [L2] Asked it: SELECT 9f8e7d6c-0000-0000-0000-000000000000 Came back EMPTY".to_string(),
];
let ids = looked_up_ids(&lines);
assert_eq!(
ids,
vec!["4c2d9e10-1111-4a2b-8c3d-0a2b3c4d5e6f", "b7f3a2c8"]
);
let diff = vec![
(
"src/test/filters.test.ts".to_string(),
"modified".to_string(),
"+ { id: 'sport-a', name: 'Multi-sport' },\n+ { id: \"sport-b\", name: 'Multi-Sport' },\n+ { sportId: '4c2d9e10-1111-4a2b-8c3d-0a2b3c4d5e6f' },\n- { id: 'old-1' }".to_string(),
),
(
"src/utils/filters.ts".to_string(),
"modified".to_string(),
"+const id = 'sport-a';".to_string(),
),
];
let found = made_up(&diff, &ids);
assert_eq!(
found.iter().map(|m| m.value.as_str()).collect::<Vec<_>>(),
vec!["sport-a", "sport-b"]
);
assert!(made_up(&diff, &[]).is_empty());
assert!(looks_made_up("id-1") && looks_made_up("test-id") && looks_made_up("fake_user"));
assert!(!looks_made_up("multi-sport") && !looks_made_up("4c2d9e10"));
}
}
7 changes: 7 additions & 0 deletions services/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ pub mod ci_repro;
/// The last check on a pull request description: no section twice, no
/// deploy maps, no empty "who this affects".
pub mod description_lint;
/// A test fixture uses the ids the run looked up, not made-up ones.
pub mod fixture_ids;
// A diff holds the lines the change needs: formatting-only hunks are told
// apart and put back.
pub mod diff_shape;
Expand Down Expand Up @@ -204,7 +206,12 @@ pub mod pr_steps;
/// A repository's pull request template as the description's structure.
pub mod pr_template;
pub mod preview;
/// What a fix must show before it is committed and pushed.
pub mod push_gate;
pub mod run_prs;
/// Scope decided once at plan time, held in every round and in the
/// description.
pub mod scope_ledger;
pub mod waiting_line;
// review_stats: time-ordered review records for analytics
/// How a comment reads: the renderer and lint every comment passes before
Expand Down
Loading
Loading