Skip to content

Stop restarting a ticket whose last 3 runs failed while it is unchanged - #773

Merged
nambok merged 7 commits into
mainfrom
fm/coderhelm-failed-run-cap
Nov 19, 2026
Merged

nambok merged 7 commits into
mainfrom
fm/coderhelm-failed-run-cap

Conversation

@thinkaxelthink

@thinkaxelthink thinkaxelthink commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #706 at the reviewer's request: this cap was part of that pull request and is now its own change.

A failed latest run never blocked a ticket event, so every field or status change on a ticket whose runs kept failing started the same failing run again. There was no per-ticket cap on these restarts.

What changes

After 3 runs in a row on a ticket ended failed, an event that leaves the ticket unchanged starts no further run (trigger_gate::MAX_FAILED_RUNS_IN_A_ROW).

  • The cap counts only runs that ended failed. A run a person retried (status retried, whatever it ended as) neither counts nor ends the streak, so runs that stopped to ask a question and were retried don't add up to the cap.
  • A person's retry is never capped: changing the ticket's content, Retry, a /coderhelm command, and a retry gesture on the ticket all still start a run.
    • GitHub: every issue event that starts a run is a retry gesture (adding the coderhelm label, or assigning the issue to CoderHelm; github_retry_gesture).
    • Jira: re-adding the team's trigger label or re-assigning the ticket to CoderHelm, read from the event's changelog (jira_retry_gesture). Other field and status changes stay capped, which is what the cap is for.
  • No status change skips the cap, including reopening a done ticket: after 3 failed runs on an unchanged ticket, moving it between statuses (To Do -> In Progress, or Done -> open) starts nothing; a content edit, a retry gesture, Retry or a command does. Reopening no longer always restarts a capped ticket. The reopen rule elsewhere in the gate (after a merged or closed pull request, or a run a person closed) is unchanged.
  • The skip is logged with its reason, like the gate's other skips.

Worth knowing:

  • Alerts pass through the same gate as non-explicit events, so a recurring alert with the same title and body stops starting runs after 3 failed runs in a row, until someone retries from the dashboard. That is intended: those repeats were spending runs on the same failure.
  • An alert's take_daily_slot is spent before the gate decides, so a capped alert still uses its daily slot. That was already the case for other gate skips; with the cap it happens more often.

Evidence

  • Locally on this branch's head with the pinned 1.97.1 toolchain: cargo fmt --check clean, cargo clippy -p gateway --all-targets -- -D warnings clean, and cargo test -p gateway passed, including the cap tests (restarts stop on an unchanged ticket, status moves To Do -> In Progress and Done -> open included, while new content or a retry gesture still start one; failures in a row are counted from the newest run with retried runs passed over) and the retry-gesture helpers for GitHub (label add, bot assign) and Jira (trigger label re-added, re-assigned to CoderHelm; a field or status change isn't one).
  • Remote CI runs on this pull request.

The no-mistakes test step drove the gate live against a local DynamoDB emulator (19 scenarios), including the status-move case this change closes. Not driven against the hosted product: a ticket whose last 3 runs failed and then gets a field or status change starts no run; an edit or a retry gesture (label or assignee on GitHub or Jira) still starts one.

Follow-up: a one-line ticket comment the first time the cap skips an event ("the last 3 runs failed; edit the ticket or press Retry"), so a person isn't left wondering why nothing ran.

@nambok nambok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice split, the gate logic itself reads right. ulid ordering in failed_in_a_row matches how latest is picked, the dashboard retry (api::retry_run) never goes through the gate so it can't hit the cap, /coderhelm comments and run_start pass explicit=true and return before decide, and a content change or jira reopen still gets through. clippy -D warnings clean and cargo test -p gateway passes locally on 6b51106.

one real problem, the cap blocks deliberate retries it says it doesn't:

github_webhook.rs line 593: pass is_labeled || is_assigned_to_bot, not just is_labeled
handle_issue_event returns early unless the event is the coderhelm label being added or the bot being assigned (line 537), so every github issue event that reaches the gate is a person doing one of those two things. there's no incidental unchanged event on this path at all. with only is_labeled exempt, the only thing the cap ever blocks on github is a person assigning coderhelm to the issue, which is exactly the explicit retry the pr says stays allowed, and they get no comment, just a log line. simplest fix is passing true here (the cap never applies to github issue events), or is_labeled || is_assigned_to_bot if you want it spelled out. the pr body's "an incidental unchanged event is skipped" for github doesn't match what the handler can receive.

jira_webhook.rs line 618: same thing for jira re-labels / re-assigns
on jira, removing and re-adding the trigger label (or re-assigning to coderhelm) is the same retry gesture you exempted on github, but it comes in as an unchanged issue_updated and gets skipped at the cap. jira_reopened already reads the changelog, so a sibling that's true when a changelog item has field == "labels" and the trigger label is in toString but not fromString (and the same for assignee moving to coderhelm) can feed label_added. that keeps field/status noise capped, which is the point of the pr, while a person's re-label still retries. add a test for it next to the jira_reopened ones.

