Files
pipelines/app/lib/features/chat/domain/chat_shown_run.dart
T
alan b3c9575fde 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>
2026-12-03 14:34:53 +00:00

75 lines
2.5 KiB
Dart

import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart' show formatDuration;
import '../../runs/domain/run_events.dart' show isTerminalRunStatus;
import '../../runs/domain/run_quota.dart';
/// A `show_run` item's run, as the server records it
/// (`internal/protocol/chat_shown.go` ChatShownRunBody). The server pushes the
/// item again whenever the run changes, so this is always its latest state.
class ChatShownRun {
const ChatShownRun({
required this.id,
required this.pipeline,
required this.title,
required this.status,
required this.outcome,
required this.currentStage,
required this.startedAt,
required this.finishedAt,
});
/// The run of a `run` item, or null for any other item or a malformed one.
static ChatShownRun? of(JsonMap item) {
final body = item['run'];
if (item['kind'] != 'run' || body is! Map) return null;
final id = body['id'];
if (id is! num || id <= 0) return null;
return ChatShownRun(
id: id.toInt(),
pipeline: _text(body['pipeline']),
title: _text(body['title']),
status: _text(body['status']),
outcome: _text(body['outcome']),
currentStage: _text(body['current_stage']),
startedAt: _millis(body['started_at']),
finishedAt: _millis(body['finished_at']),
);
}
final int id;
final String pipeline;
final String title;
final String status;
final String outcome;
final String currentStage;
final int? startedAt;
final int? finishedAt;
/// Whether the run has ended (succeeded, failed, canceled, interrupted).
bool get finished => isTerminalRunStatus(status);
/// The status in words: the outcome of a finished run when it says more.
String get statusLabel {
if (isWaitingQuotaStatus(status)) return runWaitingQuotaLabel;
final word = status.isEmpty ? 'unknown' : status;
final label = '${word[0].toUpperCase()}${word.substring(1)}';
return finished && outcome.isNotEmpty && outcome != status
? '$label · $outcome'
: label;
}
/// How long it ran, or has been running at [now] (epoch milliseconds); null
/// without a start time.
String? duration(int now) {
final start = startedAt;
if (start == null) return null;
final end = finishedAt ?? (finished ? null : now);
if (end == null) return null;
return formatDuration((end - start) ~/ 1000);
}
}
String _text(Object? value) => '${value ?? ''}'.trim();
int? _millis(Object? value) => value is num && value > 0 ? value.toInt() : null;