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
@@ -0,0 +1,43 @@
import 'package:pipelines_app/core/api_gateway.dart';
/// A run waiting on the server-created decision of an exhausted review loop:
/// the waiting stage is the model stage, not a human stage in the graph.
JsonMap exhaustedDecisionRun({dynamic output}) => {
'id': 9,
'status': 'waiting',
'current_stage': 'review',
'name': 'Build',
'graph': {
'stages': [
{
'key': 'review',
'type': 'model',
'edges': {'pass': '#', 'fail': 'implement'},
},
{'key': 'implement', 'type': 'model'},
],
},
'steps': [
{
'stage': 'review',
'sequence': 6,
'status': 'waiting',
'output':
output ??
{
'prompt': 'Review used all its visits.',
'options': ['accept', 'continue', 'abort'],
'exhausted': {
'stage': 'review',
'visit': 3,
'max_visits': 3,
'targets': {
'accept': '#success',
'continue': 'implement',
'abort': '#failure',
},
},
},
},
],
};
@@ -0,0 +1,70 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
import 'package:pipelines_app/features/runs/domain/run_decisions.dart';
import 'run_exhausted_decision_fixture.dart';
void main() {
test('an exhaustion decision on a model stage uses the recorded options', () {
final decision = pendingDecision(exhaustedDecisionRun())!;
expect(decision.stageKey, 'review');
expect(decision.instructions, 'Review used all its visits.');
expect(decision.options.map((o) => o.key), ['accept', 'continue', 'abort']);
expect(decision.options.map((o) => o.displayLabel), [
'Accept as is',
'One more round',
'Abort',
]);
expect(decision.options.map((o) => o.target), [
'SUCCESS',
'implement',
'FAILURE',
]);
expect(decision.exhausted?.visit, 3);
expect(decision.exhausted?.maxVisits, 3);
expect(
decisionExhaustedText(decision),
'review reached its visit limit: visit 3 of 3',
);
});
test('unknown option keys keep their recorded wording', () {
final decision = pendingDecision(
exhaustedDecisionRun(
output: {
'options': ['accept', 'extend'],
'exhausted': {'stage': 'review'},
},
),
)!;
expect(decision.options.map((o) => o.displayLabel), [
'Accept as is',
'extend',
]);
expect(decision.options.last.target, '');
expect(decisionExhaustedText(decision), 'review reached its visit limit');
});
test('a model stage waiting without an exhaustion record is no decision', () {
expect(
pendingDecision(
exhaustedDecisionRun(
output: {
'options': ['accept'],
},
),
),
isNull,
);
expect(
pendingDecision(
exhaustedDecisionRun(
output: {
'exhausted': {'stage': 'review'},
},
),
),
isNull,
);
});
}
@@ -0,0 +1,48 @@
import 'package:pipelines_app/core/api_gateway.dart';
/// A run detail with a small findings ledger: one open, one fixed with its
/// event history, one dismissed, and a malformed entry.
JsonMap findingsRun() => {
'id': 4,
'findings': [
{
'id': 'F1',
'severity': 'critical',
'origin': 'introduced',
'location': 'internal/cache.go:42',
'summary': 'Cache never evicts',
'status': 'open',
'raised_by': 'review',
'raised_sequence': 4,
},
{
'id': 'F2',
'severity': 'minor',
'origin': 'pre-existing',
'location': '',
'summary': 'Typo in log',
'status': 'fixed',
'reason': 'Corrected',
'raised_by': 'review',
'raised_sequence': 4,
'updated_by': 'implement',
'updated_sequence': 5,
'events': [
{
'sequence': 5,
'stage': 'implement',
'status': 'fixed',
'reason': 'Corrected',
},
],
},
{
'id': 'F3',
'severity': 'nit',
'origin': 'introduced',
'summary': 'Naming',
'status': 'dismissed',
},
'not a finding',
],
};
@@ -0,0 +1,65 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/run_findings.dart';
import 'run_findings_fixture.dart';
void main() {
test('parses the recorded ledger and skips malformed items', () {
final findings = runFindings(findingsRun());
expect(findings.map((f) => f.id), ['F1', 'F2', 'F3']);
final fixed = findings[1];
expect(fixed.severity, FindingSeverity.minor);
expect(fixed.origin, 'pre-existing');
expect(fixed.location, '');
expect(fixed.reason, 'Corrected');
expect(fixed.updatedBy, 'implement');
expect(fixed.updatedSequence, 5);
expect(fixed.events.single.stage, 'implement');
expect(fixed.events.single.sequence, 5);
expect(findings.first.events, isEmpty);
expect(findings.first.raisedSequence, 4);
});
test('older servers without findings show nothing', () {
expect(runFindings({'id': 1}), isEmpty);
expect(runFindings({'findings': []}), isEmpty);
expect(runFindings(null), isEmpty);
});
test('filters by status and minimum severity', () {
final findings = runFindings(findingsRun());
expect(openFindingCount(findings), 1);
expect(defaultFindingStatus(findings), 'open');
expect(defaultFindingStatus(findings.skip(1)), isNull);
ids(List<RunFinding> list) => list.map((f) => f.id).toList();
expect(ids(filterFindings(findings)), ['F1', 'F2', 'F3']);
expect(ids(filterFindings(findings, status: 'fixed')), ['F2']);
expect(ids(filterFindings(findings, minSeverity: FindingSeverity.minor)), [
'F1',
'F2',
]);
expect(
ids(filterFindings(findings, minSeverity: FindingSeverity.critical)),
['F1'],
);
expect(
filterFindings(
findings,
status: 'fixed',
minSeverity: FindingSeverity.important,
),
isEmpty,
);
});
test('visit grants summarise as stage +n', () {
expect(
visitGrantsSummary({
'visit_grants': {'review': 1, 'implement': 2, 'idle': 0},
}),
'review +1, implement +2',
);
expect(visitGrantsSummary({'visit_grants': {}}), isNull);
expect(visitGrantsSummary({}), isNull);
});
}