non-blocking:

  • the decide() test sets label_added: true by hand, so nothing would catch the github wiring regressing (or the two fixes above). a small pure helper for "is this event a person's retry gesture" per source, with tests, would cover it.
  • a skip at the cap is silent to the person. if someone does hit it from a field change that's fine, but a one-line ticket comment the first time it trips ("3 runs failed, edit the ticket or hit retry") would save a "why didn't it run" question. fine as a follow-up.
  • alerts also pass false, so a recurring alert with the same title/body stops after 3 failed runs until someone retries from the dashboard. probably what you want (it was burning runs), just worth a line in the pr body since it isn't mentioned. also note take_daily_slot is spent before the gate skips, pre-existing but now it'll happen more.
  • the status != "retried" literal could use common::run_status::RETRIED / FAILED like the rest of the codebase.

Shoyu added 6 commits November 19, 2026 00:40
A failed latest run never blocked a ticket event, so every field or
status change on a ticket whose runs kept failing started the same
failing run again. There was no per-ticket cap.

After 3 runs in a row ended failed, an event that leaves the ticket
unchanged now starts no further run. The cap counts only runs that ended
failed: a run a person retried (status `retried`, whatever it ended as)
neither counts nor ends the streak. Changing the ticket, reopening it, or
a person's Retry or command still starts a run; explicit triggers never
reach the cap.

Split out of #706 at the reviewer's request.
@thinkaxelthink
thinkaxelthink force-pushed the fm/coderhelm-failed-run-cap branch from 6b51106 to 79f8bf6 Compare November 19, 2026 14:52
@thinkaxelthink

Copy link
Copy Markdown
Contributor Author

Thanks. Point by point:

  • GitHub (github_webhook.rs): fixed. The gate now gets github_retry_gesture(payload), which is true for adding the coderhelm label or assigning the issue to CoderHelm, so the cap never applies to a GitHub issue event, as you pointed out every one that reaches the gate is a person's retry. The stale comment says so, and the PR body no longer claims an incidental GitHub event is skipped.
  • Jira (jira_webhook.rs): fixed. jira_retry_gesture(payload, trigger_label) reads the changelog like jira_reopened: the team's trigger label in toString but not fromString, or the assignee moving to CoderHelm. That feeds the gate's retry flag (renamed from label_added to retry_gesture), so a person's re-label or re-assign retries, while other field and status changes stay capped. The label check is the same one the Jira trigger uses (is_trigger_label, so a repo-pinned coderhelm:acme/web counts too), and the GitHub handler and the gate share one rule (github_retry_gesture).
  • Also changed: status moves stay capped. Testing this round against a local DynamoDB emulator showed a capped, unchanged Jira ticket still restarting on any status move (To Do -> In Progress), because jira_reopened is true for any move into a non-done status and the cap let reopens through. The Jira event doesn't carry the old status category, so on the captain's call no status change skips the cap now, including Done -> open; content edits, retry gestures, Retry and commands still restart. jira_reopened and its use in the other gate branches are unchanged.
  • Pure helper with tests (non-blocking): done. Both gestures are pure functions next to jira_reopened, with tests for label adds, bot assigns, still-labelled/still-assigned, label removals, other fields and status moves, so the wiring no longer rests on a hand-set flag in the decide() test.
  • Status literals (non-blocking): done. failed_in_a_row uses common::run_status::RETRIED and FAILED.
  • Alerts and take_daily_slot (non-blocking): noted in the PR body. A recurring alert with the same title and body stops after 3 failed runs until someone retries from the dashboard (intended), and its daily slot is spent before the gate skips.
  • First-trip ticket comment (non-blocking): left as a follow-up, as you suggested; it's listed in the PR body.

@nambok nambok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It conflicts with main now that #706 merged; please merge main and I'll approve.

nambok
nambok previously approved these changes Nov 19, 2026

@nambok nambok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@thinkaxelthink

Copy link
Copy Markdown
Contributor Author

Merged main into this branch now that #706 is in (head 754d4d67). Both pull requests added an argument to gate_ticket_trigger, so the conflicts in trigger_gate.rs, alerts.rs, run_start.rs, jira_webhook.rs and github_webhook.rs keep both: the gate takes the GitHub issue's repository (#706, so only that repository's runs count, the failed-run streak included) and then the retry gesture (this PR). Docs and tests from both are kept. gate_ticket_trigger now has eight arguments, so it carries #[allow(clippy::too_many_arguments)] like the rest of the gateway. Clippy is clean and all 1096 gateway tests pass locally; the branch merges cleanly with main.

@nambok nambok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@nambok
nambok merged commit 020de7b into main Nov 19, 2026
10 checks passed
@nambok
nambok deleted the fm/coderhelm-failed-run-cap branch November 19, 2026 16:08
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.

2 participants