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
358 changes: 356 additions & 2 deletions docs/api/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/incidents/vo_pass_errors_recover_not_fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

**What happened:** Any error a pass returned that the run had no special case for ended the run as failed, usually with the raw HTTP error as its reason. Some were passing (a 5xx in the middle of the coder's work), some were states CoderHelm could put right itself (a branch that wasn't there, a base branch someone deleted), and the run tried the same thing again in a fresh step without changing anything until its ceilings ran out.

**The guarantee:** Every pass error takes one recovery path before anything is marked failed. It is classified as transient (tried again after a backoff), a state CoderHelm repairs (repaired, then the same pass resumes from its checkpoint, with no second plan and no repeated ticket or pull request), or something only a person has. The same error again with no progress takes the next repair strategy, never the same one. Only a person's step stops a run, as "needs you" with what to do in plain words. An error nobody classified is tried once more and then stops as "needs you", never as failed. Runs left failed on an error CoderHelm now gets past are resumed by the self-heal sweep, on deploy and every 15 minutes, once per run per deploy.
**The guarantee:** Every pass error takes one recovery path before anything is marked failed. It is classified as transient (tried again after a backoff), a state CoderHelm repairs (repaired, then the same pass resumes from its checkpoint, with no second plan and no repeated ticket or pull request), or something only a person has. The same error again with no progress takes the next repair strategy, never the same one. Only a person's step stops a run, as "needs you" with what to do in plain words. An error nobody classified is CoderHelm's own problem: tried again with longer waits, then parked for the self-heal sweep with an internal alert for its maintainers, never a person's step (see `xg`). Runs left failed on an error CoderHelm now gets past are resumed by the self-heal sweep, on deploy and every 15 minutes, once per run per deploy.
5 changes: 5 additions & 0 deletions docs/incidents/xg_token_limit_pauses_and_resumes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# xg. `xg_token_limit_pauses_and_resumes`

**What happened:** Several runs on one install planned, then stopped at the start of building. Their page said "CoderHelm met an error it doesn't know how to repair, and stopped without trying again: Monthly new tokens limit reached", headed "Look at what stopped the run, put it right, then press Retry" and "Needs a person". The limit is counted per UTC month, but when the month turned nothing resumed them; they waited for hours until a person pressed Retry. The error classifier knew only the older wording of the limit ("limit exceeded"), so the refusal every model call now gives ("limit reached") read as an error nobody knew. No warning came before the limit, and new runs kept starting into it. The same night another run stopped with the same frame because the ticket's branch held a teammate's commits and had no pull request.

**The guarantee:** A model call the team's token limit refuses is a typed pause, never an unknown error and never a person's step. The run keeps its plan, branch and finished steps; its continuation is kept, and it resumes in place from the step that was refused when the month turns (a schedule at 00:00 UTC on the 1st) or as soon as an admin raises the limit. The run page and the runs list say it in one line, with when it resumes, and the webhook event is `run.paused`, never `run.needs_input`. A new run whose kind takes more than the room left waits for token room instead of starting, and runs already in progress come first on what is left. Admins are warned at 80% and 95%, once each a month, with the day the limit runs out at this month's pace. A teammate's branch is left as it is: the run works on the next free `<branch>-N` and says so once. "An error it doesn't know how to repair ... put it right, then press Retry" can't be produced: an error nobody classified is CoderHelm's own problem, with an internal alert, one plain line and retries with longer waits. Runs an older release stopped this way are found by their stored words and go on by themselves after the deploy.
2 changes: 1 addition & 1 deletion docs/self-host/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A self-hosted install sends the emails it needs, and nothing else until you turn
| Team invites | Essential | The only way an invited person learns how to join. |
| Plugin approval requests | Essential | A named approver must approve a plugin draft before it publishes. |
| Knowledge source sign-in alerts | Essential | Tells admins a knowledge source stopped syncing. |
| Token limit warnings | Essential | Tells the team before work stops at the monthly limit. Each person can turn these off. |
| Token limit warnings | Essential | Tells the team at 80% and 95% of a monthly limit, once each a month, with the day it runs out at this pace, and when it is reached. Runs that reach it pause and go on by themselves. Each person can turn these off. |
| Support ticket updates | Essential | Replies and status changes on tickets someone filed. |
| Webhook endpoint turned off | Essential | Tells a team's admins when CoderHelm stopped sending to an endpoint that failed for days. |
| Two-factor lockout alerts | Essential | Tells admins and owners when someone's two-factor sign-in was paused after too many wrong codes. |
Expand Down
17 changes: 17 additions & 0 deletions infra/lib/api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,23 @@ export class ApiStack extends cdk.Stack {
],
});

