Skip to content

apps server analytics and notifications

bondiano edited this page Nov 12, 2026 · 1 revision

Analytics and notifications

Active contributors: Vassiliy Kuzenkov.

Analytics exposes scoped counts of usefulness, gaps, spend and observed latency. Weekly Slack/email delivery and the read-only Slack slash command consume those same projections, rather than running another review. See Findings and policy for where the judgments and lifecycle states originate.

Analytics are counts with specific cohorts

crates/sych-app/src/server/analytics.rs builds a scope from tenant, readable repository IDs, optional repository filter and period start. The four analytics endpoints default to 30 days; weekly reports combine them over seven days as JSON or Markdown.

Projection Cohort and meaning
Quality judgments Feedback in the period, each actor's latest judgment of a finding once; grouped by repository, rule, category, severity and judgment
Settled findings Findings updated in the period on currently merged/closed PRs, excluding OBSOLETE; not every historical closed finding
Merged with open findings Distinct merged PRs by severity among their open findings updated in the period; older untouched backlog is not included
Honesty Completed-result outcome/gap/unknown reason counts for runs created in the period, plus daily coverage and older runs with unrecorded reasons
Cost Model attempts created in the period, grouped by repository, answered/requested model and purpose; top ten PRs by known cost, superseded spend and distinct findings judged useful in the period
Latency Sample count, median and p90 of creation-to-first-delivery, completed-run duration, and job creation-to-first-claim

The quality API returns counts, not a universal accuracy score. A “useful finding” cost counter means someone recorded USEFUL during the period, not independently proven product value. Unknown charge attempts stay separately counted rather than being presented as zero-cost calls.

crates/sych-storage/src/analytics.rs copies the result's execution outcome and leading reason codes into run_reasons when finalization commits. These survive pruning of result artifacts. Older completed runs without those rows are explicitly counted as unrecorded instead of assigned invented reasons.

crates/sych-storage/src/spend.rs computes observed durations from retained rows and ranks period samples in memory. Queue history depends on retained jobs and first-claim recording; those observations are not latency guarantees or SLOs.

Tenant budgets are not repository analytics

Cost analytics includes daily/monthly ledger spend, caps and a month forecast only for a caller scoped to every repository of the tenant with no repository filter. Settled charges and held reservations count toward that budget view. Repository-scoped callers do not receive tenant budget totals; subscription fees in /v1/usage follow the same tenant-wide restriction.

Playground review data is excluded from review analytics and weekly projections, but its real spend remains in the tenant budget and operational accounting. This means a tenant budget total need not equal the sum of the displayed review-only cost rows.

Three distinct outbound/read paths

flowchart LR
    Results["Result and lifecycle records"] --> Scope["Scoped analytics and weekly report"]
    Scope --> API["Authenticated JSON or Markdown reads"]
    Scope --> Slash["Signed Slack command: workspace scope"]
    Scope --> Digest["Scheduled digest: configured tenant"]
    Digest --> Claim["Claim slot and channel"]
    Claim --> Incoming["Slack incoming webhook"]
    Claim --> SMTP["SMTP fixed recipients"]
    Reviews["Review result outbox"] --> GitHub["GitHub summary, inline, neutral check"]
Loading

GitHub review publication has a separate outbox and reconciliation lifecycle. Weekly notifications do not use that publication outbox. Slack command replies are synchronous ephemeral reads, not weekly webhook sends.

Weekly digest

The trusted notifications.weekly_digest configuration selects tenant, weekday/hour in UTC, Slack incoming webhook, email, or both. Default scheduling is Monday at 09:00 UTC. A slot stays due for less than one day; a longer outage skips the old slot instead of backfilling stale weeks.

Engine::digest_once runs from the background maintenance loop, whose due check is every 60 seconds. Before building/sending, each worker claims a unique tenant/slot/channel row in digest_deliveries. This coordinates workers without claiming infallible end-to-end exactly-once delivery.

State/path Behavior
New due slot/channel Claim as SENDING, attempt 1
Send reports success DELIVERED
Send reports failure FAILED; retry after 300 seconds, at most three attempts while due
Worker never records outcome Remain SENDING; not automatically sent again

An interrupted SENDING row is an unknown outcome, not a retryable proof of non-delivery. The admin digest view shows recent slot/channel/state/attempt/error records. sych_digests_undelivered counts exhausted failures and sends still SENDING after an hour among slots in the last eight days.

The report covers every repository of the configured tenant, and links to /ui/analytics when http.public_base_url is set. Recipients therefore need to be appropriate for tenant-wide data; this is not a per-recipient repository authorization flow.

crates/sych-adapters/src/notify.rs posts Slack text to a configured incoming-webhook URL and sends plain-text email to fixed recipients. The webhook URL is itself a credential. The HTTP client has a 30-second timeout and follows neither redirects nor environment proxies. SMTP supports STARTTLS, TLS and validated loopback-only plain transport. Missing configured channel secrets fail startup; error handling avoids returning the webhook URL or password.

Slack slash command

POST /slack/commands is authenticated by Slack signing, not an API client's bearer token:

  1. Verify X-Slack-Signature as the HMAC of v0:<timestamp>:<raw body>.
  2. Require X-Slack-Request-Timestamp to be within five minutes of the server clock.
  3. Parse command text only after verification.
  4. Read only repositories permitted by trusted slack.tenant_id and slack.repositories.
Input Response
/sych owner/name#123 Latest review state, coverage, unknown obligations, open findings, known/unknown cost and optional dashboard link
/sych digest Seven-day report over workspace-allowed repositories, without tenant budget
/sych help or empty text Supported command list

The workspace acts as one configured reader, not a mapping from each Slack user to GitHub permissions. Responses are ephemeral, visible to the requester. An inaccessible PR is indistinguishable from an absent one; the same repository name under several allowed connections produces an ambiguity response rather than choosing a connection.

This command makes no model call and cannot rerun, cancel or give feedback. Do not confuse it with /sych rerun|deep|stop in a GitHub PR comment, which enters the scheduler's permission-checked command path.

Metrics versus report reads

The Prometheus renderer in crates/sych-app/src/server/metrics.rs exports bounded labels for states, coverage, judgments and fixed rejection reasons. It includes queue/outbox/uncertain age, model tokens/charges/reservations, repairs, tour activity, artifacts, webhook outcomes and reconciliation failures.

Webhook/reconciliation counters are process-local since startup; many other values are storage-derived gauges. Budget metrics expose the highest tenant spend for daily/monthly scopes against configured caps, not a repository-labeled spend series. No path or repository/run ID label is added by these renderers. Access and private-listener isolation are explained in Operator capabilities; operational response belongs in Monitoring.

Key source files

File Responsibility
crates/sych-app/src/server/analytics.rs Reader scopes, budget visibility and weekly assembly
crates/sych-storage/src/analytics.rs Feedback/lifecycle cohorts and durable outcome/gap reasons
crates/sych-storage/src/spend.rs Cost grouping, ledger budget totals and latency samples
crates/sych-app/src/server/views.rs Overview and daily usage/CSV read paths
crates/sych-app/src/server/digest.rs Channel configuration, secrets, report assembly and sends
crates/sych-storage/src/digest.rs Unique claims, bounded retries and undelivered projection
crates/sych-core/src/config/notifications.rs Due-slot calculation and channel validation
crates/sych-adapters/src/notify.rs Slack incoming-webhook and SMTP transports
crates/sych-app/src/server/slack.rs Workspace-scoped slash-command reads and ephemeral formatting
crates/sych-adapters/src/slack.rs Raw-body signature and timestamp checks
crates/sych-app/src/server/metrics.rs Prometheus rendering and main-listener peer allowlist

Change entry points

  • Change a metric cohort in storage and update crates/sych-app/tests/analytics.rs; do not silently redefine a denominator in the UI alone.
  • Extend weekly content through shared report assembly so authenticated reads, Slack commands and scheduled delivery do not diverge unintentionally.
  • Change delivery with crates/sych-app/tests/digest.rs, preserving the distinction between failed and unknown sends.
  • Change command parsing/signing/scope with crates/sych-app/tests/slack.rs and the adapter's inline signature tests.

Inventory and contributor history are scoped in the server index. Notification configuration and public DTO details are in Configuration and the API reference.

Clone this wiki locally