Files
pipelines/app/lib/features/runs/ui/run_detail_summary_fields.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

119 lines
4.5 KiB
Dart

import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart';
import '../domain/run_deletion.dart' show formatByteSize, runSizeBytes;
import '../domain/run_failure_class.dart' show runBudgetText;
import '../domain/run_tokens.dart';
import 'run_detail_visit_facts.dart';
/// One recorded Summary row: the web run summary's key/value shape.
///
/// [monospace] marks a value the web renders as a code identifier (the content
/// hash); [block] marks a multi-line recorded document (the diagnostic) that is
/// drawn as its own block rather than a short row.
typedef DetailSummaryRow = ({
String label,
String value,
bool monospace,
bool block,
});
/// The run Summary's rows: Pipeline, Stage, Workspace, Content hash, Started,
/// Finished, Duration, Size on disk, Tokens, Cost, Retry of and the Diagnostic
/// block.
///
/// Only values the server actually recorded are rows: a blank field is omitted
/// rather than drawn as an empty or invented placeholder, exactly as
/// `summaryRows` in the web client does. A run with no pipeline id shows its
/// recorded pipeline name, and shows no Pipeline row at all when it recorded
/// neither.
///
/// An executing run with no recorded finish shows its elapsed Duration up to
/// [now]; without [now] it has none.
List<DetailSummaryRow> detailSummaryRows(JsonMap run, {DateTime? now}) {
final rows = <DetailSummaryRow>[];
void add(
String label,
String? value, {
bool monospace = false,
bool block = false,
}) {
final text = value?.trim() ?? '';
if (text.isEmpty) return;
rows.add((label: label, value: text, monospace: monospace, block: block));
}
final pipelineId = _number(run['pipeline_id'])?.toInt() ?? 0;
if (pipelineId > 0) {
final version = _number(run['version'])?.toInt() ?? 0;
add('Pipeline', 'id $pipelineId · v$version');
} else {
add('Pipeline', _text(run['name']));
}
add('Stage', _text(run['current_stage']));
add('Workspace', _text(run['workspace']));
add('Content hash', _text(run['content_hash']), monospace: true);
add('Started', formatLocalTimestamp(_text(run['created_at'])));
add('Finished', formatLocalTimestamp(_text(run['finished_at'])));
final since = detailRunningSince(run);
final seconds = since != null
? now?.difference(since).inSeconds
: durationSeconds(_text(run['created_at']), _text(run['finished_at']));
if (seconds != null) add('Duration', formatDuration(seconds));
// What the run occupies on disk and what it spent, as the server measured
// and the harness reported; an unmeasured size or unreported usage has no
// row.
final bytes = runSizeBytes(run);
if (bytes != null) add('Size on disk', formatByteSize(bytes));
final usage = runTokenUsage(run);
if (usage != null) {
add('Tokens', tokenUsageDetail(usage));
add('Cost', tokenUsageCost(usage));
}
add('Budget', runBudgetText(run));
final retryOf = _number(run['retry_of'])?.toInt() ?? 0;
if (retryOf > 0) add('Retry of', 'run $retryOf');
// A diagnostic is a recorded document: its own whitespace is preserved, but a
// blank one is not a row.
final diagnostic = '${run['diagnostic'] ?? ''}';
if (diagnostic.trim().isNotEmpty) {
rows.add((
label: 'Diagnostic',
value: diagnostic,
monospace: false,
block: true,
));
}
return rows;
}
/// The run's identity line: `run {id} · {n} recorded visits · {m} completed
/// visits`, the same recorded/completed vocabulary the web summary and the
/// server use.
String detailSummaryIdentity(JsonMap run) {
final recorded = detailRunSteps(run).length;
final completedValue = _number(run['completed_steps'])?.toInt() ?? 0;
final completed = completedValue < 0 ? 0 : completedValue;
String visits(int count, String adjective) =>
'$count $adjective ${count == 1 ? 'visit' : 'visits'}';
return 'run ${run['id'] ?? ''} · ${visits(recorded, 'recorded')} · '
'${visits(completed, 'completed')}';
}
/// When the run started, while it is executing and has no recorded finish;
/// null otherwise, so its Duration is the recorded one (or none).
DateTime? detailRunningSince(JsonMap run) {
if (run['executing'] != true || _text(run['finished_at']) != null) {
return null;
}
return parseInstant(_text(run['created_at']));
}
String? _text(dynamic value) {
if (value == null) return null;
final text = '$value'.trim();
return text.isEmpty ? null : text;
}
num? _number(dynamic value) =>
value is num ? value : num.tryParse('${value ?? ''}'.trim());