Reprovision gateway-dependent state on gateway bring-up #516
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Umbrella issue: when the gateway is (re)built, reconcile every already-running bottle against the fresh gateway, rather than persisting gateway state on volumes.
Folds in #510 (CA) and #512 (git-gate), which are two symptoms of one root cause. Supersedes the abandoned persistent-volume PRs (#511 CA-volume, #513 git-gate-volume).
The root cause
Gateway-dependent state is provisioned into the gateway once, at bottle launch, and lives only in the gateway's ephemeral rootfs. Rebuilding or restarting the gateway wipes it, and nothing re-provisions the bottles that were already running.
orchestrator/reprovision.pyrestores only egress tokens (reprovision_from_secret) — not the CA, not git-gate declarations — and the registry does not store the git upstreams or keys.Symptom 1 — CA (was #510)
Rebuilding the Firecracker gateway mints a brand-new mitmproxy CA, breaking every already-running bottle with
SSL certificate verification failedon egress.The #450 fix ("the gateway CA must survive recreation") was implemented only for the Docker backend, via the persistent
host_gateway_ca_dir()bind-mount. The Firecracker gateway had no equivalent:backend/firecracker/gateway.pybooted the VM throughinfra_vm.boot_vm(...)with nodata_drive— contrast the orchestrator VM, which getsdata_drive=self._ensure_registry_volume()(persistent/dev/vdb). The CA lives at/home/mitmproxy/.mitmproxy/inside the rootfs, whichboot_vmre-materializes on every boot. Each bottle only captures a point-in-time CA snapshot at launch (launch.py→egress/gateway-ca/gateway-ca.pem), never re-synced when the gateway rotates.Observed:
66:63:6F:06:94:…66:63:6F:06:94:…✅C6:B1:80:C0:22:…❌agent-3 → rebuilt gateway bumps TLS with a leaf signed by
66:63:6F…→ agent-3's trust store only hasC6:B1:80…→ handshake fails.Symptom 2 — git-gate (was #512)
Restarting the gateway drops every already-running bottle's git-gate state, so its agent gets
HTTP 404from the git-gate smart-HTTP server (port 9420) oninfo/refs— fetch and push both fail.Per-bottle repos and creds are provisioned at launch (
consolidated_launchstep 3 →provision_gateway/git_gate/render) under/git/<bottle_id>and/git-gate/creds/<bottle_id>. On firecracker these live in the per-boot rootfs; on docker only the CA is bind-mounted, not/gitor/git-gate/creds. Either way a gateway restart wipes them.Observed (firecracker): after a gateway rebuild the live gateway VM held exactly ONE bottle's repo —
/git/<id>/bot-bottle.git, created at gateway boot — the bottle relaunched together with the gateway. Bottles predating the restart had no/git/<id>and no/git-gate/creds/<id>, so their agents 404'd.mountshowed only/dev/vda(rootfs); nothing persistent.Approach — reconcile, don't persist
One flow across all services, run when the gateway comes up:
The trigger lives in the gateway startup flow (
FirecrackerGateway.connect_to_orchestrator, the cold-boot path), so it fires exactly when the gateway was (re)booted and never on an adopt.Reconciling also avoids the persistent-volume approach's one-time break: seeding a fresh CA volume still mints one final CA on the first restart after the fix, breaking running bottles once. Teardown already
rm -rfs/git/<id>+ creds (deprovision_git_gate), so there is no accumulating state to manage either.Status / building blocks
OrchestratorCore.update_agent_secret+POST /bottles/<id>/secret(single-secret in-place update — the reusable primitive from the 2026-07-26 hotfix)connect_to_orchestratorOut of scope
Refreshing short-lived host credentials (e.g. the Codex access token) as part of the bring-up reconcile — deliberately not a criterion here.
Docker
bot-bottle-orch-gatewayis attached to a stale CI CA volume (bot-bottle-ci-ca-<run>) because CI reuses the production gateway singleton name — separate latent issue.orchestrator/rotate_ca.pyis docker-only.Reprovision gateway-dependent state on gateway bring-up (PRD 0081)to Reprovision gateway-dependent state on gateway bring-up