Skip to content
bondiano edited this page Nov 12, 2026 · 1 revision

HTTP API

Active contributors: Vassiliy Kuzenkov.

Sych's API admits durable review requests and reads saved review state; it does not synchronously return a new review. Routes are assembled in crates/sych-app/src/server/mod.rs, authorization lives in crates/sych-app/src/server/caller.rs, and DTOs/OpenAPI are defined in crates/sych-core/src/api.rs.

Contract sources

Use the router and handler as the route and behavior authority. schemas/openapi.json is generated OpenAPI 3.1.0 with 46 paths and 47 operations at the documented revision, not a complete inventory of operational HTTP routes. In particular, OAuth login/callback, GitHub hooks, Slack commands, probes, metrics and static UI delivery must also be checked in the router.

just schemas regenerates contracts; web/package.json generates dashboard types from OpenAPI with pnpm gen:api. Do not edit generated JSON or web/src/modules/Api/schema.gen.d.ts as the primary implementation.

Authentication and authorization

All /v1 handlers extract a Caller. An explicit Authorization: Bearer … takes precedence over the sych_session cookie; an invalid explicit bearer does not fall back to a session.

  • Configured clients: http.api_clients assigns actor, tenant, cumulative role and connection/owner/name scopes, or *. Tokens are loaded from named environment variables and compared in constant time.
  • People: GitHub OAuth captures repository grants at sign-in. GitHub read, triage, write, and maintain/admin map to reader, triage, writer and maintainer. Reads use saved grants; repository decisions above reader recheck current permission through GitHub.
  • Browser writes: cookie-authenticated methods other than GET/HEAD require Origin equal to the configured public origin. This does not replace repository authorization.
  • Object visibility: foreign-tenant or unreadable-repository objects return 404; lists are filtered. A role somewhere is not access to every repository.
  • Operators: admin views require a configured maintainer client scoped to *. A GitHub maintainer person is not automatically a tenant operator.

Sessions last eight hours. Cookies are HttpOnly, SameSite=Lax, and Secure for an HTTPS public URL; only the token digest is stored. /auth/token exchanges a configured client bearer for a browser session. Logout requires the same origin and clears the session. Details: crates/sych-app/src/server/auth.rs and Operator capabilities.

Endpoint groups

Templates below are literal router paths. Run and tour identifiers are strings/UUIDs; repository, change, stored finding and publication path IDs are numeric. A stored finding row ID is not the UUID FindingId inside a result.

Group Routes Access and meaning
Review admission POST /v1/reviews; POST /v1/changes/{id}/reruns; POST /v1/runs/{id}/cancel Writer; create a generation or cancel active work, not mutate a committed result
Saved runs GET /v1/runs/{id}; GET /v1/runs/{id}/result; GET /v1/runs/{id}/snapshots; GET /v1/runs/{id}/attempts Reader; status, immutable result, source/policy identity and attempt accounting
Repository/change reader GET /v1/repositories; GET /v1/repositories/{id}/policy; GET /v1/changes; GET /v1/changes/{id} Reader; repository-filtered views
Findings GET /v1/findings; GET /v1/findings/{id}; POST /v1/findings/{id}/feedback Reader for reads, triage for feedback
Risk acceptance GET /v1/waivers; POST /v1/waivers; POST /v1/waivers/{id}/revoke Reader for list, maintainer for decisions; never changes the historical assessment
Suggestions GET /v1/repositories/{id}/suggestions; POST /v1/repositories/{id}/suggestions/{fingerprint}/decision Reader for list, maintainer for decision; proposed policy edit, not automatic application
Playground GET /v1/playground; POST /v1/changes/{id}/playground Reader for visible tries, maintainer to start; requires dedicated money cap, never publishes
Publications/jobs GET /v1/publications; GET /v1/publications/{id}; GET /v1/jobs; POST /v1/publications/{id}/reconcile Reader for publications, writer for jobs/recreation decision
Private tour GET /v1/runs/{id}/tour; POST /v1/runs/{id}/tours/{tour}/reveal, /complete, /dismiss, /questions Reader; actor-private progress/exchanges. A RISK_DECISION question additionally requires maintainer
Handoff POST /v1/runs/{id}/handoff Reader; deterministic export of selected result findings, no inference or source change
Aggregates GET /v1/summary; GET /v1/usage; GET /v1/analytics/quality, /honesty, /cost, /latency; GET /v1/reports/weekly Reader, filtered to accessible repositories
Audit GET /v1/audit Maintainer visibility by repository; non-repository events require tenant operator
Administration GET /v1/admin/connections, /deliveries, /config, /digests Tenant operator only; configuration is redacted
Identity GET /v1/me Current caller, grants, admin capability and configured instance links

Handlers are separated into crates/sych-app/src/server/api.rs, views.rs, analytics.rs, queue.rs, tours.rs, questions.rs, handoff.rs, suggestions.rs, playground.rs and admin.rs under the same server directory. See Server for their durable effects.

