From b803a500912f53d033d19c381936a542a953baaf Mon Sep 17 00:00:00 2001 From: REPPL <77722411+REPPL@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:42:07 +0000 Subject: [PATCH 1/9] feat: land a lane at its fix-round cap unless a security or major finding stands A lane now takes five fix rounds when nothing sets the cap, still set per repository by pace.fix_rounds and per run by --fix-rounds. At the cap the lane is handed back only while a security reviewer, the intent-auditor, or a finding tagged major or critical (or untagged) does not pass; otherwise each minor or nitpick finding left is filed as an open issue through the ledger's capture in the landing's records commit, and the lane lands. The ruthless reviewer's brief asks for a severity tag and a remedy on each finding, the landing's diff judges accept only the records the filing writes, the records round is told of them, the pull request body says so, and the records commit discloses the reviewer whose words they carry. The run's pace line, the build, implement and drain pages and the brief state both rules; the severity reading is recorded as a decision. Assisted-by: Claude:claude-opus-5-5 --- .../development/brief/04-surfaces/34-build.md | 29 +- .../development/brief/04-surfaces/35-drain.md | 2 +- ...t-a-lane-s-fix-round-cap-the-loop-reads.md | 6 + commands/build.md | 14 +- commands/drain.md | 2 +- commands/implement.md | 6 +- docs/reference/cli/commands.md | 21 +- internal/core/implement/loop/capdefer.go | 525 ++++++++++++++++++ internal/core/implement/loop/capdefer_test.go | 231 ++++++++ .../core/implement/loop/fixrounds_test.go | 10 +- internal/core/implement/loop/land.go | 127 ++++- internal/core/implement/loop/pace.go | 14 +- .../testdata/drain_bundle_one/cap-of-1.golden | 6 +- .../drain_bundle_one/no-candidates.golden | 6 +- internal/core/implement/loop/validate.go | 27 +- internal/surface/cli/build.go | 19 +- .../cli/build_fixrounds_surface_test.go | 15 +- internal/surface/cli/drain.go | 2 +- 18 files changed, 982 insertions(+), 80 deletions(-) create mode 100644 .abcd/work/decisions/dcn-2612021257543635-at-a-lane-s-fix-round-cap-the-loop-reads.md create mode 100644 internal/core/implement/loop/capdefer.go create mode 100644 internal/core/implement/loop/capdefer_test.go diff --git a/.abcd/development/brief/04-surfaces/34-build.md b/.abcd/development/brief/04-surfaces/34-build.md index 2811fb8cda..80bf75ec4c 100644 --- a/.abcd/development/brief/04-surfaces/34-build.md +++ b/.abcd/development/brief/04-surfaces/34-build.md @@ -347,16 +347,17 @@ intent's grounds entry is left as written. A run is paced without being told: a working window, a pause after it, a ceiling on the run's lanes and validators alive at once, and the fix rounds a -lane may take before it is handed back (ruling DR1, 2026-09-29: a per-run value -set beside the pace, default 3). The four numbers are +lane may take before its cap is judged (ruling DR1, 2026-09-29: a per-run value +set beside the pace, default 3, raised to 5 by the ruling of 2 December 2026, +iss-2612021201375528). The four numbers are resolved once, when a new run is created, through the one layered configuration reader (`internal/core/layered`), each key on its own, highest layer first: the build's own pace, sub-agent and fix-round flags, the pace written as `/`; `pace.work_minutes`, `pace.pause_minutes`, `pace.sub_agents` and `pace.fix_rounds` in the repository's `.abcd/config.json`; the same keys in `~/.abcd.noindex/config.json`; and -the bundled default, 120 minutes of work, no pause, 2 sub-agents and 3 fix -rounds (decision 5, the pause removed by the ruling of 2026-10-10, and ruling DR1), held in one set of constants. The files are read through the +the bundled default, 120 minutes of work, no pause, 2 sub-agents and 5 fix +rounds (decision 5, the pause removed by the ruling of 2026-10-10, and ruling DR1 as the ruling of 2 December 2026 raised it), held in one set of constants. The files are read through the reader's guards (a regular file inside the checkout; on the machine, one the caller owns and nobody else can write), and the reader claims the `pace` namespace, so a key under it the loop does not read is refused rather than @@ -1136,9 +1137,23 @@ the work, never closes like a pass). A return the loop cannot read as a verdict records nothing and is refused, so it starts no fix round and counts against nothing. -**The fix-round bound** (ruling DR1; itd-50, criterion 2). A round that does not -pass once the lane has taken the run's cap of fix rounds starts no further fix -round: the lane stops at the `handed-back` stage with a `hand_back` record (the +**The fix-round bound** (ruling DR1; itd-50, criterion 2; the ruling of 2 +December 2026, iss-2612021201375528). A round that does not pass once the lane +has taken the run's cap of fix rounds starts no further fix round. When every +finding it leaves is minor or nitpick, the lane goes to its landing, and the +landing's records commit files each finding as an open issue through the +ledger's capture: found at the finding's location, with its severity and the +remedy the reviewer named (or the ledger's machine remedy), and found during a +line naming the lane, the run, the round and the head it judged, by which a +killed landing finds what it already filed. A finding carries no severity of its +own, so the cap reads the narrowest sound one (dcn-2612021257543635): a failing +security reviewer is a security finding, a failing intent-auditor a major one, +and a ruthless reviewer's finding carries the tag its bullet gives it after its +location (`[critical]`, `[major]`, `[minor]` or `[nitpick]`, which its brief +asks for), an untagged finding or a failing return that locates none reading as +major; a finding naming no file the lane's worktree holds, or a reviewer whose +model the records commit cannot disclose, holds the lane too. Otherwise the +lane stops at the `handed-back` stage with a `hand_back` record (the verdict `unachievable`, the round, the cap, the last round's verdicts, the returns of the validators that did not pass, and the criteria the audit judged not met or could not decide). The step's result carries it and says so first; diff --git a/.abcd/development/brief/04-surfaces/35-drain.md b/.abcd/development/brief/04-surfaces/35-drain.md index ed80f5327f..672442aa7e 100644 --- a/.abcd/development/brief/04-surfaces/35-drain.md +++ b/.abcd/development/brief/04-surfaces/35-drain.md @@ -1430,7 +1430,7 @@ The drain then routes each hand-back: | `user-visible` | the issue is promoted to an intent draft by the capture verb's promotion | the draft, and the issue's `related_intents` naming it; nothing else | | `trust-rule` | flagged as needing a decision record, the lane's reason as the question | `decision_needed:` on the open issue, holding the question; nothing else; no record is minted | | `design-finding`, `second-package` | flagged with the home the lane names | nothing | -| a lane stopped after its fix rounds | flagged, the issue staying open with the last findings | nothing | +| a lane stopped after its fix rounds (a security, major or critical finding left; one leaving only minor or nitpick findings lands and files each as an open issue, iss-2612021201375528) | flagged, the issue staying open with the last findings | nothing | | a lane handed back as stuck (`stuck`) | flagged, the issue staying open, naming the discard of its run | nothing | | a lane whose pull request closed unmerged (`closed`) | flagged, the issue staying open, naming the discard of its run | nothing | diff --git a/.abcd/work/decisions/dcn-2612021257543635-at-a-lane-s-fix-round-cap-the-loop-reads.md b/.abcd/work/decisions/dcn-2612021257543635-at-a-lane-s-fix-round-cap-the-loop-reads.md new file mode 100644 index 0000000000..d91a41a946 --- /dev/null +++ b/.abcd/work/decisions/dcn-2612021257543635-at-a-lane-s-fix-round-cap-the-loop-reads.md @@ -0,0 +1,6 @@ +--- +id: dcn-2612021257543635 +slug: at-a-lane-s-fix-round-cap-the-loop-reads +date: 2026-12-02 +--- +2026-12-02 — At a lane's fix-round cap the loop reads a finding's severity narrowly, since review findings carry none of their own: a failing security reviewer is a security finding and a failing intent-auditor a major one, so either hands the lane back; a ruthless reviewer's finding carries the ledger severity its bullet tags after its location ([critical], [major], [minor] or [nitpick]), which the reviewer's brief now asks for, and an untagged finding, a failing return that locates none, a finding naming no file in the lane's worktree, or a reviewer whose model the records commit cannot disclose in Assisted-by all hold the lane as major. Only a round whose every remaining finding is minor or nitpick lands, and the landing's records commit files each through the ledger's capture as an open issue (found_at the finding's location, remedy the reviewer's or the machine remedy, found_during naming lane, run, round and judged head, which also makes a killed landing file each once). Nothing new enters the run's state: the round is re-read from the returns as recorded. Applies the ruling of 2 December 2026 on iss-2612021201375528. diff --git a/commands/build.md b/commands/build.md index 0d77dff0f4..ccd5d5ad7a 100644 --- a/commands/build.md +++ b/commands/build.md @@ -661,7 +661,7 @@ naming the lane and making no commit: A new run is paced without being told: a working window, a pause after it, a ceiling on the run's lanes and validators alive at once, and the fix rounds a -lane may take before it is handed back. The four numbers are read once, when the +lane may take before its cap is judged. The four numbers are read once, when the run starts, each from the highest layer that sets it: 1. `--pace /` (for example `--pace 90/240`), @@ -669,7 +669,17 @@ run starts, each from the highest layer that sets it: 2. `pace.work_minutes`, `pace.pause_minutes`, `pace.sub_agents` and `pace.fix_rounds` in the repository's `.abcd/config.json`; 3. the same keys in `~/.abcd.noindex/config.json`, for every checkout on the machine; -4. the bundled 120/0 (no pause) with 2 sub-agents and 3 fix rounds. +4. the bundled 120/0 (no pause) with 2 sub-agents and 5 fix rounds. + +At the cap, a lane whose round still does not pass is handed back only while a +security finding, or a major or critical one, stands. Otherwise every finding +it leaves is minor or nitpick, and the lane lands: its records commit files +each finding as an open issue through the ledger's capture, at the finding's +location and with its remedy, naming the lane, the run and the head the round +judged. A failing security reviewer counts as a security finding, a failing +intent-auditor as a major one, and a ruthless reviewer's finding carries the +severity its tag gives it (`[minor]`, `[nitpick]`, `[major]`, `[critical]`), +an untagged one counting as major. Tell the user both rules when a run starts. The payload's `pace` carries each number as `value`, `layer` (`flag`, `repo`, `machine` or `bundled`) and `origin` (the flag as typed, or the file), and the diff --git a/commands/drain.md b/commands/drain.md index 9a6c1d1254..f007583ca1 100644 --- a/commands/drain.md +++ b/commands/drain.md @@ -1264,7 +1264,7 @@ it still holds is handed back. The drain routes each hand-back: | `user-visible` | `promoted`: an intent draft seeded from the issue (`capture promote`) | the draft, and the issue's `related_intents`; nothing else | | `trust-rule` | `decision-record`: flagged, with the lane's reason as `question` | `decision_needed:` on the open issue, holding the question; nothing else; no record is minted | | `design-finding`, `second-package` | `home`: flagged with the `home` the lane names | nothing | -| (fix rounds exhausted) | `home`: flagged, the issue staying open | nothing | +| (fix rounds exhausted with a security, major or critical finding left; a lane leaving only minor or nitpick findings lands, filing each as an open issue) | `home`: flagged, the issue staying open | nothing | | `stuck` (the lane kept refusing) | `home`: flagged, the issue staying open, naming the discard of the lane's run | nothing | | `closed` (its pull request closed unmerged) | `home`: flagged, the issue staying open, naming the discard of the lane's run | nothing | diff --git a/commands/implement.md b/commands/implement.md index 479ec0a77d..fc161fd478 100644 --- a/commands/implement.md +++ b/commands/implement.md @@ -934,7 +934,11 @@ the host. A routing table or provider configuration `step` cannot read is refused at `routing`, and its non-fatal reports are said on stderr; nothing is written by a refusal. A round's `routes` is state schema version 16's. A lane that has taken -the run's fix rounds (`build --fix-rounds`, bundled 3) and still does not pass +the run's fix rounds (`build --fix-rounds`, bundled 5) and still does not pass +lands when every finding the round leaves is minor or nitpick: the step goes to +`land`, and the records commit files each finding as an open issue (a failing +security reviewer or intent-auditor, a finding tagged `[major]` or +`[critical]`, and an untagged one count as more). Otherwise it is handed back: the result's `hand_back` names the verdict `unachievable` and the last findings, and the loop starts nothing further for it. Its sibling lanes finish under the same ceiling, window and fix rounds; no new lane opens, diff --git a/docs/reference/cli/commands.md b/docs/reference/cli/commands.md index c730d922f6..d24365f238 100644 --- a/docs/reference/cli/commands.md +++ b/docs/reference/cli/commands.md @@ -615,18 +615,20 @@ intent is not counted as a peer's. A session that has not joined is refused. Wit the run holds no claim, and the result says so. A new run is paced: a working window, a pause after it, a ceiling on the run's lanes and -validators alive at once, and the fix rounds a lane may take before it is handed back. The +validators alive at once, and the fix rounds a lane may take before its cap is judged. The four numbers are read once, when the run starts: --pace /, --sub-agents and --fix-rounds for this run, else pace.work_minutes, pace.pause_minutes, pace.sub_agents and pace.fix_rounds in the repository's .abcd/config.json, else in -~/.abcd.noindex/config.json, else the bundled 120/0 (no pause) with 2 sub-agents and 3 fix rounds. The result and the run +~/.abcd.noindex/config.json, else the bundled 120/0 (no pause) with 2 sub-agents and 5 fix rounds. The result and the run record name each number's layer. A malformed pace or ceiling, typed or configured, is refused naming the value and the accepted form, and writes nothing. Starting again keeps the run's pace; a flag naming another is refused. The window, the pause and the ceiling bind through `abcd implement step`, which hands out work only while a slot under the ceiling is free. A lane whose validators still do not pass after its fix rounds is -handed back: it stops as unachievable with the last round's findings, the run starts nothing -further for it, and `abcd implement step` refuses naming the hand-back. +handed back while a security finding, or a major or critical one, stands: it stops as +unachievable with the last round's findings, the run starts nothing further for it, and +`abcd implement step` refuses naming the hand-back. Otherwise every finding left is minor +or nitpick, and the lane lands with each filed as an open issue in its records commit. A new run reads its review set once, too: review.reviewers (one or two model classes per code-review role, for both roles or per role; bundled: research and default), review.judge @@ -713,7 +715,7 @@ Exit 2 on a refusal, exit 3 when a peer holds the intent or the run state is loc ``` --auto-plan[=true|false] plan a draft intent with no person present, after two plan reviews, on adr-2610310235000654's substitute for the sign-off - --fix-rounds string the fix rounds a lane of this run may take before it is handed back, a whole number from 0 (bundled: 3); wins over every configured layer + --fix-rounds string the fix rounds a lane of this run may take before its cap is judged, a whole number from 0 (bundled: 5); wins over every configured layer --pace string this run's working window and pause, / (e.g. 90/240); wins over every configured layer --release[=true|false] push the tombstone over this copy's reservation on the key, changing nothing in the run's state --session string the host session's id in the shared run state; a new run claims the intent for it @@ -791,7 +793,7 @@ state or the series is locked. **Flags:** ``` - --fix-rounds string the fix rounds a lane of the new run may take before it is handed back; wins over every configured layer + --fix-rounds string the fix rounds a lane of the new run may take before its cap is judged; wins over every configured layer --max int how many picks to make, one at a time under the pace rule; above 1 begins a series (default one pick) --pace string the new run's working window and pause, /; wins over every configured layer --session string the host session's id in the shared run state; the new run claims the picked intent for it @@ -2105,7 +2107,7 @@ passes that issue over as held. ``` --drive[=true|false] make every move from this terminal, starting each agent on a separate login and each next drain itself, until its end time, its own cap, an empty ledger or a stop --dry-run[=true|false] show every open issue's disposition and the order a drain takes them; writes nothing - --fix-rounds string the fix rounds a lane may take before it is handed back; wins over every configured layer + --fix-rounds string the fix rounds a lane may take before its cap is judged; wins over every configured layer --in-work int the most lanes a drain beginning now holds in work, 1 to 10; wins over the repository's drain.in_work_max (1 when neither sets it) --judgement string the host's answer to the judgement the drain awaits, at the path its request names --max int cap the lanes this drain opens, or with --drive the lanes the drive opens across the drains it works; the default is all @@ -4349,7 +4351,10 @@ round's routes with the failing gate output; a role on a runner, a review the re route takes, one pointed at a provider, a host-decides row and the implementer name no tier and do not move. A round that does not pass once the lane -has taken the run's fix rounds (--fix-rounds, bundled 3) hands the lane back instead: it +has taken the run's fix rounds (--fix-rounds, bundled 5) goes to its landing when every +finding it leaves is minor or nitpick (a security reviewer's failing verdict, an +intent-auditor's, and an untagged finding count as more), and the records commit files +each finding as an open issue; otherwise it hands the lane back instead: it stops as unachievable, the result and the run record name the last round's findings, and the run starts nothing further for it. Its sibling lanes finish: no new lane opens, no lane closes the spec, and a sibling whose round passes is held before its push, or before diff --git a/internal/core/implement/loop/capdefer.go b/internal/core/implement/loop/capdefer.go new file mode 100644 index 0000000000..8066ccea24 --- /dev/null +++ b/internal/core/implement/loop/capdefer.go @@ -0,0 +1,525 @@ +package loop + +// capdefer.go is what a lane does at its fix-round cap (the product thinker's +// ruling of 2 December 2026, iss-2612021201375528, replacing DR1's hand-back of +// every lane at the cap). A lane whose round still does not pass once it has +// taken the run's fix rounds is handed back only while a security finding, or a +// major or critical one, stands. Otherwise each finding the round leaves, minor +// or nitpick, is filed as an open issue through the ledger's capture, in the +// landing's records commit, and the lane goes on to land. +// +// A finding carries no severity of its own, so the rule reads the narrowest +// sound one (dcn-2612021257543635): +// +// - a security reviewer that did not pass is a security finding, whatever it +// located, and the intent-auditor that did not pass is a major one: a +// criterion not met, or not decided; +// - a ruthless reviewer's finding carries the severity its bullet's tag gives +// it, `[critical]`, `[major]`, `[minor]` or `[nitpick]` straight after its +// location, as the reviewer's brief asks (findingSeverityLine); an untagged +// finding reads as major, and so does a return that did not pass and +// locates none, since there is then nothing to file; +// - a finding filed must name a file the lane's worktree holds, as a +// capture's found_at must, and the reviewer whose words the record carries +// must name a model the records commit can disclose in its Assisted-by: +// trailer. +// +// Nothing new is kept in the run's state: the round the landing files from is +// the lane's latest round over its own change, read again from the returns as +// the loop recorded them (recordedReturn), and each record is known by its +// found_during, which names the lane, the run, the round and its head, and its +// found_at, so a call killed after a capture finds the record and files it once. + +import ( + "fmt" + "os" + "path/filepath" + "regexp" + "slices" + "strconv" + "strings" + "unicode/utf8" + + "github.com/intentdriven/abcd/internal/core/capture" + "github.com/intentdriven/abcd/internal/core/issuerecord" + "github.com/intentdriven/abcd/internal/core/issueschema" + "github.com/intentdriven/abcd/internal/gitutil" + "github.com/intentdriven/abcd/internal/termsafe" +) + +// findingSeverityLine is what a ruthless reviewer's brief says of each finding's +// severity and remedy, which the fix-round cap reads. +const findingSeverityLine = "Tag each finding bullet with its severity straight after its location, one of `[critical]`, `[major]`, `[minor]` or `[nitpick]` " + + "(`- **path/file.go:12** [minor] — ...`; a NOTE is minor or nitpick), and give a minor or nitpick finding a nested `- *Remedy:* `. " + + "Once the lane has taken the run's fix rounds, a round whose findings are all minor or nitpick lets the lane land with each filed as an open issue, " + + "and an untagged finding counts as major." + +// The severities a finding below major carries, which the cap files. +var belowMajor = []string{string(capture.SeverityMinor), string(capture.SeverityNitpick)} + +// severityTagRe is the severity tag a finding bullet's text opens with once its +// location is read. +var severityTagRe = regexp.MustCompile(`^\[(?i:(critical|major|minor|nitpick))\]`) + +// remedyLineRe is a nested line of a finding bullet naming its remedy: +// `- *Remedy:* ...`, `**Remedy**: ...` or `Remedy: ...`. +var remedyLineRe = regexp.MustCompile(`^[ \t]+(?:[-*+][ \t]+)?[*_]{0,2}(?i:remedy)[*_]{0,2}[ \t]*:[*_]{0,2}[ \t]*(\S.*)$`) + +// The bounds on what a filed record carries of a reviewer's words, in bytes. +const ( + maxCapStatement = 2000 + maxCapRemedy = 500 +) + +// capFinding is one finding a lane at its fix-round cap files as an open issue. +type capFinding struct { + file string + line int + severity string + statement string + remedy string + // role and reviewer are the reviewer whose return located it, and + // assisted the Assisted-by: value naming that reviewer's model. + role string + reviewer int + assisted string +} + +// foundAt is the finding's found_at. +func (f capFinding) foundAt() string { return f.file + ":" + strconv.Itoa(f.line) } + +// capFiling is what a lane's landing files at the fix-round cap: the round's +// findings, each one record, and the found_during every record carries. +type capFiling struct { + round ValidationRound + foundDuring string + findings []capFinding +} + +// capRound is the lane's round that left findings open at the fix-round cap, the +// round its landing files them from: its latest round over its own change (never +// the round that reads its records commit), when a validator of it did not pass +// and the lane is past its validate stage. nil otherwise, a lane still in its +// first validate stage included, where the cap is yet to be judged. +func (l Lane) capRound() *ValidationRound { + if l.Stage != StageLand && l.Landing == nil { + return nil + } + for i := len(l.Validation) - 1; i >= 0; i-- { + r := l.Validation[i] + if l.readsRecords(r) { + continue + } + if slices.ContainsFunc(r.Validators, func(v ValidatorRun) bool { return v.Verdict != "" && !v.Pass }) { + return &l.Validation[i] + } + return nil + } + return nil +} + +// capFoundDuring is the found_during of every record a lane files from round r. +func capFoundDuring(st State, lane Lane, r ValidationRound) string { + return fmt.Sprintf("the review of %s in run %s, round %d at %s, left open at the fix-round cap", lane.ID, st.RunID, r.Round, r.HeadSHA) +} + +// capFilingFor reads what round r leaves at the fix-round cap: the filing when +// every validator that did not pass leaves only findings below major, or why +// the lane is handed back instead. +func capFilingFor(c Context, lane Lane, r ValidationRound) (*capFiling, string, error) { + f := &capFiling{round: r, foundDuring: capFoundDuring(c.State, lane, r)} + seen := map[location]bool{} + for _, v := range r.Validators { + if v.Verdict == "" || v.Pass { + continue + } + switch v.Role { + case RoleRuthless: + case RoleSecurity: + return nil, fmt.Sprintf("the %s said %s, a security finding", v.Role, v.Verdict), nil + default: + return nil, fmt.Sprintf("the %s said %s, which reads as a major finding", v.Role, v.Verdict), nil + } + assisted, problem := reviewerTrailer(v) + if problem != "" { + return nil, fmt.Sprintf("the %s's model cannot be disclosed in the records commit that would carry its words (its model %s)", v.Role, problem), nil + } + raw, err := recordedReturn(c.RepoRoot, lane, v) + if err != nil { + return nil, "", err + } + found := readCapFindings(string(raw), lane.Worktree) + if len(found) == 0 { + return nil, fmt.Sprintf("the %s said %s and locates no finding to file, which reads as a major finding", v.Role, v.Verdict), nil + } + for _, x := range found { + switch { + case x.severity == "": + return nil, fmt.Sprintf("the %s's finding at %s carries no severity, which reads as major", v.Role, x.foundAt()), nil + case !slices.Contains(belowMajor, x.severity): + return nil, fmt.Sprintf("the %s's finding at %s is %s", v.Role, x.foundAt(), x.severity), nil + case !fileHeld(lane.Worktree, x.file): + return nil, fmt.Sprintf("the %s's finding at %s names no file the lane's worktree holds, so it cannot be filed there", v.Role, x.foundAt()), nil + } + at := location{x.file, x.line} + if seen[at] { + // Two reviewers citing one place file one record. + continue + } + seen[at] = true + x.role, x.reviewer, x.assisted = v.Role, v.Reviewer, assisted + if x.remedy == "" { + x.remedy = issueschema.MachineRemedy + } + f.findings = append(f.findings, x) + } + } + if len(f.findings) == 0 { + return nil, "no validator that did not pass left a finding to file", nil + } + return f, "", nil +} + +// capFilingOf is what the lane's landing files at the fix-round cap, nil when +// its latest round over its own change passed. A round that no longer reads as +// one to file from is refused: the validate stage let the lane land on it. +func capFilingOf(c Context, lane Lane) (*capFiling, error) { + r := lane.capRound() + if r == nil { + return nil, nil + } + f, why, err := capFilingFor(c, lane, *r) + if err != nil { + return nil, err + } + if why != "" { + return nil, refuse(string(StageLand), "", lane.ID, + fmt.Sprintf("round %d did not pass, and the lane went to its landing because every finding it left was below major, but now %s", r.Round, why), + "put back the round's returns as the loop recorded them, or restore the run's state file, then run `abcd implement step` again") + } + return f, nil +} + +// reviewerTrailer is the Assisted-by: value naming the model whose words a +// reviewer's return carries, or what is wrong with it: the model its runner +// reported, else the one its return named, else the one it was asked for, a +// route's `/` taken off, as the trailer names a model. +func reviewerTrailer(v ValidatorRun) (string, string) { + model := v.ReviewerModel + if v.ModelStatus != ModelReported && v.ReviewerNamed != "" { + model = v.ReviewerNamed + } + if _, problem := modelTrailer(model); problem != "" { + if i := strings.LastIndex(model, "/"); i >= 0 { + model = model[i+1:] + } + } + return modelTrailer(model) +} + +// fileHeld reports whether the lane's worktree holds a regular file at rel. +func fileHeld(worktree, rel string) bool { + info, err := os.Lstat(filepath.Join(worktree, filepath.FromSlash(rel))) + return err == nil && info.Mode().IsRegular() +} + +// readCapFindings reads each finding bullet under a return's Findings headings, +// as recordFindings reads their locations, each location once: the severity +// its tag gives, the statement after it, and the remedy a nested line names. +func readCapFindings(text, worktree string) []capFinding { + var out []capFinding + seen := map[location]bool{} + cur := -1 + eachFindingsLine(relativeTo(text, worktree), func(ln string) { + if at, rest, ok := leadBullet(ln); ok { + cur = -1 + if seen[at] { + return + } + seen[at] = true + sev, statement := severityOf(rest) + out = append(out, capFinding{file: at.file, line: at.line, severity: sev, statement: statement}) + cur = len(out) - 1 + return + } + if cur < 0 || strings.TrimSpace(ln) == "" { + return + } + if ln[0] != ' ' && ln[0] != '\t' { + cur = -1 + return + } + if m := remedyLineRe.FindStringSubmatch(ln); m != nil && out[cur].remedy == "" { + out[cur].remedy = strings.TrimSpace(m[1]) + } + }) + return out +} + +// leadBullet is leadLocation with the text after the location. +func leadBullet(ln string) (location, string, bool) { + m := leadRe.FindStringIndex(ln) + if m == nil { + return location{}, "", false + } + c := leadCitationRe.FindStringSubmatch(ln[m[1]:]) + if c == nil { + return location{}, "", false + } + at, ok := toLocation(c[1], c[2]) + return at, ln[m[1]+len(c[0]):], ok +} + +// severityOf reads the severity tag and the statement from a finding bullet's +// text after its location: the closing marks the location stood behind go, +// then the tag, then the dash or colon before the statement. +func severityOf(rest string) (string, string) { + rest = strings.TrimLeft(rest, "*_`)]>\"' \t") + sev := "" + if m := severityTagRe.FindStringSubmatch(rest); m != nil { + sev = strings.ToLower(m[1]) + rest = rest[len(m[0]):] + } + rest = strings.TrimLeft(rest, " \t-:—–") + return sev, strings.TrimSpace(rest) +} + +// clipBytes bounds s to n bytes on a rune boundary. +func clipBytes(s string, n int) string { + if len(s) <= n { + return s + } + for n > 0 && !utf8.RuneStart(s[n]) { + n-- + } + return strings.TrimSpace(s[:n]) + "..." +} + +// capRecordText is the body of the record a lane files for f. +func capRecordText(st State, lane Lane, filing *capFiling, f capFinding) string { + statement := clipBytes(termsafe.Sanitize(f.statement), maxCapStatement) + if statement == "" { + statement = "The finding states nothing beyond its location." + } + what := "building " + st.Intent + " against " + st.Spec + if iss := st.Issue(); iss != "" { + what = "fixing " + iss + } + r := filing.round + return fmt.Sprintf("%s\n\nThe %s (reviewer %d) of lane %s in run %s, %s, found this at %s in round %d, which judged %s. "+ + "The round came after the run's cap of %s, and nothing it left was a security, major or critical finding, "+ + "so the lane landed and its landing filed this %s finding as an open issue.\n", + statement, f.role, f.reviewer, lane.ID, st.RunID, what, f.foundAt(), r.Round, r.HeadSHA, fixRoundsPhrase(st.FixRoundCap()), f.severity) +} + +// capRemedy is the remedy of the record a lane files for f: one line. +func capRemedy(f capFinding) string { + r := clipBytes(strings.Join(strings.Fields(termsafe.Sanitize(f.remedy)), " "), maxCapRemedy) + if r == "" { + return issueschema.MachineRemedy + } + return r +} + +// match is the index of the finding a record's text files, or -1: an issue +// record valid as written whose found_during is the filing's and whose +// found_at and severity are one finding's that taken does not hold already. +func (f *capFiling) match(content string, taken map[int]bool) int { + fm, _, err := issuerecord.Parse(content) + if err != nil || issuerecord.ValidateStrict(fm) != nil { + return -1 + } + if s, _ := fm["found_during"].(string); s != f.foundDuring { + return -1 + } + at, _ := fm["found_at"].(string) + sev, _ := fm["severity"].(string) + for i, x := range f.findings { + if !taken[i] && at == x.foundAt() && sev == x.severity { + return i + } + } + return -1 +} + +// fileAtCap files each finding of filing as an open issue in the lane's +// worktree, through the ledger's capture, unless the worktree's open/ already +// holds its record, as a call killed after the capture leaves it. It says how +// many it filed and how many it found. +func fileAtCap(st State, lane Lane, filing *capFiling) (filed, found int, err error) { + open := filepath.Join(lane.Worktree, filepath.FromSlash(capture.LedgerRelPath), string(capture.StateOpen)) + names, err := filepath.Glob(filepath.Join(open, "iss-*.md")) + if err != nil { + return 0, 0, err + } + taken := map[int]bool{} + for _, name := range names { + info, err := os.Lstat(name) + if err != nil || !info.Mode().IsRegular() || info.Size() > maxRecordBytes { + continue + } + data, err := os.ReadFile(name) + if err != nil { + continue + } + if i := filing.match(string(data), taken); i >= 0 { + taken[i] = true + found++ + } + } + for i, x := range filing.findings { + if taken[i] { + continue + } + if _, err := capture.Capture(capture.CaptureRequest{RepoRoot: lane.Worktree, Text: capRecordText(st, lane, filing, x), + Severity: capture.Severity(x.severity), Category: "bug", Source: "impl-review", + FoundDuring: filing.foundDuring, FoundAt: x.foundAt(), Remedy: capRemedy(x)}); err != nil { + return filed, found, fmt.Errorf("filing the finding at %s: %w", x.foundAt(), err) + } + filed++ + } + return filed, found, nil +} + +// openAdds are the entries of git's raw list that add a record to the issue +// store's open/. +func openAdds(raw string) ([]rawEntry, error) { + entries, err := parseRawDiff(raw) + if err != nil { + return nil, err + } + var out []rawEntry + for _, e := range entries { + if store, bucket, _, ok := storeRecord(e.path); ok && store.rel == issueStore.rel && bucket == string(capture.StateOpen) && e.status == "A" { + out = append(out, e) + } + } + return out, nil +} + +// filedAdds matches each added open record to the finding of filing it files: +// the id each finding's record carries, by the finding's index, and the path +// of the first added record that files none, "" when every one files one. +func filedAdds(repo string, filing *capFiling, adds []rawEntry) (map[int]string, string, error) { + ids := map[int]string{} + if len(adds) == 0 { + return ids, "", nil + } + if filing == nil { + return nil, adds[0].path, nil + } + objects := make([]string, len(adds)) + for i, e := range adds { + objects[i] = e.newObject + } + blobs, err := gitutil.CatFileBatch(repo, objects, len(adds)*(maxRecordBytes+256)) + if err != nil || len(blobs) != len(adds) { + return nil, adds[0].path, nil + } + taken := map[int]bool{} + for k, e := range adds { + if blobs[k].Missing { + return nil, e.path, nil + } + i := filing.match(blobs[k].Content, taken) + if i < 0 { + return nil, e.path, nil + } + taken[i] = true + fm, _, _ := issuerecord.Parse(blobs[k].Content) + id, _ := fm["id"].(string) + ids[i] = id + } + return ids, "", nil +} + +// filingLacks names the first finding of filing no record added in raw files, +// "" when each has its record. +func filingLacks(repo string, filing *capFiling, raw string) (string, error) { + if filing == nil { + return "", nil + } + adds, err := openAdds(raw) + if err != nil { + return "", err + } + ids, odd, err := filedAdds(repo, filing, adds) + if err != nil { + return "", err + } + if odd != "" { + return "a record of " + strconv.Quote(termsafe.Sanitize(odd)) + " that files no finding left at the fix-round cap", nil + } + for i, x := range filing.findings { + if _, ok := ids[i]; !ok { + return "the record filing the " + x.severity + " finding at " + x.foundAt() + " left at the fix-round cap", nil + } + } + return "", nil +} + +// filedIDs are the ids of the records the commit range base..head adds for +// filing, in finding order. +func filedIDs(repo string, filing *capFiling, base, head string) ([]string, error) { + if filing == nil { + return nil, nil + } + raw, err := gitutil.RunCappedAsStored(repo, maxBaseListing, "diff-tree", "-r", "--raw", "--no-renames", "--no-abbrev", "--ignore-submodules=none", "-z", base, head, "--") + if err != nil { + return nil, fmt.Errorf("reading what %s changes: %w", shortSHA(head), err) + } + adds, err := openAdds(raw) + if err != nil { + return nil, err + } + ids, _, err := filedAdds(repo, filing, adds) + if err != nil { + return nil, err + } + var out []string + for i := range filing.findings { + if id, ok := ids[i]; ok && id != "" { + out = append(out, id) + } + } + return out, nil +} + +// landingAssisted are the records commit's Assisted-by: trailers: one per model +// the lane's receipts reported, and, where the commit files findings left at the +// fix-round cap, one per model of the reviewers whose words those records carry. +func landingAssisted(lane Lane, filing *capFiling) ([]string, string) { + out, gap := assistedByTrailers(lane.Receipts) + if gap != "" { + return nil, gap + } + if filing != nil { + for _, f := range filing.findings { + if t := "Assisted-by: " + f.assisted; !slices.Contains(out, t) { + out = append(out, t) + } + } + } + return out, "" +} + +// filedPhrase names how many findings a filing holds. +func filedPhrase(n int) string { + if n == 1 { + return "1 finding" + } + return fmt.Sprintf("%d findings", n) +} + +// capFilingScope is what the round that reads a records commit is told of the +// records it files for the findings the lane left at the fix-round cap, "" for +// a lane that left none. +func capFilingScope(lane Lane) string { + r := lane.capRound() + if r == nil { + return "" + } + return fmt.Sprintf("This lane reached its landing at the run's cap of fix rounds: round %d at `%s` did not pass, and every finding it left was minor or nitpick, "+ + "so this commit also files each of them as an open issue in `%s/%s/`. Judge each such record against the finding it files: its location, severity, statement and remedy.\n\n", + r.Round, r.HeadSHA, capture.LedgerRelPath, capture.StateOpen) +} diff --git a/internal/core/implement/loop/capdefer_test.go b/internal/core/implement/loop/capdefer_test.go new file mode 100644 index 0000000000..6f07f58d83 --- /dev/null +++ b/internal/core/implement/loop/capdefer_test.go @@ -0,0 +1,231 @@ +package loop + +import ( + "encoding/json" + "os" + "path/filepath" + "regexp" + "strings" + "testing" + + "github.com/intentdriven/abcd/internal/gittest" +) + +// The fix-round cap's ruling of 2 December 2026 (iss-2612021201375528): five +// rounds when nothing sets the cap, and at the cap a lane is handed back only +// while a security finding or a major or critical one stands; otherwise each +// finding left, minor or nitpick, is filed as an open issue and the lane lands. + +// capReviewerModel is the model a cap test's reviewer names: one the records +// commit can disclose, and not the fixtures' writer. +const capReviewerModel = "claude-sonnet-9" + +// capReturn is a ruthless reviewer's return naming capReviewerModel, with +// findings under its Findings heading. +func capReturn(verdict, findings string) string { + return ReviewerModelPrefix + " " + capReviewerModel + "\n\n### Analysis\n\nRead the lane's diff.\n\n### Findings\n\n" + findings + + "\n### Verdict\n\n- **" + verdict + "** — as stated.\n" +} + +// minorFinding is a finding bullet at one.txt:1 tagged minor, with its remedy. +const minorFinding = "- **one.txt:1** [minor] — the line ends without a newline.\n" + + " - *Failure scenario:* a reader concatenating files joins two lines.\n" + + " - *Remedy:* end the file with a newline.\n" + +// TestTheBundledFixRoundCapIsFive is the ruling's default: a run on nothing +// set takes five fix rounds before the cap is judged. +func TestTheBundledFixRoundCapIsFive(t *testing.T) { + if BundledFixRounds != 5 { + t.Fatalf("the bundled fix-round cap is 5, not %d", BundledFixRounds) + } + repo := loopRepo(t, readyIntent("", settledQuestions), specWithSteps("")) + res, err := startedOnce(t, repo, "itd-10") + if err != nil { + t.Fatal(err) + } + st, _ := ReadState(repo.Root(), res.RunID) + if f := st.Pace.FixRounds; f.Value != 5 || f.Layer != "bundled" { + t.Fatalf("a run on nothing set holds its lanes to 5 fix rounds: %+v", f) + } +} + +// atTheCap starts a run on itd-10 with no fix round allowed and implements its +// lane, so its first round that does not pass is judged at the cap. +func atTheCap(t *testing.T) (*gittest.Repo, string, Stages) { + t.Helper() + repo := briefRepo(t, agentsMarked) + start, err := Start(repo.Root(), "itd-10", Options{FixRounds: strp("0")}) + if err != nil { + t.Fatal(err) + } + implemented(t, repo, start.RunID, DefaultStages(), "one.txt") + return repo, start.RunID, DefaultStages() +} + +// TestAtTheCapARoundLeavingOnlyMinorFindingsGoesToItsLanding: a ruthless +// reviewer whose every finding is tagged minor or nitpick does not hand the +// lane back at the cap; the lane goes to its landing, naming the findings it +// will file, and no fix brief is written. +func TestAtTheCapARoundLeavingOnlyMinorFindingsGoesToItsLanding(t *testing.T) { + repo, id, stages := atTheCap(t) + handBack(t, repo, id, stages, RoleRuthless, capReturn("FIX FIRST", minorFinding+ + "- **one.txt:2** [nitpick] — a word is misspelt.\n")) + passRound(t, repo, id, stages, RoleSecurity, RoleAuditor) + res, err := advance(repo.Root(), id, stages, Options{}) + if err != nil { + t.Fatal(err) + } + if res.HandBack != nil || res.Awaiting != nil { + t.Fatalf("a round leaving only minor findings at the cap neither hands the lane back nor starts a fix round: %+v", res) + } + l := currentLane(t, repo, id) + if l.Stage != StageLand || l.HandBack != nil { + t.Fatalf("the lane goes to its landing: %+v", l) + } + st, _ := ReadState(repo.Root(), id) + var record strings.Builder + for _, e := range st.Record { + record.WriteString(e.Note + "\n") + } + for _, want := range []string{"minor or nitpick", "2 findings", "open issues"} { + if !strings.Contains(record.String(), want) { + t.Fatalf("the run record says why the lane lands and what it files (%q):\n%s", want, record.String()) + } + } + if _, err := os.Stat(filepath.Join(repo.Root(), filepath.FromSlash(RunRelDir), id, l.ID, "validate", "round-1", FixDirName)); !os.IsNotExist(err) { + t.Fatalf("no fix brief is written past the cap: %v", err) + } +} + +// TestAtTheCapASecurityOrMajorFindingHandsTheLaneBack: at the cap, a security +// reviewer that did not pass, a finding tagged major or critical, an untagged +// finding and a return that locates nothing each hand the lane back as before. +func TestAtTheCapASecurityOrMajorFindingHandsTheLaneBack(t *testing.T) { + for name, tc := range map[string]struct{ ruthless, security string }{ + "security": {capReturn("SHIP", ""), capReturn("BLOCK", minorFinding)}, + "major": {capReturn("FIX FIRST", minorFinding+"- **one.txt:3** [major] — the file is truncated.\n"), ""}, + "critical": {capReturn("FIX FIRST", "- **one.txt:3** [critical] — the file is lost.\n"), ""}, + "untagged": {capReturn("FIX FIRST", "- **one.txt:3** — the file is truncated.\n"), ""}, + "unlocated": {capReturn("FIX FIRST", "- the file is truncated somewhere.\n"), ""}, + "unheld": {capReturn("FIX FIRST", "- **gone.txt:3** [minor] — a file no tree holds.\n"), ""}, + } { + t.Run(name, func(t *testing.T) { + repo, id, stages := atTheCap(t) + handBack(t, repo, id, stages, RoleRuthless, tc.ruthless) + if tc.security != "" { + handBack(t, repo, id, stages, RoleSecurity, tc.security) + passRound(t, repo, id, stages, RoleAuditor) + } else { + passRound(t, repo, id, stages, RoleSecurity, RoleAuditor) + } + res, err := advance(repo.Root(), id, stages, Options{}) + if err != nil { + t.Fatal(err) + } + if res.HandBack == nil || res.Stage != StageHandedBack || res.HandBack.Verdict != VerdictUnachievable { + t.Fatalf("the lane is handed back at the cap: %+v", res) + } + }) + } +} + +// TestTheReviewerBriefAsksForEachFindingsSeverity: the ruthless reviewer's +// brief asks for the severity tag and the remedy the cap reads. +func TestTheReviewerBriefAsksForEachFindingsSeverity(t *testing.T) { + repo, id, stages := atTheCap(t) + res, err := advance(repo.Root(), id, stages, Options{}) + if err != nil || res.Awaiting == nil || res.Awaiting.Role != RoleRuthless { + t.Fatalf("want the ruthless reviewer handed out: %+v %v", res, err) + } + brief, err := os.ReadFile(filepath.Join(repo.Root(), filepath.FromSlash(res.Awaiting.Brief))) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(brief), findingSeverityLine) { + t.Fatalf("the ruthless reviewer's brief asks for each finding's severity and remedy:\n%s", brief) + } +} + +// TestALandingAtTheCapFilesEachFindingAsAnOpenIssue: the landing of a lane +// that reached it at the cap files each finding left as an open issue in its +// records commit, through the ledger's capture: found at the finding's +// location, with its severity and remedy, naming the lane, the run, the round +// and the head it judged; the commit discloses the reviewer whose words the +// records carry, and the pull request's body says what was filed. +func TestALandingAtTheCapFilesEachFindingAsAnOpenIssue(t *testing.T) { + f := newLandFixture(t, queueRuleset("MERGE")) + repo, id := f.repo, f.runID + // No fix round allowed: the first round that does not pass is at the cap. + path := filepath.Join(repo.Root(), filepath.FromSlash(StateRelPath(id))) + raw, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + var st State + if err := json.Unmarshal(raw, &st); err != nil { + t.Fatal(err) + } + st.Pace.FixRounds = PaceValue{Value: 0, Layer: "flag", Origin: "--fix-rounds 0"} + out, _ := json.Marshal(st) + if err := os.WriteFile(path, out, 0o600); err != nil { + t.Fatal(err) + } + + stepTo(t, repo, id, f.stages, StageImplement) + if res, err := advance(repo.Root(), id, f.stages, Options{}); err != nil || res.Awaiting == nil { + t.Fatalf("the implement stage awaits an implementer: %+v %v", res, err) + } + l := currentLane(t, repo, id) + dir := filepath.Join(repo.Root(), filepath.FromSlash(RunRelDir), id, l.ID) + sha := laneCommit(t, repo, l, "one.txt") + rc := goodReceipt(t, id, l, dir, sha) + receipt := writeReceipt(t, dir, map[string]any{ + "schema_version": rc.SchemaVersion, "run_id": rc.RunID, "lane": rc.Lane, "branch": rc.Branch, + "commits": rc.Commits, "definition_of_done": rc.DefinitionOfDone, "report": rc.Report, "model": f.model, + }) + if _, err := Receipt(repo.Root(), id, receipt, f.stages, Options{}); err != nil { + t.Fatalf("the receipt verifies: %v", err) + } + handBack(t, repo, id, f.stages, RoleRuthless, capReturn("FIX FIRST", minorFinding)) + passRound(t, repo, id, f.stages, RoleSecurity, RoleAuditor) + l = stepTo(t, repo, id, f.stages, StageLand) + judged := l.HeadSHA + + for range 2 { + if res := f.step(t); res.Stage != StageLand { + t.Fatalf("a landing step leaves the lane at land: %+v", res) + } + } + l = currentLane(t, repo, id) + if l.HeadSHA == judged || l.Landing == nil || !l.Landing.RecordsDone { + t.Fatalf("the landing's records are committed on the lane: %+v", l.Landing) + } + files := repo.Git("-C", l.Worktree, "diff-tree", "-r", "--name-status", "--no-renames", judged, l.HeadSHA) + var filed []string + for _, ln := range strings.Split(files, "\n") { + if p, ok := strings.CutPrefix(ln, "A\t.abcd/work/issues/open/"); ok { + filed = append(filed, p) + } + } + if len(filed) != 1 { + t.Fatalf("the records commit files the one finding left as an open issue:\n%s", files) + } + record := repo.Git("-C", l.Worktree, "show", l.HeadSHA+":.abcd/work/issues/open/"+filed[0]) + for _, field := range []string{`(?m)^severity: "?minor"?$`, `(?m)^found_at: "?one\.txt:1"?$`, `(?m)^remedy: "?end the file with a newline\.?"?$`} { + if !regexp.MustCompile(field).MatchString(record) { + t.Fatalf("the filed record's frontmatter matches %s:\n%s", field, record) + } + } + for _, want := range []string{"the line ends without a newline", + l.ID, id, "round 1", judged} { + if !strings.Contains(record, want) { + t.Fatalf("the filed record carries %q:\n%s", want, record) + } + } + msg := repo.Git("-C", l.Worktree, "log", "-1", "--format=%B", l.HeadSHA) + for _, want := range []string{"Assisted-by: Claude:" + capReviewerModel, "Assisted-by: Claude:" + f.model, "1 finding"} { + if !strings.Contains(msg, want) { + t.Fatalf("the records commit says what it filed and discloses the reviewer (%q):\n%s", want, msg) + } + } +} diff --git a/internal/core/implement/loop/fixrounds_test.go b/internal/core/implement/loop/fixrounds_test.go index 40936d4818..abb1f3bfd5 100644 --- a/internal/core/implement/loop/fixrounds_test.go +++ b/internal/core/implement/loop/fixrounds_test.go @@ -13,7 +13,7 @@ import ( // The fix-round rulings of 2026-09-29: DQ1a (an undecided criterion in the // fidelity audit reopens the work exactly as a not-met one does) and DR1 (the // fix rounds a lane may take before it is handed back are a per-run value set -// beside --pace, default 3), on itd-50's criteria 1 and 2 and +// beside --pace, default 3, raised to 5 on 2 December 2026), on itd-50's criteria 1 and 2 and // itd-2609211116005482's falsified pick. // TestAnUndecidedCriterionReopensTheWorkLikeANotMet is ruling DQ1a: an audit @@ -52,7 +52,7 @@ func TestAnUndecidedCriterionReopensTheWorkLikeANotMet(t *testing.T) { } // TestTheFixRoundCapIsSetBesideThePace is ruling DR1: a run's fix-round cap is -// 3 when nothing sets it, the repository's pace.fix_rounds over the bundled +// 5 when nothing sets it (iss-2612021201375528), the repository's pace.fix_rounds over the bundled // value, --fix-rounds over every layer; the run keeps it in its state and its // record names it; a malformed value is refused naming the accepted form and // writes no state; a resume naming another cap is refused. @@ -64,10 +64,10 @@ func TestTheFixRoundCapIsSetBesideThePace(t *testing.T) { t.Fatal(err) } st, _ := ReadState(repo.Root(), res.RunID) - if f := st.Pace.FixRounds; f.Value != BundledFixRounds || f.Layer != "bundled" || BundledFixRounds != 3 { - t.Fatalf("the bundled cap is 3 fix rounds: %+v", f) + if f := st.Pace.FixRounds; f.Value != BundledFixRounds || f.Layer != "bundled" || BundledFixRounds != 5 { + t.Fatalf("the bundled cap is 5 fix rounds: %+v", f) } - if note := paceRecord(t, st); !strings.Contains(note, "3 fix rounds") { + if note := paceRecord(t, st); !strings.Contains(note, "5 fix rounds") { t.Fatalf("the run record names the cap: %q", note) } }) diff --git a/internal/core/implement/loop/land.go b/internal/core/implement/loop/land.go index 5eb0fe5574..88101ae855 100644 --- a/internal/core/implement/loop/land.go +++ b/internal/core/implement/loop/land.go @@ -461,6 +461,13 @@ func landPrepare(c Context, lane *Lane) (Outcome, error) { for _, r := range lane.Resolves { does = append(does, "resolves "+r.Issue) } + filing, err := capFilingOf(c, *lane) + if err != nil { + return Outcome{}, err + } + if filing != nil { + does = append(does, "files "+filedPhrase(len(filing.findings))+" left below major at the fix-round cap as open issues") + } if len(does) == 0 { // The records commit is made on every lane, so the rule the lane was // admitted under rides it into history (itd-2610301850454860). @@ -539,8 +546,13 @@ func landRecords(c Context, lane *Lane) (Outcome, error) { ld.Records, ld.RecordsDone, lane.HeadSHA = tip, true, tip return Outcome{Stay: true, Note: "found the landing's records commit " + shortSHA(tip) + " on " + lane.Branch}, nil } + // What the lane left at the fix-round cap, filed below as open issues. + filing, err := capFilingOf(c, *lane) + if err != nil { + return Outcome{}, err + } - if why, err := strayChanges(st, *lane); err != nil { + if why, err := strayChanges(st, *lane, filing); err != nil { return Outcome{}, fmt.Errorf("reading the lane's worktree: %w", err) } else if why != "" { return Outcome{}, strayRefusal(*lane, why) @@ -592,10 +604,10 @@ func landRecords(c Context, lane *Lane) (Outcome, error) { } assisted := []string{composedAssistedBy()} composed := true - if ld.Closes || len(lane.Resolves) > 0 || ld.SpecSettled { + if ld.Closes || len(lane.Resolves) > 0 || ld.SpecSettled || filing != nil { composed = false var gap string - if assisted, gap = assistedByTrailers(lane.Receipts); gap != "" { + if assisted, gap = landingAssisted(*lane, filing); gap != "" { return Outcome{}, modelGap(*lane, "the landing's records commit carries text the lane's implementer composed", gap) } } @@ -721,6 +733,20 @@ func landRecords(c Context, lane *Lane) (Outcome, error) { done = append(done, "resolved "+r.Issue+" with "+shortSHA(r.Commit)) } } + if filing != nil { + // Each finding the round left at the cap becomes an open issue, through the + // ledger's capture, in the records this commit carries. + filed, found, err := fileAtCap(st, *lane, filing) + if err != nil { + return Outcome{}, refuse(string(StageLand), "", lane.ID, "`capture` refused a finding left at the fix-round cap in the lane's worktree: "+fsutil.RedactHome(err.Error()), + "settle what the capture store names in the lane's worktree and leave it uncommitted, then run `abcd implement step` again") + } + line := fmt.Sprintf("filed %s left below major at the fix-round cap (round %d at %s) as open issues", filedPhrase(filed+found), filing.round.Round, shortSHA(filing.round.HeadSHA)) + if found > 0 { + line += fmt.Sprintf(", %d of them found filed already", found) + } + done = append(done, line) + } trailers = append(trailers, resolutionTrailers(st, *lane)...) if beforeLandingStage != nil { beforeLandingStage(wt) @@ -750,7 +776,7 @@ func landRecords(c Context, lane *Lane) (Outcome, error) { if err != nil { return Outcome{}, fmt.Errorf("reading the landing's staged records: %w", err) } - if why, err := judgeLandingDiff(wt, st, *lane, raw); err != nil { + if why, err := judgeLandingDiff(wt, st, *lane, raw, filing); err != nil { return Outcome{}, err } else if why != "" { return Outcome{}, strayRefusal(*lane, why) @@ -786,7 +812,7 @@ func landRecords(c Context, lane *Lane) (Outcome, error) { // A mark is abcd's only when this landing writes it. if !only || ld.MarkStep == 0 { var gap string - if assisted, gap = assistedByTrailers(lane.Receipts); gap != "" { + if assisted, gap = landingAssisted(*lane, filing); gap != "" { return Outcome{}, modelGap(*lane, "the landing's records commit carries text abcd did not compose", gap) } done = append(done, "carried what else was left in the lane's worktree") @@ -849,7 +875,11 @@ func refuseNotTheRecords(c Context, lane Lane, tip, which string) error { if err != nil { return fmt.Errorf("reading what %s changes: %w", shortSHA(tip), err) } - if why, err := judgeLandingDiff(c.RepoRoot, st, lane, raw); err != nil { + filing, err := capFilingOf(c, lane) + if err != nil { + return err + } + if why, err := judgeLandingDiff(c.RepoRoot, st, lane, raw, filing); err != nil { return err } else if why != "" { return refuse(string(StageLand), "", lane.ID, shortSHA(tip)+", the commit "+which+" on the judged head "+shortSHA(lane.HeadSHA)+", holds "+why+", and "+strayRule, @@ -858,7 +888,7 @@ func refuseNotTheRecords(c Context, lane Lane, tip, which string) error { if err := refuseFoundCloseRecords(c, lane, tip, which, lane.Landing.Closes); err != nil { return err } - if lacks, err := foundCommitLacks(c, lane, tip, raw); err != nil { + if lacks, err := foundCommitLacks(c, lane, tip, raw, filing); err != nil { return err } else if lacks != "" { return refuse(string(StageLand), "", lane.ID, shortSHA(tip)+", the commit "+which+" on the judged head "+shortSHA(lane.HeadSHA)+", lacks "+lacks+", so it is not the landing's records", @@ -1484,7 +1514,7 @@ func stagedRawArgs(head string) []string { // strayChanges judges the lane's worktree as `git add` would stage it, on a copy of the // lane's index, so the lane's own index and its flags stay as they are and the person's // filters and ignore files read the tree. "" when nothing in it stops the landing. -func strayChanges(st State, lane Lane) (string, error) { +func strayChanges(st State, lane Lane, filing *capFiling) (string, error) { wt := lane.Worktree own, err := pickGit(wt, "rev-parse", "--git-path", "index") if err != nil { @@ -1517,7 +1547,7 @@ func strayChanges(st State, lane Lane) (string, error) { if err != nil { return "", err } - return judgeLandingDiff(wt, st, lane, raw) + return judgeLandingDiff(wt, st, lane, raw, filing) } // parseRawDiff reads git's raw NUL-separated list of changes. @@ -1551,15 +1581,15 @@ func parseRawDiff(raw string) ([]rawEntry, error) { // such resolution is returned as its pair of entries, the record leaving open/ and the // record standing in resolved/, for the caller to hold to what a resolve writes // (resolvedAsWritten). -func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move, []rawEntry, [][2]rawEntry, string, error) { +func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move, []rawEntry, [][2]rawEntry, []rawEntry, string, error) { entries, err := parseRawDiff(raw) if err != nil { - return nil, nil, nil, "", err + return nil, nil, nil, nil, "", err } from, to, left := map[string]string{}, map[string]string{}, map[string]string{} resolvedFrom, resolvedTo := map[string]rawEntry{}, map[string]rawEntry{} var resolutions [][2]rawEntry - var outside []rawEntry + var outside, adds []rawEntry for _, e := range entries { store, bucket, name, ok := storeRecord(e.path) if !ok { @@ -1581,8 +1611,12 @@ func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move resolvedFrom[key] = e case e.status == "A" && bucket == string(capture.StateResolved) && namesIssueRecord(named, name): resolvedTo[key] = e + case e.status == "A" && bucket == string(capture.StateOpen): + // A record new to open/: one the landing files for a finding left at the + // fix-round cap, as the caller judges (filedAdds), unless it moved there. + adds = append(adds, e) default: - return nil, nil, nil, e.path, nil + return nil, nil, nil, nil, e.path, nil } continue } @@ -1593,6 +1627,11 @@ func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move to[key] = e.path } } + for _, e := range adds { + if _, _, name, _ := storeRecord(e.path); left[issueStore.rel+"/"+name] != "" { + return nil, nil, nil, nil, e.path, nil + } + } // A resolution the lane's worktree made is one move: its record leaves open/ and // stands in resolved/, so either half alone is no resolution. The list's order picks // which path a refusal names. @@ -1608,7 +1647,7 @@ func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move case !gone && !came: continue case !gone || !came: - return nil, nil, nil, e.path, nil + return nil, nil, nil, nil, e.path, nil } if _, seen := from[key]; !seen { resolutions = append(resolutions, [2]rawEntry{was, reached}) @@ -1625,7 +1664,7 @@ func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move had = left[store.rel+"/"+name] } if !recordModeHolds(e.newMode, had) { - return nil, nil, nil, e.path, nil + return nil, nil, nil, nil, e.path, nil } } var moves []relink.Move @@ -1634,7 +1673,7 @@ func landingDiff(st State, lane Lane, raw string, named []string) ([]relink.Move moves = append(moves, relink.Move{From: was, To: reached}) } } - return moves, outside, resolutions, "", nil + return moves, outside, resolutions, adds, "", nil } // resolveFields are the frontmatter keys a resolve sets (capture.Resolve): its note, the @@ -1777,18 +1816,25 @@ type rawEntry struct { // head already holds. It says which path fails, "" when none does. Everything it needs is // in the list and the object store, so a call after a refusal or a kill reads the same // answer. -func judgeLandingDiff(repo string, st State, lane Lane, raw string) (string, error) { +func judgeLandingDiff(repo string, st State, lane Lane, raw string, filing *capFiling) (string, error) { named, err := shippedIssues(repo, st, lane) if err != nil { return "", err } - moves, outside, resolutions, odd, err := landingDiff(st, lane, raw, named) + moves, outside, resolutions, adds, odd, err := landingDiff(st, lane, raw, named) if err != nil { return "", err } if odd != "" { return strconv.Quote(termsafe.Sanitize(odd)), nil } + // A record new to open/ is the landing's only as the filing of a finding the lane + // left at the fix-round cap (capdefer.go). + if _, odd, err := filedAdds(repo, filing, adds); err != nil { + return "", err + } else if odd != "" { + return strconv.Quote(termsafe.Sanitize(odd)), nil + } if len(outside) > 0 || len(resolutions) > 0 { standing, err := standingMoves(repo, st, lane) if err != nil { @@ -1829,7 +1875,7 @@ func judgeLandingDiff(repo string, st State, lane Lane, raw string) (string, err // intent's record and the trailers the landing writes. Such a commit is the landing's // records, and any other leaves its close and resolutions unrun. raw is git's list of what // it changes. -func foundCommitLacks(c Context, lane Lane, tip, raw string) (string, error) { +func foundCommitLacks(c Context, lane Lane, tip, raw string, filing *capFiling) (string, error) { st, ld := c.State, lane.Landing // Only a landing that moves no spec record may change no file: one with nothing to // move, or one whose resolutions the branch already held, each checked below. @@ -1907,20 +1953,23 @@ func foundCommitLacks(c Context, lane Lane, tip, raw string) (string, error) { } } } - return foundTrailersLack(c, lane, tip, raw, delivers) + if lacks, err := filingLacks(c.RepoRoot, filing, raw); err != nil || lacks != "" { + return lacks, err + } + return foundTrailersLack(c, lane, tip, raw, delivers, filing) } // foundTrailersLack says which trailers a commit found on the judged head lacks, "" when // the ones it carries are the ones the landing writes: its delivery, each resolution and // its disclosure, which is abcd's only on a commit of the mark alone. -func foundTrailersLack(c Context, lane Lane, tip, raw string, delivers bool) (string, error) { +func foundTrailersLack(c Context, lane Lane, tip, raw string, delivers bool, filing *capFiling) (string, error) { st, ld := c.State, lane.Landing var want []string if delivers { want = append(want, "Delivers: "+st.Intent) } want = append(want, resolutionTrailers(st, lane)...) - composed := !ld.Closes && len(lane.Resolves) == 0 && !ld.SpecSettled + composed := !ld.Closes && len(lane.Resolves) == 0 && !ld.SpecSettled && filing == nil if composed && raw != "" { only, err := rawOnlyTheMark(c.RepoRoot, st.Spec, raw, shortSHA(lane.HeadSHA)) if err != nil { @@ -1932,7 +1981,7 @@ func foundTrailersLack(c Context, lane Lane, tip, raw string, delivers bool) (st if composed { want = append(want, composedAssistedBy()) } else { - assisted, gap := assistedByTrailers(lane.Receipts) + assisted, gap := landingAssisted(lane, filing) if gap != "" { return "a model to disclose: " + gap, nil } @@ -2103,7 +2152,20 @@ func recordsParked(c Context, lane Lane) string { if last.HeadSHA == lane.HeadSHA { return "" } - why, err := landing.RecordsCommitShape(c.RepoRoot, last.HeadSHA, lane.HeadSHA, last.ResolvesShown) + // The records the landing filed for the findings left at the fix-round cap are its + // own, as the resolutions the full round was shown are. + issues := last.ResolvesShown + filing, err := capFilingOf(c, lane) + if err == nil && filing != nil { + var filed []string + if filed, err = filedIDs(c.RepoRoot, filing, last.HeadSHA, lane.HeadSHA); err == nil { + issues = append(slices.Clone(issues), filed...) + } + } + if err != nil { + return termsafe.Sanitize(fsutil.RedactHome(err.Error())) + } + why, err := landing.RecordsCommitShape(c.RepoRoot, last.HeadSHA, lane.HeadSHA, issues) if err != nil { return termsafe.Sanitize(fsutil.RedactHome(err.Error())) } @@ -2614,9 +2676,16 @@ func prBodyParked(st State, lane Lane, assisted []string, parked bool) string { p("- Branch `%s`, from %s to %s.\n", lane.Branch, shortSHA(lane.BaseSHA), shortSHA(lane.HeadSHA)) if n := len(lane.Validation); n > 0 { r := lane.Validation[n-1] - if slices.ContainsFunc(r.Validators, func(v ValidatorRun) bool { return !v.Pass }) { + capped := lane.capRound() + if capped != nil { + p("- Validation round %d at %s did not pass (%s) after the run's fix rounds, and every finding it left is minor or nitpick, so the records commit files each as an open issue and the lane lands.\n", + capped.Round, shortSHA(capped.HeadSHA), verdictsLine(*capped)) + } + switch { + case capped != nil && capped.Round == r.Round: + case slices.ContainsFunc(r.Validators, func(v ValidatorRun) bool { return !v.Pass }): p("- Validation round %d at %s did not pass (%s), so the lane is parked at this pull request for a person.\n", r.Round, shortSHA(r.HeadSHA), verdictsLine(r)) - } else { + default: p("- Validation round %d at %s passed: %s.\n", r.Round, shortSHA(r.HeadSHA), verdictsLine(r)) } for _, v := range r.Validators { @@ -2671,7 +2740,11 @@ func landPullRequest(c Context, lane *Lane) (Outcome, error) { } else if note != "" { return Outcome{Stay: true, Note: note}, nil } - assisted, gap := assistedByTrailers(lane.Receipts) + filing, err := capFilingOf(c, *lane) + if err != nil { + return Outcome{}, err + } + assisted, gap := landingAssisted(*lane, filing) if gap != "" { return Outcome{}, modelGap(*lane, "the pull request's body describes a change carrying text the lane's implementer composed", gap) } diff --git a/internal/core/implement/loop/pace.go b/internal/core/implement/loop/pace.go index a8b0bdd3ce..c6c207c0d9 100644 --- a/internal/core/implement/loop/pace.go +++ b/internal/core/implement/loop/pace.go @@ -32,10 +32,13 @@ const ( BundledSubAgents = 2 ) -// BundledFixRounds is the fix rounds a lane may take before it is handed back -// when nothing sets it (ruling DR1 of 2026-09-29: "tied to the pace settings, a -// per-run value set alongside --pace, default 3"; itd-50 decision 2). -const BundledFixRounds = 3 +// BundledFixRounds is the fix rounds a lane may take before the cap is judged +// when nothing sets it: five, by the product thinker's ruling of 2 December 2026 +// (iss-2612021201375528), which replaced DR1's three of 2026-09-29 (itd-50 +// decision 2) and kept the value per run, beside --pace. At the cap a lane is +// handed back only while a security, major or critical finding stands, and +// otherwise lands with what it leaves filed as open issues (capdefer.go). +const BundledFixRounds = 5 // The accepted ranges. A week bounds the minutes, so the window arithmetic // stays far inside time.Duration and a typed extra digit is refused rather than @@ -143,7 +146,8 @@ func (p Pace) String() string { if p.FixRounds.Layer == "" { return head } - return fmt.Sprintf("%s; %s before a lane is handed back (%s)", head, fixRoundsPhrase(p.FixRounds.Value), describeOrigin(p.FixRounds)) + return fmt.Sprintf("%s; %s, then a lane is handed back only on a security or major finding and otherwise files what is left as issues and lands (%s)", + head, fixRoundsPhrase(p.FixRounds.Value), describeOrigin(p.FixRounds)) } // fixRoundsPhrase is a number of fix rounds in words a reader counts. diff --git a/internal/core/implement/loop/testdata/drain_bundle_one/cap-of-1.golden b/internal/core/implement/loop/testdata/drain_bundle_one/cap-of-1.golden index bf78fe4090..ec4bbc1e43 100644 --- a/internal/core/implement/loop/testdata/drain_bundle_one/cap-of-1.golden +++ b/internal/core/implement/loop/testdata/drain_bundle_one/cap-of-1.golden @@ -103,7 +103,7 @@ drive iss-2609300000000103's lane, run : run `abcd implement step` to take "fix_rounds": { "layer": "bundled", "origin": "bundled", - "value": 3 + "value": 5 }, "pause_minutes": { "layer": "bundled", @@ -151,7 +151,7 @@ drive iss-2609300000000103's lane, run : run `abcd implement step` to take "fix_rounds": { "layer": "bundled", "origin": "bundled", - "value": 3 + "value": 5 }, "pause_minutes": { "layer": "bundled", @@ -179,7 +179,7 @@ drive iss-2609300000000103's lane, run : run `abcd implement step` to take }, { "at": "