Runs park on usage limits; failure classes, harness error policy, run budgets
- A stage refused for a Claude usage limit no longer fails its run: the runner tries the chats' Claude account auto-switch (per-home setting) and reruns the visit, else parks the run in the new waiting_quota status (persisted, with reset/resume time in run summaries, details and events) and resumes the same visit at reset + 1 min, also after a restart. resume_run / `pipelines resume` resumes now; cancel works on parked runs. The rerun visit gets a "# Previous attempt" interruption note. Subscription limits no longer say "top up the provider account". - run/retry into an account known to be limited are deferred (quota_policy defer/refuse/now; CLI refuses under --json/--yes unless --defer or --now). - failure_class on runs (quota, loop_exhausted, timeout, permission_denied, harness_error, blocked, environment, canceled, interrupted, budget, check_failed, other) in RunSummary/RunDetail/events, CLI inspect/runs/wait/ stats and the app failure line. - Claude permission denials (permission_denials / refused tool results) fail a blocked visit with permission_denied naming the tool use. - Harness failures are classified transient vs deterministic; deterministic ones (and a repeated empty readback) skip error self-loops; transient self-loops back off 15 s, 1 min, 4 min. - Whole-run USD budget: run --budget, server default (run-budget / get/set_run_settings); 80% warning notification, stop with class budget. - App: waiting_quota status/filter with resume time, Resume now and Cancel, failure class wording. Docs and skill references updated. Merges main (check stage, delivery gate, Claude stage restart survival, schedule changes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+143
-7
@@ -61,6 +61,43 @@ type options struct {
|
||||
version, expected, limit, retryVisit int
|
||||
timeout, waitTimeout time.Duration
|
||||
stageModels stageModelFlags
|
||||
// quotaNow / quotaDefer choose what run and retry do about a known usage
|
||||
// limit; budgetUSD caps the whole run.
|
||||
quotaNow, quotaDefer bool
|
||||
budgetUSD float64
|
||||
}
|
||||
|
||||
// quotaPolicy is the run/retry request's protocol.QuotaPolicy: --now starts
|
||||
// anyway, --defer queues the run for the reset, and otherwise a person at a
|
||||
// prompt gets the deferral while --json/--yes automation is refused, so an
|
||||
// agent never burns a retry into a known limit by accident.
|
||||
func (o *options) quotaPolicy() (string, error) {
|
||||
switch {
|
||||
case o.quotaNow && o.quotaDefer:
|
||||
return "", fmt.Errorf("--now and --defer are exclusive")
|
||||
case o.quotaNow:
|
||||
return protocol.QuotaNow, nil
|
||||
case o.quotaDefer:
|
||||
return protocol.QuotaDefer, nil
|
||||
case o.json || o.yes:
|
||||
return protocol.QuotaRefuse, nil
|
||||
}
|
||||
return protocol.QuotaDefer, nil
|
||||
}
|
||||
|
||||
// quotaFlags registers --now, --defer and --budget for run and retry.
|
||||
func quotaFlags(f *flag.FlagSet, o *options) {
|
||||
f.BoolVar(&o.quotaNow, "now", false, "Start even though the Claude account is known to be out of usage until its reset")
|
||||
f.BoolVar(&o.quotaDefer, "defer", false, "When the Claude account is known to be out of usage, queue the run to start at the reset (default at a prompt; --json/--yes refuse instead)")
|
||||
f.Float64Var(&o.budgetUSD, "budget", 0, "Cap this run's reported model cost in USD (warns at 80%, stops at 100%; default: the server's run budget)")
|
||||
}
|
||||
|
||||
// quotaHint adds the CLI flags to a refusal for a known usage limit.
|
||||
func quotaHint(err error) error {
|
||||
if err != nil && strings.Contains(err.Error(), "not starting into a known limit") {
|
||||
return fmt.Errorf("%w (pass --defer to queue it for the reset, or --now to start anyway)", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// stageModelFlags collects the repeatable --stage-model STAGE=PROVIDER/MODEL
|
||||
@@ -172,6 +209,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.Var(o.stageModels, "stage-model", "Override one stage's model; repeatable (STAGE=PROVIDER/MODEL); beats --model")
|
||||
f.BoolVar(&o.wait, "wait", false, "In JSON mode, wait for a terminal run state")
|
||||
f.DurationVar(&o.waitTimeout, "wait-timeout", 0, "Client limit for --wait after the run is admitted (0 waits until terminal); separate from per-request --timeout")
|
||||
quotaFlags(f, o)
|
||||
case "runs":
|
||||
f.StringVar(&o.name, "pipeline", "", "Filter by exact pipeline name or ID")
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm `runs rm` without an interactive prompt")
|
||||
@@ -190,10 +228,11 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.IntVar(&o.version, "version", 0, "Explicit published version of the same pipeline (default: source version)")
|
||||
f.StringVar(&o.retryInputFile, "input-file", "", "JSON object merged into the selected stage input; '-' reads stdin")
|
||||
f.StringVar(&o.notifyMode, "notify", "auto", "Notifications for this retry: auto, on, or off")
|
||||
quotaFlags(f, o)
|
||||
case "inspect":
|
||||
f.IntVar(&o.step, "step", 0, "Show one step (its sequence number) in full, without its transcript")
|
||||
f.BoolVar(&o.transcripts, "transcripts", false, "Include stage transcripts (long)")
|
||||
case "cancel", "draft-delete":
|
||||
case "cancel", "draft-delete", "resume":
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
|
||||
case "retention":
|
||||
f.StringVar(&o.db, "db", "", "Existing database path (default: standard data directory)")
|
||||
@@ -605,6 +644,12 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
fmt.Fprintln(a.Out, line)
|
||||
}
|
||||
if u.WaitingQuota > 0 {
|
||||
fmt.Fprintf(a.Out, "%d run(s) waiting for a usage limit to reset\n", u.WaitingQuota)
|
||||
}
|
||||
if line := failureClassLine(u.FailureClasses); line != "" {
|
||||
fmt.Fprintln(a.Out, "Why runs did not succeed: "+line)
|
||||
}
|
||||
fmt.Fprint(a.Out, "\nPipeline\tRuns\tSucceeded\tFailed\tActive\n")
|
||||
for _, p := range u.Pipelines {
|
||||
fmt.Fprintf(a.Out, "%s\t%d\t%d\t%d\t%d\n", p.Name, p.Total, p.Succeeded, p.Failed, p.Active)
|
||||
@@ -843,7 +888,14 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
case "runs":
|
||||
for _, run := range r.Runs {
|
||||
fmt.Fprintf(a.Out, "%d\t%s\t%s\tv%d\t%s\n", run.ID, run.Label(), run.Name, run.Version, run.Status)
|
||||
status := run.Status
|
||||
if run.FailureClass != "" && run.Status != protocol.RunStatusCanceled {
|
||||
status += " (" + protocol.FailureClassLabel(run.FailureClass) + ")"
|
||||
}
|
||||
if run.QuotaWait != nil {
|
||||
status += " (resumes " + localClock(run.QuotaWait.ResumeAt) + ")"
|
||||
}
|
||||
fmt.Fprintf(a.Out, "%d\t%s\t%s\tv%d\t%s\n", run.ID, run.Label(), run.Name, run.Version, status)
|
||||
}
|
||||
case "ping":
|
||||
fmt.Fprintln(a.Out, "Connected ·", r.Time)
|
||||
@@ -1036,10 +1088,17 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if o.retryVisit < 0 {
|
||||
return fmt.Errorf("--visit must be positive")
|
||||
}
|
||||
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput, NotifyMode: o.notifyMode})
|
||||
policy, err := o.quotaPolicy()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput, NotifyMode: o.notifyMode, QuotaPolicy: policy, BudgetUSD: o.budgetUSD})
|
||||
if err != nil {
|
||||
return quotaHint(err)
|
||||
}
|
||||
if r.RunDetail != nil && r.RunDetail.Status == protocol.RunStatusWaitingQuota {
|
||||
a.notice(quotaWaitLine(r.RunDetail))
|
||||
}
|
||||
return a.finishRun(ctx, r, o, call)
|
||||
}
|
||||
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode})
|
||||
@@ -1055,6 +1114,62 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
return a.inspect(r.RunDetail, o)
|
||||
}
|
||||
return a.output(r.RunDetail)
|
||||
case "resume":
|
||||
value, err := one()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return fmt.Errorf("run ID must be positive")
|
||||
}
|
||||
if err := a.confirmAction(fmt.Sprintf("Resume run #%d now, before its usage limit is known to have reset?", id), o.yes); err != nil {
|
||||
return err
|
||||
}
|
||||
r, err := call(protocol.Message{Type: protocol.ResumeRun, RunID: id})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RunDetail == nil {
|
||||
return fmt.Errorf("server did not return run detail")
|
||||
}
|
||||
if o.json {
|
||||
return a.output(r.RunDetail)
|
||||
}
|
||||
_, err = fmt.Fprintf(a.Out, "Resumed run #%d: %s\n", r.RunDetail.ID, r.RunDetail.Status)
|
||||
return err
|
||||
case "run-budget":
|
||||
if len(pos) > 1 {
|
||||
return fmt.Errorf("run-budget takes at most one value: USD or off")
|
||||
}
|
||||
request := protocol.Message{Type: protocol.GetRunSettings}
|
||||
if len(pos) == 1 {
|
||||
value := strings.TrimSpace(strings.TrimPrefix(pos[0], "$"))
|
||||
limit := 0.0
|
||||
if value != "off" && value != "0" {
|
||||
limit, err = strconv.ParseFloat(value, 64)
|
||||
if err != nil || limit <= 0 {
|
||||
return fmt.Errorf("run-budget takes a positive USD amount or off")
|
||||
}
|
||||
}
|
||||
request = protocol.Message{Type: protocol.SetRunSettings, RunSettings: &protocol.RunSettings{DefaultBudgetUSD: limit}}
|
||||
}
|
||||
r, err := call(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.RunSettings == nil {
|
||||
return fmt.Errorf("server did not return run settings; update pipelines-server")
|
||||
}
|
||||
if o.json {
|
||||
return a.output(r.RunSettings)
|
||||
}
|
||||
if r.RunSettings.DefaultBudgetUSD <= 0 {
|
||||
_, err = fmt.Fprintln(a.Out, "Default run budget: off (runs are capped only by their own --budget and their stages' budget_usd)")
|
||||
} else {
|
||||
_, err = fmt.Fprintf(a.Out, "Default run budget: $%.2f per run (warns at 80%%, stops at 100%%)\n", r.RunSettings.DefaultBudgetUSD)
|
||||
}
|
||||
return err
|
||||
case "decide":
|
||||
if len(pos) < 1 || len(pos) > 2 {
|
||||
return fmt.Errorf("decide requires a run ID and an optional stage key")
|
||||
@@ -1389,7 +1504,15 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
|
||||
if o.wait || o.key != "" || o.version > 0 {
|
||||
return fmt.Errorf("--wait, --request-key and --version require --json")
|
||||
}
|
||||
_, err := tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Title: o.title, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode, OutputFormat: o.outputFormat}), tea.WithContext(ctx), tea.WithAltScreen()).Run()
|
||||
policy, err := o.quotaPolicy()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Title: o.title, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode, OutputFormat: o.outputFormat, QuotaPolicy: policy, BudgetUSD: o.budgetUSD}), tea.WithContext(ctx), tea.WithAltScreen()).Run()
|
||||
return err
|
||||
}
|
||||
policy, err := o.quotaPolicy()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if o.name == "" || strings.TrimSpace(o.prompt) == "" {
|
||||
@@ -1411,9 +1534,12 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
|
||||
if key == "" {
|
||||
key = fmt.Sprintf("cli-%d-%d", os.Getpid(), time.Now().UnixNano())
|
||||
}
|
||||
r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Title: o.title, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode, OutputFormat: o.outputFormat})
|
||||
r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Title: o.title, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode, OutputFormat: o.outputFormat, QuotaPolicy: policy, BudgetUSD: o.budgetUSD})
|
||||
if err != nil {
|
||||
return err
|
||||
return quotaHint(err)
|
||||
}
|
||||
if r.RunDetail != nil && r.RunDetail.Status == protocol.RunStatusWaitingQuota {
|
||||
a.notice(quotaWaitLine(r.RunDetail))
|
||||
}
|
||||
return a.finishRun(ctx, r, o, call)
|
||||
}
|
||||
@@ -1480,6 +1606,9 @@ func (a App) finishRun(ctx context.Context, r protocol.Message, o *options, call
|
||||
if hint := waitingHint(r.RunDetail); hint != "" {
|
||||
message += "; " + hint
|
||||
}
|
||||
if line := quotaWaitLine(r.RunDetail); line != "" {
|
||||
message += "; " + line
|
||||
}
|
||||
return &StatusError{Code: WaitRunsUnsuccessful, Message: message}
|
||||
}
|
||||
return nil
|
||||
@@ -1526,6 +1655,10 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
|
||||
announced := map[int64]string{}
|
||||
onActive := func(r protocol.Message) {
|
||||
hint := waitingHint(r.RunDetail)
|
||||
if hint == "" {
|
||||
// A run parked for a usage limit resumes on its own; say when.
|
||||
hint = quotaWaitLine(r.RunDetail)
|
||||
}
|
||||
if hint == "" || announced[r.RunDetail.ID] == hint {
|
||||
return
|
||||
}
|
||||
@@ -1644,7 +1777,7 @@ func runInProgress(status string) bool {
|
||||
// runInProgress plus a run parked on a human decision (waiting), which has not
|
||||
// finished either.
|
||||
func runUnfinished(status string) bool {
|
||||
return runInProgress(status) || status == protocol.RunStatusWaiting
|
||||
return runInProgress(status) || status == protocol.RunStatusWaiting || status == protocol.RunStatusWaitingQuota
|
||||
}
|
||||
|
||||
// runIDs extracts the ids of the runs still active when a wait limit passed.
|
||||
@@ -1681,6 +1814,9 @@ func waitLine(d *protocol.RunDetail) string {
|
||||
if outcome := strings.TrimSpace(d.Outcome); outcome != "" {
|
||||
line += " (" + outcome + ")"
|
||||
}
|
||||
if d.FailureClass != "" && d.Status != protocol.RunStatusCanceled {
|
||||
line += " [" + d.FailureClass + "]"
|
||||
}
|
||||
if stage := strings.TrimSpace(d.CurrentStage); stage != "" {
|
||||
line += " · " + stage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user