Files
forge/LLM.md
zeekay afa2c25fc8 Answer an unusable branch or tag name with 422 and a flash
A tag named like an object id, and a branch the same, are refused in the
service layer, and the API answered the refusal with a 500 and the web
create-branch page with an error page. The API's create tag, create and
edit release, create branch and rename branch answer 422 with the
reason; the web create-branch and rename-branch pages flash it.

LLM.md lists every push that names an id, and the services that refuse
the names where no hook runs.

Claude-Session: https://claude.ai/code/session_015XYKLo5aivJF2MHLneVUYc
2026-11-08 16:51:20 -08:00

36 KiB

Hanzo Forge — github.com/hanzoai/git

The Git forge that serves git.hanzo.ai: IAM-native code hosting for the Hanzo / Lux / Zoo orgs, with native GitHub-Actions-compatible CI.

What it is

  • Base: upstream 1.26.4, credited in NOTICE. Module path is github.com/hanzoai/git — the GitHub repo rename to hanzoai/forge did not change it. The daemon is gitd (/app/git/gitd, wrapper /usr/local/bin/gitd); upstream's CLI subcommands are intact under the new name (gitd admin auth …, gitd migrate).

    /usr/local/bin/gitd is load-bearing, not cosmetic. It is what setting.AppPath resolves to, and AppPath is written verbatim into every repository's hooks/<hook>.d/gitd delegate. The outer hooks/<hook> script runs EVERY executable in <hook>.d/ and rejects the push if any exits non-zero, so moving that path — or leaving a delegate from an older binary name behind — breaks pushes. Both are handled automatically: routers.syncAppConfForGit re-runs SyncRepositoryHooks over every repo when AppPath changes, before the web listener opens, and createDelegateHooks deletes legacyDelegateHookNames. gitd admin regenerate hooks is the manual lever. Anything outside this repo that invokes the binary by absolute path — notably the oauth-sync init container in hanzoai/universe — must be updated in the SAME change that bumps the image tag.

  • [actions] intact: services/actions, models/actions, routers/api/actions — full runner registration + job API. Enabled via GIT__actions__ENABLED=true.

  • The runner protocol is ours: five typed zip operations at /v1/runner — register, declare, task, state, log, declared once with zip.Post and answered on two faces: POST /v1/runner/<name> for a runner over HTTP, and post_runner_<name> on ZAP's own call plane at /.well-known/zip/op/. Both are the same app on the forge's one listener — routers/init.go hangs it on two chi routes with adaptor.FiberApp, registered with Post and never Mount, because Mount strips the prefix and the operations declare absolute paths. It is spoken only between this forge and hanzoai/git-runner, so it is written to suit us: no protobuf, no generated code, no service name in the path. Two rules govern every value on it, and a test in routers/api/actions holds both: no map, which the ZAP layout refuses outright, and no time.Time, which it accepts and then silently blanks because every field of one is unexported. Named values cross as []Pair; instants as int64 unix nanoseconds. routers/api/actions/runner.go holds the handlers; the messages live in modules/actions/runner, a NESTED MODULE (github.com/hanzoai/git/modules/actions/runner) with an empty require block. That nesting is the point: the runner imports the very types the handlers declare, so there is one definition of the protocol and it does NOT inherit this module's dependency graph. Requiring the whole forge instead breaks the runner outright — the forge pins go.yaml.in/yaml/v4 forward with a replace, a dependent does not inherit a replace, and actionlint then fails to compile.

  • A runner's job context is a struct, and that is the point. As a map the two sides could disagree in silence, and did: the forge wrote one spelling of the runtime-token key while the runner read another, and quietly fell back to the task token. runner.Context names the twenty-one values the forge computes AND the runner reads, so a missing one is a compile error. GenerateGitContext keeps its map — the forge evaluates workflow expressions against it — and generateTaskContext is the ONE place the two vocabularies meet.

  • The forge and the runner share that wire, so they are deployed together. The forge serves one runner protocol and the runner speaks one; nothing negotiates a version and there is no shim, deliberately. So a protocol change lands in both repos or in neither, and a rollout goes forge first, runner fleet second: in the gap a runner's operations fail, it backs off, jobs queue here, and the queue drains once the fleet is rolled. The other order points runners at a forge that does not yet answer them.

  • Artifacts are third-party JavaScript and the paths are not ours. actions/upload-artifact@v3 concatenates _apis/pipelines/… onto whatever the runner set as ACTIONS_RUNTIME_URL, so that base IS ours and it sits at /v1/artifact/. The v4 protocol is different: @actions/artifact v2 reads ACTIONS_RESULTS_URL and keeps only new URL(…).origin, then appends twirp/github.actions.results.api.v1.ArtifactService/… itself — so ArtifactV4RouteBase cannot be moved anywhere, and it stays at the root. That same library throws GHESNotSupportedError for any host that is not github.com, *.ghe.com or *.localhost, so on git.hanzo.ai every upload-artifact@v4+ / download-artifact@v4+ step fails before it opens a connection: the v4 endpoints answer nobody today.

  • Identity = hanzo.id OIDC only. No fork-baked issuer; binding is a standard OAuth2 auth source (goth openidConnect) pointed at https://hanzo.id/.well-known/openid-configuration. Org membership is driven by the IAM owner claim (--group-claim-name owner --group-team-map … --group-team-map-removal), reconciled declaratively by the deploy's oauth-sync init container. hanzo.id IAM app: see the universe repo for the registered name.

  • A Hanzo IAM access token IS a git credential. iamUser (services/auth/iam.go), called from the basic-auth path (services/auth/basic.go), takes a hanzo.id access token as the git-over-HTTP password so CI and buildkit stop needing a hand-made PAT. Sign-in here is external, so a user has no password to give git and a PAT was a second credential with a second lifetime for an identity IAM already issues tokens for.

    • Two wire shapes, one credential. basic.go takes the token as the Basic PASSWORD, which is what git-over-https sends; auth.IAM{} (iam.go) takes it as a BEARER, which is what the API takes. That Method is registered in the API group and is NOT the same feature twice — 3dd8a290b8 added it to close the bearer gap this file used to list as owed. An earlier draft of this bullet said the Method "must not become one"; it was written before that gap was closed, and the commit supersedes it.
    • No local credential is asked before it, because none is left. The OAuth2 access token and the personal access token are gone from BOTH readers — parseAuthBasic and OAuth2.userFromToken — since IAM signs the JWT behind every access token and API key, and a credential this instance mints for itself is a second authority for an identity that already has one. Removing it from one reader only would have left the other answering: they are two paths to the same two credentials, which is why the change is not complete until both are cut.
    • What those readers still accept is the Actions task credential, in both its shapes — the JWT a current runner carries and the opaque token an older one sends. It is not a user identity and not IAM's to issue: the protocol mints it per job, scoped to that job, for the runner already executing it.
    • Verification is the shared reader, hanzoai/authz's edge.Verifier over the issuer's JWKS — algorithm, kid, signature, issuer, expiry. Issuer and keys come from THIS instance's own OIDC login source via discovery, so the tokens accepted are the ones minted by the provider users already sign in through, and no [iam] config exists to drift from it. There is no bespoke verifier; building one is the custom auth the house rules forbid.
    • aud is deliberately NOT checked. IAM sets it to the client that ASKED for the token, not the server that accepts it, so an allowlist here would mean enumerating every client in the estate and 401ing every user of the next one. What bounds the credential instead is its SCOPE: basic.go sets ApiTokenScope to write:repository, so it clones, fetches and pushes and cannot mint tokens, add keys or administer anything.
    • Whose token it is comes from the link sign-in already wrote — sub against external_login_user for that source. No claim is trusted to NAME a user; email and username are mutable and a match on one would land a renamed identity on somebody else's account. An account that may not sign in is refused here too (!IsIndividual || !IsActive || ProhibitLogin), the same question db, ldap and signin each ask — without it one credential would outlive a suspension.
    • The container routes stay out, deliberately. /v2/token mints a 24h registry token of its own, which would outlive the short-lived IAM token and survive its revocation, so a longer-lived credential is not issued off a shorter-lived one.
  • Config = env. GIT__<section>__<KEY> (upstream's app.ini API under our prefix; modules/setting.EnvConfigKeyPrefixGit). No other prefix is accepted, and there is no fallback, so a stale variable under an old prefix is ignored in silence. No custom/conf baked, no Helm — the running config lives entirely in the deployment's env (see universe).

  • KV, not redis. The client is github.com/hanzokv/go and the vocabulary is KV end to end — there is no redis spelling left and no alias accepting one. Connection URIs are kv://, kvs://, kv+socket://, kv+sentinel://, kv+cluster:// (the trailing s on kv is the one way to ask for TLS, so kvs+sentinel:// / kvs+cluster:// too). The operator-facing values are [cache] ADAPTER = kv, [session] PROVIDER = kv, [queue] TYPE = kv, [global_lock] SERVICE_TYPE = kv. modules/nosql.getKVOptions hand-parses the URI, so the scheme family is this repo's to define — it never reaches the client's own parser.

The URL namespace

routers.NormalRoutes (routers/init.go) allocates the whole top level, and it is the only place that may: chi matches the most specific mount first, so a /v1/… route declared inside routers/web would be swallowed by the /v1 mount. Five prefixes:

  • / — the browser. Every page a person sees (routers/web), plus /-/fetch-redirect, the delegate that lets a fetch response redirect to a URL carrying a hash.
  • /v1 — every machine surface. The REST API is mounted here whole (routers/api/v1). Beside that mount, not inside it, sit the endpoints that arrive with their own credential and so must not meet the session and API-token middleware: /v1/internal (the daemon calling itself from a git hook or the SSH command, holding the internal token), /v1/sync (HMAC-SHA256 over the payload), /v1/healthz (no auth and no database, so a probe stays a probe), /v1/packages, /v1/runner and /v1/artifact.
  • /.well-known/zip/op/ — ZAP's call plane, the second face of the same five runner operations. It is a top-level path because that is where zip addresses an operation by name, and it rides the forge's existing listener.
  • /v2 — the OCI distribution spec. The registry API fixes this at the root of the host, so a sub-path deploy has to map it there in the proxy. Not ours to place.
  • /twirp/github.actions.results.api.v1.ArtifactService — the v4 artifact protocol, also not ours to place, and answering nobody. See artifacts above.

Nothing lives under /api. The only thing that ever did was the runner control plane, which is now /v1/runner. The host is api.* where an API surface deserves its own name; the path carries /v1/ and never a second /api/ segment as well.

Upstream naming: what is left, and why

The tree names itself. Source files carry an SPDX line and the Hanzo copyright; upstream authorship is recorded once in NOTICE. Everything addressable is spelled for this product: webhook type native, storage bucket and container forge, indexer names forge_issues / forge_codes, bleve analyzer forge/path, lock prefix forge:globallock:, SSH host keys ssh/forge.*, markdown front-matter key forge:, metrics namespace git_.

What remains is there for a reason. Do NOT sed these:

  • Attribution. LICENSE and NOTICE carry the upstream copyright the MIT licence requires, and assets/go-licenses.json embeds each dependency's licence text verbatim — including github.com/hanzoai/act, whose own LICENSE still credits its upstream. Rewriting a licence text falsifies it.
  • go.sum. gitea.com/xorm/sqlfiddle is in the module graph because github.com/hanzoai/builder keeps it as a test dependency. Dropping it there and releasing a new builder clears the last entry here.
  • Legacy on-disk names, which are load-bearing. modules/gitrepo/hooks.go keeps legacyDelegateHookNames and models/asymkey/ssh_key_authorized_keys.go keeps the old authorized_keys marker. Both exist so state an earlier release wrote is removed: an unrecognised delegate exits 127 and rejects every push, and an unrecognised marker is copied through as a hand-added key, leaving a revoked key authorized. Forgetting these is a defect, not a cleanup.
  • "gitea-actions" in the reserved-username list (models/user/user.go). Unblocking it would let an account squat the name the Actions bot used to have.
  • The reserved secret-name prefix (services/secrets/validation.go) rejects GITEA_ alongside GITHUB_. Nothing in this tree injects the former, but the runner is a separate component; narrow the denylist only after confirming it there.
  • email_notification.gitea_actions (models/user/setting_options.go) is a stored user_setting key. The Go identifiers around it were renamed; the value needs a migration, so it waits for one.
  • models/migrations. A migration must keep describing what it did: theme values, service-type enum values, the io.gitea.commits payload field it reads, and the fixture rows it ran against all stay. Comment text is fair game; nothing else is.
  • tools/generate-svg.ts names the upstream icons it prunes, because the third-party icon theme is what ships them.

Every header we emit is X-Git-*. Webhook delivery (services/webhook/deliver.go), notification mail (services/mailer/), and the API response headers X-Git-Warning and X-Git-Object-Type (routers/api/v1/). The vendor families beside them stay and carry the same values, because they are what lets a receiver written for another server work against us unchanged: X-Gogs-*, X-GitHub-*, X-GitLab-*, and X-Hub-Signature/-256 — that last pair is GitHub's own spelling, which third parties genuinely send us. TestWebhookDeliverGitHeaders asserts the parity and refuses any delivery header named after the upstream server, so the emission cannot come back by accident.

No inbound header is branded either. The OTP request header was declared in the CORS allow-list and both swagger specs and read by nothing — identity here is IAM's, and basic auth takes a token — so it and the test that asked for a response the server could not produce are gone.

Sync with GitHub, both ways

An estate repo lives at the same <org>/<name> here and on GitHub, and a push to either side reaches the other. There is no mode to set.

  • Out (forge to GitHub): a push mirror with sync_on_commit. It pushes refs/heads/* and refs/tags/* without +, so a diverged GitHub ref is refused, never overwritten (services/mirror/mirror_push.go). It takes no lock. Where the inbound sync is on, a successful push out also records the tips it put there under refs/upstream, so a branch pushed out and then deleted here is not brought back.
  • In, pull mirror: the GitHub org webhook reaches /v1/sync (routers/web/misc/sync.go, HMAC under [mirror] SYNC_SECRET) and queues a pull. Only X-GitHub-Event: push, create and delete do; any other event is answered ok and ignored. The whole payload (up to 25 MiB) goes through the HMAC as it is read, and only the first MiB is held, to read the repository name from.
  • In, regular repo: with no pull mirror row, the same event finds the push mirror whose address is github.com/<owner>/<name> (IsGitHubRepo: https:// or ssh ([email protected]: / ssh://) only, any credentials, .git, case; no http://, git://, port, query, fragment or odd path) and queues InboundMirrorType. SyncInboundMirror (services/mirror/mirror_inbound.go):
    • takes the pull lock (repo_pull_mirror_<id>) and re-checks that the repo is not archived (before each ref, too), has no pull mirror, and still mirrors to the GitHub repository of its own name (a forge rename turns it off, with a warning), and that [mirror] SYNC_USER is set and can write; otherwise it does nothing;
    • hides refs/upstream (uploadpack.hideRefs, receive.hideRefs; pre-receive refuses any push there, GetRefsFiltered never lists it, and the dumb HTTP protocol, which lists every ref and serves any object, is refused whole: info/refs without a service, HEAD, objects/...). Only the sync's own pushes are told of refs/upstream/staging, by git push --receive-pack='git -c receive.hideRefs=!refs/upstream/staging receive-pack': a push learns which commits the repository has from what receive-pack advertises to it, and without that, filling an empty repo from itself would send it its whole history again. (The environment cannot carry this: git clears GIT_CONFIG_* for a push to a local path.) The repo's uploadpack.allowAnySHA1InWant is set false, over the forge's global true, which stops a client of the old protocol fetching a hidden tip by id; the new protocol serves any object it is asked for, so what is not to be seen is not brought in (bot branches are not fetched), and a tip the sync only records (the first sync's branches) is held, reachable by its id for whoever knows it. It fetches into refs/upstream/staging/{heads,tags}/ with forced refspecs and --prune, and acts only on names whose staged tip is not the one recorded in refs/upstream/{heads,tags}/. A tip is recorded only after the forge has dealt with it (pushed, found equal or ahead, or skipped as below), so a push cut short, refused or failed is looked at again, and a branch deleted on the forge stays deleted until GitHub moves it again. A fetch that finds no refs at all changes no record; a record is dropped only when its ref is gone while others remain;
    • enters through the normal push path: one non-force git push per ref, from the repo to itself, under PushingEnvironment of the sync user. The source of each refspec is <id>^{object}: a bare <id> is read as a ref's name before it is read as an object, and a writer may have made refs/heads/<id> or refs/tags/<id> to take its place. Every push of an object by its id in the forge says git.ObjectName(id): the sync, create branch from a commit, update branch, restore branch, the file editor and file API (TemporaryUploadRepository.Push) and the wiki. The other pushes name branches, not ids. Pre-receive refuses to make a branch or tag named like a full object id, or refs/<id>, or anything under refs/remotes/ (deleting one is allowed). Where no hook runs, the service refuses the name itself: createTag (tag and release API and UI), RenameBranch, and branch creation (checkBranchName), as ErrInvalidTagName and ErrBranchNameLikeObject, which the API answers 422 and the UI flashes. The importer does not take upstream's, with a notice; Post-receive runs the push queue, which starts Actions (PushCommits), pull request checks, issue references and the push out. The Sync* notifiers are a pull mirror's and are not used. Archived repos are not written (pre-receive does not check it);
    • creates an absent ref, and fast-forwards a branch the forge holds an ancestor of. A branch the forge is ahead of is left. A diverged branch, a tag that differs (tags are create-only, so an annotated tag is never retyped), and a ref the push refuses each raise a repository notice and are looked at again on the next sync. A notice is raised once per (repository, ref, reason) for a week (cache, not a scan of the notice table), however far the commits move;
    • on the first sync of a repo that has content, only records upstream's branches (a tag the forge lacks is still created: tags are immutable). GitHub keeps every branch the forge ever deleted, since the push out never deletes, and creating them all would bring them back. The repository setting hanzo.inboundprimed says that first sync is done; a branch GitHub gained in that very first event waits until it next moves;
    • on an empty repo, sets the default branch to GitHub's (ls-remote --symref, else main, master, the first), pushes it alone, then the other branches in one push, and re-checks that the repo is not archived before each. The repo is marked first, so a seed that stops partway is carried on by the ordinary loop, whatever the repo then looks like;
    • creates tags the forge lacks one push each when it is one, and in one push when it is more than one, in any run, not only a seed: a push event per historical tag would run, for every old tag, every workflow a tag push starts, which for a release workflow is a release. The only rule pre-receive applies to a tag is the protected tag list (a branch rule has no bearing on a tag), so that is applied in Go, right before the push, by IsUserAllowedToControlTag: a tag SYNC_USER may not create is left and noticed, once; the rest go in one push that skips the hooks (GIT_INTERNAL_PUSH). After it, whatever landed, even in a push that reports failure, is recorded and gets its release (SyncReleasesWithTags), as a pull mirror makes them. Where the rules cannot be read the hooks decide (one push, then tag by tag). A tag or branch the hooks decline is not offered to them again for an hour unless its tip or the rules (the protected tag list, or the protected branch rules' ids and update times) change. So two tags that appear together on GitHub raise no tag events here;
    • never brings in the branches bots open, by name prefix in any case: dependabot/, renovate/, gh-readonly-queue/, copilot/, release-please--, changeset-release/ (botBranches, the one list). The remote's refs are listed first (ls-remote --symref, which also says where its HEAD points), and each bot or object-named one is left out of the fetch by its exact name, in whatever case, with a negative refspec (git 2.29; at most 4000 of them), beside a glob for each lower case prefix so that a bot branch made after the listing is left out too, so their objects never reach the repo. Staged and recorded refs of such names, left by an earlier version or past that bound, are deleted on every run. deps/ is not a bot prefix;
    • Not carried in: LFS objects and wikis.
  • What the push path enforces for SYNC_USER. Pre-receive applies what it applies to any direct push, not to a merge: the user's write permission; a protected branch's push rule (push enabled, and SYNC_USER in the push whitelist if there is one, or the push is refused); signed commits if the branch requires them (GitHub's own merge commits are signed with a key the forge must know); protected file patterns; no force push or deletion; and a protected tag's allow list for creating a tag. Required approvals and status checks gate merges, not pushes, so they do not apply; there is no quota on a push. Give SYNC_USER write access and add it to the push whitelist of every protected branch that GitHub also moves and to the allow list of every protected tag pattern; where a branch is protected with push disabled, inbound sync cannot move it and says so in a notice.
  • Trust. Whoever can push to a repo on GitHub can push to it here, as SYNC_USER, and the forge then runs that repo's Actions with its org secrets. This is the same trust as GitHub Actions, and intended: there is no allowlist of GitHub authors. The one exception is the branches bots open (dependabot/, renovate/, gh-readonly-queue/, copilot/, release-please--, changeset-release/), which are never brought in, so the forge never runs bot-authored code with those secrets. Pull requests are not brought in at all: only branches and tags are.
  • Recovery: the scheduled sweep (Update) queues an inbound sync for each push mirror of a regular repo that mirrors to GitHub when none has run for [mirror] DEFAULT_INTERVAL, when SYNC_USER is set. It runs on its own clock, push_mirror.last_inbound_unix, set whenever an inbound sync looks at the remote or is scheduled, so a repo that pushes out constantly, or only on commit, is covered like any other.
  • Queues, all running doMirrorSync (services/mirror/queue.go): mirror carries the scheduled sweep over every mirror (thousands), mirror_event the syncs an event asked for (/v1/sync, POST /v1/repos/{owner}/{repo}/mirror-sync, and push out on commit), so an event never waits behind the sweep. The settings page buttons use mirror. Tune each in [queue.mirror] and [queue.mirror_event].
  • Rolling back. Migration 346 adds push_mirror.last_inbound_unix and sets the version row to 347 (a migration's number plus one). A binary whose last migration is 345 expects at most 346 and refuses to start on 347, so rolling back past it needs UPDATE version SET version = 346 WHERE id = 1; first. The column is NOT NULL DEFAULT 0, so the older binary inserts push mirrors without it and leaves it be.

Image / release lane

  • Published as ghcr.io/hanzoai/git — v1-only, semver-pinned, never :latest. First release 1.26.5 (next patch over the upstream base 1.26.4).
  • The git tag IS the version. .hanzo/workflows/cicd.yml (native CI, on the self-hosted hanzo-build-linux-amd64 pool) delegates to hanzoai/ci/.github/workflows/build.yml@v1, which reads hanzo.yml and, on a v* ref, tags the image from the ref itself — ghcr.io/hanzoai/git:v1.26.22 plus the v-stripped 1.26.22. A branch push gets only sha-<sha7>-amd64. The Makefile derives main.Version from the same tag (git describe over the checkout), so the tag, the image tag and gitd --version are one fact.
  • Cut a release: git tag -a v1.26.22 && git push canonical v1.26.22. canonical is git.hanzo.ai/hanzoai/git. Pushing a tag to the GitHub mirror builds NOTHING: sync-from-github.yml fast-forwards main and nothing else, by design — releases are declared where CI runs.
  • Do not crane copy a sha- image onto a semver name. v1.26.19 and v1.26.20 were made that way while the tag lane was red, and both carry a binary that reports its commit instead of its version.

Where it runs

Operator-managed in hanzoai/universe (DOKS hanzo-k8s, namespace hanzo):

  • infra/k8s/operator/crs/git.yaml — the hanzo-git App (this image), SQLite on an RWO data PVC, OIDC via the oauth-sync init container. Synced by Hanzo CD (ArgoCD; the App-only successor to the operator GitSource).
  • infra/k8s/git/ — the App's non-App supporting resources (Hanzo CD's project is hanzo.ai/App-only): the data PVC, hanzo-git-oauth ConfigMap, the git.hanzo.ai Ingress, and git-secrets-kms.yaml (secrets from KMS).
  • infra/k8s/git-runner/ — the DinD pool that runs Actions jobs (statefulset.yaml, image oci.hanzo.ai/hanzoai/git-runner); maps hanzo-build-linux-amd64. It rolls in the same change as this image, one after the other, because of the shared wire above.
  • Push-to-deploy: a push webhook → cloud /v1/git/webhook → cloud's own /v1/runner build core — which is a different service on a different host that happens to share the path, not the runner surface described above. Architecture: universe/docs/architecture/paas-in-cloud.md §9.

The migration (fork becomes THE git server, replacing the raw upstream-image deploy and the cloud embedded git seam as the host) is STAGED — the coordinator flips it.

Credentials over https: the token a user already holds

Sign-in here is EXTERNAL (ENABLE_PASSWORD_SIGNIN_FORM=false, ALLOW_ONLY_EXTERNAL_REGISTRATION=true), so a user has no password to hand git over https and the only credential left used to be a personal access token they had to go and make. services/auth/iam.go reads the one they already have: a Hanzo IAM access token is accepted as the basic-auth password, so

git clone https://x:$(hanzo auth token)@git.hanzo.ai/<org>/<repo>.git

works from anywhere the CLI is signed in — a laptop, a CI job, a leased sandbox (cloud's apps/sandbox/cred.go points a credential helper at it, which is what makes git work in a shell with no browser).

  • Read once, by the platform's own verifier. hanzoai/authz over the issuer's JWKS: algorithm, key id, signature, issuer, expiry. Issuer and keys come from THIS instance's OIDC login source, so what is accepted is what the provider users sign in through mints, and changing that provider changes this with it.
  • Resolved only through the link sign-in already wrote — the token's sub against external_login_user. No claim NAMES a user; email and username are mutable and a match on one would land a renamed identity on another account. A subject that never signed in here resolves to nobody, and nothing is created from a credential: registration stays the web flow's, which is the only place that applies the whole policy (auto-registration, account linking, group and team mapping).
  • Scope is write:repository. Clone, fetch, push. A credential that exists so a checkout works does not mint tokens, add keys, or administer anything.
  • Asked LAST, after the OAuth2 token, the personal access token and the task token have each declined, and only for a credential shaped like a JWT — so a token this instance issued itself is never sent to a verifier that would reject it, and a PAT costs no network call.
  • The AUDIENCE is not checked, matching authz's documented position: IAM sets aud to the client that ASKED for the token, not to the server that may accept it.

Cloud-native, multi-tenant: the house pattern, not Postgres

Measured 2026-07-26 against the running deploy. An earlier draft of this section recommended SQLite -> Postgres. That was wrong for this stack and is removed: Postgres buys HA for one shared schema, which is the opposite of what we want. The house answer is SQLite per tenant, S3 as the source of truth, stateless nodes.

What is already true

Blobs are on S3 (GIT__storage__STORAGE_TYPE=s3 -> s3.hanzo.svc:9000, bucket git): attachments, LFS, avatars, archives, packages, Actions artifacts. Done.

What pins the server to one node is the 250Gi RWO PVC, 166G used:

Path Size What it is
<data>/data 145G bare repositories
<data>/indexers 18.4G bleve index (derived, rebuildable)
<data>/forge.db 2.3G ONE SQLite for the whole instance

That is why it is replicas: 1 + Recreate, and why an image bump took git.hanzo.ai down ~10 min on 2026-07-26 (new pod hit Multi-Attach while terminated pods still held the volume; the ReplicaSet wedged at zero).

The house stack this should use

  • hanzoai/replicate — SQLite WAL replication to S3. One import, zero config files, zero sidecars; set REPLICATE_S3_ENDPOINT and it runs. Already wrapped as a Base plugin (base/plugins/replicate). luxfi/kms does the same shape with the ZapDB Replicator.
  • DB per tenant — hanzoai/commerce already does this: db.Manager holds userDBs map[string]*SQLiteDB and orgDBs map[string]*SQLiteDB, opened on demand.

So the target for git is one SQLite per org/project, replicated to S3, with local disk as a cache rather than the source of truth. Nodes become stateless: any node can serve any tenant by materialising that tenant's DB from S3.

Two gaps to close first — and they are shared, not git-specific

  1. No eviction. commerce's userDBs/orgDBs maps are unbounded; handles are only closed by Manager.Close(). Open-per-tenant without eviction is a file descriptor and memory leak that grows with tenant count — exactly what makes a node stop being lightweight. Needs an LRU (or idle TTL) that closes cold handles and lets the local file be re-fetched on next use.
  2. Per-tenant DBs are not replicated. commerce does NOT import hanzoai/replicate — its tenant DBs are local-only. So per-tenant SQLite exists and S3-backed SQLite exists, but nothing yet does both.

Close those two once, in the shared layer, and both commerce and git get it.

Then: git embeds into cloud

hanzoai/cloud already owns the git control plane, smart-HTTP and SSH surface (clients/git/git.go — /v1/git/repos, /usage, and root /:org/:repo/* smart-HTTP for the git host). Today it fronts a separate stateful hanzo-git Deployment; cloud/go.mod does not import hanzoai/git.

Embedding it natively is the actual "cloud-native" step, and it is the right one because cloud is already horizontally scalable and stateless. Order matters:

  1. eviction + replication in the shared tenant-DB layer (above),
  2. git's schema split from one instance DB to per-org/project DBs,
  3. cloud imports the fork as a module and serves git in-process,
  4. the standalone hanzo-git Deployment and its RWO PVC go away.

Only step 4 removes the single-replica constraint, and it cannot come first.

Repositories are still the hard part, and S3 is not the answer

git wants POSIX rename-into-place, locking and mmap'd packfiles; an object store provides none of them, so "repos on S3" is a storage engine, not a config flag. With per-tenant DBs the honest option is shard by tenant — a node owns a tenant's repos while it owns that tenant's DB, which is the same sharding key, and DO block volumes attach per node. Keep a KV in front for hot reads. An RWX filesystem also works and needs no code change, but it means running a filesystem service and it does not give tenancy — only HA.

Do not "fix" this

Hooks re-exec the binary per push. That is node-local to whoever holds the repo, so it blocks neither HA nor tenancy. The hook scripts embed setting.AppPath (the runtime path), not a hardcoded name — which is why the binary rename regenerated every repo's hooks by itself. Turning that into a constant would break the next rename.

Working here

Merged from AGENTS.md, which held these and nothing else. Two files meant two places for a rule to live, and a rule that exists twice drifts.

  • Use make help to find available development targets
  • Run make fmt to format .go files, and run make lint-go to lint them
  • Run make lint-js to lint .ts files
  • Run make tidy after any go.mod changes
  • Run single go tests with go test -run '^TestName$' ./modulepath/
  • Run single js test files with pnpm exec vitest <path-filter>
  • Run single playwright e2e test files with GIT_TEST_E2E_FLAGS='<filepath>' make test-e2e
  • Add the current year into the copyright header of new .go files
  • Ensure no trailing whitespace in edited files
  • Use Conventional Commits for commit messages and PR titles, e.g. type(scope): subject; ! before the colon if breaking. Use test type for test-only changes.
  • Never force-push, amend, or squash unless asked. Use new commits and normal push for pull request updates
  • Preserve existing code comments, do not remove or rewrite comments that are still relevant
  • Keep comments short, prefer same-line, explain why, never narrate code
  • Prefer unit tests over integration tests when logic is testable in isolation
  • Aim for sub-2s local runtime for integration and e2e tests
  • In TypeScript, use ! (non-null assertion) instead of ?./?? when a value is known to always exist
  • For CSS layout, prefer flex-* helpers over per-child tw-ml-* / tw-mr-* margins; fall back to tw-* utilities when specificity requires !important
  • Include authorship attribution in issue and pull request comments
  • Always add Assisted-By trailers to commit messages in format Assisted-by: AGENT_NAME:MODEL_VERSION
  • Never add Co-Authored-By Signed-off-by trailer to commit messages. Sign off must be done by a human.