Skip to content

Run endings decided in one place: no partial salvage, no #0, never ready or done on red CI - #624

Merged
nambok merged 1 commit into
mainfrom
fix/run-endings-one-gate
Nov 12, 2026
Merged

nambok merged 1 commit into
mainfrom
fix/run-endings-one-gate

Conversation

@nambok

@nambok nambok commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two runs ended wrong on one afternoon, and both came from paths that bypassed the rules every other ending follows.

  • A Jira run did 7 of its 8 planned tasks. On the 8th, the coder read the file, found it already does what the task asked, and said so twice ("needed no code change", "stays as it is"). The plan check only knew a few fixed phrases, so it never accepted that answer. Two steps changed nothing and the progress guard stopped the run. Then a legacy salvage path opened a draft titled "⚠️ Partial". Its body said "Closes #0" (the ticket is not a GitHub issue) and "the agent ran out of time", which wasn't true. The path also marked the run completed, and the ready decision later marked that pull request ready.
  • Another run's CI failed. The fix pass read a job log that only showed the report upload step, so it changed nothing. The run was then marked completed and its pull request marked ready while every check was red. The cause: the ready decision only read CI when CoderHelm's own checks had findings.

This PR removes the bypasses and puts each decision in one place, with the rules checked in code and by tests:

  • One outcome rule (passes/outcome.rs). A run is completed only with no planned task left, no recorded stop, and CI that is green, absent, or red only on checks the base branch fails too. Any other run needs a person, with every reason named. Words about a stop come from the recorded reason: only a recorded time limit mentions time. A property test covers all 120 combinations.
  • One way to open a stopped run's pull request (stop_pr). salvage_timeout_pr and both of its call sites are deleted. A run stopped mid-implement, or at its time limit, gets the standard held draft: the ticket line, a "Not finished" section, Summary, Changes, Verification, and Open items. "Not finished" lists why the run stopped, the tasks done (N of M), each task left, what a person can do, and a link to the run page.
  • No #0, ever. The ticket line comes from one function. Closes #N is used only for a real GitHub issue; anything else gets Source ticket: KEY. The GitHub client also removes any reference to issue #0 from every body it creates or updates.
  • The plan check accepts "no change needed" (root cause of the stopped run):
    • More ways of saying it are recognized, plus an explicit No change needed: <path>: <why> line that the instructions now ask for.
    • The check runs on the implement pass's own notes and after every round, not only after a round that wrote nothing.
    • A settled task is saved on the checklist, so later steps read it as optional and don't ask it again.
  • The stuck detector changes approach before it stops. After one step that changed nothing, the next step gets one task only, the files the branch already changes, and the two ways to finish it: make the change, or write the no-change line. A run stops only if that step also changes nothing. The stop names the task (while working on task 8 of 8 (...)).
  • CI is read for every draft (ready::decide). A failing check holds any pull request, with the check named. A running check is a wait. A failure the base branch has too doesn't hold it.
  • The CI fix loop tries again with fresh evidence, and never ends as completed while CI is red:
    • Every attempt reads the failing jobs' logs, the failing checks' annotations and output, and the latest comments from CI reporter bots on the pull request. In the red-CI run, the failing test and its error were only in such a comment.
    • A failure whose logs show an infrastructure problem (DNS, a reset connection, a gateway error, a runner that went away, a full disk, a rate limit) is re-run once per head.
    • An attempt that changes nothing is followed by up to CODERHELM_CI_FIX_ATTEMPTS attempts in all (default 3). Each later attempt is told what was tried, to reproduce the failure with run_checks first, and gets the evidence again.
    • Every give-up (budget, stalled, no change, fix error, no progress) goes through one hand-off. It writes a "CI is failing" section on the pull request (the check, the error, what was tried, what is needed), keeps the draft through ready::settle, and sets the run to needs_input. That status notifies the team.
    • The CI fix's conversation is now saved for each attempt, and so are plan rounds' conversations.
    • Any remaining complete_run_with_status("completed") is checked against the run's CI record, so red CI becomes a wait on a person.
  • A detector: the Reliability data adds ci.ended_wrong. It counts runs completed with this change's CI still red, and runs completed after a stop with work left, each with its newest run ids. Both should stay at zero.

