Repository navigation
Closed
Labels
Description
Summary
Add per-schedule execution analytics — duration distributions, cost totals, success rate, tool-call breakdown, and a daily timeline — surfaced inline in SchedulesPanel.vue so operators can answer "is this cron job degrading?" in one glance.
Scope (v1)
Single surface, single endpoint, single DB function. Per-agent rollup deferred to #18 (Unified Executions Dashboard, P1) because that's the natural cross-trigger home AND because Session-tab traffic (GA since 2026-05-04, writes to agent_session_messages) is not in schedule_executions — a per-agent rollup that only reads schedule_executions would systematically under-report cost.
Acceptance Criteria
Backend
-
GET /api/agents/{name}/schedules/{schedule_id}/analytics?window_hours={24,168,720}— auth viaAuthorizedAgent - Route registered BEFORE parameterised
/{schedule_id}handlers insrc/backend/routers/schedules.py(Invariant fix: add missing logging_config.py to backend Dockerfile #4) - DB function
get_schedule_analytics(schedule_id, hours)insrc/backend/db/schedules.py - Tenant boundary: DB function MUST verify
schedule_idbelongs to an agent the caller can access (AuthorizedAgentonly validates the agent name in the path — schedule_id is user-supplied). Implemented by joiningagent_schedulesand assertingagent_name = ?in the same query; 404 on mismatch. - Soft-deleted schedule policy: 404 (matches existing
db.get_schedule()behavior). Documented in docstring. - Time-window cutoffs via
iso_cutoff(hours)fromutils/helpers.py(Invariant #16) - Pydantic response model in
src/backend/models.py -
window_hoursvalidated to{24, 168, 720}only; other values → 422
Response envelope:
{
"window_hours": 168,
"total_executions": 142,
"success_count": 126,
"failed_count": 13,
"cancelled_count": 3,
"success_rate": 0.887,
"duration_ms": {"p50": 45000, "p95": 120000, "p99": 240000},
"cost": {"total": 2.34},
"tool_calls": {"top": [{"name": "Read", "total_duration_ms": 84120}, ...], "total_calls": 980},
"timeline": [{"date": "2026-05-15", "success": 18, "failed": 2, "cost": 0.32}, ...],
"sampled": false,
"sample_size": 142
}Implementation constraints (locked by /autoplan):
- Percentiles in Python, not SQL. Pull
duration_msvalues in a single sequential scan withWHERE status='success' AND duration_ms IS NOT NULL. Compute viastatistics.quantiles(durations, n=100). AvoidsROW_NUMBER OVERblocking SQLite writers. - Rowset cap of 5000 newest (by
started_at DESC). When the unclamped count would exceed 5000, returnsampled: true, sample_size: 5000. Counts come from the unclamped SQLCOUNT(*)aggregate (only percentiles + tool-calls + timeline use the sampled set). - Tool-call parsing wraps each
json.loads(row.tool_calls)intry/except (json.JSONDecodeError, TypeError)and skips malformed rows with a WARN log includingexecution_id(legacy/partial-write defensiveness). - Tool-call top-5 weighted by
sum(duration_ms), not raw count (avoids "Read/Bash always wins"). Tool-call objects intool_callsJSON have shape{"name": "Read", "duration_ms": <int>, ...}; fall back to0ifduration_msmissing. - Daily timeline: SQL bucketing via
GROUP BY substr(started_at, 1, 10)(faster thandate()on ISO-Z TEXT). Python-side left-join against full date range so days with zero executions render as{"date": "...", "success": 0, "failed": 0, "cost": 0.0}. Bucketing is UTC — documented in OpenAPI description. - Only
status='success'rows feed percentiles (failed/cancelled durations are not representative of healthy runtime).
Frontend
-
ScheduleAnalyticsCard.vue— rendered inline insideSchedulesPanel.vue's existing expanded-schedule row, below the execution list - Window toggle pill group: 24h / 7d / 30d, default 7d, persists per-schedule in
localStorage - Stat tiles: total executions, success rate (threshold ladder per design system:
≥95% success-500,≥80% warning-500,<80% danger-500), p50/p95/p99 duration (ms→human-readable), total cost - Tool-call top-5 list — tool name + total wall time (with subtitle "by total duration")
- Daily timeline rendered via pure-SVG, following
src/frontend/src/components/process/TrendChart.vuepattern. Stacked success/failed bars + cost as a thin overlay line. No Chart.js adoption in v1 — keeps dark-mode-clean and dependency-free. - Empty state: "No executions in selected window" (per design system §3.9)
- Loading state: skeleton tiles per design system §3.10
- Error state: inline banner; card still renders shell
- If
sampled: true, surface a small badge: "Showing latest 5,000 — older runs excluded from distribution" - No new design-system tokens; no new top-level dependencies
Tests
tests/unit/test_schedule_analytics.py:
- Percentile correctness on known dataset (durations
[100, 200, …, 1000]→ known p50/p95/p99) - Time-window boundary: execution at
cutoff - 1msexcluded, atcutoff + 1msincluded - Empty schedule → returns
{p50: null, p95: null, p99: null, total_executions: 0}(no 500) - All-
runningschedule → percentiles null, counts populated -
duration_ms IS NULLrows excluded from percentile pool, counted in totals - Malformed
tool_callsJSON → skipped + WARN logged, endpoint returns 200 - Cross-tenant
schedule_id: caller has access to agent A, passes/api/agents/A/schedules/<B's-schedule-id>/analytics→ 404 (not 200) - Soft-deleted schedule → 404
- Sampled response: with 6000 rows,
sampled=true, sample_size=5000; counts use full 6000 - Daily timeline: schedule with execution on day N-1 but none on day N → day N still present with zeros
- Route order smoke test:
/schedules/analytics(literal) routes to … wait, that's the existing list endpoint; the new analytics route is/schedules/{schedule_id}/analytics— verify it doesn't collide with/schedules/{schedule_id}GET
Documentation
-
docs/memory/architecture.md— add 1 endpoint row under Schedules section + 1 DB-function row - No
requirements.mdchange (derived view, not new feature category) - No
feature-flows/doc (feat: per-schedule and per-playbook execution analytics — duration, token, and tool call distributions #868 is a thin slice over existing schedule infra)
Out of Scope (deferred, with destinations)
- Per-agent rollup tab on AgentDetail → deferred to Unified Executions Dashboard (EXEC-022) #18 (Unified Executions Dashboard, P1, in-progress label, unassigned). Will land with cross-fleet
/executionspage and naturally include Session-tab traffic via UNION overchat_messages+agent_session_messages. - Per-chat-session analytics card → follow-up issue to be created when Unified Executions Dashboard (EXEC-022) #18 is closer to landing (avoids creating issues that compete with Unified Executions Dashboard (EXEC-022) #18's scope).
- "Playbook" as first-class multi-schedule entity — defer until concrete demand emerges. Current scope uses "per-schedule" terminology only.
- Tool-call top-N pre-aggregated column on
schedule_executions— perf optimization, only justified once usage proves bottleneck. - Real-time WebSocket push for analytics card — window refetch on toggle / manual refresh only.
- Export to CSV / cost-projection / anomaly detection.
Related
- Unified Executions Dashboard (EXEC-022) #18 Unified Executions Dashboard (the cross-fleet home for per-agent rollup)
- feat: Subscription usage observability — 5h/7d usage dashboard, per-agent breakdown, and rate-limit event history #471 Subscription usage observability (per-subscription totals; distinct surface)
- Add frontend test infrastructure (Vitest + Playwright) #556 Frontend test infrastructure (Vitest + Playwright)
Design Decisions Locked (from /autoplan)
- Where it lives: Inline in
SchedulesPanel.vueexpanded row only - Levels: Per-schedule (single surface)
- Metrics: Counts, success rate, duration p50/p95/p99, total cost, tool-call duration-weighted top-5, daily timeline
- Time ranges: 24h / 7d / 30d, default 7d
- Percentile compute: Python
statistics.quantiles, rowset capped at 5000 newest - Chart lib: None (pure-SVG, following
TrendChart.vue)
Activity
oleksandr-korin commentedon May 22, 2026
/claim
github-actions commentedon May 22, 2026
Claimed by @oleksandr-korin. Label
status-in-progressadded.Next steps:
feature/868-<short-slug>Fixes #868feat(analytics): per-schedule execution analytics (#868)
feat(analytics): per-schedule execution analytics (#868) (#932)
feat(ui): Agent Detail Overview dashboard as default tab + Info redes…
docs: restructure architecture.md around cross-cutting subsystem blocks
docs(user-docs): sync to post-v0.6.0 platform state
feat(ui): per-schedule performance scorecards on Agent Detail (#1115) (…
Release: v0.8.0 (#1529)
test(db/schedules): edge cases + Hypothesis properties for analytics …
test(db/schedules): edge cases + Hypothesis properties for analytics …
test(db/schedules): edge-case + property coverage for CAS status writ…