Skip to content

Architecture ​

bupha is a port/adapter monorepo: every external concern sits behind a trait (a port), and each integration is a crate that implements it (an impl). bupha-core is the pure domain — config shape, queue semantics, shared primitives — and depends on nothing outside itself; the binary is a thin composition root that wires impls to ports.

Crate map ​

cratelayerpurpose
bupha-coredomainbupha domain core: config types, job queues, shared primitives — no ports, no integrations
bupha-accessportAccess port: who may trigger a repo
bupha-attestportAttest port: signed run provenance (SLSA-style predicate)
bupha-cacheportCache port: artifact-cache backend for runners
bupha-configportConfig port: where bupha.yaml/toml-shaped config comes from
bupha-queueportQueueStore port: queue persistence
bupha-queue-leaseportQueue-lease port: multi-worker fencing (try_claim + Fence)
bupha-runnerportRunner port: how a job becomes a spawned process
bupha-secretportSecret port: resolve named secrets from storage
bupha-serviceportService port: OS service lifecycle
bupha-statusportStatusSink port: where run outcomes are reported
bupha-telemetryportTelemetry port: fire-and-forget pipeline events
bupha-triggerportSource port: where pushes come from — forge webhooks, WAL polls, …
bupha-tunnelportTunnel port: expose the webhook listener publicly
bupha-vcsportVcs port: VCS operations for repos and worktrees
bupha-access-fileadapterAccess adapter: allowlist of forge logins from config
bupha-access-forgeadapterAccess adapter: forge collaborator-permission check
bupha-attest-fileadapterAttest adapter: SLSA-shape predicate JSON per run (unsigned v1)
bupha-attest-sigstoreadapterAttest adapter: cosign-signed run predicates (needs cosign + key)
bupha-audit-fileadapterAudit adapter: append access/outcome decisions to a JSONL file
bupha-cache-sccacheadapterCache impl: sccache-compatible conf (file/S3/R2/GCS via conf)
bupha-cloudflaredadapterTunnel impl: cloudflared (named tunnel preferred, quick tunnel fallback)
bupha-config-fileadapterFile impl of ConfigSource — resolves bupha.yaml/.yml/.toml path, dispatches parse to the per-syntax adapter
bupha-config-tomladapterTOML impl of ConfigSource — parses a bupha.toml file
bupha-config-yamladapterYAML impl of ConfigSource — parses a bupha.yaml/.yml file
bupha-containeradapterRunner adapter: unprivileged container (podman/docker), network-off
bupha-daggeradapterRunner impl: dagger call <fn> per job
bupha-dotenvadapterSecret impl: KEY=VAL env file (chmod 600)
bupha-gitadapterVcs impl: git via the git CLI
bupha-githubadapterGitHub impl: push-webhook trigger + commit-status sink
bupha-historyadapterRun-history adapter: JSONL records per finished run
bupha-httpadapterRunner impl: remote execution via HTTP agent (tar worktree + poll)
bupha-keyringadapterSecret impl: OS keyring via secret-tool (libsecret)
bupha-queue-redbadapterQueueStore impl: redb embedded store (single file, ACID)
bupha-queue-redisadapterQueueStore adapter: redis (multi-worker; SET NX claim + INCR fence)
bupha-shelladapterRunner impl: bash -c <cmd> per job — no containers
bupha-sshadapterRunner impl: remote execution over ssh (rsync worktree + run)
bupha-sturnadaptersturn source impl: reads refs/sturn/* WAL state out of a clone via git plumbing
bupha-systemdadapterService impl: systemd user units
bupha-telemetry-oteladapterTelemetry adapter: OpenMetrics textfile for Prometheus
bupha-webhookadapterSource impl: forge-webhook listener driving a Trigger port impl
buphabinarybupha — queue engine for event-driven jobs: shipped as CI

modules/dagger/ (Python SDK) is the shared pipeline module bupha init installs into consumer repos — pinned to a sha.

Sources — the ingest edge ​

bupha is a queue engine: source → queue → effect. Everything in front of the queue is a Source — a long-running ingest that emits normalized (repo, ref, sha, sender) pushes; everything behind it (queues, runner, status sinks) is source-agnostic. A bupha watch process runs every configured source and feeds one shared ingest path.

sourceconfigemits on
github-webhooktrigger.kind = "github" (+ [trigger] listener, secrets, tunnel)verified push deliveries
sturn-wal[trigger.sturn] + [[repo]] sturn = trueOp::Snapshot WAL events

Trigger is the narrower per-request port a webhook Source drives — is this our event, which repo (untrusted hint), does the signature verify, what does the payload ask for. New forges mean a new Trigger impl reusing the same webhook listener; new kinds of ingest (gitlab webhook, cron, poll-ref, file-watch) are new Source impls — neither touches the queue.

Webhook request flow ​

The github-webhook source's per-request pipeline (byte-stable — routing and statuses are part of the contract):

POST /hook
  → 1. path check (404 otherwise)
  → 2. read body (≤ 2 MiB)
  → 3. repo hint — untrusted peek at repository.full_name,
       selects the watched [[repo]] and its secret; an
       unwatched repo 404s (it can never verify)
  → 4. signature verify (Trigger port — github impl: HMAC
       sha256, constant-time; key = repo's secret_env,
       falling back to trigger.secret_env)
  → 5. dedup delivery id (bounded 10k ring; github impl uses
       X-GitHub-Delivery)
  → 6. parse — skip deletes/zero-sha; revision must be path-safe
  → 7. route — git_ref selects every job of the repo watching it
       ([[repo.jobs]] entries, or the repo's implicit pipeline);
       forge-attested sender checked against the access policy
  → 8. enqueue — one queue per job; a push fan-outs into every
       matched queue; persist via QueueStore (redb, ACID)
  → 9. one global worker — Vcs fetch, detached worktree
       at <base>-<repo>[-<job>]-<sha12>
  → 10. spawn run handle (token via env:// name, never argv)
  → 11. status — pending → success/error; superseded and
        cancelled shas get honest error statuses

Queue semantics ​

Queues are per job: a [[repo]] is one implicit pipeline unless it declares [[repo.jobs]], in which case each job gets an independent queue (name:job keys), branch filter, runner and status context. One push fan-outs into every job queue whose branch matches the ref — same-repo jobs are independent of each other (latest-wins on one never touches another's pending slot, and cancel_running only kills its own job's in-flight run).

policypendingon new pushuse for
latest (default)1 shasupersedes pending; cancel_running may kill in-flightCI gates
allbounded FIFO (32)appends; oldest evicted past cap; cancel_running rejected at load — it would drop a promised commitreleases

Persistence: accepted work writes through the QueueStore port (redb, single embedded file) inside worktree.base; on restart the interrupted running sha is re-queued at the front.

One global worker serializes runs across all repos — a second push queues behind the in-flight job. Deliberate (one box, bounded resource use), not a hang: journalctl --user -u bupha-watch shows the queue moving.

Security model ​

  • mandatory HMAC (constant-time compare) — unauthenticated payloads never reach the queue
  • per-repo webhook secrets ([[repo]] secret_env, falling back to trigger.secret_env) — the repo is resolved before verify, so a hook admin on one repo can't forge signed pushes for another
  • body cap, delivery-id replay dedup, hex-sha validation before the value touches paths or status URLs
  • webhook takeover is exact-URL only; hook API calls are timed out
  • config names secrets (secret_env/token_env) — values resolve env → OS keyring → ~/.config/bupha/env (0600); the runner gets the token through its own mechanism (env:// for dagger)

Extending ​

to add…write…core changes?
push source (cron, poll)Source adapter crateno
forge (gitea/gitlab)Trigger + StatusSink adapter crateno
pipeline backendRunner adapter crateno
ingress (fly/tailscale)Tunnel adapter crateno