Changes

  • services/worker/src/passes/outcome.rs (new): CiState, Stop (read from the recorded stop sentence), decide, broken_rules, ci_blocker, ticket_line, guard_body, body_problems.
  • services/worker/src/clients/github.rs: create_pull_request and update_pr_body send outcome::guard_body(body).
  • services/worker/src/passes/mod.rs:
    • salvage_timeout_pr and its two call sites are deleted. The error arm and the timeout arm both call stop_pr::open.
    • The stall stop names the current task.
    • continuation_feedback takes the stall count and switches to narrowed_feedback.
    • Settled tasks are saved with with_declined.
  • services/worker/src/passes/stop_pr.rs: Progress, not_finished, with_unfinished (an already open pull request gets the section too), and a Verification section. The ticket line now comes from outcome, and the body is checked with body_problems.
  • services/worker/src/passes/plan_coverage.rs:
    • More no-change phrases, and NO_CHANGE_LINE.
    • settle_declined is applied to the implement pass's notes and to every round.
    • New with_declined, narrowed_feedback and current_task.
    • Plan rounds' conversations are saved.
  • services/worker/src/passes/steps.rs: stall_reason names the task.
  • services/worker/src/passes/ready.rs: reads_ci covers every open draft. repo_ci holds on failing checks and waits on running ones. red_on_base is read for every failing CI.
  • services/worker/src/passes/resume.rs:
    • ci_evidence, ci_reporter_comments, looks_infra (feeds should_rerun and try_rerun_once), ci_fix_attempts, next_attempt_feedback, failure_excerpt.
    • ci_failing_section and with_ci_failing write the pull request's section; hand_off_red_ci is the one give-up path.
    • The attempts loop.
    • red_ci_blocks_completion guards complete_run_with_status.
  • services/worker/src/passes/pr.rs: the ticket line comes from outcome::ticket_line_for.
  • services/gateway/src/routes/analytics.rs: ended_wrong under ci.
  • services/worker/src/passes/incidents/ac_partial_and_red_ci.rs and docs/incidents.md: the new incident case.

Verification

  • On the current main (with Reliability: retried failures count, usage writes outlast races, edit_file reads stringified edits #619): cargo test -p worker: 1547 passed (12 ignored). cargo test -p gateway analytics: 50 passed. cargo clippy --workspace -- -D warnings and cargo fmt --check are clean.
  • New tests:
    • outcome::tests checks every combination of tasks, CI, review and stop against the rules, and catches both old endings: completed or ready with red CI, and "ran out of time" for a no-progress stop.
    • incidents::ac_partial_and_red_ci:
      • a source scan that allows create_pull_request only in pr.rs, stop_pr.rs and e2e_setup.rs, and mark_pr_ready only in ready.rs;
      • a stopped Jira run gets the standard held draft;
      • #0 never renders;
      • the coder's own no-change words (file renamed) settle the task and stay settled in the next step;
      • the narrowed ask after a stalled step;
      • ready::decide holds a draft with red CI and waits on running CI, checked across 128 combinations;
      • a CI fix that changes nothing retries, then hands off with needs_input and never completes.
    • stop_pr::tests: the stopped run's body has the Source ticket line and Not finished, with no "Closes #0", "Partial" or "ran out of time".
    • resume::ci_triage_tests: an infrastructure failure is re-run once; the failure excerpt is the error line, not the upload step; CI reporter comments are read; the next attempt's ask and the CI failing section.
    • analytics: ended_wrong counts both states.
  • Each new test fails on the old behavior. A mutation run reverted each production change one at a time, and every one turned its tests red:
    • the ready decision's CI rule;
    • the added no-change phrases;
    • saving a settled task;
    • the narrowed ask after a stalled step;
    • the retry after a no-change CI fix;
    • the completion guard;
    • the client's #0 guard;
    • guard_body itself;
    • the task named in the stop;
    • the infrastructure re-run;
    • ci_blocker;
    • the Not finished section.

…ady or done on red CI

A run stopped mid-implement now gets the standard held draft (stop_pr):
ticket line, a Not finished section with done and remaining tasks and the
recorded reason, Summary, Changes, Verification. salvage_timeout_pr and its
call sites are gone. The GitHub client strips any issue #0 reference from
every body it sends.

The plan check accepts a coder's "no change needed" in the words coders use
and an explicit line, from the implement pass's own notes and every round,
and saves it on the checklist so later steps don't ask again. After a step
that changed nothing, the next one takes one task with a different approach.

ready::decide reads CI on every open draft: a failing check holds it, a
running one is a wait. The CI fix loop reads annotations and CI reporter
comments, re-runs infrastructure failures once, tries up to
CODERHELM_CI_FIX_ATTEMPTS (default 3) times with fresh evidence, and every
give-up holds the draft with what fails and sets the run to needs_input.
outcome.rs holds the rules, with a property test and a source scan that
allows create_pull_request and mark_pr_ready in one place each. Reliability
counts runs that ended done with red CI or after a stop.
@nambok
nambok merged commit fb73663 into main Nov 12, 2026
10 checks passed
@nambok
nambok deleted the fix/run-endings-one-gate branch November 12, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant