Repository navigation
apps server workers and publication
Active contributors: Vassiliy Kuzenkov.
A worker holds a fenced job while preparing evidence and running the review. Finalization saves an immutable result and durable publication intent; a different step delivers it or reconciles an unknown outcome. See Admission and scheduling for how the job is created.
crates/sych-storage/src/jobs.rs claims the oldest due queued job in a write transaction, increments its lease epoch and records owner, expiry, attempts and first-claim time. Fence consists of job_id, owner and epoch.
The shared predicate in crates/sych-storage/src/sql.rs requires a matching claimed job, live lease and matching run. Normal reviews must also equal the change's desired generation; playground runs explicitly bypass that generation comparison. Authoritative run operations additionally check the appropriate active state.
The worker heartbeats during token acquisition, fetch, source pinning, CI collection and analysis. Lease and heartbeat durations come from workers; the documented defaults are 60 and 15 seconds. Supersede, cancellation or reaping invalidates stale holders. Protected prepare/freeze/artifact/result writes do not accept an old fence.
Preparation is polled alongside renewals. Analysis runs on a separate thread, with cancellation signalled on lost ownership. No SQL transaction spans Git, SCM or model work. Cancellation is cooperative, not a claim that every in-flight external request can be recalled.
Expired claims are requeued with a new epoch or failed according to the stored attempt/deadline checks. The normal retry classifier allows two retries of rate-limited/transient steps, with backoff and Retry-After, never beyond its deadline. retry_at supports jitter; the current worker calls it with zero jitter.
stateDiagram-v2
[*] --> Queued
Queued --> Prepare: claim and fence
Prepare --> Evidence: pin source and trusted policy
Evidence --> Waiting: CI still pending before deadline
Waiting --> Evidence: CI wake or due time and new claim
Evidence --> Analyze: freeze imported inputs and gaps
Analyze --> Completed: fenced result and outbox commit
Prepare --> Failed: nonretryable or exhausted
Analyze --> Failed: no committed result
Prepare --> Abandoned: ownership lost
Analyze --> Abandoned: ownership lost
-
Fetch pinned commits.
crates/sych-app/src/server/worker.rsfetches head and target SHAs into a bare mirror addressed by connection and repository. The Git adapter uses installation credentials without placing them in argv or a credential-bearing URL. It does not check out or run the reviewed repository. -
Pin source and trusted policy.
review::pincaptures the source comparison and target-tip policy. Expected CI reports are filtered by changed paths andapplies_to. - Wait only for pending sources. A missing/incomplete CI job can release the claim until the evidence deadline, with a CI intent able to wake it earlier. The default CI wait is 180 seconds. PREPARE extends the job deadline to leave the configured analysis deadline plus 120 seconds of transport slack after the evidence wait.
- Freeze. Storage records expected reports, imported run/attempt/job/artifact/binding identities, gaps and missing sources. A later significant external input needs a successor, not a mutation of this frozen input set.
- Review and finalize. The worker passes imported facts, explicit CI gaps, active repository waivers and targeted execution-profile requests into the same review engine used locally.
crates/sych-app/src/server/mirrors.rs keeps source mirrors separately from immutable artifacts. Missing/pruned source can prevent later policy reconstruction or comprehension questions even when result/history rows remain.
The target policy declares what reports are expected. Trusted connection configuration declares each report's workflow file, event, job name, artifact name, report path and optional checkout-manifest path. crates/sych-app/src/server/ci.rs selects the exact head, workflow/event and run attempt; it does not use the latest green branch build.
The checkout manifest binds tested_oid to:
-
SOURCE_HEADwhen it is the requested head. -
MERGE_RESULTwhen a fetched commit's second parent is that head, retaining its target parent. -
UNVERIFIEDotherwise, including a missing manifest, with an explicit binding gap.
Reports retain provider/run/job/artifact provenance and separate job conclusion from parsed test results. Authenticated provenance does not make assertions independent or prove correctness.
Downloads use allowlisted artifact hosts without forwarding the GitHub token. The collector bounds a zip at 64 MiB and delegates archive/parser validation to CI adapters. Missing, expired, malformed, unbound or unavailable evidence becomes a CI_* gap, not a fabricated success. Actions run/job/artifact queries currently read their first 100 entries; do not assume complete enumeration at higher volume. See Facts and Security for parsers and execution boundaries.
A late-CI successor records its parent. Accepted model responses can be pinned as checkpoint artifacts under the run's fence and reused only when the dependency record exactly matches: template/schema, role/chain, redacted sent messages, output schema and model-configuration digest. The successor revalidates a reused response against its own context; reuse is not blanket reuse of the parent's conclusions.
Changed source, policy, CI or model routing can invalidate the match. Manual rerun/deep intentionally repeats inference rather than importing parent checkpoints. Local derived facts are rederived, and the parent's frozen input manifest is not rewritten. A missing checkpoint may cost a new call; it is not a review pass. Storage mechanics are in crates/sych-storage/src/checkpoints.rs and the storage page.
Storage::complete_run in crates/sych-storage/src/lib.rs verifies stored result bytes and the current fence, then commits result pointer, usage/coverage, recorded reason counts, job completion and outbox intent together. A crash after this commit leaves publication work without requiring another analysis.
| Object | Identity and rendering |
|---|---|
| Summary | One change slot, marker sych:summary:<change_id>, with generation-specific operations |
| Inline comment | Slot and marker keyed by finding fingerprint; existing fingerprints are not posted afresh each revision |
| Advisory check | Change check slot, enabled by trusted publication/check settings; Sych (advisory) with neutral conclusion, including failed reviews |
sych_core::publication renders from immutable result data and the diff manifest, not an unchecked model-written comment. Defects and rule violations are ranked by severity/fingerprint for at most eight new inline comments per revision. Anchors must match the correct blob and shown diff range, including three lines of context. Target-tip locations, unavailable anchors, incomplete provider diffs, optional nits/improvements and overflow stay in the summary with reasons.
An inline-position rejection is recorded and the finding is returned to the summary. Summaries retain explicit partial/unavailable coverage and required unknown checks. The adapter has no approve, request-changes or merge operation.
stateDiagram-v2
[*] --> PENDING
PENDING --> PUBLISHING: gates pass and body/attempt/fence stored
PENDING --> SUPERSEDED: generation changed
PENDING --> CANCELLED: change closed
PUBLISHING --> DELIVERED: reply and observed remote ID committed
PUBLISHING --> PENDING: definite retryable refusal
PUBLISHING --> FAILED: definite nonretryable refusal or limit
PUBLISHING --> UNCERTAIN: lost reply or expired publishing lease
UNCERTAIN --> DELIVERED: own remote object found
UNCERTAIN --> PENDING: proven absence after grace or audited operator decision
Before sending, the publisher checks local generation/open-state eligibility, rereads whether the PR is open and checks recorded capabilities. begin_publishing persists the exact body, request digest, attempt ID and publication fence before the write. Known remote IDs use UPDATE; new objects use CREATE.
Unknown outcomes never become blind retries. The reconciler looks by remote ID, otherwise by marker in the bot's own comments. Bot identity requires both GitHub's Bot type and configured login; a copied human marker grants nothing.
Current recovery bounds in crates/sych-app/src/server/publisher.rs:
- Revisit unresolved operations after 30 seconds; the enclosing reaper runs on its own tick.
- A complete empty marker search, no stored remote ID and a five-minute grace can permit audited automatic recreation within five publication attempts.
- Failed/truncated reads and check-run enumeration do not prove absence. A known ID does not permit a new CREATE through this path.
- After the one-hour reconciliation window, an unresolved operation remains
UNCERTAINfor an operator.
sych reconcile lists unresolved operations without contacting SCM. An authorized --allow-create decision needs actor and reason, accepts duplicate risk and is audited; it is not an exactly-once guarantee. See Operator capabilities.
Delivery and relevance are separate: a previous delivery may be stale after a new generation. Closing cancels pending publication, while uncertain work remains eligible for read-only reconciliation. Periodic verification can repair a delivered bot summary overwritten by a late older update and records PUBLICATION_REPAIRED.
| File | Responsibility |
|---|---|
crates/sych-app/src/server/worker.rs |
Claim lifetime, preparation, waits, freeze and analysis thread |
crates/sych-app/src/server/ci.rs |
Exact producer selection, checkout binding and gaps |
crates/sych-storage/src/jobs.rs |
Claims, heartbeats, reaper and fenced transitions |
crates/sych-storage/src/sql.rs |
Shared active-state, fencing and visibility predicates |
crates/sych-storage/src/outbox.rs |
Publication intent creation and slot/revision identity |
crates/sych-storage/src/publish.rs |
Publication claim, durable sending state and reconciliation state |
crates/sych-storage/src/recreate.rs |
Audited automatic/operator recreation |
crates/sych-app/src/server/publisher.rs |
Gates, rendering, delivery, marker reconciliation and repairs |
crates/sych-core/src/publication/mod.rs |
Pure exact-anchor and inline-placement decisions |
- Change worker lifecycle with storage predicates and
crates/sych-storage/tests/scheduler.rs, not just the async loop. - Extend evidence collection with
crates/sych-app/tests/ci_evidence.rs; test both the provenance and explicit gap path. - Change delivery/recovery with
crates/sych-app/tests/outbox.rsandcrates/sych-app/tests/publication.rs, including lost replies and restart traces. - Change placement/rendering with
crates/sych-core/tests/publication.rsand golden summaries infixtures/publication/. Keep output policy separate from delivery mechanics.
Inventory and author-count definitions are in the server index.