// The month's turn: the token limit's counters start again at 00:00 UTC
// on the 1st, and runs paused on the limit (or waiting for room) go on
// then, not at the next 15-minute tick. Sent at 00:00 and again at 00:01
// in case the first lands before the new month's counters are read.
new events.Rule(this, "TokenMonthTurnSchedule", {
ruleName: `${prefix}-token-month-turn`,
description: "Resume runs paused on the token limit when the month turns",
schedule: events.Schedule.cron({ minute: "0,1", hour: "0", day: "1" }),
targets: [
new targets.SqsQueue(this.ticketQueue, {
message: events.RuleTargetInput.fromObject({
type: "self_heal_sweep",
}),
}),
],
});

// Paused agent work: every 5 min, send again the work kept while a
// team's agents were paused once the pause has ended (an until-time
// passing needs nobody to click anything). Does nothing when no team is
Expand Down
11 changes: 6 additions & 5 deletions infra/lib/email-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ export class EmailStack extends cdk.Stack {
});

// Token limit emails: one per limit (new tokens, cache read, cache write)
// at 80% and at 100%. {{limit_name}} names the limit.
// at 80%, 95% and 100%, each once a month. {{limit_name}} names the
// limit; {{pace}} says when it runs out at this month's pace.
new ses.CfnTemplate(this, "TokenWarningTemplate", {
template: {
templateName: `${prefix}-token-warning`,
Expand Down Expand Up @@ -388,31 +389,31 @@ const TOKEN_WARNING_HTML = EMAIL_WRAPPER(`
<h1 style="color:#f59e0b;font-size:20px;margin:0 0 16px">{{usage_pct}}% of your {{limit_name}} limit used</h1>
<p style="color:#ccc;font-size:15px;line-height:1.6;margin:0 0 16px">
Your team has used <strong style="color:#fff">{{used_tokens}}</strong> of its <strong style="color:#fff">{{limit_tokens}}</strong> monthly {{limit_name}} limit for {{month}}.
When it reaches the limit, CoderHelm stops starting new work until the month ends or the limit is raised.
{{pace}}
</p>
<a href="__APP_URL__/settings/budget" style="display:inline-block;background:#fff;color:#000;padding:10px 20px;border-radius:6px;text-decoration:none;font-weight:600;margin-top:8px">Review token limits</a>
`);

const TOKEN_WARNING_TEXT = `{{usage_pct}}% of your {{limit_name}} limit used

Your team has used {{used_tokens}} of its {{limit_tokens}} monthly {{limit_name}} limit for {{month}}.
When it reaches the limit, CoderHelm stops starting new work until the month ends or the limit is raised.
{{pace}}

Token limits: __APP_URL__/settings/budget`;

const TOKEN_LIMIT_REACHED_HTML = EMAIL_WRAPPER(`
<h1 style="color:#ef4444;font-size:20px;margin:0 0 16px">Monthly {{limit_name}} limit reached</h1>
<p style="color:#ccc;font-size:15px;line-height:1.6;margin:0 0 16px">
Your team has used <strong style="color:#fff">{{used_tokens}}</strong> of its <strong style="color:#fff">{{limit_tokens}}</strong> monthly {{limit_name}} limit for {{month}}.
CoderHelm won't start new work until the month ends or an admin raises or clears this limit.
Runs pause with their work kept and go on by themselves when the month turns or an admin raises or clears this limit.
</p>
<a href="__APP_URL__/settings/budget" style="display:inline-block;background:#fff;color:#000;padding:10px 20px;border-radius:6px;text-decoration:none;font-weight:600;margin-top:8px">Review token limits</a>
`);

const TOKEN_LIMIT_REACHED_TEXT = `Monthly {{limit_name}} limit reached

Your team has used {{used_tokens}} of its {{limit_tokens}} monthly {{limit_name}} limit for {{month}}.
CoderHelm won't start new work until the month ends or an admin raises or clears this limit.
Runs pause with their work kept and go on by themselves when the month turns or an admin raises or clears this limit.

Token limits: __APP_URL__/settings/budget`;

Expand Down
8 changes: 7 additions & 1 deletion lambda/stuck-run-cleanup/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ def wait_since(run):


def reminder_due(run, now):
"""One reminder, WAIT_REMIND_AFTER_HOURS into the wait (run_wait::reminder_due)."""
"""One reminder, WAIT_REMIND_AFTER_HOURS into the wait (run_wait::reminder_due).
A run paused on the team's token limit (its wait carries a `pause`) waits
on nobody: it resumes by itself when the month turns or the limit is
raised, so it gets no reminder."""
wait = _json(run.get(WAITING_ON_FIELD)) or {}
if isinstance(wait, dict) and wait.get("pause"):
return False
since = wait_since(run)
if since is None or now - since < timedelta(hours=WAIT_REMIND_AFTER_HOURS):
return False
Expand Down
16 changes: 16 additions & 0 deletions lambda/tests/test_stuck_run_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,22 @@ def test_one_reminder_after_the_wait(self):
self.assertIn("attribute_not_exists(#r)", updates[0]["ConditionExpression"])
self.assertEqual(sent[0]["why"], "reminder")

def test_a_run_paused_on_the_token_limit_gets_no_reminder(self):
# It waits on nobody: it resumes by itself when the month turns or
# the limit is raised.
wait = sweep.json.dumps({
"action": "Paused: this month's token limit is used up (40.3M of 40M).",
"since": "2026-11-01T00:00:00+00:00",
"handback": "usage_limit",
"pause": {"kind": "token_limit", "limit": "new tokens", "used": 40300000,
"max": 40000000, "resumes_at": "2026-12-01T00:00:00+00:00"},
})
run = {"team_id": "T", "run_id": "R", "status": "needs_input", "waiting_on": wait}
self.assertFalse(sweep.reminder_due(run, self.NOW + sweep.timedelta(days=5)))
out, updates, sent = self._sweep([run])
self.assertEqual(out["waiting_reminded"], 0)
self.assertEqual(sent, [])

def test_a_run_with_questions_and_a_fresh_wait_is_left_alone(self):
run = {
"team_id": "T",
Expand Down
3 changes: 3 additions & 0 deletions services/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ pub mod ticket_decisions;
pub mod ticket_state;
/// A team's monthly token limits: new tokens, cache read, cache write.
pub mod token_limits;
/// A run the token limit refuses is paused and resumes by itself; new runs
/// wait for room; runs in progress come first (`token_room::plan_wakes`).
pub mod token_room;
/// Whether a tool works right now: one failure, one diagnosis, one report.
pub mod tool_health;
/// Every tool an agent can be given, with its risk (read, write, consequential).
Expand Down
2 changes: 1 addition & 1 deletion services/common/src/mail/golden/token_limit_reached.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<tr><td class="px" style="padding:32px 32px 28px;text-align:left">
<h1 class="t1 h1" style="margin:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:24px;line-height:32px;font-weight:700;letter-spacing:-0.01em;color:#18181b">Monthly token limit reached, new work waits</h1>
<div style="height:20px;line-height:20px;font-size:0">&nbsp;</div>
<p class="t2" style="margin:0 0 16px;font-size:16px;line-height:24px;color:#3f3f46">Your team reached its monthly new tokens limit for October 2026. New work waits until an admin raises the limit or the month ends.</p><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="width:100%;margin:0 0 16px;border-collapse:collapse"><tr><td class="t3 ln" style="padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Used</td><td class="t1 ln" style="padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">10.0M</td></tr><tr><td class="t3 ln" style="border-top:1px solid #e4e4e7;padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Limit</td><td class="t1 ln" style="border-top:1px solid #e4e4e7;padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">10M</td></tr><tr><td class="t3 ln" style="border-top:1px solid #e4e4e7;padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Month</td><td class="t1 ln" style="border-top:1px solid #e4e4e7;padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">October 2026</td></tr></table><p class="t2" style="margin:0 0 16px;font-size:16px;line-height:24px;color:#3f3f46">To go on now, an admin raises the limit in Settings, Usage.</p><table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin:8px 0 4px"><tr><td align="center" bgcolor="#2563eb" style="border-radius:8px;background:#2563eb"><a href="https://helm.example.org/settings/usage/" style="display:inline-block;padding:12px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:16px;line-height:24px;font-weight:600;color:#ffffff;text-decoration:none;border-radius:8px;white-space:nowrap">See usage</a></td></tr></table>
<p class="t2" style="margin:0 0 16px;font-size:16px;line-height:24px;color:#3f3f46">Your team reached its monthly new tokens limit for October 2026. Runs pause with their work kept and go on by themselves when the month turns or an admin raises the limit.</p><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="width:100%;margin:0 0 16px;border-collapse:collapse"><tr><td class="t3 ln" style="padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Used</td><td class="t1 ln" style="padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">10.0M</td></tr><tr><td class="t3 ln" style="border-top:1px solid #e4e4e7;padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Limit</td><td class="t1 ln" style="border-top:1px solid #e4e4e7;padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">10M</td></tr><tr><td class="t3 ln" style="border-top:1px solid #e4e4e7;padding:8px 16px 8px 0;font-size:14px;line-height:20px;color:#71717a;vertical-align:top;white-space:nowrap">Month</td><td class="t1 ln" style="border-top:1px solid #e4e4e7;padding:8px 0;font-size:14px;line-height:20px;color:#18181b;vertical-align:top;word-break:break-word">October 2026</td></tr></table><p class="t2" style="margin:0 0 16px;font-size:16px;line-height:24px;color:#3f3f46">To go on now, an admin raises the limit in Settings, Usage.</p><table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin:8px 0 4px"><tr><td align="center" bgcolor="#2563eb" style="border-radius:8px;background:#2563eb"><a href="https://helm.example.org/settings/usage/" style="display:inline-block;padding:12px 24px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:16px;line-height:24px;font-weight:600;color:#ffffff;text-decoration:none;border-radius:8px;white-space:nowrap">See usage</a></td></tr></table>
</td></tr>
</table>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" class="t3" style="padding:20px 16px 0;font-size:12px;line-height:18px;color:#71717a"><p style="margin:8px 0 0">Sent for the self-hosted CoderHelm install at helm.example.org; its links go only there. Questions go to its admin, admin@example.org. CoderHelm never asks for your password or sign-in codes by email.</p></td></tr></table>
Expand Down
2 changes: 1 addition & 1 deletion services/common/src/mail/golden/token_limit_reached.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Subject: Acme CoderHelm: monthly token limit reached, new work waits

Monthly token limit reached, new work waits

Your team reached its monthly new tokens limit for October 2026. New work waits until an admin raises the limit or the month ends.
Your team reached its monthly new tokens limit for October 2026. Runs pause with their work kept and go on by themselves when the month turns or an admin raises the limit.

Used: 10.0M
Limit: 10M
Expand Down
Loading