Repository navigation
features models
Active contributors: Eduard; Vassiliy Kuzenkov (also recorded as bondiano).
Models answer typed tasks; they do not set the final review verdict. The core router fixes eligible routes, the gateway reserves every attempt before dispatch, and storage durably records settled or unknown spend.
| Provider | Transport and constraints | Accounting |
|---|---|---|
| OpenRouter | Streaming chat completions; exact model slug and explicit upstream order; provider fallback off; native strict JSON schema and enforced output cap |
api_usage / api_hard; reported cost or full-usage price calculation |
| OpenCode Go | Official /inference/go/openai/v1 endpoint, exact Go model ID, one session header per task; schema in prompt, no native schema/output-cap claim |
subscription_quota / subscription_observable; reported charge and plan allowance are separate |
| GLM Coding Plan via Pi | Real Pi 1.4.0, pinned Coding Plan endpoint; new empty workspace/HOME, no tools, extensions, skills, MCP, sessions, retries or compaction | Observable tokens; Pi's catalog cost is reference only, not a charge |
| Sign in with ChatGPT | Official OAuth/PKCE plus text-only Responses API; store: false, no tools or agent loop; strict schema requested, unsupported capability is not silently dropped |
Observable plan usage; charge is unreported, not standard API pricing |
crates/sych-app/src/backend.rs resolves mode, credentials, egress, billing, model and runtime before use. The openai_compatible configuration adapter currently has no implemented transport. Subscription adapters are permitted only in personal_local; corporate validation rejects external OpenRouter/subscription routes, including fallbacks.
OpenCode Go and GLM require confirmed disabled overage; fixed fees are mandatory for subscription reservations. ChatGPT uses the external token file named by connection_ref_env, not a regular API key. sych auth chatgpt signs in and lists account models without inference. Transport tests use fixtures/loopback servers; browser sign-in and live provider entitlement are not automated guarantees.
crates/sych-core/src/model/router.rs creates a revision-hashed route plan:
- Assessment, combined review and discovery use
reviewer; high-risk audit usesrisk_auditor; candidate checks useverifier. -
--models rolesusesmodels.roles, withmodels.deep_rolestaking priority for deep runs and the reviewer assignment supplying missing roles. -
--models PROFILEpins that primary for all review roles and ignores role-specific fallback chains. - Exactly one flat chain is selected by priority: profile, then role when role-routed, then provider. A fallback profile's own chain is not recursively attached.
Each task visits a profile at most once. Configured quota/rate/transient/timeout/unsupported triggers may advance; route-local NO_PRICE_BOUND, FIXED_FEE_UNKNOWN or BILLING_MISMATCH can also advance. Authentication, entitlement, configuration, cancellation, shared-cap/deadline exhaustion and invalid/truncated/refused output do not become unlimited retries.
Every hop rechecks eligibility and uses the same durable run/purpose and tenant pools. Unknown charges remain held across providers. Cooldowns are run-local; quota exhaustion is remembered for the run and reset windows are never awaited. Hops and failures are recorded, and an unanswered pass becomes a gap, not empty success.
For each initial, repair or no-reasoning attempt, budget.rs and gateway.rs perform:
- Input bound: sum of UTF-8 message bytes plus 16 per message.
-
Output bound:
budgets.<purpose>.max_output_tokens_per_request, default 2,000. The route receives a cap only when it can enforce one. Hard output-token accounting applies toapi_hard, not observable subscriptions. -
Money bound: for API usage,
ceil((input_bound × input_per_mtok + output_bound × output_per_mtok) / 1,000,000)micro-USD, with no cache discount. Missing price card or unenforced output cap denies dispatch asNO_PRICE_BOUND. Prices are operator-maintained, revisioned catalog entries keyed by model; the operator must cover the most expensive permitted upstream. -
Subscription bound: zero incremental request reservation only with an accepted
{amount_micro_usd, allocated_micro_usd}fixed fee. Unknown fee isFIXED_FEE_UNKNOWN, not zero. - Atomic admission: one storage write transaction checks attempts, input/output bounds and run-purpose money; tenant UTC day, Monday-based week and calendar-month pools; and the shared playground day pool when applicable. The monthly pool includes allocated subscription fees once per provider/month, not once per call. Run caps remain lifetime across month boundaries.
- Deadline: checked before reservation and again before dispatch; the app also bounds waiting by the remaining run deadline.
Purposes are ANALYSIS, TOUR and FOLLOWUP; follow-up run limits are additionally scoped to the reader's tour session. Tenant pools remain shared.
The engine can reduce limits with Limits::reserving(k): retain k attempts, capped by available attempts, and their floor-divided per-attempt shares of run money/input/output tokens. Search keeps verifier capacity. Discovery allocation is at most min(discovery_calls, (max_attempts - 1) / 2); earlier passes preserve that allocation and, where applicable, the verifier's attempt. Repairs and fallback consume the same remaining allowance.
| Outcome | Ledger transition | Meaning |
|---|---|---|
| Definitely not dispatched | RELEASED |
Money/token reservation released; the attempt still counts |
| Reply with charge or complete API usage | SETTLED |
Actual charge retained separately from reference estimate |
| Subscription reply without money |
SETTLED, charge NULL
|
Money not reported; not a zero-cost claim |
| Dispatched timeout/cancel/disconnect, or API reply without cost/full usage | UNKNOWN |
Reservation remains held as unknown charge |
Admission counts settled charges + held reservations + unknown charges against caps. An unexpectedly larger actual charge is still recorded and marked billing_mismatch; accounting does not rewrite reality to preserve a cap claim. For subscription-only routes, such a mismatch blocks further reservations for that provider that month.
Settlement is idempotent by attempt ID: settled rows do not change, while unknown rows can later settle to known charges. Cancelled in-flight reservations are held as unknown. Durable transactions work through the storage abstraction, not an in-memory per-provider counter.
Automatic provider-generation reconciliation of unknown charges is not implemented. A generation ID/error can help diagnosis, but the held reservation does not disappear because another route succeeds.
crates/sych-core/src/model/gateway.rs generates the schema from the parsed Rust type. Routes lacking native schema support receive it in the system prompt. Parsing accepts the full JSON reply, optionally one enclosing code fence, not JSON extracted from prose.
One schema repair is allowed and separately reserved. A reasoning-truncated reply can get one separately reserved no-reasoning attempt on a capable route; splittable engine calls disable that retry and split work instead. Truncated/refused output is not a result. Prompt data is redacted and framed separately from trusted instructions; no chain-of-thought is requested or stored.
| Source | Change entry point |
|---|---|
crates/sych-core/src/model/contract.rs |
Provider, prompt, capability and usage contracts |
crates/sych-core/src/model/router.rs |
Role plan, fallback, cooldown and checkpoint routing |
crates/sych-core/src/model/budget.rs |
Bounds, prices and admission rules |
crates/sych-core/src/model/gateway.rs |
Reserve/dispatch/settle/validate sequence |
crates/sych-app/src/backend.rs |
Callable transport resolution |
crates/sych-adapters/src/chat.rs |
Shared HTTP/SSE parsing and errors |
crates/sych-storage/src/ledger.rs |
Atomic reservations and settlement |
crates/sych-storage/src/spend.rs |
Spend reporting |
17 source files, 11 test files; ratio 0.647; 2 unique human authors. Method: capability measurements. Scope: core model/; adapter chat.rs, openrouter.rs, opencode_go.rs, pi.rs, siwc/; app backend.rs, probe.rs; storage ledger.rs, spend.rs; core tests gateway.rs, router.rs, route_plan.rs; matching provider tests including siwc_auth.rs; app tests probe.rs, router_ledger.rs; storage test ledger.rs.
Change admission with ledger concurrency/idempotence tests; change routing with crates/sych-core/tests/router.rs; change transport fields with its loopback fixtures. See Configuration for profile fields and Review for the callers of these roles.