Merge branch 'worktree-agent-a5f621112ab3cad4f'
# Conflicts: # app/lib/features/chat/domain/chat_shown_run.dart
This commit is contained in:
@@ -12,7 +12,12 @@ const ValueKey<String> runArtifactsButtonKey = ValueKey<String>(
|
||||
'run-detail-artifacts',
|
||||
);
|
||||
|
||||
const Set<String> _executingStatuses = {'queued', 'running', 'waiting'};
|
||||
const Set<String> _executingStatuses = {
|
||||
'queued',
|
||||
'running',
|
||||
'waiting',
|
||||
'waiting_quota',
|
||||
};
|
||||
|
||||
/// The detail's `steps` exactly as returned by the server. The pushed page
|
||||
/// snapshots the returned list once, so it never re-derives on each rebuild.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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';
|
||||
import 'chat_shown_run_map.dart';
|
||||
|
||||
export 'chat_shown_run_map.dart';
|
||||
@@ -57,6 +58,7 @@ class ChatShownRun {
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -15,6 +15,7 @@ IconData chatShownRunIcon(String status) => switch (status) {
|
||||
'canceled' => Icons.cancel_outlined,
|
||||
'interrupted' => Icons.pause_circle_outline,
|
||||
'waiting' => Icons.front_hand_outlined,
|
||||
'waiting_quota' => Icons.hourglass_bottom,
|
||||
'queued' => Icons.schedule,
|
||||
_ => Icons.play_circle_outline,
|
||||
};
|
||||
@@ -22,7 +23,7 @@ IconData chatShownRunIcon(String status) => switch (status) {
|
||||
Color _statusColor(ColorScheme colors, String status) => switch (status) {
|
||||
'succeeded' => colors.primary,
|
||||
'failed' || 'interrupted' => colors.error,
|
||||
'waiting' => colors.tertiary,
|
||||
'waiting' || 'waiting_quota' => colors.tertiary,
|
||||
_ => colors.onSurfaceVariant,
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ const runStatusFilters = <String>[
|
||||
'queued',
|
||||
'running',
|
||||
'waiting',
|
||||
'waiting_quota',
|
||||
'succeeded',
|
||||
'failed',
|
||||
'canceled',
|
||||
|
||||
@@ -64,6 +64,7 @@ const _runStateAliases = <String, String>{
|
||||
'running': 'running',
|
||||
'queued': 'queued',
|
||||
'waiting': 'waiting',
|
||||
'waiting_quota': 'waiting_quota',
|
||||
'active': 'active',
|
||||
'succeeded': 'succeeded',
|
||||
'success': 'succeeded',
|
||||
@@ -88,6 +89,7 @@ String runStateOf(String? status) {
|
||||
/// `Running`-style title for a run state.
|
||||
String runStateLabel(String? status) {
|
||||
final state = runStateOf(status);
|
||||
if (state == 'waiting_quota') return 'Waiting for usage limit';
|
||||
return state.isEmpty
|
||||
? state
|
||||
: '${state[0].toUpperCase()}${state.substring(1)}';
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_findings.dart' show visitGrantsSummary;
|
||||
import '../domain/run_tokens.dart';
|
||||
import 'run_detail_visit_facts.dart';
|
||||
@@ -69,6 +70,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');
|
||||
add('Extra visits', visitGrantsSummary(run));
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
||||
/// The shared status glyph whose tooltip and accessible name say the state.
|
||||
///
|
||||
/// [state] is the normalised run state (`succeeded`, `failed`, `running`,
|
||||
/// `waiting`, `queued`, `canceled`, `interrupted`, anything else unknown);
|
||||
/// `waiting`, `waiting_quota`, `queued`, `canceled`, `interrupted`, anything else unknown);
|
||||
/// [label] is the word a person reads. Colours are the platform's dynamic
|
||||
/// system colours, so the glyph keeps its contrast in light and dark themes.
|
||||
class RunStatusIcon extends StatelessWidget {
|
||||
@@ -45,7 +45,8 @@ Color runStatusColor(String state, [ColorScheme? colorScheme]) {
|
||||
'failed' => dark ? const Color(0xFFFF453A) : const Color(0xFFFF3B30),
|
||||
'running' ||
|
||||
'active' => dark ? const Color(0xFF0A84FF) : const Color(0xFF007AFF),
|
||||
'waiting' => dark ? const Color(0xFFFFD60A) : const Color(0xFFFFCC00),
|
||||
'waiting' ||
|
||||
'waiting_quota' => dark ? const Color(0xFFFFD60A) : const Color(0xFFFFCC00),
|
||||
'interrupted' => dark ? const Color(0xFFFF9F0A) : const Color(0xFFFF9500),
|
||||
_ => const Color(0xFF8E8E93),
|
||||
};
|
||||
@@ -58,6 +59,8 @@ IconData _materialIcon(String state) => switch (state) {
|
||||
'canceled' => Icons.block,
|
||||
'interrupted' => Icons.pause_circle_outline,
|
||||
'waiting' => Icons.person_outline,
|
||||
// Parked until a usage limit resets: a timer, not a person.
|
||||
'waiting_quota' => Icons.hourglass_bottom,
|
||||
'queued' => Icons.schedule,
|
||||
_ => Icons.help_outline,
|
||||
};
|
||||
|
||||
@@ -29,7 +29,13 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-filter')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('No schedules'));
|
||||
// The status list (with waiting_quota) pushes scheduling below the
|
||||
// lazily built part of the page: scroll to it.
|
||||
await tester.dragUntilVisible(
|
||||
find.text('No schedules'),
|
||||
find.byType(ListView).last,
|
||||
const Offset(0, -200),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('No schedules'));
|
||||
await tester.pump();
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/resume_quota_action.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_decisions.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_actions.dart';
|
||||
|
||||
import 'cancel_test_support.dart';
|
||||
|
||||
JsonMap _parked({bool cancelRequested = false}) => {
|
||||
'id': 7,
|
||||
'title': 'Nightly build',
|
||||
'status': 'waiting_quota',
|
||||
'executing': false,
|
||||
'cancel_requested': cancelRequested,
|
||||
'quota_wait': {
|
||||
'resets_at': DateTime(2026, 12, 3, 9).toUtc().toIso8601String(),
|
||||
'resume_at': DateTime(2026, 12, 3, 9, 1).toUtc().toIso8601String(),
|
||||
'sequence': 2,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
},
|
||||
};
|
||||
|
||||
Future<List<JsonMap>> _pump(
|
||||
WidgetTester tester,
|
||||
FakeCancelGateway gateway,
|
||||
) async {
|
||||
final changed = <JsonMap>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunDetailActions(
|
||||
run: _parked(),
|
||||
gateway: gateway,
|
||||
onRunChanged: changed.add,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return changed;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('a parked run is cancellable and resumable, never a decision', () {
|
||||
final run = _parked();
|
||||
expect(canCancelRun(run), isTrue);
|
||||
expect(canResumeQuotaRun(run), isTrue);
|
||||
expect(canResumeQuotaRun(_parked(cancelRequested: true)), isFalse);
|
||||
expect(canCancelRun(_parked(cancelRequested: true)), isFalse);
|
||||
expect(canResumeQuotaRun({'id': 7, 'status': 'waiting'}), isFalse);
|
||||
expect(attentionKindForRun(run), isNull);
|
||||
expect(orderAttention([run]), isEmpty);
|
||||
expect(pendingDecision(run), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Resume now sends resume_run and applies the reply', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeCancelGateway(
|
||||
(type, fields) async => {
|
||||
'type': 'run',
|
||||
'run_detail': {'id': 7, 'status': 'running', 'executing': true},
|
||||
},
|
||||
);
|
||||
final changed = await _pump(tester, gateway);
|
||||
expect(find.text('Waiting for usage limit'), findsOneWidget);
|
||||
expect(find.textContaining('account work'), findsOneWidget);
|
||||
expect(find.byKey(cancelActionKey), findsOneWidget);
|
||||
await tester.tap(find.byKey(resumeQuotaActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls.single.type, 'resume_run');
|
||||
expect(gateway.calls.single.fields, {'run_id': 7});
|
||||
expect(changed.single['status'], 'running');
|
||||
});
|
||||
|
||||
testWidgets('a refused resume shows the server message', (tester) async {
|
||||
final gateway = FakeCancelGateway(
|
||||
(type, fields) async =>
|
||||
throw Exception('run 7 is not waiting for a usage limit'),
|
||||
);
|
||||
final changed = await _pump(tester, gateway);
|
||||
await tester.tap(find.byKey(resumeQuotaActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(resumeQuotaErrorKey), findsOneWidget);
|
||||
expect(
|
||||
find.textContaining('not waiting for a usage limit'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_events.dart';
|
||||
|
||||
void main() {
|
||||
const wait = {
|
||||
'resets_at': '2026-12-03T09:00:00Z',
|
||||
'resume_at': '2026-12-03T09:01:00Z',
|
||||
'sequence': 2,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
};
|
||||
final running = {
|
||||
'id': 4,
|
||||
'pipeline_id': 1,
|
||||
'name': 'build',
|
||||
'status': 'running',
|
||||
'executing': true,
|
||||
};
|
||||
|
||||
test('a running run parks with its wait and resumes without it', () {
|
||||
final parked = foldRunEvent(
|
||||
[running],
|
||||
{'run_id': 4, 'status': 'waiting_quota', 'quota_wait': wait},
|
||||
).runs.single;
|
||||
expect(parked['status'], 'waiting_quota');
|
||||
expect(parked['executing'], isFalse);
|
||||
expect(parked['quota_wait'], wait);
|
||||
// A frame without a status keeps the wait.
|
||||
final same = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'current_stage': 'implement'},
|
||||
).runs.single;
|
||||
expect(same['quota_wait'], wait);
|
||||
final resumed = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'status': 'running'},
|
||||
).runs.single;
|
||||
expect(resumed['status'], 'running');
|
||||
expect(resumed['executing'], isTrue);
|
||||
expect(resumed.containsKey('quota_wait'), isFalse);
|
||||
});
|
||||
|
||||
test('a deferred run goes back to queued when resumed', () {
|
||||
final deferred = {
|
||||
...running,
|
||||
'status': 'waiting_quota',
|
||||
'executing': false,
|
||||
};
|
||||
final queued = foldRunEvent(
|
||||
[deferred],
|
||||
{'run_id': 4, 'status': 'queued'},
|
||||
).runs.single;
|
||||
expect(queued['status'], 'queued');
|
||||
expect(queued['executing'], isTrue);
|
||||
final parkedAgain = foldRunEvent(
|
||||
[queued],
|
||||
{'run_id': 4, 'status': 'waiting_quota', 'quota_wait': wait},
|
||||
).runs.single;
|
||||
expect(parkedAgain['status'], 'waiting_quota');
|
||||
});
|
||||
|
||||
test('a parked run can be canceled and records the failure class', () {
|
||||
final parked = {...running, 'status': 'waiting_quota', 'quota_wait': wait};
|
||||
final canceled = foldRunEvent(
|
||||
[parked],
|
||||
{'run_id': 4, 'status': 'canceled', 'failure_class': 'canceled'},
|
||||
).runs.single;
|
||||
expect(canceled['status'], 'canceled');
|
||||
expect(canceled['failure_class'], 'canceled');
|
||||
expect(canceled.containsKey('quota_wait'), isFalse);
|
||||
// Terminal stays terminal.
|
||||
final stale = foldRunEvent(
|
||||
[canceled],
|
||||
{'run_id': 4, 'status': 'waiting_quota'},
|
||||
).runs.single;
|
||||
expect(stale['status'], 'canceled');
|
||||
});
|
||||
|
||||
test('the detail folds the same fields and re-reads on parking', () {
|
||||
final detail = foldRunEventDetail(
|
||||
{...running, 'steps': []},
|
||||
{
|
||||
'run_id': 4,
|
||||
'status': 'failed',
|
||||
'failure_class': 'quota',
|
||||
'failure_reason': 'usage limit',
|
||||
},
|
||||
)!;
|
||||
expect(detail['failure_class'], 'quota');
|
||||
expect(
|
||||
runDetailNeedsFullSync({'run_id': 4, 'status': 'waiting_quota'}),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('a new row from a parked frame keeps its wait', () {
|
||||
final row = newRunSummaryFromFrame({
|
||||
'run_id': 9,
|
||||
'pipeline_id': 1,
|
||||
'name': 'build',
|
||||
'status': 'waiting_quota',
|
||||
'quota_wait': wait,
|
||||
})!;
|
||||
expect(row['executing'], isFalse);
|
||||
expect(row['quota_wait'], wait);
|
||||
expect(row['failure_class'], '');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_format.dart'
|
||||
show runStateLabel;
|
||||
import 'package:pipelines_app/features/runs/domain/run_failure_class.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_outcome_line.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_quota.dart';
|
||||
|
||||
String _local(int hour, int minute) =>
|
||||
DateTime(2026, 12, 3, hour, minute).toUtc().toIso8601String();
|
||||
|
||||
void main() {
|
||||
final now = DateTime(2026, 12, 3, 8);
|
||||
final parked = {
|
||||
'id': 4,
|
||||
'status': 'waiting_quota',
|
||||
'quota_wait': {
|
||||
'resets_at': _local(9, 0),
|
||||
'resume_at': _local(9, 1),
|
||||
'sequence': 3,
|
||||
'stage': 'implement',
|
||||
'account': 'work',
|
||||
},
|
||||
};
|
||||
|
||||
test('quota_wait parses and reads in local time', () {
|
||||
final wait = runQuotaWait(parked)!;
|
||||
expect(wait.sequence, 3);
|
||||
expect(wait.stage, 'implement');
|
||||
expect(wait.account, 'work');
|
||||
expect(quotaResumeText(wait, now: now), 'resumes 09:01');
|
||||
expect(
|
||||
quotaWaitMeta(wait, now: now),
|
||||
'Limit resets 09:00 · run resumes 09:01 · account work · at implement',
|
||||
);
|
||||
expect(runQuotaWait({'status': 'waiting_quota'}), isNull);
|
||||
});
|
||||
|
||||
test('a resume on another day carries its date', () {
|
||||
final later = DateTime(2026, 12, 4, 9, 1);
|
||||
expect(quotaClockText(later, now: now), '4 Dec 09:01');
|
||||
});
|
||||
|
||||
test('waiting_quota is its own state with its own words', () {
|
||||
expect(runStateOf('waiting_quota'), 'waiting_quota');
|
||||
expect(runStates, contains('waiting_quota'));
|
||||
expect(runStateLabel('waiting_quota'), 'Waiting for usage limit');
|
||||
expect(
|
||||
runStatusLabel(parked, now: now),
|
||||
'Waiting for usage limit · resumes 09:01',
|
||||
);
|
||||
expect(
|
||||
runStatusLabel({'status': 'waiting_quota'}),
|
||||
'Waiting for usage limit',
|
||||
);
|
||||
final filtered = filterRuns(
|
||||
[
|
||||
parked,
|
||||
{'id': 5, 'status': 'waiting'},
|
||||
],
|
||||
statuses: {'waiting_quota'},
|
||||
);
|
||||
expect(filtered.map((run) => run['id']), [4]);
|
||||
});
|
||||
|
||||
test('failure classes use the server wording', () {
|
||||
expect(runFailureClassLabel({'failure_class': 'quota'}), 'usage limit');
|
||||
expect(
|
||||
runFailureClassLabel({'failure_class': 'loop_exhausted'}),
|
||||
'loop limit reached',
|
||||
);
|
||||
expect(
|
||||
runFailureClassLabel({'failure_class': 'budget'}),
|
||||
'budget exhausted',
|
||||
);
|
||||
expect(runFailureClassLabel({'failure_class': 'new_kind'}), 'new kind');
|
||||
expect(runFailureClassLabel({}), isNull);
|
||||
expect(runFailureClassLabels.length, 12);
|
||||
});
|
||||
|
||||
test('the outcome line leads with the failure class', () {
|
||||
final line = runOutcomeLine({
|
||||
'status': 'failed',
|
||||
'failure_class': 'quota',
|
||||
'failure_reason': 'Claude usage limit\nreset at 9',
|
||||
})!;
|
||||
expect(line.line, 'Failed · usage limit: Claude usage limit');
|
||||
expect(line.full, 'Failed · usage limit: Claude usage limit\nreset at 9');
|
||||
expect(line.failed, isTrue);
|
||||
expect(
|
||||
runOutcomeLine({'status': 'failed', 'failure_class': 'timeout'})?.line,
|
||||
'Failed · timed out',
|
||||
);
|
||||
// The catch-all class adds nothing to the reason.
|
||||
expect(
|
||||
runOutcomeLine({
|
||||
'status': 'failed',
|
||||
'failure_class': 'other',
|
||||
'failure_reason': 'exit 2',
|
||||
})?.line,
|
||||
'exit 2',
|
||||
);
|
||||
expect(
|
||||
runOutcomeLine({'status': 'failed', 'failure_class': 'other'}),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('a capped run shows its budget', () {
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 5, 'spent_usd': 1.25, 'source': 'run'},
|
||||
}),
|
||||
r'$1.25 of $5.00 budget',
|
||||
);
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 2, 'spent_usd': 0, 'source': 'server'},
|
||||
}),
|
||||
r'$0.00 of $2.00 budget (server default)',
|
||||
);
|
||||
expect(
|
||||
runBudgetText({
|
||||
'budget': {'limit_usd': 0},
|
||||
}),
|
||||
isNull,
|
||||
);
|
||||
expect(runBudgetText({}), isNull);
|
||||
});
|
||||
}
|
||||
@@ -120,8 +120,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const ValueKey('runs.filter')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Seven statuses may be combined: those keep their checkboxes.
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(7));
|
||||
// Eight statuses (with waiting_quota) may be combined: those keep their
|
||||
// checkboxes.
|
||||
expect(find.byType(CheckboxListTile), findsNWidgets(8));
|
||||
final anyTime = find.widgetWithText(ListTile, 'Any time');
|
||||
expect(anyTime, findsOneWidget);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user