feat(taskstate): count completed runs in the per-workflow stats

The transition table moved the no-change outcomes to StatusCompleted, so a
run that opens no pull request now ends in a status the per-workflow stats
did not count at all: it was not merged, not in review, not parked, and the
workflows page would have shown it as a run that went nowhere. The count
travels the whole State Store path, since every dashboard consumer reads it
through the gRPC client rather than the local store.

- WorkflowStats filters `completed` beside merged and pr_open; the SQL is
  the count, so a wrong filter reads as zero rather than failing, and
  TestWorkflowStatsCountsCompletedRuns holds it against a real store.
- storecontract.WorkflowStat gains Completed (json "completed"), the proto
  message gains field 9, and workflowStatProto/workflowStatValue carry it;
  TestWorkflowStatProtoCarriesEveryField round-trips every field by name.
- The gateway's chat task report names the status.
- The dashboard counts a completed run as delivered in GatePulseCard's
  totals and badge numerator, and the WorkflowStat/WorkflowStats/WorkflowRow
  interfaces carry the field.
- TestOutcomeSitesAreTransitionsFromRunning is the guard that keeps the
  producer and the table agreeing: it re-reads this package's tc.Outcome
  assignment sites from source and requires each status to be one
  internal/taskstate allows from running, so a new or moved site has to be
  adjudicated against the table instead of discovered on a live run.
This commit is contained in:
sam committed 2026-09-26 04:01:08 +10:00
1 parent ded863e0dc
commit 36b25f78cf
14 files changed
+279 -10

No files matched your search

@@ -295,6 +295,7 @@ const workflowStats = `-- name: WorkflowStats :many
SELECT workflow,
COUNT(*)::int AS runs,
COUNT(*) FILTER (WHERE status = 'merged')::int AS merged,
COUNT(*) FILTER (WHERE status = 'completed')::int AS completed,
COUNT(*) FILTER (WHERE status = 'pr_open')::int AS pr_open,
COUNT(*) FILTER (WHERE status = 'parked')::int AS parked,
CAST(AVG(tokens_used) AS bigint) AS avg_tokens,
@@ -310,6 +311,7 @@ type WorkflowStatsRow struct {
Workflow string
Runs int32
Merged int32
Completed int32
PrOpen int32
Parked int32
AvgTokens int64
@@ -330,6 +332,7 @@ func (q *Queries) WorkflowStats(ctx context.Context) ([]WorkflowStatsRow, error)
&i.Workflow,
&i.Runs,
&i.Merged,
&i.Completed,
&i.PrOpen,
&i.Parked,
&i.AvgTokens,