Integration and operational routes

Routes Independent contract
GET /auth/github; GET /auth/github/{connection}/login; GET /auth/github/{connection}/callback; POST /auth/token; POST /auth/logout Sign-in discovery, OAuth state/callback, client session and logout
POST /hooks/github/{connection} Raw-body HMAC verification, configured connection/repository admission and delivery deduplication, not API bearer auth
POST /slack/commands Slack signature and timestamp validation, configured workspace reader scope; read-only
GET /health/live; GET /health/ready Unauthenticated process life and database/artifact-store readiness
GET /metrics Main listener checks peer IP against http.metrics_allow, not forwarded headers
/, /ui, /ui/… Only when a UI directory is configured; static SPA and security headers

The worker-only role exposes probes and metrics, not /v1. SYCH_METRICS_BIND creates a separate metrics-only listener without the main listener's IP allowlist: isolate it at the network boundary. Sources: crates/sych-app/src/server/mod.rs, hooks.rs, slack.rs, metrics.rs and ui.rs in that server directory.

Request bounds and retries

Contract Enforced behavior
JSON/form body Router group containing /v1, auth and Slack is limited to 1 MiB
GitHub hook Per-connection max_body_bytes, default 2 MiB; JSON content type, HMAC, event and nonempty delivery ID of at most 128 bytes checked before admission
Command idempotency Nonempty Idempotency-Key of at most 200 bytes on handlers using api::idempotent
JSON list pages Shared page limit defaults to 50, accepts 1–200; endpoint-specific unpaginated arrays are not this page contract
CSV exports Findings, usage and audit exports accept format=csv, default/cap 10,000 rows; remaining cursor is Sych-Next-Before
Review request schema_version: 1, change: {connection_id, repository, external_number}; numeric external PR number; profile economical or deep; publish defaults false; optional approved checks
Feedback USEFUL, NOT_USEFUL, FALSE_POSITIVE or WONT_FIX, plus scope/rationale
Waiver Nonempty path list and either expiry or completion condition; maintainer and change scope required
Follow-up Nonblank question and a valid tour step; waiver terms only with RISK_DECISION
Recreate publication Nonblank reason; only an UNCERTAIN operation without a known remote object is eligible

Bounds are in crates/sych-app/src/server/mod.rs, hooks.rs, api.rs, views.rs, questions.rs and queue.rs; strict request fields are in crates/sych-core/src/api.rs. Do not infer per-string or per-array caps that the handler does not implement from the overall body limit.

Idempotency is scoped to tenant + actor + endpoint + key. Its request digest includes path resource identity, a NUL separator and the raw body bytes. Same key and request replay the saved status/body with reused: true; different body/target returns 409 IDEMPOTENCY_CONFLICT; unfinished work returns 409 REQUEST_IN_PROGRESS. JSON whitespace changes therefore matter. Handoff is a read-only POST and does not use this command ledger; auth and signed integrations have separate retry contracts.

The idempotency row is opened before the handler runs and finished only after successful handling. Handler failure or a crash can leave it in progress; there is no promised automatic recovery or distributed exactly-once execution. Inspect run/operation state before deciding whether a new key is safe. Source: crates/sych-app/src/server/api.rs.

Responses and important conflicts

202 Accepted means durable admission. Poll its status_url; do not equate it with completion, complete coverage or publication. Manual requests reread current PR state, reject closed changes, and publish only when both request and trusted connection allow it (crates/sych-app/src/server/requests.rs).

Application refusals use {error: {code, message, retryable, correlation_id, details}}; 429 and 503 are marked retryable. Examples include UNAUTHENTICATED (401), FORBIDDEN (403), NOT_FOUND (404), CHANGE_CLOSED, NO_RESULT, RESULT_PRUNED and idempotency conflicts (409), RATE_LIMITED (429), and DEPENDENCY_UNAVAILABLE (503). Extractor/router rejections, including body/query decoding, need not use that application envelope. Source: crates/sych-app/src/server/error.rs.

GET …/snapshots can return source: null after shorter source retention while the result remains readable. Missing result/tour artifacts are explicit conflicts, never a silent rerun. Check source/policy identity, coverage, UNKNOWN obligations and relevance before treating a saved result as a gate. See Data models.

Key source files and change entry points

File Change here
crates/sych-app/src/server/mod.rs Register a route, role surface or body limit
crates/sych-app/src/server/caller.rs Bearer/session extraction and repository authorization
crates/sych-app/src/server/api.rs Command idempotency, validation and core review commands
crates/sych-core/src/api.rs DTOs, OpenAPI assembly and referenced API submodules
crates/sych-app/tests/api.rs Cross-scope, idempotency and command contracts
crates/sych-app/tests/auth.rs Session, origin, OAuth and revoked-permission contracts
crates/sych-core/tests/contracts.rs Generated contract synchronization

For a new operation, update router, handler, authorization tests and DTO/OpenAPI together. See Security before exposing an internal storage method.

Clone this wiki locally