apps/gitea -> apps/rithub-server; compose services/containers renamed (rithub-server-app/postgres/act-runner) with explicit project name and volume names pinned to the exact existing Docker volumes (no data loss); our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs -> ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter + giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram (tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go internal/giteaclient -> internal/ritclient in rithub-async-import (go build/test clean); new /auth/rit + /forges/rit/connect routes with /gitea back-compat aliases; locale/swagger/footer/captcha template text scrubbed of remaining "Gitea" strings. Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea renamed to /srv/rithub-server with a symlink kept, docker compose up -d from the new path, act_runner network-alias fix for its persisted instance URL. Live-verified: docker compose config diff showed zero unintended value changes, DB row counts unchanged (19 users, 635 repos), full route regression 200/expected, 0 "gitea" in headers/bodies on every checked page, real git clone+push over HTTPS and SSH with a disposable account (deleted after). Deferred on purpose (documented in plans/railyard.md): the forge discriminator / DB column names / Postgres role+volume names (data migrations, not a naming change) and the upstream GITEA__ env-to-ini keys and X-Gitea-* wire headers (hardcoded in the vendored engine binary). See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and live evidence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
8.0 KiB
apps/rithub-async-import — async repo migration (RIT-ACT)
Problem (products-46, 2026-11-30): POST /api/v1/repos/migrate against
rithub.dev runs the clone synchronously before answering. A caller going
through Cloudflare's edge can time out on a big repo well before the clone
finishes (same family of issue already fixed server-side for
apps/gitea/scripts/lib/bulk-migrate.sh by moving those callers to the
engine's loopback port — but that fix doesn't help a caller that has to go
through the public domain, e.g. apps/rithub-mcp's import_from_github
tool, the rit CLI run from someone's own machine, or github-backup-cli).
What this is: a small Go sidecar that sits in front of the real engine
and adds one optional field, async: true, to the same
POST /api/v1/repos/migrate request body:
asyncomitted orfalse(every existing caller): the request body andAuthorizationheader are forwarded byte-for-byte to the real engine and its response relayed verbatim. No behavior change — this is the "keep the existing sync endpoint working for small repos" half of the ask.async: true: the service- checks the caller's token against the real engine (
GET /user) so a bad token fails immediately, not inside a background job nobody is watching anymore, - creates the destination repo empty, with its description
prefixed
"[migrating] ", via the real engine's ownPOST /user/reposorPOST /orgs/{org}/repos, - answers 202 immediately with
{id, status, repo_owner, repo_name, html_url, status_url}, - in the background,
git clone --mirrors the source andgit push --mirrors it into the placeholder repo, then clears the"[migrating] "marker, - a caller polls
GET /api/v1/repos/migrate/status/{id}untilstatusisdoneorfailed.
- checks the caller's token against the real engine (
Scope / honest limitations
- Code only.
git push --mirrorcarries every branch, tag and commit — the actual bytes that make a migrate request slow on a big repo — but it does not carry GitHub-side issues/PRs/wiki/releases/labels/ milestones (those come from the real engine's own GitHub-API-driven importer, which is a different code path with its own, usually much shorter, running time). A request withasync:trueand any ofwiki/issues/pull_requests/releases/milestones/labelsset is rejected with a 400 explaining this — it never silently drops data. Closing this gap for real would mean either reimplementing the GitHub issue/PR importer here too, or patching the real engine's own migrate handler to make that path async (a genuine source-level engine fork, which this service deliberately is not — see "Why not a real engine fork" below). mirror: true(continuous sync) is rejected underasyncfor the same reason: the engine's mirror repos are a real repo type (repo.IsMirror, its own sync scheduler) that a plaingit push --mirrorinto a normal repo does not set up. Use the sync endpoint for mirrors.- Owner must equal the caller, or an org the caller can create repos
in. The real engine's sync API lets an admin token migrate into
any owner; this service's async path only tries
/user/repos(same owner as the token) or/orgs/{owner}/repos. Documented, not silently wrong. - Job state does not survive a service restart mid-migration. The
job store is persisted to a JSON file (
ASYNC_IMPORT_JOBS_FILE) so a restart doesn't lose a job's last known status, but the background goroutine itself is not resumed — a job that wascloningorpushingwhen the service restarted will just stay in that state forever. Good enough for a first version; a real job queue (or at least a startup sweep that marks stale in-flight jobsfailed) is the natural next step before this carries real traffic.
Why not a real engine fork
The task that produced this service allowed patching the engine's own Go
source directly ("we fork like Cursor on VS Code"). That source isn't
vendored into this repo today — apps/gitea runs the official upstream
image unmodified, with only template/CSS overlays in apps/gitea/custom
(see apps/gitea/README.md). Vendoring the full upstream source tree to
patch one internal handler is a much larger, multi-day undertaking (and a
standing risk every other lane touching apps/gitea/custom would now
have to coordinate a real source fork with). This sidecar gets the actual
user-facing problem — Cloudflare edge timeouts on big-repo migrates —
fixed today, using only the real engine's already-public REST API plus
real git, with the scope gap above stated plainly instead of papered
over. If/when a real engine fork happens for other reasons, the
cleanest long-term fix is to move this logic into that fork's own
migrate handler (reusing its existing Task/repo.Status = Migrating
machinery, which already does exactly this for the web UI's own migrate
flow) and retire this sidecar.
Build & test
cd apps/rithub-async-import
go build ./... # compiles clean, zero new deps beyond the Go stdlib
go vet ./...
gofmt -l . # no output = formatted
go test ./... -race
Unit tests cover request validation, the sync-passthrough proxy, the full
async happy path (fake upstream + fake worker), every rejection (mirror,
metadata, missing auth, upstream auth failure), and the background
Runner's clone/push/failure/description-update-failure orchestration
(via a fake gitOps, so no real git or network is needed to run
go test).
A full local run against the real git binary (no mocks for the git
calls) was also done by hand: a throwaway fake-engine HTTP stand-in
(git init --bares a real local repo instead of calling the real engine,
since no railyard-box engine is reachable from this sandbox) plus the
real compiled async-import binary, driven over real HTTP with curl.
Confirmed: immediate 202 with a working status_url; the destination
repo, cloned fresh afterward, has the exact same commit as the source;
mirror:true and issues:true both 400 with the documented message; a
missing Authorization header 401s; a bad clone_addr still 202s
immediately and then surfaces as status:"failed" with a real (sanitized
— no credentials) git error once polled; the default sync-passthrough
request is forwarded byte-for-byte to the upstream and its response
relayed verbatim.
Running it
RIT_API_BASE=http://127.0.0.1:3350 \ # the real engine's own loopback port — never rithub.dev (GITEA_API_BASE still read as a fallback)
ASYNC_IMPORT_LISTEN_ADDR=:3360 \
ASYNC_IMPORT_JOBS_FILE=/var/lib/rithub-async-import/jobs.json \
go run ./cmd/async-import
Deploy wiring (not done by this pass — explicitly out of scope)
To actually take over /api/v1/repos/migrate for public traffic:
- Build this binary on
railyard-box(plaingo build, same pattern as every other Go/Rust binary already built directly on the box for this repo — no new CI). - Run it as its own
pm2/systemd service listening on a free loopback port (e.g.:3360), withRIT_API_BASEpointing at the engine's own loopback API port (http://127.0.0.1:3350, the same oneapps/gitea/scripts/lib/bulk-migrate.shalready uses to avoid the Cloudflare round trip). - In
/etc/caddy/sites-enabled/rithub-dev.caddy, add one route that sendsPOST /api/v1/repos/migrateandGET /api/v1/repos/migrate/status/*to this service's port, leaving every other path routed to the engine exactly as today. - Smoke-test with a real small migrate (
asyncomitted) to confirm sync behavior is unchanged, then a realasync:truemigrate of a real repo, pollingstatus_urltodone, before trusting it with production traffic. - Update
apps/rithub-mcp'simport_from_githubtool (and, if desired, theritCLI /github-backup-cli) to sendasync: trueand pollstatus_urlinstead of the current "raise your client's timeout and hope" workaround documented in that tool's own description.