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:
@@ -8,12 +8,14 @@ import '../../../core/api_gateway.dart';
|
||||
///
|
||||
/// The status word alone is not enough: a stale `running` status without
|
||||
/// `executing` is not cancellable, while a run waiting on a pending session
|
||||
/// export is.
|
||||
/// export is. A run parked in `waiting_quota` has no live executor but the
|
||||
/// server cancels it directly, so it is cancellable too.
|
||||
bool canCancelRun(JsonMap? run) {
|
||||
if (run == null) return false;
|
||||
final exportPending = _number(run['export_pending_sequence']);
|
||||
return (run['executing'] == true ||
|
||||
(run['status'] == 'waiting' && exportPending > 0)) &&
|
||||
(run['status'] == 'waiting' && exportPending > 0) ||
|
||||
run['status'] == 'waiting_quota') &&
|
||||
run['cancel_requested'] != true &&
|
||||
run['cleanup_unconfirmed'] != true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../data/runs_repository.dart';
|
||||
import '../domain/run_quota.dart';
|
||||
|
||||
const resumeQuotaActionLabel = 'Resume now';
|
||||
const resumeQuotaActionKey = ValueKey<String>('resume-quota-run-action');
|
||||
const resumeQuotaErrorKey = ValueKey<String>('resume-quota-run-error');
|
||||
|
||||
/// Whether [run] is parked for a usage limit and may be resumed now.
|
||||
bool canResumeQuotaRun(JsonMap? run) =>
|
||||
run != null &&
|
||||
run['id'] is num &&
|
||||
isWaitingQuotaStatus(run['status']) &&
|
||||
run['cancel_requested'] != true;
|
||||
|
||||
/// "Resume now" for a run parked in `waiting_quota`: one `resume_run` request
|
||||
/// whose accepted `run_detail` reaches [onRunChanged]. A refusal is shown
|
||||
/// beside the button verbatim and leaves the button for a deliberate retry.
|
||||
class ResumeQuotaRunAction extends StatefulWidget {
|
||||
const ResumeQuotaRunAction({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.gateway,
|
||||
required this.onRunChanged,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final ApiGateway gateway;
|
||||
final ValueChanged<JsonMap> onRunChanged;
|
||||
|
||||
@override
|
||||
State<ResumeQuotaRunAction> createState() => _ResumeQuotaRunActionState();
|
||||
}
|
||||
|
||||
class _ResumeQuotaRunActionState extends State<ResumeQuotaRunAction> {
|
||||
bool _sending = false;
|
||||
String? _error;
|
||||
|
||||
Future<void> _resume() async {
|
||||
final id = widget.run['id'];
|
||||
if (_sending || id is! num || !canResumeQuotaRun(widget.run)) return;
|
||||
setState(() {
|
||||
_sending = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final run = await RunsRepository(widget.gateway).resumeRun(id);
|
||||
if (mounted && widget.run['id'] == id) widget.onRunChanged(run);
|
||||
} catch (error) {
|
||||
final message = '$error'.trim();
|
||||
if (mounted) {
|
||||
setState(
|
||||
() => _error = message.isEmpty
|
||||
? 'The server did not resume the run.'
|
||||
: message,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _sending = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!canResumeQuotaRun(widget.run)) return const SizedBox.shrink();
|
||||
final error = _error;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
key: resumeQuotaActionKey,
|
||||
onPressed: _sending ? null : _resume,
|
||||
child: const Text(resumeQuotaActionLabel),
|
||||
),
|
||||
if (error != null)
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
error,
|
||||
key: resumeQuotaErrorKey,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,12 @@ class RunsRepository {
|
||||
'run_detail',
|
||||
);
|
||||
|
||||
/// Resumes a run parked in `waiting_quota` now instead of at its reset.
|
||||
Future<JsonMap> resumeRun(num id) async => _required(
|
||||
await _gateway.call('resume_run', {'run_id': id}),
|
||||
'run_detail',
|
||||
);
|
||||
|
||||
/// Deletes finished runs and their recorded data. The server answers
|
||||
/// `runs_deleted` with the ids it removed, the ones it refused (with its
|
||||
/// reason) and the bytes it freed.
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
// A check stage visit's recorded output: the per-command results the server
|
||||
// ran for a `check` stage, read without widget imports.
|
||||
//
|
||||
// Only an output map carrying a `checks` list is a check output; older
|
||||
// servers never send one, so every other step keeps its ordinary rendering.
|
||||
|
||||
/// How one command ended. [unknown] keeps a status this client does not know
|
||||
/// (its raw word stays in [CheckCommandResult.statusWord]).
|
||||
enum CheckCommandStatus { passed, failed, timedOut, notRun, unknown }
|
||||
|
||||
CheckCommandStatus checkCommandStatus(String word) =>
|
||||
switch (word.trim().toLowerCase()) {
|
||||
'passed' => CheckCommandStatus.passed,
|
||||
'failed' => CheckCommandStatus.failed,
|
||||
'timed_out' => CheckCommandStatus.timedOut,
|
||||
'not_run' => CheckCommandStatus.notRun,
|
||||
_ => CheckCommandStatus.unknown,
|
||||
};
|
||||
|
||||
/// The status as the row reads it; an unknown status shows its raw word.
|
||||
String checkStatusLabel(CheckCommandResult check) => switch (check.status) {
|
||||
CheckCommandStatus.passed => 'Passed',
|
||||
CheckCommandStatus.failed => 'Failed',
|
||||
CheckCommandStatus.timedOut => 'Timed out',
|
||||
CheckCommandStatus.notRun => 'Not run',
|
||||
CheckCommandStatus.unknown =>
|
||||
check.statusWord.isEmpty ? 'Unknown status' : check.statusWord,
|
||||
};
|
||||
|
||||
/// One command's recorded result.
|
||||
class CheckCommandResult {
|
||||
const CheckCommandResult({
|
||||
required this.command,
|
||||
required this.statusWord,
|
||||
this.exitCode,
|
||||
this.durationMs,
|
||||
this.output = '',
|
||||
this.truncated = false,
|
||||
});
|
||||
|
||||
final String command;
|
||||
|
||||
/// The server's status word verbatim.
|
||||
final String statusWord;
|
||||
|
||||
/// Null when not recorded (a command that never ran has none).
|
||||
final int? exitCode;
|
||||
final int? durationMs;
|
||||
final String output;
|
||||
|
||||
/// Whether the server cut [output] at its capture limit.
|
||||
final bool truncated;
|
||||
|
||||
CheckCommandStatus get status => checkCommandStatus(statusWord);
|
||||
|
||||
/// `exit 1 · 51s`, leaving out whichever fact was not recorded.
|
||||
String get meta => [
|
||||
if (exitCode != null) 'exit $exitCode',
|
||||
if (durationMs != null) formatCheckDuration(durationMs!),
|
||||
].join(' · ');
|
||||
}
|
||||
|
||||
/// A check visit's whole recorded output.
|
||||
class CheckStepOutput {
|
||||
const CheckStepOutput({
|
||||
required this.checks,
|
||||
this.summary,
|
||||
this.markdown,
|
||||
this.delivery = false,
|
||||
});
|
||||
|
||||
final List<CheckCommandResult> checks;
|
||||
|
||||
/// The server's one-line summary (`1 of 2 checks failed: go test ./...`).
|
||||
final String? summary;
|
||||
|
||||
/// The handoff document the next stage reads.
|
||||
final String? markdown;
|
||||
|
||||
/// Whether this visit was the delivery gate.
|
||||
final bool delivery;
|
||||
}
|
||||
|
||||
/// The check output recorded in [output], or null when it is not one.
|
||||
CheckStepOutput? checkStepOutput(dynamic output) {
|
||||
if (output is! Map) return null;
|
||||
final checks = output['checks'];
|
||||
if (checks is! List) return null;
|
||||
return CheckStepOutput(
|
||||
checks: [
|
||||
for (final item in checks)
|
||||
if (item is Map) _check(item),
|
||||
],
|
||||
summary: _text(output['summary']),
|
||||
markdown: _text(output['markdown']),
|
||||
delivery: output['delivery'] == true,
|
||||
);
|
||||
}
|
||||
|
||||
CheckCommandResult _check(Map item) => CheckCommandResult(
|
||||
command: '${item['command'] ?? ''}',
|
||||
statusWord: '${item['status'] ?? ''}'.trim(),
|
||||
exitCode: _int(item['exit_code']),
|
||||
durationMs: _int(item['duration_ms']),
|
||||
output: item['output'] is String ? item['output'] as String : '',
|
||||
truncated: item['truncated'] == true,
|
||||
);
|
||||
|
||||
/// A command duration: `850ms`, `2.1s`, `51s`, `3m 05s`.
|
||||
String formatCheckDuration(int ms) {
|
||||
if (ms < 1000) return '${ms}ms';
|
||||
if (ms < 10000) {
|
||||
final tenths = (ms / 100).round();
|
||||
return tenths % 10 == 0 ? '${tenths ~/ 10}s' : '${tenths / 10}s';
|
||||
}
|
||||
final seconds = (ms / 1000).round();
|
||||
if (seconds < 60) return '${seconds}s';
|
||||
final minutes = seconds ~/ 60;
|
||||
final rest = (seconds % 60).toString().padLeft(2, '0');
|
||||
if (minutes < 60) return '${minutes}m ${rest}s';
|
||||
return '${minutes ~/ 60}h ${(minutes % 60).toString().padLeft(2, '0')}m';
|
||||
}
|
||||
|
||||
int? _int(dynamic value) {
|
||||
if (value is num) return value.toInt();
|
||||
if (value is String) return int.tryParse(value.trim());
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _text(dynamic value) {
|
||||
if (value is! String) return null;
|
||||
return value.trim().isEmpty ? null : value;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'run_quota.dart';
|
||||
import 'run_step_evidence.dart';
|
||||
|
||||
/// ApiGateway preserves wire envelopes; callers may also supply an extracted
|
||||
@@ -16,7 +17,7 @@ bool isWaitingRunStatus(dynamic status) => _word(status) == 'waiting';
|
||||
|
||||
int runLifecycleRank(dynamic status) => switch (_word(status)) {
|
||||
'queued' => 0,
|
||||
'running' || 'waiting' => 1,
|
||||
'running' || 'waiting' || runStatusWaitingQuota => 1,
|
||||
'succeeded' || 'failed' || 'canceled' || 'interrupted' => 2,
|
||||
_ => -1,
|
||||
};
|
||||
@@ -27,8 +28,19 @@ int stepLifecycleRank(dynamic status) => switch (_word(status)) {
|
||||
_ => -1,
|
||||
};
|
||||
|
||||
/// A run parks in waiting_quota from queued or running and leaves it for
|
||||
/// queued (a deferred launch) or running (a resumed visit), so a move into or
|
||||
/// out of it between live states is never stale.
|
||||
bool _quotaHop(dynamic current, dynamic incoming, int Function(dynamic) rank) =>
|
||||
(isWaitingQuotaStatus(current) || isWaitingQuotaStatus(incoming)) &&
|
||||
rank(current) >= 0 &&
|
||||
rank(current) < 2 &&
|
||||
rank(incoming) >= 0 &&
|
||||
rank(incoming) < 2;
|
||||
|
||||
bool _stale(dynamic current, dynamic incoming, int Function(dynamic) rank) {
|
||||
if (_word(incoming).isEmpty) return false;
|
||||
if (_quotaHop(current, incoming, rank)) return false;
|
||||
final oldRank = rank(current);
|
||||
final newRank = rank(incoming);
|
||||
return oldRank >= 0 &&
|
||||
@@ -39,6 +51,7 @@ bool _stale(dynamic current, dynamic incoming, int Function(dynamic) rank) {
|
||||
|
||||
String _advance(dynamic current, dynamic incoming, int Function(dynamic) rank) {
|
||||
if (_word(incoming).isEmpty || incoming == current) return '${current ?? ''}';
|
||||
if (_quotaHop(current, incoming, rank)) return '$incoming';
|
||||
final oldRank = rank(current);
|
||||
final newRank = rank(incoming);
|
||||
if (oldRank < 0) return '$incoming';
|
||||
@@ -50,7 +63,12 @@ String _advance(dynamic current, dynamic incoming, int Function(dynamic) rank) {
|
||||
|
||||
bool executingFor(dynamic status, bool current) => switch (_word(status)) {
|
||||
'queued' || 'running' => true,
|
||||
'waiting' || 'succeeded' || 'failed' || 'canceled' || 'interrupted' => false,
|
||||
'waiting' ||
|
||||
runStatusWaitingQuota ||
|
||||
'succeeded' ||
|
||||
'failed' ||
|
||||
'canceled' ||
|
||||
'interrupted' => false,
|
||||
_ => current,
|
||||
};
|
||||
|
||||
@@ -119,9 +137,16 @@ JsonMap _mergeRunFields(JsonMap current, JsonMap frame) {
|
||||
for (final key in ['outcome', 'current_stage', 'created_at', 'finished_at']) {
|
||||
if (!_blank(frame[key])) merged[key] = frame[key];
|
||||
}
|
||||
for (final key in ['failure_kind', 'failure_reason']) {
|
||||
for (final key in ['failure_kind', 'failure_reason', 'failure_class']) {
|
||||
if (frame[key] != null) merged[key] = frame[key];
|
||||
}
|
||||
// A status frame for waiting_quota carries the wait; any other status
|
||||
// clears it.
|
||||
if (status != runStatusWaitingQuota) {
|
||||
merged.remove('quota_wait');
|
||||
} else if (frame['quota_wait'] is Map) {
|
||||
merged['quota_wait'] = frame['quota_wait'];
|
||||
}
|
||||
// Snapshot and terminal frames carry the measured size; others omit it.
|
||||
if (frame['size_bytes'] is num) merged['size_bytes'] = frame['size_bytes'];
|
||||
final oldExport = _positiveInt(current['export_pending_sequence']);
|
||||
@@ -173,6 +198,8 @@ JsonMap? newRunSummaryFromFrame(JsonMap frame) {
|
||||
'current_stage': frame['current_stage'] ?? '',
|
||||
'failure_kind': frame['failure_kind'] ?? '',
|
||||
'failure_reason': frame['failure_reason'] ?? '',
|
||||
'failure_class': frame['failure_class'] ?? '',
|
||||
if (frame['quota_wait'] is Map) 'quota_wait': frame['quota_wait'],
|
||||
'resource_wait': frame['resource_wait'],
|
||||
'cancel_requested': frame['cancel_requested'] == true,
|
||||
'cleanup_unconfirmed': frame['cleanup_unconfirmed'] == true,
|
||||
@@ -245,6 +272,7 @@ bool runDetailNeedsFullSync(JsonMap frame) {
|
||||
final stepStatus = step is Map ? step['status'] : null;
|
||||
return isTerminalRunStatus(frame['status']) ||
|
||||
isWaitingRunStatus(frame['status']) ||
|
||||
isWaitingQuotaStatus(frame['status']) ||
|
||||
frame['cancel_requested'] == true ||
|
||||
frame['cleanup_unconfirmed'] == true ||
|
||||
isWaitingRunStatus(stepStatus) ||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
|
||||
/// The operator wording of each server failure class, matching
|
||||
/// `protocol.FailureClassLabel` in `internal/protocol/run_quota.go`.
|
||||
const runFailureClassLabels = <String, String>{
|
||||
'quota': 'usage limit',
|
||||
'loop_exhausted': 'loop limit reached',
|
||||
'timeout': 'timed out',
|
||||
'permission_denied': 'permission denied',
|
||||
'harness_error': 'harness error',
|
||||
'blocked': 'blocked',
|
||||
'environment': 'environment problem',
|
||||
'canceled': 'canceled',
|
||||
'interrupted': 'interrupted',
|
||||
'budget': 'budget exhausted',
|
||||
'check_failed': 'check failed',
|
||||
'other': 'failed',
|
||||
};
|
||||
|
||||
/// The wording of [run]'s `failure_class`, or null when it has none. An
|
||||
/// unknown class from a newer server is shown verbatim, as the server does.
|
||||
String? runFailureClassLabel(JsonMap run) {
|
||||
final word = '${run['failure_class'] ?? ''}'.trim().toLowerCase();
|
||||
if (word.isEmpty) return null;
|
||||
return runFailureClassLabels[word] ?? word.replaceAll('_', ' ');
|
||||
}
|
||||
|
||||
/// The run's whole-run USD budget (`protocol.RunBudget`): absent, or a zero
|
||||
/// limit, means the run has no cap.
|
||||
typedef RunBudget = ({double limit, double spent, String source});
|
||||
|
||||
RunBudget? runBudget(JsonMap run) {
|
||||
final budget = run['budget'];
|
||||
if (budget is! Map) return null;
|
||||
final limit = budget['limit_usd'];
|
||||
final spent = budget['spent_usd'];
|
||||
if (limit is! num || limit <= 0) return null;
|
||||
return (
|
||||
limit: limit.toDouble(),
|
||||
spent: spent is num ? spent.toDouble() : 0,
|
||||
source: '${budget['source'] ?? ''}'.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
/// `$1.25 of $5.00 budget`, noting a server-wide default cap.
|
||||
String? runBudgetText(JsonMap run) {
|
||||
final budget = runBudget(run);
|
||||
if (budget == null) return null;
|
||||
final text =
|
||||
'\$${budget.spent.toStringAsFixed(2)} of '
|
||||
'\$${budget.limit.toStringAsFixed(2)} budget';
|
||||
return budget.source == 'server' ? '$text (server default)' : text;
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import '../../pipelines/pipeline_format.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'run_quota.dart';
|
||||
import 'run_tokens.dart';
|
||||
|
||||
const runStates = [
|
||||
'queued',
|
||||
'running',
|
||||
'waiting',
|
||||
runStatusWaitingQuota,
|
||||
'succeeded',
|
||||
'failed',
|
||||
'canceled',
|
||||
@@ -86,6 +88,7 @@ String runStateOf(dynamic status) =>
|
||||
'queued' ||
|
||||
'running' ||
|
||||
'waiting' ||
|
||||
runStatusWaitingQuota ||
|
||||
'active' ||
|
||||
'blocked' ||
|
||||
'skipped' => '${status ?? ''}'.trim().toLowerCase(),
|
||||
@@ -208,8 +211,11 @@ RunRowFacts runRowFacts(JsonMap run, DateTime now) {
|
||||
);
|
||||
}
|
||||
|
||||
String runStatusLabel(JsonMap run) {
|
||||
String runStatusLabel(JsonMap run, {DateTime? now}) {
|
||||
final status = '${run['status'] ?? ''}';
|
||||
if (status == runStatusWaitingQuota) {
|
||||
return waitingQuotaStatusLabel(run, now: now);
|
||||
}
|
||||
if (!{'queued', 'running', 'waiting'}.contains(status)) {
|
||||
return status.isEmpty ? 'unknown' : status;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'run_failure_class.dart';
|
||||
import 'run_models.dart' show runStateOf;
|
||||
|
||||
/// The longest result preview a succeeded run's row shows; a longer one is
|
||||
@@ -13,16 +14,27 @@ typedef RunOutcomeLine = ({String line, String full, bool failed});
|
||||
/// The row's outcome line, or null when the run recorded nothing to show.
|
||||
///
|
||||
/// A failed run shows its failure reason, else its diagnostic's first
|
||||
/// non-blank line. A succeeded run shows its result preview only when it is
|
||||
/// non-blank line, after the server's failure class when it recorded one
|
||||
/// (`Failed · usage limit: <reason>`; the catch-all `other` adds nothing). A succeeded run shows its result preview only when it is
|
||||
/// short (at most [runResultPreviewRowLimit] characters on one line).
|
||||
RunOutcomeLine? runOutcomeLine(JsonMap run) {
|
||||
final state = runStateOf(run['status']);
|
||||
if (state == 'failed' && run['executing'] != true) {
|
||||
final reason = '${run['failure_reason'] ?? ''}'.trim();
|
||||
final diagnostic = '${run['diagnostic'] ?? ''}'.trim();
|
||||
final full = reason.isNotEmpty ? reason : diagnostic;
|
||||
if (full.isEmpty) return null;
|
||||
return (line: firstLine(full), full: full, failed: true);
|
||||
final text = reason.isNotEmpty ? reason : diagnostic;
|
||||
final label = runFailureClassLabel(run);
|
||||
if (label == null || label == runFailureClassLabels['other']) {
|
||||
if (text.isEmpty) return null;
|
||||
return (line: firstLine(text), full: text, failed: true);
|
||||
}
|
||||
final prefix = 'Failed · $label';
|
||||
if (text.isEmpty) return (line: prefix, full: prefix, failed: true);
|
||||
return (
|
||||
line: '$prefix: ${firstLine(text)}',
|
||||
full: '$prefix: $text',
|
||||
failed: true,
|
||||
);
|
||||
}
|
||||
if (state == 'succeeded') {
|
||||
final preview = '${run['result_preview'] ?? ''}'.trim();
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../pipelines/pipeline_format.dart'
|
||||
show formatLocalTimestamp, parseInstant;
|
||||
|
||||
/// The server's status word for a run parked until a provider usage limit
|
||||
/// resets (`protocol.RunStatusWaitingQuota`). It is not terminal: the server
|
||||
/// resumes the run on its own after the reset, or on `resume_run`.
|
||||
const runStatusWaitingQuota = 'waiting_quota';
|
||||
|
||||
/// The operator's words for [runStatusWaitingQuota].
|
||||
const runWaitingQuotaLabel = 'Waiting for usage limit';
|
||||
|
||||
bool isWaitingQuotaStatus(dynamic status) =>
|
||||
'${status ?? ''}'.trim().toLowerCase() == runStatusWaitingQuota;
|
||||
|
||||
/// A parked run's `quota_wait` (`protocol.RunQuotaWait`). [sequence] is the
|
||||
/// interrupted visit, 0 when the run was deferred before its first stage.
|
||||
typedef RunQuotaWait = ({
|
||||
DateTime? resetsAt,
|
||||
DateTime? resumeAt,
|
||||
int sequence,
|
||||
String stage,
|
||||
String account,
|
||||
});
|
||||
|
||||
/// The run's quota wait, or null when it carries none.
|
||||
RunQuotaWait? runQuotaWait(JsonMap run) {
|
||||
final wait = run['quota_wait'];
|
||||
if (wait is! Map) return null;
|
||||
final sequence = wait['sequence'];
|
||||
return (
|
||||
resetsAt: parseInstant('${wait['resets_at'] ?? ''}'),
|
||||
resumeAt: parseInstant('${wait['resume_at'] ?? ''}'),
|
||||
sequence: sequence is num ? sequence.toInt() : 0,
|
||||
stage: '${wait['stage'] ?? ''}'.trim(),
|
||||
account: '${wait['account'] ?? ''}'.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
/// [instant] in local time: `HH:mm` on [now]'s local day, else `d MMM HH:mm`.
|
||||
String quotaClockText(DateTime instant, {DateTime? now}) {
|
||||
final local = instant.toLocal();
|
||||
final today = (now ?? DateTime.now()).toLocal();
|
||||
if (local.year == today.year &&
|
||||
local.month == today.month &&
|
||||
local.day == today.day) {
|
||||
String two(int value) => value.toString().padLeft(2, '0');
|
||||
return '${two(local.hour)}:${two(local.minute)}';
|
||||
}
|
||||
return formatLocalTimestamp(local.toUtc().toIso8601String()) ?? '';
|
||||
}
|
||||
|
||||
/// `resumes 09:01`, or null when the server sent no usable resume time.
|
||||
String? quotaResumeText(RunQuotaWait? wait, {DateTime? now}) {
|
||||
final at = wait?.resumeAt ?? wait?.resetsAt;
|
||||
return at == null ? null : 'resumes ${quotaClockText(at, now: now)}';
|
||||
}
|
||||
|
||||
/// The status line of a parked run: `Waiting for usage limit · resumes 09:01`.
|
||||
String waitingQuotaStatusLabel(JsonMap run, {DateTime? now}) {
|
||||
final resume = quotaResumeText(runQuotaWait(run), now: now);
|
||||
return resume == null
|
||||
? runWaitingQuotaLabel
|
||||
: '$runWaitingQuotaLabel · $resume';
|
||||
}
|
||||
|
||||
/// The facts under a parked run's notice: the reset time, the account that
|
||||
/// hit the limit and the interrupted stage, each only when recorded.
|
||||
String quotaWaitMeta(RunQuotaWait wait, {DateTime? now}) => [
|
||||
if (wait.resetsAt case final at?)
|
||||
'Limit resets ${quotaClockText(at, now: now)}',
|
||||
if (quotaResumeText(wait, now: now) case final resume?) 'run $resume',
|
||||
if (wait.account.isNotEmpty) 'account ${wait.account}',
|
||||
if (wait.stage.isNotEmpty) 'at ${wait.stage}',
|
||||
].join(' · ');
|
||||
@@ -19,7 +19,7 @@ List<JsonMap> runDetailChangeSteps(JsonMap run) {
|
||||
return const <JsonMap>[];
|
||||
}
|
||||
|
||||
const _executingStatuses = {'queued', 'running', 'waiting'};
|
||||
const _executingStatuses = {'queued', 'running', 'waiting', 'waiting_quota'};
|
||||
|
||||
/// Whether the run detail offers the action at all. The opened page is a
|
||||
/// snapshot of the recorded steps, so it is offered only once nothing is
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../../chat/ui/transcript/chat_markdown_view.dart';
|
||||
import '../domain/check_step_output.dart';
|
||||
|
||||
/// The note under a command whose recorded output the server cut short.
|
||||
const String checkOutputTruncated =
|
||||
'The server truncated this output at its capture limit.';
|
||||
|
||||
/// The body of a command that recorded no output.
|
||||
const String checkOutputEmpty = 'No output recorded.';
|
||||
|
||||
/// A check visit's Output: its summary, a delivery-gate marker, one
|
||||
/// expandable row per command and the handoff document the next stage reads.
|
||||
class RunCheckOutputView extends StatelessWidget {
|
||||
const RunCheckOutputView({super.key, required this.output});
|
||||
|
||||
final CheckStepOutput output;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final summary = output.summary;
|
||||
final markdown = output.markdown;
|
||||
return Column(
|
||||
key: const Key('run-check-output'),
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (output.delivery)
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Chip(
|
||||
key: const Key('run-check-delivery'),
|
||||
avatar: const Icon(Icons.verified_outlined),
|
||||
label: const Text('Delivery gate'),
|
||||
),
|
||||
),
|
||||
if (summary != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: SelectableText(summary, style: theme.textTheme.bodyLarge),
|
||||
),
|
||||
if (output.checks.isEmpty)
|
||||
const Text('No commands were recorded.')
|
||||
else
|
||||
for (final (index, check) in output.checks.indexed)
|
||||
RunCheckCommandRow(
|
||||
key: ValueKey('run-check-command-$index'),
|
||||
check: check,
|
||||
),
|
||||
if (markdown != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text('Handoff', style: theme.textTheme.titleSmall),
|
||||
const SizedBox(height: 4),
|
||||
ChatMarkdownView(text: markdown),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One command: a status icon, the command, its status, exit code and
|
||||
/// duration; expanding it shows the recorded output as selectable monospace.
|
||||
class RunCheckCommandRow extends StatelessWidget {
|
||||
const RunCheckCommandRow({super.key, required this.check});
|
||||
|
||||
final CheckCommandResult check;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final mono = (theme.textTheme.bodyMedium ?? const TextStyle()).copyWith(
|
||||
fontFamily: appMonospaceFamily,
|
||||
);
|
||||
final color = runStatusColor(_state(check.status), theme.colorScheme);
|
||||
final meta = check.meta;
|
||||
return ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
childrenPadding: const EdgeInsets.only(bottom: 12),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
leading: Icon(
|
||||
_icon(check.status),
|
||||
color: color,
|
||||
semanticLabel: checkStatusLabel(check),
|
||||
),
|
||||
title: Text(
|
||||
check.command.isEmpty ? '(no command)' : check.command,
|
||||
style: mono,
|
||||
),
|
||||
subtitle: Text(
|
||||
[checkStatusLabel(check), if (meta.isNotEmpty) meta].join(' · '),
|
||||
),
|
||||
children: [
|
||||
if (check.output.isEmpty)
|
||||
const Text(checkOutputEmpty)
|
||||
else
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: SelectableText(check.output, style: mono),
|
||||
),
|
||||
),
|
||||
if (check.truncated)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
checkOutputTruncated,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static String _state(CheckCommandStatus status) => switch (status) {
|
||||
CheckCommandStatus.passed => 'succeeded',
|
||||
CheckCommandStatus.failed || CheckCommandStatus.timedOut => 'failed',
|
||||
CheckCommandStatus.notRun || CheckCommandStatus.unknown => 'unknown',
|
||||
};
|
||||
|
||||
static IconData _icon(CheckCommandStatus status) => switch (status) {
|
||||
CheckCommandStatus.passed => Icons.check_circle_outline,
|
||||
CheckCommandStatus.failed => Icons.cancel_outlined,
|
||||
CheckCommandStatus.timedOut => Icons.timer_off_outlined,
|
||||
CheckCommandStatus.notRun => Icons.remove_circle_outline,
|
||||
CheckCommandStatus.unknown => Icons.help_outline,
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import '../actions/cancel_run_action.dart';
|
||||
import '../actions/retry_action.dart';
|
||||
import '../actions/retry_eligibility.dart';
|
||||
import 'run_decision_notice.dart';
|
||||
import 'run_quota_notice.dart';
|
||||
|
||||
/// Native actions on the loaded run, all using the app's one gateway and
|
||||
/// applying only accepted server detail through the same controller callback.
|
||||
@@ -60,6 +61,7 @@ class RunDetailActions extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
RunDecisionNotice(run: run, gateway: gateway, onRunChanged: onRunChanged),
|
||||
RunQuotaNotice(run: run, gateway: gateway, onRunChanged: onRunChanged),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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';
|
||||
|
||||
@@ -68,6 +69,7 @@ List<DetailSummaryRow> detailSummaryRows(JsonMap run, {DateTime? now}) {
|
||||
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
|
||||
|
||||
@@ -133,6 +133,22 @@ String? detailVisitSkills(JsonMap step) {
|
||||
return (option: option, reason: reason);
|
||||
}
|
||||
|
||||
/// How many times the server sent its one "missing `# outcome`" repair
|
||||
/// follow-up for this visit (`control.outcome_repairs`); 0 when not recorded,
|
||||
/// which older servers and unrepaired visits both mean.
|
||||
int detailVisitOutcomeRepairs(JsonMap step) {
|
||||
final control = step['control'];
|
||||
if (control is! Map) return 0;
|
||||
final value = control['outcome_repairs'];
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse('${value ?? ''}'.trim()) ?? 0;
|
||||
}
|
||||
|
||||
/// The note a repaired visit shows under its facts.
|
||||
String outcomeRepairNote(int repairs) => repairs == 1
|
||||
? 'Outcome repaired by follow-up'
|
||||
: 'Outcome repaired by follow-up ($repairs times)';
|
||||
|
||||
/// The visit's diagnostic exactly as recorded, or null when it is blank.
|
||||
String? detailVisitDiagnostic(JsonMap step) => _text(step['diagnostic']);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class RunVisitFactsView extends StatelessWidget {
|
||||
final facts = detailVisitFacts(step);
|
||||
final verdict = detailVisitVerdict(step);
|
||||
final diagnostic = detailVisitDiagnostic(step);
|
||||
final repairs = detailVisitOutcomeRepairs(step);
|
||||
return Padding(
|
||||
key: const Key('run-visit-facts'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 12),
|
||||
@@ -28,6 +29,23 @@ class RunVisitFactsView extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_FactGrid(facts: facts, style: style),
|
||||
if (repairs > 0) ...[
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
key: const Key('run-visit-outcome-repaired'),
|
||||
children: [
|
||||
Icon(
|
||||
Icons.build_circle_outlined,
|
||||
size: 16,
|
||||
color: style.muted.color,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(outcomeRepairNote(repairs), style: style.muted),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (verdict != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text('Verdict', style: style.heading),
|
||||
@@ -57,10 +75,14 @@ class _FactGrid extends StatelessWidget {
|
||||
static String _stateOf(VisitFact fact) {
|
||||
final value = fact.value.trim().toLowerCase();
|
||||
if (fact.label == 'Outcome') {
|
||||
if (value == 'error' || value == 'failed' || value == 'blocked') {
|
||||
if (value == 'error' ||
|
||||
value == 'failed' ||
|
||||
value == 'fail' ||
|
||||
value == 'blocked') {
|
||||
return 'failed';
|
||||
}
|
||||
if (value == 'success') return 'succeeded';
|
||||
// A check stage routes `pass`/`fail`.
|
||||
if (value == 'success' || value == 'pass') return 'succeeded';
|
||||
return 'running';
|
||||
}
|
||||
return graphStatusState(fact.value);
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'package:flutter/services.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/floating_destination_bar.dart';
|
||||
import '../../changes/changes.dart';
|
||||
import '../domain/check_step_output.dart';
|
||||
import 'run_check_output_view.dart';
|
||||
import 'run_detail_tab_bodies.dart';
|
||||
import 'run_field_body.dart';
|
||||
import '../../../ui/layout/sticky_section.dart';
|
||||
@@ -216,6 +218,9 @@ class _VisitSummaryState extends State<_VisitSummary> {
|
||||
);
|
||||
final open = !_closed.contains(name);
|
||||
const padding = EdgeInsets.fromLTRB(16, 0, 16, 16);
|
||||
// A check visit's Output is its command results, not a field map.
|
||||
final check = name == 'Output' ? checkStepOutput(value) : null;
|
||||
final sliver = lazy && check == null;
|
||||
return StickySection(
|
||||
key: ValueKey('run-visit-section-$name'),
|
||||
title: name,
|
||||
@@ -224,13 +229,15 @@ class _VisitSummaryState extends State<_VisitSummary> {
|
||||
if (!_closed.remove(name)) _closed.add(name);
|
||||
}),
|
||||
trailing: [copy],
|
||||
body: lazy
|
||||
body: sliver
|
||||
? null
|
||||
: Padding(
|
||||
padding: padding,
|
||||
child: RunFieldBody(value: value, empty: empty),
|
||||
child: check != null
|
||||
? RunCheckOutputView(output: check)
|
||||
: RunFieldBody(value: value, empty: empty),
|
||||
),
|
||||
sliverBody: lazy
|
||||
sliverBody: sliver
|
||||
? SliverPadding(
|
||||
padding: padding,
|
||||
sliver: RunFieldSliver(value: value, empty: empty),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/check_step_output.dart';
|
||||
import 'run_detail_visit_export.dart';
|
||||
import 'run_detail_visit_recorded.dart';
|
||||
|
||||
@@ -18,6 +19,10 @@ const String visitSessionNoIdentity =
|
||||
'Runtime error: this model stage has no recorded session identity.';
|
||||
const String visitSessionNone = 'This visit has no harness session.';
|
||||
|
||||
/// A check stage runs commands, never a model, so it has no session at all.
|
||||
const String visitSessionCheck =
|
||||
'A check stage runs commands without a model; it has no harness session.';
|
||||
|
||||
/// An export that exists but cannot be resolved through the configured server.
|
||||
const String visitSessionEndpointMissing =
|
||||
'Set the server URL in Settings to open the session.';
|
||||
@@ -94,6 +99,7 @@ String _noSessionMessage(JsonMap step) {
|
||||
if (status == 'canceled' || status == 'interrupted') {
|
||||
return visitSessionStopped;
|
||||
}
|
||||
if (checkStepOutput(step['output']) != null) return visitSessionCheck;
|
||||
final model =
|
||||
recordedText(step['provider']) != null ||
|
||||
recordedText(step['model']) != null;
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../actions/resume_quota_action.dart';
|
||||
import '../domain/run_quota.dart';
|
||||
|
||||
/// A run parked until a usage limit resets: when the limit resets and the run
|
||||
/// resumes, the account that hit it, and "Resume now". The run's Cancel stays
|
||||
/// with the other run actions. Nothing for any other run.
|
||||
class RunQuotaNotice extends StatelessWidget {
|
||||
const RunQuotaNotice({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.gateway,
|
||||
required this.onRunChanged,
|
||||
this.now,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final ApiGateway gateway;
|
||||
final ValueChanged<JsonMap> onRunChanged;
|
||||
|
||||
/// The clock, for tests.
|
||||
final DateTime? now;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!isWaitingQuotaStatus(run['status'])) return const SizedBox.shrink();
|
||||
final wait = runQuotaWait(run);
|
||||
final meta = wait == null ? '' : quotaWaitMeta(wait, now: now);
|
||||
final color = Theme.of(context).colorScheme.tertiary;
|
||||
return Container(
|
||||
key: const Key('run-quota-banner'),
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.hourglass_bottom, color: color, size: 18),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Semantics(
|
||||
header: true,
|
||||
child: const Text(
|
||||
runWaitingQuotaLabel,
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
if (meta.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(meta, style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ResumeQuotaRunAction(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user