Repository navigation
apps server admission and scheduling
Active contributors: Vassiliy Kuzenkov.
Admission records a verified signal and scheduling intent without calling GitHub or a model. Scheduling later reads current provider state and decides whether to skip, generate, wake or cancel work. See the server map for inventory and contributor scope.
The trusted server configuration fixes the connection's tenant, provider instance, API/Git addresses, repository allowlist, bot login and publication/check settings. The webhook URL selects only that configured connection, not arbitrary credentials or destinations.
Startup reads the webhook secret and the App private-key file named by its environment reference. The GitHub adapter signs short-lived RS256 App JWTs and requests installation tokens scoped to one repository, cached in memory until five minutes before expiry. Its REST client follows neither redirects nor environment proxies. Webhook signing and API credentials are separate.
Reconciliation computes ProviderCapabilities from granted installation permissions and stores them in the repository binding. Missing read/write capabilities remain explicit limitations or refusals; enabling checks requires the additional check-writing capability. In self-review mode, crates/sych-app/src/server/build.rs also refuses a configured reviewer commit that differs from the running build. Proposed PR policy does not replace this trusted build or server configuration.
crates/sych-app/src/server/hooks.rs selects the trusted connection from the URL, then checks its body limit, JSON content type, raw-body HMAC-SHA256 signature, event and delivery headers before parsing. Unknown connections are 404, oversized bodies 413, wrong content type 415, bad signatures 401 and invalid deliveries 400.
The webhook adapter accepts ping, pull_request, issue_comment, workflow_run, check_suite, installation and installation_repositories. Acceptance does not imply significance: a ping, an unlisted repository, an irrelevant action or the bot's own comment can receive a durable receipt without work.
Storage::admit uses one transaction for:
- An
inbox_eventsreceipt with delivery identity, payload digest, normalized event and admission decision. - The repository binding when relevant and allowed.
- The change and its coalesced intent.
A new stored delivery returns 202; a duplicate returns 200 without changing work. Storage failure returns 503 rather than acknowledging the delivery. The raw payload is not stored. Deduplication uses provider_instance + connection_id + delivery_id; GitHub does not sign a timestamp, so this path has no timestamp-based replay window.
The connection fixes tenant and provider instance. Its repository partition is provider_instance/connection_id/external_id within that tenant, keeping the same external repository in different connections separate. See Security for the complete trust boundary.
| Provider signal | Intent | Initial debounce |
|---|---|---|
| PR opened, reopened, ready, synchronized, base edited or made draft | REFRESH |
5 seconds |
| Completed workflow run or check suite | CI |
10 seconds |
| PR closed | CLOSE |
None |
PR comment /sych rerun, /sych deep, /sych stop
|
COMMAND_RERUN, COMMAND_DEEP, COMMAND_STOP
|
None |
| Comment by configured bot login | No intent | Not applicable |
There is one open intent per change and kind. New signals move its due time, bounded by the first signal plus six debounce intervals: 30 seconds for PR refresh and 60 for CI. This bounds coalescing, not the time until analysis or delivery.
flowchart TD
Due["Due intent"] --> Read["Token, current PR, command permission"]
Read --> Sync["Persist current SCM state"]
Sync --> Decide["sych_core::schedule::decide"]
Decide --> Skip["SKIP with reason"]
Decide --> Generate["GENERATE transaction"]
Decide --> Wake["WAKE waiting job"]
Decide --> Cancel["CANCEL active work"]
Generate --> Gen["Advance desired generation"]
Gen --> Revoke["Supersede active prior review and revoke lease"]
Revoke --> Job["Insert new run and ANALYSIS job"]
crates/sych-core/src/schedule.rs is pure: it consumes current ScmState, optional Latest, intent kind and an authorized actor. The application supplies trusted publication flags only after the decision.
| Condition | Decision |
|---|---|
| Provider says closed or merged | Cancel active runs/jobs; committed results remain |
| Close signal arrived but provider now says open | Skip stale close intent |
| Automatic refresh of a draft | Skip DRAFT; authorized manual requests can review drafts |
Refresh has the same base_sha..head_sha as latest review |
Skip SAME_INPUTS, no generation increase |
| Refresh has new head or target SHA | Generate a new review generation |
| Authorized rerun/deep | Generate even with identical inputs; record manual trigger and actor |
| Authorized stop with active work | Cancel |
| CI with no prior run or mismatched current head | Skip NO_RUN or CI_FOR_OLD_HEAD
|
| CI while latest run is active and not frozen | Wake its queued job |
| CI after freeze with missing sources recorded | Generate a successor with parent run ID |
| CI after freeze without missing sources | Skip CI_NOT_SIGNIFICANT
|
PR-comment commands require current GitHub write, maintain or admin permission, checked by the scheduler. Unauthorized commands are recorded as skipped without a bot reply. This is separate from the read-only Slack slash command.
Generation creation, superseding active prior reviews and inserting the job are atomic in crates/sych-storage/src/scheduler.rs. Superseding increments job lease epochs, so old holders cannot commit protected writes. Playground creation is the explicit exception: it shares the current generation and supersedes nothing. See Operator capabilities.
On startup and periodically, Engine::reconcile_once visits configured repositories, refreshes installation capabilities and lists open PRs. It feeds synthetic receipts such as reconcile:<number>:<head>:<base> through the same admission path. Known open changes missing from the list get close signals, but the scheduler still rereads the PR before cancelling.
The current adapter bounds open-PR enumeration at 1,000 entries in crates/sych-adapters/src/github/mod.rs; it is not an unbounded repository scan. Current-state verification prevents a synthetic close signal alone from establishing closure.
The shared ScmErrorKind classifier distinguishes unauthorized, unsupported, not found, rate limited, transient, incomplete diff, invalid anchor and unknown publication outcomes. Only RATE_LIMITED and TRANSIENT are retryable unchanged. Scheduling records SCM_READ_FAILED, postpones retryable reads and consumes nonretryable intents. Analysis retries are separately bounded by attempts and deadline in Workers and publication.
Engine::run checks scheduling on a one-second tick, reconciliation and delivered-summary verification at 600-second intervals, reaping at 15 seconds, pruning at 86,400 seconds and digest due checks at 60 seconds. These are loop scheduling constants; awaited work can delay later iterations.
| File | Responsibility |
|---|---|
crates/sych-app/src/server/build.rs |
Trusted connection construction and self-review build pin |
crates/sych-adapters/src/github/app.rs |
App JWT signing and per-repository token cache |
crates/sych-adapters/src/github/client.rs |
Fixed-base REST transport and typed failure mapping |
crates/sych-app/src/server/hooks.rs |
Raw-body verification order, admission response and counters |
crates/sych-adapters/src/github/webhook.rs |
HMAC verification, accepted events, commands and normalized signals |
crates/sych-core/src/scm.rs |
Provider-neutral signals, capabilities and error mapping |
crates/sych-core/src/schedule.rs |
Pure decisions, run input identity and retry classifier |
crates/sych-storage/src/admission.rs |
Atomic receipt/binding/intent admission and bounded debounce |
crates/sych-app/src/server/engine.rs |
Provider rereads, authorization, reconciliation and loops |
crates/sych-storage/src/scheduler.rs |
Generations, supersede/cancel transactions and event history |
- Add an event meaning in the SCM contract and webhook normalization, then define its intent mapping. Do not promote free PR text into trusted configuration.
- Change significance in
schedule::decidefirst and add pure cases; then exercise application traces incrates/sych-app/tests/scheduler.rs. - Preserve partitioning, duplicate no-ops and bounded coalescing in
crates/sych-storage/tests/admission.rs. - Cover lease invalidation and successor creation in
crates/sych-storage/tests/scheduler.rsandcrates/sych-app/tests/successor.rs. General persistence contracts are in Storage.