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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions docs/incidents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions services/common/src/draft_hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions services/common/src/security_fixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `### <package> <from> to <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 `### <package> <from> to <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!(
Expand Down
7 changes: 5 additions & 2 deletions services/common/src/stop_judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion services/worker/src/agent/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
6 changes: 3 additions & 3 deletions services/worker/src/passes/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>().join("\n")
);
let _ = gh
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down
52 changes: 27 additions & 25 deletions services/worker/src/passes/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. \
Expand All @@ -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,
);
Expand Down Expand Up @@ -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(());
}

Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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, &note).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, &note)
.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
Expand Down
Loading
Loading