App: findings ledger tab, retry extra visits and exhaustion decisions

Run detail gains a Findings tab (open-count badge) listing the server's
findings ledger with status and minimum-severity filters and expandable
event history; visit grants show as an Extra visits summary fact. The
resume retry prompt can grant 1-5 extra visits to the exhausted stage or a
chosen graph stage (never sent on restart), suggested when the run failed
on a visit limit. A loop-exhaustion decision waiting on a model stage is
now decidable from its recorded options, with readable labels, targets and
the visit count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:45:43 +00:00
parent c4de1de27b
commit ebe79ebed0
27 changed files with 1255 additions and 14 deletions
@@ -117,7 +117,7 @@ class _DecisionPromptState extends State<_DecisionPrompt> {
RadioListTile<String>(
value: option.key,
enabled: !_sending,
title: Text(option.key),
title: Text(option.displayLabel),
subtitle: _target(option),
),
],
@@ -156,6 +156,12 @@ class _DecisionPromptState extends State<_DecisionPrompt> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(decisionMeta(widget.decision)),
if (decisionExhaustedText(widget.decision) case final text
when text.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(text, key: decisionExhaustedKey),
),
if (widget.decision.instructions.trim().isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8),
@@ -14,11 +14,26 @@ const decisionSendingLabel = 'Sending…';
const decisionActionKey = ValueKey<String>('human-decision-action');
const decisionFeedbackKey = ValueKey<String>('human-decision-feedback');
const decisionErrorKey = ValueKey<String>('human-decision-error');
const decisionExhaustedKey = ValueKey<String>('human-decision-exhausted');
/// `{stage} · run {id} · {label}`, as the web decision card shows it.
String decisionMeta(PendingDecision decision) =>
'${decision.stageKey} · run ${decision.runId} · ${decision.runLabel}';
/// For a loop that exhausted its visits: `review used visit 3 of 3`, or the
/// part the server recorded; "" for a declared human decision.
String decisionExhaustedText(PendingDecision decision) {
final loop = decision.exhausted;
if (loop == null) return '';
final stage = loop.stage.isEmpty ? decision.stageKey : loop.stage;
final visit = loop.visit;
final max = loop.maxVisits;
if (visit == null) return '$stage reached its visit limit';
return max == null
? '$stage reached its visit limit at visit $visit'
: '$stage reached its visit limit: visit $visit of $max';
}
/// The option's target line, `→ {target}`, or "" when no target was declared.
String decisionTargetText(String target) =>
target.trim().isEmpty ? '' : '→ $target';
@@ -4,6 +4,7 @@ import '../../../core/api_gateway.dart';
import '../data/runs_repository.dart';
import 'action_refusal.dart';
import 'retry_dialog.dart';
import 'retry_extra_visits.dart';
import 'retry_eligibility.dart';
import 'retry_wording.dart';
@@ -106,12 +107,16 @@ Future<void> openRetryRunPrompt(
await showRetryRunPrompt(
context: context,
runId: id,
stages: retryStageKeys(run),
suggestExtraVisits: runExhaustedVisits(run),
onSubmit: (intent) async {
try {
final updated = await repository.retryRun(
id,
requestKey: intent.requestKey,
mode: intent.mode.wireMode,
extraVisits: intent.wireExtraVisits,
extraStage: intent.wireExtraStage,
);
if (owns(id)) {
onRunChanged(updated);
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'action_refusal.dart';
import 'retry_extra_visits_field.dart';
import 'retry_intent.dart';
import 'retry_wording.dart';
@@ -19,8 +20,15 @@ Future<void> showRetryRunPrompt({
required BuildContext context,
required num runId,
required RetrySubmit onSubmit,
List<String> stages = const [],
bool suggestExtraVisits = false,
}) {
final prompt = _RetryPrompt(runId: runId, onSubmit: onSubmit);
final prompt = _RetryPrompt(
runId: runId,
onSubmit: onSubmit,
stages: stages,
suggestExtraVisits: suggestExtraVisits,
);
return showDialog<void>(
context: context,
barrierDismissible: false,
@@ -29,17 +37,30 @@ Future<void> showRetryRunPrompt({
}
class _RetryPrompt extends StatefulWidget {
const _RetryPrompt({required this.runId, required this.onSubmit});
const _RetryPrompt({
required this.runId,
required this.onSubmit,
required this.stages,
required this.suggestExtraVisits,
});
final num runId;
final RetrySubmit onSubmit;
/// The run's graph stage keys, offered as the extra visits' stage.
final List<String> stages;
/// Whether the run failed on an exhausted loop.
final bool suggestExtraVisits;
@override
State<_RetryPrompt> createState() => _RetryPromptState();
}
class _RetryPromptState extends State<_RetryPrompt> {
RetryMode _mode = RetryMode.resume;
int? _extraVisits;
String? _extraStage;
String? _requestKey;
bool _sending = false;
bool _checking = false;
@@ -69,6 +90,8 @@ class _RetryPromptState extends State<_RetryPrompt> {
final intent = RetryIntent(
mode: _mode,
requestKey: _requestKey ??= newRetryRequestKey(widget.runId),
extraVisits: _extraVisits,
extraStage: _extraStage,
);
final refusal = await widget.onSubmit(intent);
if (!mounted) return;
@@ -137,6 +160,18 @@ class _RetryPromptState extends State<_RetryPrompt> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(_dialogMessage),
// Extra visits extend a resumed run only; once sent, the intent (and
// its idempotency key) is fixed.
if (_mode == RetryMode.resume)
RetryExtraVisitsField(
visits: _extraVisits,
stage: _extraStage,
stages: widget.stages,
suggested: widget.suggestExtraVisits,
enabled: !_attempted,
onVisitsChanged: (value) => setState(() => _extraVisits = value),
onStageChanged: (value) => setState(() => _extraStage = value),
),
if (_error case final error?)
Padding(
padding: const EdgeInsets.only(top: 8),
@@ -0,0 +1,39 @@
import '../../../core/api_gateway.dart';
/// The most extra visits one retry may grant (the server accepts 1-5).
const maxRetryExtraVisits = 5;
/// The diagnostic phrases with which the server reports an exhausted loop.
const _exhaustedPhrases = [
'visit limit reached',
'visit budget exceeded',
'total stage budget exceeded',
];
/// Whether [run] failed because a loop exhausted its visits: its diagnostic
/// names a visit limit or budget, or a recorded step's control says the limit
/// was reached. Retrying it with extra visits is then worth suggesting.
bool runExhaustedVisits(JsonMap run) {
final diagnostic = '${run['diagnostic'] ?? ''}'.toLowerCase();
if (_exhaustedPhrases.any(diagnostic.contains)) return true;
final steps = run['steps'];
if (steps is! List) return false;
return steps.whereType<Map>().any(
(step) =>
step['control'] is Map && step['control']['limit_reached'] == true,
);
}
/// The stage keys of the run's graph, in declared order, for the extra
/// visits stage picker.
List<String> retryStageKeys(JsonMap run) {
final graph = run['graph'];
final stages = graph is Map ? graph['stages'] : null;
if (stages is! List) return const [];
final keys = <String>[];
for (final stage in stages.whereType<Map>()) {
final key = '${stage['key'] ?? ''}'.trim();
if (key.isNotEmpty && !keys.contains(key)) keys.add(key);
}
return keys;
}
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'retry_extra_visits.dart';
import 'retry_wording.dart';
/// The resume prompt's optional "Grant extra visits" choice: a checkbox, the
/// number of visits (1-5) and the stage they go to (the exhausted stage by
/// default). Null [visits] means the choice is off.
class RetryExtraVisitsField extends StatelessWidget {
const RetryExtraVisitsField({
super.key,
required this.visits,
required this.stage,
required this.stages,
required this.suggested,
required this.enabled,
required this.onVisitsChanged,
required this.onStageChanged,
});
final int? visits;
final String? stage;
final List<String> stages;
/// Whether the run failed on an exhausted loop, so the choice is suggested.
final bool suggested;
final bool enabled;
final ValueChanged<int?> onVisitsChanged;
final ValueChanged<String?> onStageChanged;
@override
Widget build(BuildContext context) {
final count = visits;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (suggested)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
retryExhaustedHint,
key: retryExhaustedHintKey,
style: Theme.of(context).textTheme.bodySmall,
),
),
CheckboxListTile(
key: retryExtraVisitsKey,
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
title: const Text(retryExtraVisitsLabel),
value: count != null,
onChanged: enabled
? (checked) => onVisitsChanged(checked == true ? 1 : null)
: null,
),
if (count != null)
Wrap(
spacing: 12,
runSpacing: 12,
children: [
DropdownMenu<int>(
key: retryExtraCountKey,
enabled: enabled,
label: const Text(retryExtraVisitsCountLabel),
initialSelection: count,
onSelected: (value) {
if (value != null) onVisitsChanged(value);
},
dropdownMenuEntries: [
for (var n = 1; n <= maxRetryExtraVisits; n++)
DropdownMenuEntry(value: n, label: '+$n'),
],
),
DropdownMenu<String?>(
key: retryExtraStageKey,
enabled: enabled,
label: const Text(retryExtraStageLabel),
initialSelection: stage,
onSelected: onStageChanged,
dropdownMenuEntries: [
const DropdownMenuEntry(
value: null,
label: retryExhaustedStageLabel,
),
for (final key in stages)
DropdownMenuEntry(value: key, label: key),
],
),
],
),
],
);
}
}
@@ -14,10 +14,35 @@ enum RetryMode {
/// belongs to it. Retrying the same uncertain intent reuses [requestKey] so the
/// server can dedupe it; a fresh deliberate intent uses a new key.
class RetryIntent {
const RetryIntent({required this.mode, required this.requestKey});
const RetryIntent({
required this.mode,
required this.requestKey,
this.extraVisits,
this.extraStage,
});
final RetryMode mode;
final String requestKey;
/// Extra visits (1-5) to grant on resume; null grants none.
final int? extraVisits;
/// The stage the extra visits go to; null lets the server grant them to the
/// exhausted stage(s).
final String? extraStage;
/// The `retry_extra_visits` value to send: only on resume, within 1-5.
int? get wireExtraVisits {
final visits = extraVisits;
if (mode != RetryMode.resume || visits == null) return null;
return visits >= 1 && visits <= 5 ? visits : null;
}
/// The `retry_extra_stage` value to send, only alongside extra visits.
String? get wireExtraStage {
final stage = extraStage?.trim() ?? '';
return wireExtraVisits == null || stage.isEmpty ? null : stage;
}
}
/// The entropy bound for a fresh key.
@@ -14,12 +14,24 @@ const restartDialogMessage =
const restartConfirmLabel = 'Restart from start';
const retryKeepLabel = 'Keep';
const retryExtraVisitsLabel = 'Grant extra visits';
const retryExtraVisitsCountLabel = 'Extra visits';
const retryExtraStageLabel = 'Stage';
const retryExhaustedStageLabel = 'Exhausted stage';
const retryExhaustedHint =
'This run stopped because a loop used up its visits. Granting extra '
'visits lets it continue when resumed.';
/// Stable test/semantics keys shared by the action and its prompt.
const retryActionKey = ValueKey<String>('retry-run-action');
const retryKeepKey = ValueKey<String>('retry-run-keep');
const retryConfirmKey = ValueKey<String>('retry-run-confirm');
const retryRestartKey = ValueKey<String>('retry-run-restart');
const retryErrorKey = ValueKey<String>('retry-run-error');
const retryExtraVisitsKey = ValueKey<String>('retry-run-extra-visits');
const retryExtraCountKey = ValueKey<String>('retry-run-extra-count');
const retryExtraStageKey = ValueKey<String>('retry-run-extra-stage');
const retryExhaustedHintKey = ValueKey<String>('retry-run-exhausted-hint');
/// The retry dialog's title: `Retry run {id}?`.
String retryDialogTitle(num runId) => 'Retry run $runId?';