From 3540988e3024c53e029ae105da4ca73f8ebd7810 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Thu, 12 Nov 2026 09:52:16 -0500 Subject: [PATCH] CoderHelm finishes the work: one stance in every prompt and message Every model that writes or fixes code now starts from the same stance (passes::ownership::coder_stance): it owns the change, verifies it with the checks it has, fixes what breaks, changes approach when stuck, defers only non-core items with the reason, and stops for a person only for a credential, missing access, a product decision, an ambiguous ticket or an approval. The planner gets the planning version. A coder reply that hands the work back without a listed reason is no longer an ending: the implement pass sends a keep-going note and runs the coder again, and a reply that still changes nothing is a stall that climbs the supervisor's ladder (incident ad). Messages shown to people say what CoderHelm did, what it deferred and why, and what happens next, instead of "handed off for human review", "over to you" or "a person should". A source scan fails on a hand-off phrase in any prompt or message in the worker or common crates. AGENTS.md states the principles for contributors and for CoderHelm when it works on this repository. --- AGENTS.md | 21 ++ docs/incidents.md | 1 + services/common/src/draft_hold.rs | 3 +- services/common/src/security_fixes.rs | 4 +- services/common/src/stop_judge.rs | 7 +- services/worker/src/agent/anthropic.rs | 4 +- services/worker/src/passes/e2e.rs | 6 +- services/worker/src/passes/feedback.rs | 52 +-- services/worker/src/passes/fix_location.rs | 2 +- services/worker/src/passes/health_check.rs | 7 +- services/worker/src/passes/implement.rs | 58 ++- .../passes/incidents/ad_hand_back_reply.rs | 125 +++++++ services/worker/src/passes/incidents/mod.rs | 1 + .../src/passes/incidents/r_github_limit.rs | 4 +- services/worker/src/passes/mod.rs | 13 +- services/worker/src/passes/ownership.rs | 339 ++++++++++++++++++ services/worker/src/passes/plan.rs | 6 +- services/worker/src/passes/pr.rs | 6 +- services/worker/src/passes/proof.rs | 4 +- services/worker/src/passes/ready.rs | 7 +- services/worker/src/passes/resume.rs | 28 +- services/worker/src/passes/review_agent.rs | 2 +- .../worker/src/passes/review_policy_eval.rs | 2 +- services/worker/src/passes/review_pr.rs | 13 +- services/worker/src/passes/review_severity.rs | 4 +- services/worker/src/passes/stop_pr.rs | 2 +- 26 files changed, 641 insertions(+), 80 deletions(-) create mode 100644 AGENTS.md create mode 100644 services/worker/src/passes/incidents/ad_hand_back_reply.rs create mode 100644 services/worker/src/passes/ownership.rs diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..f50ff0ba2 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,21 @@ +# Working on CoderHelm + +Notes for people and coding agents (CoderHelm included) changing this repository. + +## Principles + +CoderHelm is a coding agent. It finishes the work; it never does its best and hands the code back. + +- **Own the outcome.** A run finishes the task, verifies it (builds, tests, the checks the repository has) and fixes what breaks. When it is stuck it changes approach: reads more, traces the cause, tries another way, makes the change smaller. +- **Defer, don't drop.** Only an item that is not core to the task may be deferred, and it is named with the reason. +- **A person is asked only for what only a person has:** a credential, access CoderHelm doesn't have, a product decision the ticket leaves open, a ticket that reads two ways, an approval the team requires (the list is `services/common/src/handback.rs`). The ask is one specific question. +- **Words shown to people say what CoderHelm did, what it deferred and why, and what it does next.** Never "please review", "complete manually", "re-trigger", "a person should", "handed off for human review". +- **Prompts carry the same stance.** Every model that writes or fixes code gets `passes::ownership::coder_stance()`; a prompt never offers the model a way to stop or hand back outside the human-only list. + +`passes::ownership` holds the stance, the hand-off phrases, and a test that fails when a prompt or message in the worker uses one outside its small allowlist. Add to the allowlist only for a human-only case, with a comment saying which. + +## Project + +- Rust workspace at `services/Cargo.toml`: `gateway` (API server), `worker` (pipeline), `common`. +- Before a commit: `cargo fmt`, `cargo clippy --all-targets -- -D warnings`, `cargo test`. +- No `Co-authored-by` trailers in commit messages. diff --git a/docs/incidents.md b/docs/incidents.md index 2577621c6..bccb98177 100644 --- a/docs/incidents.md +++ b/docs/incidents.md @@ -58,6 +58,7 @@ pipeline still calls it there. | aa. `aa_promised_round` | A ticket run's own review requested changes. The run took review fix rounds until its automatic fix budget was spent, handed its pull request over with two of its own review's findings still listed, and finished. The draft was then held every hour for three days on "CoderHelm fixes them in its review rounds", and no round ever ran after the run was done. | A hold never promises CoderHelm work that isn't queued. A finished run's draft held on its own review's findings queues one review fix round for them, once per head, while the run has rounds left (its own review rounds, its automatic fix pushes and its fix cycles), and waits for it ("CoderHelm is fixing N findings from its review"), a wait bounded like every other. With no round left, after the run stopped its rounds itself, or once a round ran on the head and the findings are still there, the hold names what a person does and promises nothing. The security and planned work holds name a person's action too, since nothing runs those again once the run is over. A review of a finished run's pull request leaves its findings to that decision, so they are never fixed twice or outside the run's budget. | | ab. `ab_label_prefix` | A failing-test fix's staging deploy and staging end-to-end checks were skipped on its draft. The reading of why went through the staging workflow line by line and kept every quoted string next to a label test as a label name, so a prefix test (`startsWith(github.event.label.name, 'E2E:')`) became a label named `E2E:`, and a condition that needs the staging label *and* `CI:E2E` read as either one. The staging label was refused, the team's `E2E:*` family let the bare `E2E:` through, and CoderHelm added `CI:E2E` and `E2E:`. Adding a missing label creates it, so the repository got an `E2E:` label that matches no area, and `CI:E2E` alone could never run the job. | A job's `if:` is read as an expression (multi-line blocks included) into the label combinations that run it, with those of the jobs it needs. A prefix or substring test is a pattern, never a label: CoderHelm adds only an existing repository label that satisfies it, the one the team's settings name when several do, and nothing when that isn't one certain label; a family allows `E2E:nav`, never `E2E:`. A label is added only when it alone runs the check, the settings allow it, it isn't a deploy, staging or production label and none is on the pull request; otherwise the hold names the exact real label for a person to add. Labels the old reading added that were a bare prefix or couldn't run their check alone come off when CoderHelm itself put them on, and a bare-prefix repository label GitHub made for that add is deleted when nothing else carries it. | | ac. `ac_partial_and_red_ci` | A Jira run stopped after two steps that changed nothing (the coder twice said the last planned file needed no change, in words the plan check did not know) and a separate salvage path opened "⚠️ Partial", "Closes #0", "ran out of time" and marked it completed; another run's CI fix changed nothing and the run was completed with its pull request marked ready while every check was red. | One path opens a stopped run's pull request (`stop_pr`: ticket line, Not finished with done and left tasks and the recorded reason); no body names issue `#0` (client guard); a planned file the coder says needs no change settles and stays settled across steps; a step after a stalled one takes one task with a different approach; a CI fix that changes nothing tries again with fresh evidence (reporter comments, annotations, rerun on infrastructure failures), then holds the draft with what fails and the run needs a person; `ready::decide` never marks a pull request ready with a failing or running check; a source scan allows `create_pull_request` and `mark_pr_ready` only in their one place each. | +| ad. `ad_hand_back_reply` | A coder ended its step with "I couldn't finish, please complete the remaining tasks manually". Nothing it lacked was a credential, access, a product decision, an ambiguous ticket or an approval; its words alone handed the work to a person. | A model reply that hands the work back for a reason not on the human-only list is not an ending: the implement pass tells the coder to change its approach and runs it again, and a reply that still changes nothing is a step without progress, which climbs the supervisor's ladder (one task, other tools, a re-split, the strongest model, then the stuck task deferred with its reason) until the run finishes with what is done. Only a reply naming something on the list makes a hand-back. Every coder's system prompt carries the same stance (`ownership::coder_stance`), and a source scan fails on a hand-off phrase in any prompt or message (`ownership`). | ## Adding a case diff --git a/services/common/src/draft_hold.rs b/services/common/src/draft_hold.rs index d9ee0ae4b..2ed0bcc22 100644 --- a/services/common/src/draft_hold.rs +++ b/services/common/src/draft_hold.rs @@ -203,8 +203,7 @@ impl DraftHold { .join(" "); match self.kind { Kind::Held if self.ready => format!( - "Finished; {} was marked ready so its checks run, and a person needs to deal \ - with: {reasons}", + "Finished; {} was marked ready so its checks run, and is held on: {reasons}", self.pr_words() ), Kind::Waiting if self.ready => format!( diff --git a/services/common/src/security_fixes.rs b/services/common/src/security_fixes.rs index 72dd983fc..724bcaa19 100644 --- a/services/common/src/security_fixes.rs +++ b/services/common/src/security_fixes.rs @@ -2965,9 +2965,9 @@ pub fn ticket_body_with( if major_in_pr { s.push_str(" A major version is needed: follow its upgrade guide, change every call site of the APIs it changed, and fix the code it breaks so the build, type check and tests pass.\n"); } - s.push_str("4. Before you finish, call run_checks (build, type check, tests). Fix what the upgrade breaks. If a check still fails, never say it passes: write which check fails and why under `### Not fixed` in your description; the pull request then stays a draft.\n"); + s.push_str("4. Before you finish, call run_checks (build, type check, tests). Fix what the upgrade breaks. When a fix doesn't take, change the approach: read the full error, the package's upgrade guide and changelog, and the failing call site, then fix again and run the checks again. If a check still fails after that, never say it passes: write which check fails and why under `### Not fixed` in your description; the pull request then stays a draft.\n"); s.push_str(" Never edit documentation (README, CHANGELOG, docs) for these bumps unless this ticket asks for it: the pull request's description says what changed.\n"); - s.push_str("5. In your description, for each package write `### to ` with the breaking changes you found and how each was handled (file and line), the files you changed for it, and anything a person should look at (behaviour at runtime, configuration, environment).\n"); + s.push_str("5. In your description, for each package write `### to ` with the breaking changes you found and how each was handled (file and line), the files you changed for it, and what you checked for behaviour at runtime, configuration and environment.\n"); s.push_str("\n## Advisories\n"); for f in members { s.push_str(&format!( diff --git a/services/common/src/stop_judge.rs b/services/common/src/stop_judge.rs index f01368ed6..4070fb9a2 100644 --- a/services/common/src/stop_judge.rs +++ b/services/common/src/stop_judge.rs @@ -581,7 +581,8 @@ pub const DEFAULT_DEADLINE_HOURS: u32 = 24; pub const SYSTEM: &str = "You are CoderHelm's stop judge. A step of an automated coding run \ proposes a costly decision: asking a person, stopping or waiting, blocking a pull request, \ -starting another fix cycle, or handing the run off. You see the whole run and decide.\n\n\ +starting another fix cycle, or waiting on a person. CoderHelm finishes the work it is given: \ +it changes approach, defers what is not core with the reason, and ships what is done. You see the whole run and decide.\n\n\ Default to proceed. Decide the most reasonable assumption, proceed with it, and state it in one \ sentence: it is listed as an open item on the pull request, where a person can correct it. \ Uncertainty alone is never a reason to stop. A parse failure, a missing field, a rule that \ @@ -595,7 +596,9 @@ proposed block (request changes) a hold also needs a correctness, security or da and its location; style, naming, suggestions and unconfirmed concerns are notes on an approval. \ For a proposed extra fix cycle, hold means the named blocker is worth one more cycle; proceed \ means deliver what exists with open items. For a run that reached its budget, proceed means \ -deliver the draft with open items; hold means a person must act on the named blocker."; +deliver what is done with the open items named; hold only when the named blocker is something \ +only a person has, as above. A stall, a red check, an error or a spent budget is never a \ +reason to hold: CoderHelm's next approach answers those."; /// The structured answer's schema. pub fn schema() -> Value { diff --git a/services/worker/src/agent/anthropic.rs b/services/worker/src/agent/anthropic.rs index 333c03b46..60176faa7 100644 --- a/services/worker/src/agent/anthropic.rs +++ b/services/worker/src/agent/anthropic.rs @@ -25,7 +25,9 @@ pub const WRAP_UP_NOTE: &str = "[SYSTEM NOTE — DEADLINE] You are almost out of complete, in one call. Never write a stub, placeholder, or half-finished file to 'save \ progress': a partial file breaks the build and is worse than leaving it unwritten (the next \ step picks the task up). Then output a short summary: the tasks you finished, and the tasks \ - still to do. This is your LAST turn."; + still to do, each with where you got to and what you try next. CoderHelm's next step \ + carries them on from there; they are never left for a person. This is your LAST turn \ + in this step."; static ANTHROPIC_VERSION: &str = "2023-06-01"; diff --git a/services/worker/src/passes/e2e.rs b/services/worker/src/passes/e2e.rs index b4faed51c..194e67c50 100644 --- a/services/worker/src/passes/e2e.rs +++ b/services/worker/src/passes/e2e.rs @@ -823,7 +823,7 @@ async fn own_pr_failures( ) .await; let body = format!( - "These E2E failures may come from this change, but Coderhelm has used its automatic fix attempts on this PR, so it's over to you:\n\n{}", + "These E2E failures may come from this change. CoderHelm has used the automatic fix rounds this PR has, so it doesn't start another on its own; a comment naming a change starts the next one right away:\n\n{}", caused.iter().map(|l| format!("- {}", l.text)).collect::>().join("\n") ); let _ = gh @@ -920,7 +920,7 @@ async fn own_pr_failures( } } } else { - format!("The E2E failures are still there after a re-run, for reasons outside this change:\n\n{items}\n\nLeaving this for a person to decide.") + format!("The E2E failures are still there after a re-run, for reasons outside this change:\n\n{items}\n\nThey don't come from this change, so CoderHelm doesn't change this pull request's code for them; its own work is done.") }; if gh .create_issue_comment(&msg.repo_owner, &msg.repo_name, pr, &body) @@ -2037,7 +2037,7 @@ async fn follow_generated( _ => { if let Some(pr) = run.pr { let _ = gh - .create_issue_comment(&msg.repo_owner, &msg.repo_name, pr, &format!("Coderhelm couldn't run the new test {GENERATED_RUNS} times automatically (the E2E workflow has no repeat input, or the new test wasn't in this run). Please run it repeatedly before marking this ready.")) + .create_issue_comment(&msg.repo_owner, &msg.repo_name, pr, &format!("CoderHelm couldn't run the new test {GENERATED_RUNS} times: the E2E workflow has no repeat input, or the new test wasn't in this run. Its one passing run is the evidence so far; a `repeat` input on the E2E workflow lets CoderHelm run it {GENERATED_RUNS} times itself.")) .await; } } diff --git a/services/worker/src/passes/feedback.rs b/services/worker/src/passes/feedback.rs index 5c0ec7aff..a6017258f 100644 --- a/services/worker/src/passes/feedback.rs +++ b/services/worker/src/passes/feedback.rs @@ -473,7 +473,7 @@ pub async fn run( && msg.review_body.trim().is_empty() && !super::claim_auto_fix_slot(state, &msg.team_id, &msg.run_id).await { - hand_off_to_human(state, &github, &msg).await; + end_auto_fix_rounds(state, &github, &msg).await; return Ok(()); } // A person asked for this: the run guard's counts start over. A cycle only @@ -597,9 +597,10 @@ pub async fn run( ) .await; let system = format!( - "You are a feedback agent for the {owner}/{repo} repository. \ - You respond to reviewer comments on pull requests by reading and writing files \ - directly to the PR branch. \ + "You are the engineer answering reviewer comments on a pull request in the \ + {owner}/{repo} repository, by reading and writing files directly to the PR branch. \ + {stance}Every change a comment asks for is made, checked and working when you \ + finish; a reply says what you did and what you checked. \ If a comment requests a code change, commit it — use edit_file for targeted edits \ (the default, and the ONLY safe option for a few lines in a large file), and write_file \ or batch_write only for new files or whole-file rewrites — then confirm briefly. \ @@ -615,6 +616,7 @@ pub async fn run( Your output is posted directly as a GitHub comment — write natural replies, no meta-commentary.{voice_block}{team_block}{tests_block}{logs_block}{memory_block}", logs_block = super::review_fix::logs::GUIDANCE, memory_block = repo_memory.text, + stance = super::ownership::coder_stance(), owner = msg.repo_owner, repo = msg.repo_name, ); @@ -3106,7 +3108,7 @@ async fn handle_wrong_repo( }); if state.config.ticket_queue_url.is_empty() { - warn!("TICKET_QUEUE_URL not configured — cannot re-trigger in new repo"); + warn!("TICKET_QUEUE_URL not configured — cannot start the run in the new repo"); return Ok(()); } @@ -3158,7 +3160,7 @@ async fn handle_wrong_repo( from = %format!("{}/{}", msg.repo_owner, msg.repo_name), to = %target_repo, ticket_id = %ticket_id, - "Wrong-repo: closed PR and re-triggered in correct repo" + "Wrong-repo: closed PR and started the run in the correct repo" ); Ok(()) @@ -3495,7 +3497,7 @@ const CANCEL_PR_CLOSED_BY_HUMAN: &str = "pr_closed_by_human"; /// Whether the run has been cancelled (consistent read — cancel must win /// against a racing pass). -/// Hand a PR to a human after the automated-fix budget is spent. +/// End the automated CI fix rounds on a PR once their budget is spent. /// /// Ordering matters for crash-safety. The RELIABLE, idempotent signals run /// first — mark the PR ready and finalize the run (cancel-guarded, clearing the @@ -3505,7 +3507,7 @@ const CANCEL_PR_CLOSED_BY_HUMAN: &str = "pr_closed_by_human"; /// `handoff_notified` marker so repeated webhooks on the now-finalized run don't /// spam the PR. If the comment is lost to a crash, the PR is already marked /// ready — the worst case is a missing comment, never a stuck draft. -async fn hand_off_to_human(state: &WorkerState, github: &GitHubClient, msg: &FeedbackMessage) { +async fn end_auto_fix_rounds(state: &WorkerState, github: &GitHubClient, msg: &FeedbackMessage) { use aws_sdk_dynamodb::types::AttributeValue; // Respect a cancel (best-effort early out; the status write below is also @@ -3578,28 +3580,28 @@ async fn hand_off_to_human(state: &WorkerState, github: &GitHubClient, msg: &Fee .await .is_ok(); if first_notify { - warn!(run_id = %msg.run_id, "Auto-fix budget spent — handed PR to human"); - super::add_progress_note( - state, - &msg.team_id, - &msg.run_id, - "Reached the automated-fix limit without getting CI green — handed off for human review.", - ) - .await; + warn!(run_id = %msg.run_id, "Auto-fix budget spent: CI fix rounds stop on this pull request"); + let note = auto_fix_spent_note(); + super::add_progress_note(state, &msg.team_id, &msg.run_id, ¬e).await; let _ = github - .create_issue_comment( - &msg.repo_owner, - &msg.repo_name, - msg.pr_number, - "🤝 CoderHelm hit its automated-fix limit on this PR without getting CI green, so \ - it's handed off for human review. If this needs generated files (e.g. Sanity \ - types) regenerated, that step has to be run locally — the sandbox can't run \ - codegen that needs project configuration.", - ) + .create_issue_comment(&msg.repo_owner, &msg.repo_name, msg.pr_number, ¬e) .await; } } +/// What CoderHelm says when its CI fix rounds on a pull request are spent: +/// what it did, where the pull request stands, and what starts the next +/// round. Never a hand-off. +fn auto_fix_spent_note() -> String { + format!( + "CoderHelm ran {} fix rounds on this pull request's CI and it is still red; the failing \ + checks are listed on the pull request, which stays held until they pass. CoderHelm \ + stops starting rounds on its own here so the pull request doesn't loop, and a comment \ + naming a change starts the next round right away.", + super::MAX_AUTO_FIX_PUSHES + ) +} + /// A person ended the run (cancelled or closed it): no feedback runs on it. async fn run_is_cancelled(state: &WorkerState, team_id: &str, run_id: &str) -> bool { state diff --git a/services/worker/src/passes/fix_location.rs b/services/worker/src/passes/fix_location.rs index 41e806c97..ad0abdf64 100644 --- a/services/worker/src/passes/fix_location.rs +++ b/services/worker/src/passes/fix_location.rs @@ -1070,7 +1070,7 @@ Before writing tasks, decide whether the fix belongs in this code at all. - Plan logs at the right level: INFO only for actual changes and decisions, DEBUG for diagnostics, and never an INFO line per record on a scheduled job. - Count the records whose result your change alters beyond the ticket's (with a query against the real data), and name a few of them. A fix that is right for the ticket and wrong for others is not a fix; narrow it until those others are unchanged or are meant to change. - Before your first query on a table, read its columns (describe it); don't guess column names from other tables' conventions. -- Never name a cause in a system you couldn't read. If the trace through what you can read is complete and leads into another system, say so with that trace. If you couldn't finish the trace, use `unknown`, say where it stopped, and list the next lookups a person should make, without a likely culprit. +- Never name a cause in a system you couldn't read. If the trace through what you can read is complete and leads into another system, say so with that trace. If you couldn't finish the trace, use `unknown`, say where it stopped, and list the next lookups that would finish it, without a likely culprit. - If the code behaves as designed and the outcome comes from data or configuration in a source system (a booking or scheduling system, a CMS, a ticket tool's configuration, a feature flag held in another system, a cloud console setting), the fix is a change in that system, not in this code. Set `fix_location` to `outside_code`, describe the exact change, and set tasks.md to `NO_CODE_CHANGE: `. - Never override source data in code: no hardcoded record ids, allowlists, denylists or "force" lists that change behavior for specific records the source system already decides. That hides the cause and goes stale. If that is the only way you see to make the ticket's symptom go away, the fix is outside the code. - If a code change is needed AND a change in another system, use `both`: plan the code part normally and describe the outside change. diff --git a/services/worker/src/passes/health_check.rs b/services/worker/src/passes/health_check.rs index 919f9ae8f..991489d05 100644 --- a/services/worker/src/passes/health_check.rs +++ b/services/worker/src/passes/health_check.rs @@ -510,7 +510,8 @@ pub fn render(merge_sha: &str, verdict: &Verdict, follows: &[Follow]) -> String Verdict::Failed(jobs) => format!( "🔴 **Post-merge health check FAILED**: the merge of `{sha}` has NEW failing \ check(s) that were not failing before the merge:\n\n{}\n\nFailures that were \ - already there before the merge were ignored. A person should decide on a rollback.", + already there before the merge were ignored. Rolling a deploy back needs the \ + approval of whoever owns it: should `{sha}` be rolled back?", jobs.iter().map(job_line).collect::>().join("\n") ), Verdict::StillRunning(jobs) => format!( @@ -549,8 +550,8 @@ pub fn render_interim( format!( "🔴 **Post-merge health check FAILED**: the merge of `{sha}` has NEW failing \ check(s) that were not failing before the merge:\n\n{}\n\nFailures that were \ - already there before the merge were ignored. A person should decide on a \ - rollback.\n\nStill to come:\n\n{waits}\n\nI'll update this comment once it is \ + already there before the merge were ignored. Rolling a deploy back needs the \ + approval of whoever owns it: should `{sha}` be rolled back?\n\nStill to come:\n\n{waits}\n\nI'll update this comment once it is \ approved and finishes.", failed.iter().map(job_line).collect::>().join("\n") ) diff --git a/services/worker/src/passes/implement.rs b/services/worker/src/passes/implement.rs index d924a869f..80846d527 100644 --- a/services/worker/src/passes/implement.rs +++ b/services/worker/src/passes/implement.rs @@ -1060,6 +1060,56 @@ pub async fn run( } } + // Gate: a closing reply that hands the work back to a person ("I couldn't + // finish, please complete manually") for a reason not on the human-only + // list is not an ending. The coder is told to change its approach and + // keep going, once in this pass; a reply that still changes nothing is a + // step without progress, which climbs the supervisor's ladder. + if let Some(note) = super::ownership::escalation_note(&closing) { + warn!( + run_id = run_id.unwrap_or("?"), + "The coder's reply handed the work back with no human-only reason: it keeps going" + ); + messages.push(( + "user".to_string(), + vec![serde_json::json!({"type": "text", "text": note})], + )); + let opts = llm::ConverseOptions { + max_turns: 20, + max_tokens: 16384, + deadline, + effort: None, + }; + match provider::converse( + state, + provider, + common::agent_policy::Agent::Coder, + model_id, + &full_system, + &mut messages, + &tools, + &executor, + usage, + opts, + on_tool.as_ref().map(|o| o as &dyn llm::LoopObserver), + Some(&mut conv_log), + ) + .await + { + Ok(reply) if !reply.trim().is_empty() => closing = reply, + Ok(_) => {} + Err(e) => { + if crate::clients::github::outside_wait(&*e).is_some() { + return Err(e); + } + warn!(error = %e, "The keep-going pass errored — proceeding with current state"); + } + } + if let Some(s) = &skills { + s.drain_usage_into(usage); + } + } + let files: Vec = executor .write_executor .files_modified @@ -1183,8 +1233,10 @@ pub(crate) fn coder_system( tests_block: &str, ) -> String { format!( - "You are an implementation agent for the {owner}/{repo} repository. \ - Implement each task from the checklist. Follow existing code patterns exactly.{repo_context}{team}{tests_block}", + "You are the implementation engineer for the {owner}/{repo} repository. \ + {stance}Implement every task from the checklist and see it through: the change \ + written, checked and working. Follow existing code patterns exactly.{repo_context}{team}{tests_block}", + stance = super::ownership::coder_stance(), team = super::team_instructions_block(team_instructions), ) } @@ -3513,6 +3565,8 @@ mod task_prompt_tests { assert!(with.find("## Repository Instructions") < with.find("## Your team's instructions")); let without = coder_system("acme", "web", "", " \n", ""); assert!(!without.contains("team's instructions")); + // Every coder owns the outcome, with the human-only list as its only stop. + assert!(without.contains(&super::super::ownership::coder_stance())); } } diff --git a/services/worker/src/passes/incidents/ad_hand_back_reply.rs b/services/worker/src/passes/incidents/ad_hand_back_reply.rs new file mode 100644 index 000000000..ea2dec7f3 --- /dev/null +++ b/services/worker/src/passes/incidents/ad_hand_back_reply.rs @@ -0,0 +1,125 @@ +//! ad. A coder ended its step with "I couldn't finish, please complete the +//! remaining tasks manually." Nothing it lacked was a credential, access, a +//! product decision, an ambiguous ticket or an approval: the words alone +//! handed the work to a person. +//! +//! Guarantee: a model reply that hands the work back for a reason not on +//! the human-only list is not an ending. The coder is told to change its +//! approach in the same pass; a reply that still changes nothing is a step +//! without progress, which climbs the supervisor's ladder (one task, other +//! tools, a re-split, the strongest model, then the stuck task deferred +//! with its reason) and the run finishes with what is done. Only a reply +//! naming something on the list can make a hand-back. + +use crate::passes::{ownership, steps, supervisor}; +use common::handback::{human_only_in, HandBack, HumanOnly}; + +const REPLY: &str = "I couldn't finish: tasks 3 and 4 are left. Please complete the remaining \ + tasks manually, or re-trigger the run."; + +/// The ending a run with `done` of `total` planned tasks reaches after the +/// coder's `reply`, every attempt from here changing nothing (the worst +/// case): what the supervisor decides from the reply's words and the steps' +/// progress marks. +fn ending_after(reply: &str, done: u32, total: u32) -> (Vec, supervisor::Ending) { + let open: Vec = (done + 1..=total).map(|i| format!("task {i}")).collect(); + // The reply's words are a blocker only when they name a listed reason. + let blocker = human_only_in(reply).and_then(|why| HandBack::new(why, reply)); + let mut facts = supervisor::EndFacts { + open_tasks: open.clone(), + has_work: done > 0, + blocker, + ..Default::default() + }; + let mut rungs = Vec::new(); + if facts.blocker.is_none() { + // The branch didn't move: each step after the reply is a stall. + let mark = steps::progress_mark("a8c8814", "implement"); + let mut prev = Some(mark.clone()); + let mut stalled = 0; + for _ in 0..12 { + stalled = steps::stalled_after(prev.as_deref(), &mark, stalled); + prev = Some(mark.clone()); + let rung = supervisor::next_rung(stalled, true); + rungs.push(rung); + let e = supervisor::decide_end(&facts); + assert_eq!( + e, + supervisor::Ending::KeepGoing, + "ended before the ladder: {rungs:?}" + ); + if matches!(rung, supervisor::Rung::Defer | supervisor::Rung::Ship) { + break; + } + } + // The stuck tasks are deferred with their reason; the ladder is spent. + facts.deferred = facts + .open_tasks + .drain(..) + .map(|t| supervisor::defer_reason(stalled, &t, true)) + .collect(); + facts.ladder_spent = true; + } + (rungs, supervisor::end(&facts)) +} + +#[test] +fn a_reply_that_hands_back_is_no_progress_and_climbs_the_ladder() { + assert!(ownership::hands_back_without_reason(REPLY)); + // The same pass tells the coder to change its approach. + let note = ownership::escalation_note(REPLY).expect("a keep-going note"); + assert!(note.contains("different approach") && note.contains("run_checks")); + for phrase in ownership::HAND_OFF_PHRASES { + assert!( + !note.to_lowercase().contains(phrase), + "the note itself says {phrase:?}" + ); + } + + let (rungs, end) = ending_after(REPLY, 2, 4); + // Every rung changes the approach before anything is deferred. + assert_eq!(rungs[0], supervisor::Rung::Narrow, "{rungs:?}"); + for r in [ + supervisor::Rung::SwitchTools, + supervisor::Rung::Resplit, + supervisor::Rung::Escalate, + ] { + assert!(rungs.contains(&r), "{r:?} missing from {rungs:?}"); + } + // The run finishes with what is done, never as a wait on a person. + match &end { + supervisor::Ending::Finished { deferred } => assert_eq!(deferred.len(), 2, "{deferred:?}"), + other => panic!("ended as {other:?}"), + } + assert_ne!(end.status(), common::run_status::NEEDS_INPUT); +} + +#[test] +fn only_a_reply_naming_a_human_only_reason_hands_back() { + let reply = "I couldn't finish: the payments client needs the API key for the payments \ + sandbox, which isn't in the repository's secrets."; + assert!(!ownership::hands_back_without_reason(reply)); + assert!(ownership::escalation_note(reply).is_none()); + let (rungs, end) = ending_after(reply, 2, 4); + assert!(rungs.is_empty()); + match end { + supervisor::Ending::HandBack(h) => assert_eq!(h.why(), HumanOnly::Credential), + other => panic!("ended as {other:?}"), + } +} + +#[test] +fn the_implement_pass_answers_a_hand_back_reply_before_it_returns() { + let src = include_str!("../implement.rs"); + let gate = src + .find("super::ownership::escalation_note(&closing)") + .expect("the implement pass reads its closing reply for a hand-back"); + let returns = src[gate..] + .find("Ok(ImplementResult {") + .expect("the pass returns after the gate"); + // The note goes to the coder and the coder runs again, before the + // result (and its notes) leave the pass. + let between = &src[gate..gate + returns]; + assert!(between.contains("messages.push(")); + assert!(between.contains("provider::converse(")); +} diff --git a/services/worker/src/passes/incidents/mod.rs b/services/worker/src/passes/incidents/mod.rs index d2963fb35..7cdae5f99 100644 --- a/services/worker/src/passes/incidents/mod.rs +++ b/services/worker/src/passes/incidents/mod.rs @@ -19,6 +19,7 @@ mod a_whole_branch; mod aa_promised_round; mod ab_label_prefix; mod ac_partial_and_red_ci; +mod ad_hand_back_reply; mod b_open_pr_retry; mod c_codegen_egress; mod d_echoed_markers; diff --git a/services/worker/src/passes/incidents/r_github_limit.rs b/services/worker/src/passes/incidents/r_github_limit.rs index 6039567b1..68be2a7ef 100644 --- a/services/worker/src/passes/incidents/r_github_limit.rs +++ b/services/worker/src/passes/incidents/r_github_limit.rs @@ -127,8 +127,8 @@ fn the_pipeline_pauses_at_each_place_github_can_refuse() { implement .matches("if crate::clients::github::outside_wait(&*e).is_some() {") .count(), - 2, - "the remediation rounds don't swallow a pause" + 3, + "the remediation and keep-going rounds don't swallow a pause" ); let rp = run_passes_src(); diff --git a/services/worker/src/passes/mod.rs b/services/worker/src/passes/mod.rs index 854ed5d43..53bb4d0fd 100644 --- a/services/worker/src/passes/mod.rs +++ b/services/worker/src/passes/mod.rs @@ -1112,6 +1112,7 @@ pub mod outcome; pub mod outside_exec; pub mod outside_work; pub mod own_review; +pub mod ownership; mod plan; pub mod plan_chat; pub(crate) mod plan_coverage; @@ -5505,13 +5506,13 @@ async fn run_passes( msg.repo_name ) }); - let raw_clarification = elsewhere_note.as_deref().unwrap_or("I ran but produced no file changes for this issue.\n\n\ - If the issue already spells out the change (the exact file(s) and the values/content \ - to write), this is usually a transient miss on my side — **re-run it** and it \ - typically goes through.\n\n\ - If details are actually missing, add them and re-trigger — for example:\n\ + let raw_clarification = elsewhere_note.as_deref().unwrap_or( + "I made no file changes for this ticket, after a second attempt with a different \ + approach: the ticket doesn't say what to change in a way I can act on. One answer \ + lets me finish it:\n\ - Which file(s) or component(s) should change?\n\ - - The expected vs. current behavior, or the exact values/content to use?"); + - The expected vs. current behavior, or the exact values/content to use?", + ); let clarification = formatter::format_with_voice(state, &voice, raw_clarification, &provider, usage) .await; diff --git a/services/worker/src/passes/ownership.rs b/services/worker/src/passes/ownership.rs new file mode 100644 index 000000000..19433d62c --- /dev/null +++ b/services/worker/src/passes/ownership.rs @@ -0,0 +1,339 @@ +//! CoderHelm finishes the work. +//! +//! CoderHelm is a coding agent, not an agent that does its best and hands +//! the code back. Every model that writes or fixes code is told so in the +//! same words ([`CODER`], [`PLANNER`]), and every sentence CoderHelm shows a +//! person says what it did, what it deferred and why, and what it does next. +//! A person is asked for something only when only a person has it: the +//! human-only list in `common::handback`. +//! +//! The test at the bottom reads the worker's sources and fails when a prompt +//! or a message shown to people hands work back with one of +//! [`HAND_OFF_PHRASES`], outside the few human-only places on its allowlist. + +/// The human-only reasons, in the words the prompts use. A model may stop +/// for a person only for one of these. +pub const HUMAN_ONLY_WORDS: &str = "a credential or secret only a person can provide, access \ + CoderHelm doesn't have, a product decision the ticket leaves open, a ticket that reads two \ + ways that lead to different code, or an approval the team requires"; + +/// The stance of every model that writes or fixes code: the implementer, the +/// CI and test fixers, the review and feedback fixers, the log, alert and +/// security fixes. Goes at the top of their system prompt. +pub const CODER: &str = "You are the engineer who owns this change until it is done. CoderHelm \ + is a coding agent: the work is finished here, not handed back.\n\ + - Finish the task: every part of it, as working code.\n\ + - Verify it: run the checks you have (run_checks when it is offered, the build, the \ + tests) on what you changed and read their output.\n\ + - When a check fails, fix it. When you are stuck, change the approach: read more of the \ + code, trace the failure to its cause, try another way, make the change smaller.\n\ + - Defer only an item that is not core to the task, and name it with the reason.\n\ + - Never ask a person to do work you can do, and never end with \"please review\", \ + \"complete manually\", \"re-trigger\" or \"a person should\".\n\ + - Stop for a person only for what only a person has: "; + +/// The planner's stance: plan the whole job so it can be finished. +pub const PLANNER: &str = "You plan work that CoderHelm, a coding agent, finishes itself: \ + plan every part of the job, including how it is verified, never a partial plan for a \ + person to complete. Ask a person only for what only a person has: "; + +/// [`CODER`] with the human-only list, as it goes in a system prompt. +pub fn coder_stance() -> String { + format!("{CODER}{HUMAN_ONLY_WORDS}. Then ask one specific question about it.\n\n") +} + +/// [`PLANNER`] with the human-only list, as it goes in a system prompt. +pub fn planner_stance() -> String { + format!("{PLANNER}{HUMAN_ONLY_WORDS}.\n\n") +} + +/// Phrases that hand work back to a person. None may appear in a prompt or +/// a message CoderHelm writes, outside [`ALLOWED`]. +pub const HAND_OFF_PHRASES: &[&str] = &[ + "please review", + "please complete", + "complete manually", + "manually complete", + "complete the remaining", + "finish it manually", + "finish manually", + "finish the work by hand", + "finish it by hand", + "do it manually", + "re-trigger", + "retrigger", + "human review", + "for a human", + "a person should", + "needs a human", + "someone should", + "handed off", + "handing it off", + "hand it off", + "over to you", + "take it from here", + "take over from here", + "do your best", + "best effort attempt", + "if you can't, say so and stop", + "if you cannot, say so and stop", +]; + +/// How a model's reply gives the work up, besides [`HAND_OFF_PHRASES`]. +const GIVE_UP_PHRASES: &[&str] = &[ + "couldn't finish", + "could not finish", + "couldn't complete", + "could not complete", + "unable to finish", + "unable to complete", + "manually", + "for you to finish", + "for you to complete", + "left for you", + "you'll need to finish", + "you will need to finish", + "a person needs to", + "someone needs to", +]; + +/// Whether a model's reply hands the work back to a person for a reason +/// that is not on the human-only list (`common::handback`). A reply that +/// names a credential, missing access, a product decision, an ambiguous +/// ticket or an approval is a stop the stop judge weighs; anything else is +/// no progress, and the work goes on. +pub fn hands_back_without_reason(reply: &str) -> bool { + let t = reply.to_lowercase(); + let gives_up = HAND_OFF_PHRASES + .iter() + .chain(GIVE_UP_PHRASES) + .any(|p| t.contains(p)); + gives_up && common::handback::human_only_in(reply).is_none() +} + +/// What the coder is told when its reply hands the work back without a +/// human-only reason: change approach and keep going. `None` for any other +/// reply. +pub fn escalation_note(reply: &str) -> Option { + hands_back_without_reason(reply).then(|| { + format!( + "[SYSTEM NOTE] Your reply hands the work back to a person, and none of the reasons \ + that allows applies ({HUMAN_ONLY_WORDS}). CoderHelm finishes the work. Keep going \ + with a different approach: read the failing part and the code around it again, \ + trace the error to its cause, try another way, or make the change smaller, and \ + call run_checks when it is offered. Defer only an item that is not core to the \ + task, naming it with the reason. End with what you did and what you checked." + ) + }) +} + +/// The places a phrase may stay, as (file under `src/`, text around the +/// phrase). Each is a human-only case or not a hand-off at all. +#[cfg(test)] +pub const ALLOWED: &[(&str, &str)] = &[ + // The list itself, and the stance that forbids the phrases. + ("passes/ownership.rs", ""), +]; + +#[cfg(test)] +mod tests { + use super::*; + use std::path::{Path, PathBuf}; + + fn sources(dir: &Path, out: &mut Vec) { + for e in std::fs::read_dir(dir).unwrap() { + let p = e.unwrap().path(); + if p.is_dir() { + // The incident and replay suites quote old failure messages + // on purpose, to prove they never come back. + let name = p.file_name().unwrap().to_string_lossy().to_string(); + if name != "incidents" && name != "replay" { + sources(&p, out); + } + } else if p.extension().is_some_and(|x| x == "rs") { + out.push(p); + } + } + } + + /// The code of a file without its comments or test module, with Rust's + /// string line continuations joined, lowercased: what a prompt or a + /// message would say. + pub(super) fn said(src: &str) -> String { + let mut code = String::new(); + let lines: Vec<&str> = src.lines().collect(); + let mut i = 0; + while i < lines.len() { + let line = lines[i]; + let t = line.trim_start(); + // A test module, to its closing brace at the same indent + // (rustfmt's layout): tests quote phrases to prove they're gone. + if t == "#[cfg(test)]" { + if let Some(next) = lines.get(i + 1) { + let n = next.trim_start(); + if n.starts_with("mod ") && n.ends_with('{') { + let close = format!("{}}}", &next[..next.len() - n.len()]); + i += 2; + while i < lines.len() && lines[i] != close { + i += 1; + } + i += 1; + continue; + } + } + } + i += 1; + if t.starts_with("//") { + continue; + } + code.push_str(line); + code.push('\n'); + } + let mut out = String::new(); + let mut chars = code.chars().peekable(); + while let Some(c) = chars.next() { + if c == '\\' && chars.peek() == Some(&'\n') { + chars.next(); + while chars.peek().is_some_and(|c| c.is_whitespace()) { + chars.next(); + } + continue; + } + out.push(c); + } + out.split_whitespace() + .collect::>() + .join(" ") + .to_lowercase() + } + + fn allowed(file: &str, around: &str) -> bool { + ALLOWED + .iter() + .any(|(f, ctx)| *f == file && around.contains(&ctx.to_lowercase())) + } + + /// Every hand-off phrase in the worker's prompts and messages, as + /// `file: text around it`. + fn hand_offs() -> Vec { + // The worker's sources, and the shared crate's (some prompts and + // messages are built there), as `common/...`. + let worker = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src"); + let common = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../common/src"); + let mut files = Vec::new(); + sources(&worker, &mut files); + let n_worker = files.len(); + sources(&common, &mut files); + let mut found = Vec::new(); + for (i, f) in files.into_iter().enumerate() { + let rel = if i < n_worker { + f.strip_prefix(&worker) + .unwrap() + .to_string_lossy() + .to_string() + } else { + format!( + "common/{}", + f.strip_prefix(&common).unwrap().to_string_lossy() + ) + } + .replace('\\', "/"); + let text = said(&std::fs::read_to_string(&f).unwrap()); + for phrase in HAND_OFF_PHRASES { + let mut from = 0; + while let Some(i) = text[from..].find(phrase) { + let at = from + i; + let lo = text[..at] + .char_indices() + .rev() + .nth(60) + .map_or(0, |(i, _)| i); + let hi = text[at..] + .char_indices() + .nth(phrase.len() + 60) + .map_or(text.len(), |(i, _)| at + i); + let around = &text[lo..hi]; + if !allowed(&rel, around) { + found.push(format!("{rel}: …{around}…")); + } + from = at + phrase.len(); + } + } + } + found + } + + #[test] + fn no_prompt_or_message_hands_work_back() { + let found = hand_offs(); + assert!( + found.is_empty(), + "CoderHelm finishes the work: say what was done, what was deferred and why, and \ + what happens next, or ask one question for a human-only reason \ + (`common::handback`). Hand-off phrases found:\n{}", + found.join("\n") + ); + } + + #[test] + fn the_scan_sees_through_continuations_and_skips_comments() { + let src = "// a person should look\nconst A: &str = \"CI is red, handed \\\n off for human \\\n review\";\n#[cfg(test)]\nmod tests {\n const B: &str = \"over to you\";\n}\nconst C: &str = \"please complete it\";\n"; + let s = said(src); + assert!(s.contains("handed off for human review")); + assert!(!s.contains("a person should")); + assert!(!s.contains("over to you")); + // Code after an early test module is still read. + assert!(s.contains("please complete it")); + } + + #[test] + fn every_allowed_place_still_exists() { + // An allowlist entry for text that is gone would hide the next one. + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src"); + for (file, ctx) in ALLOWED { + let text = said(&std::fs::read_to_string(root.join(file)).unwrap()); + assert!( + text.contains(&ctx.to_lowercase()), + "stale allowlist entry: {file}: {ctx}" + ); + } + } + + #[test] + fn a_reply_that_gives_up_without_a_listed_reason_keeps_going() { + for reply in [ + "I couldn't finish, please complete manually.", + "Tasks 3 and 4 are left for you to finish.", + "The migration needs to be applied manually.", + "I'm handing it off: a person should look at the failing test.", + ] { + assert!(hands_back_without_reason(reply), "{reply}"); + assert!(escalation_note(reply) + .unwrap() + .contains("different approach")); + } + // A human-only reason is the stop judge's to weigh, not a give-up. + assert!(!hands_back_without_reason( + "I couldn't finish: it needs the API key for the payments sandbox." + )); + // A finished reply is not a hand-back. + assert!(escalation_note("Updated `src/a.rs`; run_checks passes.").is_none()); + } + + #[test] + fn the_stance_names_the_human_only_reasons_and_no_escape_hatch() { + let s = coder_stance(); + for w in [ + "credential", + "access", + "product decision", + "reads two ways", + "approval", + ] { + assert!(s.contains(w), "{w}"); + } + assert!(s.contains("change the approach")); + assert!(s.contains("run_checks")); + assert!(planner_stance().contains("product decision")); + } +} diff --git a/services/worker/src/passes/plan.rs b/services/worker/src/passes/plan.rs index cf0d00369..b4514c15d 100644 --- a/services/worker/src/passes/plan.rs +++ b/services/worker/src/passes/plan.rs @@ -203,13 +203,15 @@ pub async fn run( "" }; let system = format!( - "You are a planning agent for the {owner}/{repo} repository. \ - Research the codebase using the provided tools, then generate an implementation plan.\n\n\ + "You are the planning engineer for the {owner}/{repo} repository. {stance}\ + Research the codebase using the provided tools, then generate an implementation plan \ + that CoderHelm carries out to the end, verification included.\n\n\ You have access to these repos:\n{repos_list}\n\n\ All tools default to {owner}/{repo} when the `repo` parameter is omitted. \ To explore another repo, pass `repo` as `owner/name` (e.g. `\"{default_repo}\"`).{cross_repo}{instructions_block}{team_block}{tests_block}{feature_block}", owner = msg.repo_owner, repo = msg.repo_name, + stance = super::ownership::planner_stance(), feature_block = super::feature::planner_block(intent), cross_repo = if team_repos.len() > 1 { super::cross_repo::PLANNER_LINE diff --git a/services/worker/src/passes/pr.rs b/services/worker/src/passes/pr.rs index 05c2a30e7..e7d20c639 100644 --- a/services/worker/src/passes/pr.rs +++ b/services/worker/src/passes/pr.rs @@ -179,7 +179,7 @@ the change copies, the merge order of a multi-repo change, **Not in this PR** an Don't write them, and don't add a warning or note banner anywhere. - Verification says the change works only where its real output (the real API response or page) \ was checked and shows it. A matching filter or a passing test is not that; otherwise write \ -**Unproven** and the exact check a person should run. +**Unproven**, the exact check that proves it, and why CoderHelm could not run it. - Write real values: every path, name and id in full, with its environment filled in \ (`/app/prod/db-password`, never `/app//db-password`), never a template left as `${env}`, ``, \ `{}` or empty backticks. @@ -2262,7 +2262,9 @@ mod refresh_tests { let rules = super::SHAPE_RULES; assert!(rules.contains("real output (the real API response or page)")); assert!(rules.contains("A matching filter or a passing test is not that")); - assert!(rules.contains("**Unproven** and the exact check a person should run")); + assert!(rules.contains( + "**Unproven**, the exact check that proves it, and why CoderHelm could not run it" + )); assert!(rules.contains("Deploy claims come only from what was read")); assert!(rules.contains("CI workflows and module wiring")); assert!(rules.contains("docs go stale")); diff --git a/services/worker/src/passes/proof.rs b/services/worker/src/passes/proof.rs index fce954488..3e14b2adb 100644 --- a/services/worker/src/passes/proof.rs +++ b/services/worker/src/passes/proof.rs @@ -33,7 +33,7 @@ pub const CODER_RULES: &str = " - Logging: INFO only for actual changes and decisions; diagnostics go to DEBUG. Never add an INFO log that fires for every record or on every scheduled run. - Never leave \"unconfirmed\", \"not verified\" or \"not measured\" for something a connected source could answer: look it up. When no connected source can reach it, say exactly which source is missing. - A lookup that failed or came back empty (an empty list, no rows) confirms nothing about the system: it is not a payload. Find out why (a wrong path, a parent id from another record, a wrong table) and read again until a real record comes back. -- \"Fixed\" means seen fixed in the real output (the real API response or page). A matching filter or a passing unit test is not that. When you can't run that check, write `- Unconfirmed [external:]:` saying the fix is unproven and the exact check a person should run. +- \"Fixed\" means seen fixed in the real output (the real API response or page). A matching filter or a passing unit test is not that. When you can't run that check, write `- Unconfirmed [external:]:` saying the fix is unproven, the exact check that proves it, and why you could not run it here. Before writing that line, try every way you have to run the check (a connected source, the sandbox, the deployed preview). - Never run a command that prints credentials, and never fetch production secrets or API keys to answer a question. If a secret reaches a tool's output, stop using it and start your summary with \"Rotate this credential\" and where it appeared. ## Reading another system's data (every change that does) @@ -2362,7 +2362,7 @@ mod tests { // Fixed means seen fixed; secrets never printed or fetched. assert!(CODER_RULES.contains("seen fixed in the real output")); assert!(CODER_RULES.contains("A matching filter or a passing unit test is not that")); - assert!(CODER_RULES.contains("the fix is unproven and the exact check a person should run")); + assert!(CODER_RULES.contains("the fix is unproven, the exact check that proves it, and why you could not run it here")); assert!(CODER_RULES.contains("Never run a command that prints credentials")); assert!(CODER_RULES.contains("Rotate this credential")); assert!(EVIDENCE_OUTPUT.contains("`Evidence:`")); diff --git a/services/worker/src/passes/ready.rs b/services/worker/src/passes/ready.rs index f3c411253..1c0205f7a 100644 --- a/services/worker/src/passes/ready.rs +++ b/services/worker/src/passes/ready.rs @@ -288,7 +288,7 @@ pub fn body_holds_on(body: &str, ci_green: bool) -> Vec { if super::proof::holds_unfinished(body) { out.push(Reason::new( "Planned work is not done yet (listed under Not finished)", - "Finish it on the branch, or remove the section if the work isn't needed.", + "Each item there says why it was deferred; CoderHelm finishes it on this branch when a comment asks, or the section goes if the work isn't needed.", )); } // A check that would once have stopped the pull request (carried-over @@ -548,7 +548,7 @@ pub fn status_section(d: &Decision) -> String { let items: Vec = reasons.iter().map(|r| format!("- {}", r.line())).collect(); format!( "{STATUS_START}\n**This pull request stays a draft.** CoderHelm finished its \ - work; a person needs to deal with:\n{}\n{STATUS_END}", + work and holds it on what is below, each with what settles it:\n{}\n{STATUS_END}", items.join("\n") ) } @@ -567,7 +567,8 @@ pub fn status_section(d: &Decision) -> String { let items: Vec = reasons.iter().map(|r| format!("- {}", r.line())).collect(); format!( "{STATUS_START}\n{PROVING_MARK}\n**Marked ready so its checks run, and it isn't \ - proven.** Don't merge it yet; a person needs to deal with:\n{}\n{STATUS_END}", + proven.** Don't merge it yet; it is held on what is below, each with what settles \ + it:\n{}\n{STATUS_END}", items.join("\n") ) } diff --git a/services/worker/src/passes/resume.rs b/services/worker/src/passes/resume.rs index 358b33675..a6998396d 100644 --- a/services/worker/src/passes/resume.rs +++ b/services/worker/src/passes/resume.rs @@ -1480,7 +1480,8 @@ pub async fn run( if age_hours >= MAX_AWAITING_CI_HOURS { warn!( run_id = msg.run_id, - age_hours, "Run exceeded awaiting_ci wall-clock cap — finalizing for human review" + age_hours, + "Run exceeded awaiting_ci wall-clock cap — finishing with the pull request open" ); let repo_full = run_record .get("repo") @@ -1506,7 +1507,8 @@ pub async fn run( state, &msg.team_id, &msg.run_id, - "CI did not conclude within 24h — PR handed off for human review", + "CI didn't finish within 24 hours, so CoderHelm stopped waiting on it and finished the \ + run with the pull request open; the ready decision holds it until its checks pass.", ) .await; set_run_complete(state, &msg.team_id, &msg.run_id, created_at).await; @@ -1682,7 +1684,7 @@ pub async fn run( // and re-trigger so the next resume routes into the fix path. info!( run_id = msg.run_id, - "CI failed (missed webhook) — writing event and re-triggering" + "CI failed (missed webhook) — writing the event and starting the fix" ); record_synthetic_ci_failed(state, &msg.run_id, branch_head.as_deref()).await; send_delayed_resume(state, &msg, 0).await; @@ -2026,14 +2028,14 @@ pub async fn run( info!( run_id = msg.run_id, checks = ?on_base, - "CI is red only on checks that fail on the base branch too — handing off" + "CI is red only on checks that fail on the base branch too — finishing" ); super::add_progress_note( state, &msg.team_id, &msg.run_id, &format!( - "CI is red only on checks that also fail on {base_branch} ({}) — not caused by this PR; handed off for human review.", + "CI is red only on checks that also fail on {base_branch} ({}), so this pull request didn't cause them. CoderHelm finished the run with this change's own work done; those checks are the base branch's to fix.", on_base.join(", ") ), ) @@ -2846,7 +2848,7 @@ pub async fn run( repo_instructions.clone() } else { format!( - "{repo_instructions}\n\n## Human Review Feedback\nThe following feedback was left on the PR. Address these comments:\n\n{}", + "{repo_instructions}\n\n## Reviewer feedback\nThe following feedback was left on the PR. Address these comments:\n\n{}", review_feedback ) }; @@ -3124,13 +3126,15 @@ pub async fn run( if over_cycle || !claimed { warn!( run_id = msg.run_id, - cycle, "Fix budget exhausted — handing PR to human review as-is" + cycle, "Fix budget spent with CI green — finishing the run" ); super::add_progress_note( state, &msg.team_id, &msg.run_id, - "Automated fix budget exhausted — PR handed off for human review", + "The review fix rounds for this pull request are used and its CI is green: CoderHelm \ + finished the run with the pull request ready, and the review's remaining \ + notes are on it.", ) .await; super::record_ci_outcome( @@ -6257,9 +6261,9 @@ async fn resume_multi_repo( set_run_complete(state, &msg.team_id, &msg.run_id, created_at).await; }; if !failed.is_empty() { - info!(run_id = %msg.run_id, failed = ?failed, "Multi-repo run: CI failed — handing off"); + info!(run_id = %msg.run_id, failed = ?failed, "Multi-repo run: CI failed — finishing with the failing checks named"); finish(Some(format!( - "CI failed on {}. Handed off for a person: CoderHelm fixes CI within one repository, not across several in one run.", + "CI failed on {}. CoderHelm fixes CI one repository at a time and this run spans several, so it finished with the pull requests open; the ready decision holds each one while its checks fail.", failed.join(", ") ))) .await; @@ -6339,7 +6343,9 @@ async fn hand_off_after_ci_wait(state: &WorkerState, msg: &ResumeMessage) { state, &msg.team_id, &msg.run_id, - "CI didn't conclude after about a day of checks — handed off for a person", + "CI didn't finish after about a day of checks, so CoderHelm stopped waiting on it and \ + finished the run with the pull requests open; the ready decision holds each one until \ + its checks pass.", ) .await; let created_at = rec diff --git a/services/worker/src/passes/review_agent.rs b/services/worker/src/passes/review_agent.rs index d3933dba2..12b047275 100644 --- a/services/worker/src/passes/review_agent.rs +++ b/services/worker/src/passes/review_agent.rs @@ -2660,7 +2660,7 @@ pub const BLOCKING_RULE: &str = ONE-SHOT PATHS: code that runs in production and that nothing retries or rolls back \ automatically (instance startup and user data scripts, provisioning, migrations, deploy \ and release steps, cron that runs once, writes to stored data) sets `one_shot`: true and \ - is judged strictly: a failure there leaves a person to finish the work by hand, so even \ + is judged strictly: a failure there leaves the work half done in production with nothing to redo it, so even \ an unchecked concern there blocks, and a documented failure is never \"hardening\". \ THE PR'S OWN GOAL: read the title and description for what the PR says it fixes or \ achieves, and compare. A finding that the change doesn't achieve it (the very problem it \ diff --git a/services/worker/src/passes/review_policy_eval.rs b/services/worker/src/passes/review_policy_eval.rs index a231eac8e..81231875f 100644 --- a/services/worker/src/passes/review_policy_eval.rs +++ b/services/worker/src/passes/review_policy_eval.rs @@ -754,7 +754,7 @@ mod misgraded_findings { `if ($p.ExitCode -ne 0) { throw }` throws on any non-zero code, so that code \ stops the script before the next install step. A fresh install usually returns \ 0, so this may never happen. If it does, the log shows FAILED for a working \ - install and someone has to finish it by hand. You could accept the reboot code \ + install and the next install steps never run. You could accept the reboot code \ as success too.", ), }, diff --git a/services/worker/src/passes/review_pr.rs b/services/worker/src/passes/review_pr.rs index 403cae390..868767605 100644 --- a/services/worker/src/passes/review_pr.rs +++ b/services/worker/src/passes/review_pr.rs @@ -4099,7 +4099,7 @@ async fn run_once( } else if prev_verdict.as_deref() == Some("APPROVE") { info!( pr = msg.pr_number, - "Self-review flipped APPROVE→REQUEST_CHANGES — holding for a human, not re-fixing (hysteresis)" + "Self-review flipped from APPROVE to REQUEST_CHANGES — not re-fixing on a flip (hysteresis)" ); } else if claim_self_review_round( state, @@ -4122,22 +4122,23 @@ async fn run_once( ) .await { - // Cap reached — stop the auto-fix loop and hand to a human, once. + // Cap reached — stop starting fix rounds on our own, and say so once. let _ = github .create_issue_comment( &msg.repo_owner, &msg.repo_name, msg.pr_number, &format!( - "🛑 I've self-fixed this PR {MAX_SELF_REVIEW_FIX_ROUNDS} times without the \ - review converging, so I'm stopping the automatic fix loop and handing it \ - to a human. My latest findings are above." + "I've made {MAX_SELF_REVIEW_FIX_ROUNDS} fix rounds on my own review of this \ + PR and each round still finds something, so I stop starting rounds on my \ + own here. My latest findings are above, each with what fixing it takes; a \ + comment naming a change starts the next round right away." ), ) .await; info!( pr = msg.pr_number, - "Self-review→fix cap reached — handed off to a human" + "Self-review fix cap reached — rounds stop, findings stay on the PR" ); } } diff --git a/services/worker/src/passes/review_severity.rs b/services/worker/src/passes/review_severity.rs index 50193b6cb..60537d7ee 100644 --- a/services/worker/src/passes/review_severity.rs +++ b/services/worker/src/passes/review_severity.rs @@ -701,8 +701,8 @@ pub fn ground(findings: &mut [Finding], team_rules: &str) -> Grounded { if !was_held { let why = format!( "This blocks: {}, so the code fails on a success path. It runs once in \ - production with no automatic retry, so a person would have to finish \ - the work by hand; how rarely the code is returned doesn't lower that. \ + production with no automatic retry, so a failure leaves the work \ + half done with nothing to redo it; how rarely the code is returned doesn't lower that. \ Source: {}.", doc.meaning, f.source.as_deref().unwrap_or(doc.source).trim() diff --git a/services/worker/src/passes/stop_pr.rs b/services/worker/src/passes/stop_pr.rs index eed53e834..472cc81dd 100644 --- a/services/worker/src/passes/stop_pr.rs +++ b/services/worker/src/passes/stop_pr.rs @@ -713,7 +713,7 @@ async fn ship( run_id, &format!( "Shipped what is done on pull request #{number}; deferred: {}. CI and the ready \ - decision take it from here.", + decision carry it on.", common::truncate_str(&stop.words(), 300) ), )