Docs · Internals

The mechanics behind the product model.

Implementation details that matter when debugging or extending Switchyard: dual-path events, durable workflow steps, Git ref safety, credential boundaries and where each source of truth begins and ends.

Authority split

SystemAuthoritative forNot authoritative for
Cloudflare ArtifactsGit objects, commits, branches, tags and canonical refs.Work status, workflow progress, review findings or policy.
TrestleCoordination/application truth: Work, Attempts, PR metadata, workflow steps, findings, queue, policy, audit.The actual contents/history of a Git branch.
Switchyard control planeRules that connect the two: orchestration, auth, policy, reconciliation and UX.Long-term truth that exists only in process memory.

The dual-path event identity

The event fast path and reconciliation both write normalized domain events keyed by the Git transition identity (repo, ref, before, after). Delivery metadata such as queue message id or “seen at” time is deliberately excluded from the logical identity so two observers of the same Git movement converge.

Artifacts push event ──► Cloudflare Queue ──► ingest ──┐
                                                       ├─► one normalized ref transition
periodic git reconciliation ───────────────────────────┘

Trestle's idempotency behavior also matters here: the same Idempotency-Key with byte-identical content replays, while the same key with different content returns 409 idempotency_conflict. Switchyard persists the first immutable event envelope and retries its exact bytes. Conflicting bodies are surfaced; a 409 alone is not proof of successful convergence. Publication recovery additionally verifies a matching persisted fact before acknowledging a duplicate receipt.

Git/ref mutation safety

Canonical/ref movement uses ordinary Git as the final stale-write authority. Switchyard reads the expected SHA, creates the desired commit/merge, then performs a normal non-force push. If another actor moved the ref first, Git rejects the stale update. Force-push is therefore a policy-sensitive escape hatch rather than part of the normal integration substrate.

expected main = abc123
build candidate commit = def456

git push origin def456:main
# succeeds only while main is still compatible with the expected state

Workflow durability

step = (run_id, step_key, op, args_hash, status, result, attempts)

run script from top
  for each durable operation:
    completed step?  → replay recorded result
    in-flight step?  → re-execute with bounded retry
    new step?        → record intent, execute, record result

This intentionally avoids serializing arbitrary JavaScript VM state. The workflow function is reproducible control logic; durable Switchyard operations are the persistence boundaries.

Credential store

LayerRule
Provider credentialEncrypted at rest (AES-256-GCM), metadata-only API, resolved only for execution.
Agent roleDefines allowed intent/capabilities independently of a provider secret.
Repository authorityGranted by Switchyard access/policy and short-lived Git credentials, never by “having an API key.”
Fallback encryption keyMay live under the local data directory; protects against database-only compromise, not full-host compromise.

Why scratch Git exists

Preview, conflict analysis, semantic validation and integration need actual Git trees. The first implementation uses scratch clones because the correctness model is extremely clear: each operation gets isolated repository state. The measured performance cost is real and documented; a cached bare mirror/worktree design is the intended optimization once it passes equivalent isolation and credential-safety gates.

Internals principleWhere possible, Switchyard composes existing strong primitives — Git non-force pushes, Trestle CAS/idempotency, durable records — rather than inventing a second source-control or transaction model.

Historical workflows verification

During CP7 the control plane was killed during a running durable workflow and restarted. The already-completed Agent step replayed its recorded result instead of creating another repository effect; the in-flight sleep retried; later Agent/check steps executed once. Earlier false-positive crash tests were rejected before this final gate, which is useful evidence that the final claim is real rather than ceremonial.

Historical integration-queue verification

The CP9 gate exercised same-file contention. The first PR integrated. The second became blocked during preview, its Attempt was routed to conflict state, the conflict-resolver repaired the Attempt branch, and the item was explicitly re-queued. Only after the repaired branch previewed cleanly did it become canonical.

Recovery boundaries

Publication intent precedes the Git effect; stable provenance is acknowledged before operation completion. Remote observation reconciles ambiguous outcomes without another push. Candidate replay and descendant inspection require retained local scratch on the same worker; missing scratch leads to bounded failure and operator recovery rather than invented attribution. Periodic ref polling observes current state and deletions, but cannot reconstruct every intermediate push. Identical transition tuples share a deduplicated event receipt.

Pages projects share their owner origin. Switchyard protects its own production authentication with a host-only __Host- cookie. Arbitrary sibling content cannot be universally prevented from setting parent-domain cookies at the DNS suffix level.

The raw sy api command reports HTTP 401 as exit status 1. This is the current behavior, not a uniform authentication-specific exit-code guarantee.