api: list service DAGs apart from their runs

Merged
SC
25d ago
+3507-1308

Summary

Part of #3257, together with the UI PR (#3261), which closes it.

A DAG with a restart_policy adds a run to the lists at each restart. This PR adds the API to keep those runs out of the run lists, and to list the DAGs as one object each.

Changes

  • excludeServiceDAGRuns on GET /dag-runs, the activity API and their SSE topics: leaves out every run of the service DAGs, whoever started it. The names come from the saved DAG index, and the file store skips those DAGs' run directories before reading anything there. A cursor records only whether DAGs are left out, so it stays valid when the set changes.
  • GET /service-dags and the servicedags SSE topic: one compact state per service DAG (pending, running, restarting, failing, suspended, stopped), with the latest run's error, a per-DAG readError, and consecutiveFailures (newest ended runs in a row that did not succeed, up to 10). The state agrees with the restart scanner: a stop counts whatever status the run ends with, and a stopped always DAG shows restarting.
  • SSE: only the runs of service DAGs wake the service DAG topic, and the filtered lists skip those runs. Run lists refetch at least every 30 seconds, as the activity does.
  • A DAG index rebuild cut short by a cancel is no longer saved.
  • The scheduler logs "Restarting DAG" after the run is queued, so an invalid DAG does not log it every second.

Related Issues

Part of #3257 (closed by the UI PR #3261)

Checklist

  • Code follows the project style guidelines
  • Self-review of the code has been performed
  • Tests have been added or updated as needed
  • Documentation has been updated as needed
  • Changes have been tested locally

Tests: go test on internal/persis/..., internal/service/frontend, internal/service/frontend/api/v1, internal/service/frontend/sse, internal/service/scheduler, internal/intake and internal/spec, plus the affected tests in internal/cmd and internal/runtime; pnpm typecheck. Checked on a running server with 20 service DAGs and a crash-looping one.