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:
2026-12-03 14:34:53 +00:00
193 changed files with 11295 additions and 505 deletions
@@ -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,77 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/check_step_output.dart';
void main() {
test('a check output reads each command result', () {
final output = checkStepOutput({
'markdown': '# outcome\n\nfail\n',
'summary': '1 of 2 checks failed: go test ./...',
'delivery': true,
'checks': [
{
'command': 'go vet ./...',
'status': 'passed',
'exit_code': 0,
'duration_ms': 2100,
'output': '',
'truncated': false,
},
{
'command': 'go test ./...',
'status': 'failed',
'exit_code': 1,
'duration_ms': 51000,
'output': '--- FAIL',
'truncated': true,
},
{'command': 'make lint', 'status': 'not_run'},
'not a map',
],
})!;
expect(output.delivery, isTrue);
expect(output.summary, '1 of 2 checks failed: go test ./...');
expect(output.markdown, startsWith('# outcome'));
expect(output.checks, hasLength(3));
final [vet, test, lint] = output.checks;
expect(vet.status, CheckCommandStatus.passed);
expect(vet.meta, 'exit 0 · 2.1s');
expect(test.status, CheckCommandStatus.failed);
expect(test.meta, 'exit 1 · 51s');
expect(test.truncated, isTrue);
expect(lint.status, CheckCommandStatus.notRun);
expect(lint.meta, '');
expect(checkStatusLabel(lint), 'Not run');
});
test('statuses this client does not know keep their own word', () {
final output = checkStepOutput({
'checks': [
{'command': 'x', 'status': 'skipped_by_policy'},
{'command': 'y'},
{'command': 'z', 'status': 'timed_out'},
],
})!;
expect(output.checks[0].status, CheckCommandStatus.unknown);
expect(checkStatusLabel(output.checks[0]), 'skipped_by_policy');
expect(checkStatusLabel(output.checks[1]), 'Unknown status');
expect(checkStatusLabel(output.checks[2]), 'Timed out');
expect(output.delivery, isFalse);
});
test('outputs without a checks list are not check outputs', () {
expect(checkStepOutput(null), isNull);
expect(checkStepOutput('text'), isNull);
expect(checkStepOutput({'markdown': '# outcome'}), isNull);
expect(checkStepOutput({'checks': 'go test'}), isNull);
});
test('durations read compactly', () {
expect(formatCheckDuration(850), '850ms');
expect(formatCheckDuration(2000), '2s');
expect(formatCheckDuration(2100), '2.1s');
expect(formatCheckDuration(51000), '51s');
expect(formatCheckDuration(185000), '3m 05s');
expect(formatCheckDuration(3720000), '1h 02m');
});
}
@@ -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);
});
}
@@ -0,0 +1,141 @@
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/runs/ui/run_check_output_view.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
import 'run_detail_graph_support.dart';
import 'run_detail_visit_support.dart';
/// verify (a delivery check) -> review, with one failed check visit.
JsonMap _checkRun({int repairs = 0}) => <String, dynamic>{
'id': 78,
'title': 'Check run',
'name': 'release',
'pipeline_id': 7,
'version': 4,
'status': 'succeeded',
'graph': <String, dynamic>{
'stages': <dynamic>[
<String, dynamic>{
'key': 'verify',
'type': 'check',
'configs': <String, dynamic>{'delivery': 'true'},
'edges': <String, String?>{'pass': '#', 'fail': 'verify'},
'blocks': <String, dynamic>{'commands': 'go vet ./...\ngo test ./...'},
},
],
},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'verify',
'sequence': 1,
'status': 'completed',
'outcome': 'fail',
'target': 'verify',
'started_at': '2026-10-22T00:00:00Z',
'finished_at': '2026-10-22T00:01:00Z',
if (repairs > 0)
'control': <String, dynamic>{'visit': 1, 'outcome_repairs': repairs},
'output': <String, dynamic>{
'markdown': '# outcome\n\nfail\n\n# handoff\n\nFix the test.',
'summary': '1 of 2 checks failed: go test ./...',
'delivery': true,
'checks': <dynamic>[
<String, dynamic>{
'command': 'go vet ./...',
'status': 'passed',
'exit_code': 0,
'duration_ms': 2100,
'output': 'vet ok',
'truncated': false,
},
<String, dynamic>{
'command': 'go test ./...',
'status': 'failed',
'exit_code': 1,
'duration_ms': 51000,
'output': '--- FAIL: TestX',
'truncated': true,
},
],
},
},
],
};
void main() {
const platform = RunDetailTestPlatform.material;
testWidgets('a check visit shows one row per command with its output', (
tester,
) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.byKey(const Key('run-check-output')), findsOneWidget);
expect(find.byKey(const Key('run-check-delivery')), findsOneWidget);
expect(find.text('1 of 2 checks failed: go test ./...'), findsOneWidget);
expect(find.text('go vet ./...'), findsOneWidget);
expect(find.text('Passed · exit 0 · 2.1s'), findsOneWidget);
expect(find.text('Failed · exit 1 · 51s'), findsOneWidget);
// The raw checks list is never shown as a `key=value` field dump.
expect(find.text('checks'), findsNothing);
// Output is collapsed until the row is expanded; then it is selectable
// monospace with the truncation note.
expect(find.text('--- FAIL: TestX'), findsNothing);
final row = find.byKey(const ValueKey('run-check-command-1'));
await tester.ensureVisible(row);
await tester.tap(find.text('go test ./...'));
await tester.pumpAndSettle();
final output = tester.widget<SelectableText>(
find.widgetWithText(SelectableText, '--- FAIL: TestX'),
);
expect(output.style?.fontFamily, appMonospaceFamily);
expect(find.text(checkOutputTruncated), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('a check visit has no model row and an honest session note', (
tester,
) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.text('Provider/model'), findsNothing);
expect(find.text('fail'), findsWidgets);
await openVisitTab(tester, RunVisitSection.session);
expect(find.text(visitSessionCheck), findsOneWidget);
expect(find.text(visitSessionNoIdentity), findsNothing);
});
testWidgets('a repaired outcome is noted on the visit', (tester) async {
await openVisit(tester, platform, run: _checkRun(repairs: 1));
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsOne);
expect(find.text('Outcome repaired by follow-up'), findsOneWidget);
});
testWidgets('an unrepaired visit shows no repair note', (tester) async {
await openVisit(tester, platform, run: _checkRun());
expect(find.byKey(const Key('run-visit-outcome-repaired')), findsNothing);
});
test('outcome repairs read from control, absent meaning none', () {
expect(detailVisitOutcomeRepairs({}), 0);
expect(detailVisitOutcomeRepairs({'control': 'x'}), 0);
expect(
detailVisitOutcomeRepairs({
'control': {'visit': 2},
}),
0,
);
expect(
detailVisitOutcomeRepairs({
'control': {'outcome_repairs': 2},
}),
2,
);
expect(outcomeRepairNote(2), 'Outcome repaired by follow-up (2 times)');
});
}
@@ -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(