Skip to content

Dev coordinator: prod env contract, host setup, seed, swap and deploy scripts (DBLM-556) - #1367

Closed
davidtai wants to merge 27 commits into
masterfrom
devnet/dev-deploy-scripts
Closed

davidtai wants to merge 27 commits into
masterfrom
devnet/dev-deploy-scripts

Conversation

@davidtai

@davidtai davidtai commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Dev now uses the production env contract and the production swap steps of docs/operations/coordinator-deploy.md. Scripts do the steps that a human does in production. With these scripts, David can do the first dev deploy (Linear DBLM-559) after the infrastructure apply in Layr-Labs/darkbloom-devnet-infra.

Linear: DBLM-556 (this PR), DBLM-559 (first deploy). Infrastructure: Layr-Labs/darkbloom-devnet-infra, branch initial-footprint (head a7ed811): VM d-inference-dev in us-east4-a, Cloud SQL d-inference-dev-db (private IP), the 22 secrets that the VM account can read (coordinator_secret_ids), deploy account d-inference-dev-deploy, trigger dev-build.

Nothing in this PR ran against a real VM or GCP project.

What changes

File What it does
deploy/gcp/dev/env-overrides Values only. Dev literals and secret-manager:<name> references for exactly the 22 secrets of coordinator_secret_ids. A literal can use ${KEY} for an earlier key.
deploy/gcp/dev/seed-env.sh --check (default, read only), --seed, --reseed. Builds /etc/d-inference/env from the overlay, Secret Manager (VM account) and the EIGENINFERENCE_* lines of deploy/environments/prod.env (first value wins). Checks the new file with the production refresh-env.sh --check, then moves it into place (atomic, 0600, 0700 dir) and runs --apply. A failed check writes nothing; a failed --reseed keeps the live file. Prints names only.
deploy/gcp/host-setup.sh Replaces vm-startup.sh. A human runs it once over IAP. --check (default, read only) or --apply. Packages, Docker credentials for us-east4-docker.pkg.dev, data disk, the production refresh unit and manifests (runbook step 3), Caddyfile for DOMAIN, Datadog Agent only when DD_API_KEY is set. Writes no env value, starts no container.
deploy/gcp/dev/swap.sh Runbook steps 2 to 4, Verification and Rollback, under systemd-run. Pull by digest, label checks, --migrate-only (default on), last-good-image, coordinator_fallback_<ts>, docker stop -t 75, /health + build_commit + /readyz, automatic rollback on a hard-gate failure. OK/FAIL/REPORT lines. A failed container log goes to a root-only file on the VM, never to the output (the repository is public).
deploy/gcp/dev/deploy.sh [deploy|rollback] [--dry-run] [--override-pause "<reason>"]. Pause gate, runbook step 1 (candidate = origin/master, trigger file, SUCCESS dev-build, digest), ships the commit's deploy files over IAP and runs swap.sh. SSH_KEY_FILE, MIGRATE_ONLY, ON_SUPERSEDED=skip, deployed=true|false to stdout and GITHUB_OUTPUT: the interface of examples/d-inference/deploy-dev.yml.
deploy/gcp/dev/preflight.sh Read-only checks before the first deploy, PASS/FAIL (with the fix)/WARN per line, exit 1 on a FAIL.
scripts/smoke-dev.sh Reads active_providers; MODEL (default Qwen3.5-9B); default host from DOMAIN of the overlay.
scripts/test-dev-deploy.py New, in the Release Integrity job.
Deleted deploy/gcp/refresh-env.sh, deploy/gcp/cloudbuild.yaml, deploy/gcp/bootstrap.sh, deploy/gcp/vm-startup.sh. Every reference is fixed except frozen reports.
Docs docs/operations/dev-environment.md rewritten; one-line updates in configuration.md, build.md, enrollment.md, threat-model.yaml, coordinator-deploy.md (intro), test.md, AGENTS.md; CHANGELOG.md (topic "Unreleased — DevNet").

Unchanged: deploy/gcp/prod/*, deploy/gcp/cloudbuild-prod.yaml, coordinator/Dockerfile, coordinator/deploy/start.sh. The intro of coordinator-deploy.md has one new sentence.

Host names

API api.dev.darkbloom.dev (confirmed). Console console.dev.darkbloom.dev (pending confirmation). They are in one place: DOMAIN and EIGENINFERENCE_CONSOLE_URL in deploy/gcp/dev/env-overrides. EIGENINFERENCE_BASE_URL, CORS_ORIGIN, the Caddy site, the preflight DNS check and the smoke-dev.sh default come from these two keys. A test fails if the host names appear in a script.

Decisions to review

  1. Stop timeout 75 s, not 690 s. The plan said docker stop -t 690. The current production runbook (docs/operations/coordinator-deploy.md, since refactor(coordinator): reorganize domain ownership and storage backends #1324) uses --stop-timeout 75, docker stop -t 75 and requires EIGENINFERENCE_DRAIN_GRACE=45s in the env file and in the running container. Dev follows the runbook. The overlay sets EIGENINFERENCE_DRAIN_GRACE=45s.
  2. EIGENINFERENCE_DEPLOYMENT_ENVIRONMENT=development is in the overlay. Without it the coordinator starts as production and the App Attest cutover checks stop it. DD_AGENT_HOST is dropped: the coordinator starts Datadog when DD_API_KEY is set.
  3. EIGENINFERENCE_TRUST_GEO_HEADERS=0 and EIGENINFERENCE_STATE_EXPORT_ENABLED=false: required keys; the values are the code defaults (coordinator/api/geo/resolver.go, coordinator/api/operations/state_export.go).
  4. Other dev values: EIGENINFERENCE_MIN_TRUST=self_signed, cache routing off, Stripe Global Payouts false, EIGENINFERENCE_WARM_POOL_MIN_WARM=Qwen3.5-9B=1, APNs placeholders, throwaway MDM push P12 from Secret Manager, models from the production R2 CDN read only (MODEL_REGISTRY_CDN_BASE_URL not set, no sidecar override), releases on R2 d-inf-app-dev through eigeninference-r2-cdn-url, Caddy ACME TLS, no image cleanup policy beyond the local 7-day prune. host-setup.sh is dev only.
  5. EIGENINFERENCE_IPAPI_KEY is out of dev on purpose. This reverses the dev part of feat(devnet): bind dev-installed providers to their coordinator and add seed data #1330: eigeninference-ipapi-key is not one of the 22 secrets that the VM account can read. Geo lookups use the free tier.
  6. DEV_DEPLOY_PAUSED is enforced (Josh). deploy.sh reads the variable before any change: the env var DEV_DEPLOY_PAUSED when set, else gh variable get DEV_DEPLOY_PAUSED -R Layr-Labs/d-inference. Only false continues. true, an empty value or a failed read stops with exit 3 and changes nothing (rollback too). A human can pass --override-pause "<reason>"; a REPORT line records the account, user, host and reason. --dry-run reports the state and continues. The first manual deploy uses --override-pause "first deploy DBLM-559".
    • The gh token used by deploy.sh needs read access to the Layr-Labs/d-inference repository variables.
    • The future deploy-dev.yml (DBLM-569) must pass DEV_DEPLOY_PAUSED: ${{ vars.DEV_DEPLOY_PAUSED }} and must not use --override-pause. The sample in darkbloom-devnet-infra skips push runs when paused but runs workflow_dispatch; with this gate a dispatch while paused also stops.
  7. deploy.sh uses git ls-remote (not git fetch) for runbook step 1, and git archive HEAD to ship the files, so it changes no local ref and ships exactly the commit.

First-deploy sequence (DBLM-559)

From a clean detached worktree at origin/master (details in docs/operations/dev-environment.md):

  1. deploy/gcp/dev/preflight.sh: fix every FAIL except the two host lines.
  2. host-setup.sh --apply over IAP.
  3. seed-env.sh --seed, then host-setup.sh --apply again (Datadog Agent), then the preflight again: all PASS or WARN.
  4. deploy/gcp/dev/deploy.sh --dry-run, then deploy/gcp/dev/deploy.sh --override-pause "first deploy DBLM-559": expect OK <commit> drain_s=0 ....
  5. Verify /health (version, build_commit) and the VM state.
  6. Second deploy (fallback container, last-good-image).
  7. deploy.sh rollback --override-pause "rollback test DBLM-559", then a reboot test.

Before and after

flowchart LR
  classDef old fill:#fde2e2,stroke:#b42318,color:#000
  classDef new fill:#dcfce7,stroke:#15803d,color:#000
  classDef gate fill:#fef3c7,stroke:#b45309,color:#000
  subgraph Before["Before: old dev path"]
    B1["gcloud builds submit<br/>cloudbuild.yaml"]:::old --> B2["VM metadata DINF_IMAGE_TAG"]:::old
    B2 --> B3["refresh-env.sh heredoc<br/>reads Secret Manager each deploy"]:::old
    B3 --> B4["systemctl restart<br/>d-inference-coordinator (30 s stop)"]:::old
    B4 --> B5["/health version dev"]:::old
  end
  subgraph After["After: production steps"]
    A0{"DEV_DEPLOY_PAUSED<br/>== false?"}:::gate -->|"no: exit 3, no change"| AX["stop<br/>(or --override-pause reason)"]:::gate
    A0 -->|yes| A1["step 1: origin/master,<br/>SUCCESS dev-build, digest"]:::new
    A1 --> A2["IAP SSH: git archive of commit<br/>systemd-run swap.sh"]:::new
    A2 --> A3["steps 2-4: locks, pull by digest,<br/>labels, --migrate-only, refresh, stop -t 75"]:::new
    A3 --> A4{"/health commit<br/>+ /readyz in 180 s?"}:::gate
    A4 -->|yes| A5["OK, last-good-image"]:::new
    A4 -->|no| A6["automatic rollback, FAIL"]:::gate
  end
Loading
flowchart TB
  classDef file fill:#e0ecff,stroke:#1d4ed8,color:#000
  classDef prod fill:#eeeeee,stroke:#666,color:#000
  classDef del fill:#fde2e2,stroke:#b42318,color:#000
  subgraph Code["Code: who calls what (after)"]
    D["dev/deploy.sh"]:::file --> S["dev/swap.sh (VM, root)"]:::file
    S --> R["prod/refresh-env.sh (unchanged)"]:::prod
    S --> K["dev/seed-env.sh --check"]:::file
    K --> R
    SE["dev/seed-env.sh --seed"]:::file --> O["dev/env-overrides"]:::file
    SE --> P["environments/prod.env"]:::prod
    SE --> R
    H["host-setup.sh"]:::file --> R
    H --> O
    PF["dev/preflight.sh"]:::file --> H
    PF --> K
  end
  subgraph Removed["Removed (before)"]
    X1["vm-startup.sh"]:::del
    X2["refresh-env.sh (dev)"]:::del
    X3["cloudbuild.yaml"]:::del
    X4["bootstrap.sh"]:::del
  end
Loading

Legend: blue = new dev script or file, grey = production file (unchanged), red = removed or old path, amber = a gate.

Test plan

  • shellcheck -S warning and bash -n on every new and changed script: clean.
  • python3 scripts/test-dev-deploy.py: 22 tests pass on macOS and in ubuntu:24.04 as a non-root user (awk is mawk).
  • python3 scripts/test_operations_scripts.py: 4 tests pass. ./scripts/test-prod-env-refresh.sh: pass.
  • actionlint .github/workflows/ci.yml: clean. python3 scripts/test-ci-component-paths.py, python3 scripts/test-provider-ci-workflow.py: pass. python3 scripts/test-integration-ci-workflow.py fails on origin/master too (not caused by this PR).
  • make docs-check: 339 files OK. make docs-impact-check BASE=origin/master: coverage OK.
  • Mutation proof: a mutating call put into host-setup --check, seed-env --check and deploy --dry-run, and a disabled pause gate, each made the matching test fail; the files were then restored and confirmed by checksum.

Unit tests (scripts/test-dev-deploy.py), all pass:

Class Test
DevEnvContractTests test_every_required_key_has_a_dev_source, test_host_names_live_only_in_the_overlay, test_overlay_is_values_only_with_secret_references
SeedEnvTests test_check_is_read_only, test_failed_reseed_keeps_the_live_file, test_missing_required_secret_writes_nothing, test_multiline_secret_is_refused, test_other_project_is_refused_before_any_change, test_reseed_replaces_the_file_and_keeps_the_old_one, test_seed_keeps_an_existing_file, test_seed_writes_a_file_that_passes_the_production_check
ZeroMutationTests test_deploy_dry_run_makes_no_mutating_call, test_deploy_refuses_when_paused, test_deploy_refuses_when_the_pause_state_is_unknown, test_deploy_stops_when_master_moved, test_dry_run_reports_the_pause_and_continues, test_host_setup_check_makes_no_mutating_call, test_host_setup_refuses_other_project, test_override_with_a_reason_proceeds, test_preflight_makes_no_mutating_call, test_preflight_vm_part_makes_no_mutating_call, test_swap_refuses_other_project

The zero-mutation tests replace every command that can change state (gcloud, docker, systemctl, apt-get, mount, install, mv, rm, gh, git, …) with a stub that records its arguments, and fail on any call outside a read-only allowlist.

Swap rehearsal (not in CI): seed-env.sh and swap.sh ran as root in ubuntu:24.04, with stateful stubs for docker, curl, psql and gcloud:

Case Expected Result
seed-env.sh --seed OK wrote, root:root 0600 file in 0700 dir pass
seed-env.sh --check all PASS, no change pass
First deploy A OK <A> drain_s=0, no fallback pass
Second deploy B OK <B>, fallback with image A stopped, last-good-image = B, old file dir removed pass
MODE=rollback OK rolled back to <image A> pass
Deploy C whose /health never reports C FAIL candidate not ready within 180 s; rolled back to <image A>, log in a root-only file pass (this failure is the expected result)
Secret value in any output none pass

The refactor subagent pass (AGENTS.md) made small cleanups and found one bug: die printed the exit code. Its other findings are fixed in the second commit: the result wait stops when the unit ends early; rollback stops at once with no verified swap; manual Rollback checks the drain grace of the running containers as the runbook does; preflight filters builds by the dev-build trigger.

Not verified

  • Nothing ran against the real VM, Cloud SQL, Secret Manager, Artifact Registry, IAP or DNS. gcloud auth to darkbloom-dev had expired, so no live read was made.
  • host-setup.sh --apply did not run anywhere (apt, Caddy, mkfs, the Datadog install script).
  • The Docker credential helper with the snap gcloud of the Ubuntu GCE image (the script installs the apt package when docker-credential-gcloud is missing).
  • roles/cloudbuild.builds.viewer for gcloud builds triggers describe by the deploy account.
  • The behavior of the placeholder APNs key and throwaway MDM P12 at a real boot.

Overlaps

Follow-ups outside this PR

  • provider-swift/Sources/ProviderCore/Security/MDMEnrollment.swift:32-33: the MDM host list names api.dev.darkbloom.xyz, not api.dev.darkbloom.dev. Enrollment on the new dev host needs this change (provider code; not in this PR).
  • deploy/provider-fleet/update-fleet.sh:24: the dev COORD_URL default is the .xyz host.
  • Docs that name the .xyz dev host: docs/architecture/overview.md:27, docs/glossary.md:18, docs/operations/model-migration.md:13, docs/operations/model-revisions.md:40, docs/operations/provider-release.md:487, docs/operations/routing-v2-rollout.md:31, docs/threat-model.yaml:155.
  • Tests that use the .xyz host as a fixture (they still pass): coordinator/tests/api/releases/contracts/install_test.go, scripts/test-install-coordinator-binding.py, provider-swift/Tests/DarkbloomCLITests/InstallerCoordinatorBindingTests.swift, provider-swift/Tests/ProviderCoreTests/Coordinator/CoordinatorClientTests.swift, provider-swift/Tests/ProviderCoreTests/Diagnostics/MDMTrustDiagnosisTests.swift, provider-swift/Tests/ProviderCoreTests/Security/MDMEnrollmentTests.swift.
  • DBLM-569: deploy-dev.yml (see decision 6).
  • Confirm the console host name.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

davidtai and others added 2 commits October 6, 2026 17:24
…cripts

Dev now uses the production env contract and the production swap steps
(DBLM-556):

- deploy/gcp/dev/env-overrides: dev values and the 22 Secret Manager
  references. The host names are only in DOMAIN and
  EIGENINFERENCE_CONSOLE_URL.
- deploy/gcp/dev/seed-env.sh: writes /etc/d-inference/env once, checks it
  with the production refresh, and writes nothing when the check fails.
- deploy/gcp/host-setup.sh: host setup that a human runs over IAP.
- deploy/gcp/dev/swap.sh: steps 2 to 4, Verification and Rollback of
  docs/operations/coordinator-deploy.md, with automatic rollback.
- deploy/gcp/dev/deploy.sh: step 1, ships swap.sh over IAP, enforces
  DEV_DEPLOY_PAUSED (fail closed, --override-pause with a reason).
- deploy/gcp/dev/preflight.sh: read-only checks for the first deploy.
- Remove the old dev path: vm-startup.sh, refresh-env.sh, cloudbuild.yaml,
  bootstrap.sh.
- scripts/smoke-dev.sh reads active_providers and takes MODEL.
- scripts/test-dev-deploy.py runs in Release Integrity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- deploy.sh: die() prints only the message, not the exit code. The
  pause variable no longer uses the name of the bash builtin "source".
- deploy.sh: the wait for a swap result stops when the systemd unit ends
  without a result, and "rollback" stops at once when the VM has no
  verified swap.
- swap.sh: Rollback checks EIGENINFERENCE_DRAIN_GRACE=45s in the running
  coordinator and fallback containers before it stops them, as the
  production runbook does.
- preflight.sh: the build check filters by the dev-build trigger, as
  deploy.sh does.
- host-setup.sh: one die() helper; cmp replaces a one-use helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@davidtai
davidtai marked this pull request as ready for review October 6, 2026 23:07
@davidtai
davidtai requested a review from joshconverse October 6, 2026 23:07
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 683795bd50b4 against base e3575b993cb5.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Review unavailable or invalid response; completed findings retained

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 14/169 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 3 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Bedrock: 1 request(s), 54642 input / 1267 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately.

@joshconverse joshconverse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the exact head and targeted offline tests. I confirmed the five routing-test failures and five Vercel permission failures also occur on the base SHA, so those are not the reason for this review.

The following introduced issues need correction before host setup or deployment:

  • High: host-setup.sh:131 formats the data device with mkfs.ext4 -F after any blkid failure, including read/probe errors. Verify the expected block device is blank and unused; require explicit first-format intent and reject probe errors or existing signatures.
  • High: swap.sh:160 discards seed-env.sh --check failure with || true. Enforce the check before persistent changes, pull, or migration; require root:root ownership as well as exact 0600 file/0700 directory modes.
  • Medium: swap.sh installs candidate refresh tooling before prechecks and changes the live env before recording rollback state. Several failure paths and first-deploy rollback leave changed env/tooling behind. Stage and validate first, record rollback inputs before mutation, and restore both on every later failure.
  • Medium: deploy.sh checks pause and master only before a possible 20-minute build wait. Recheck the live pause variable and current master immediately before SSH/archive mutation, preserving the explicit audited human override.
  • Medium: the documented CI-green prerequisite is absent from deploy.sh. Gate the exact candidate's required checks; any accepted pre-existing failure needs a narrow, auditable exception rather than a blanket bypass.
  • Medium: swap.sh passes the database URL, including its password, as a psql positional argument. Use a credential-safe libpq environment or private passfile so the password does not appear in process arguments.
  • Low: host setup leaves already-installed but inactive/disabled Docker or Caddy down when configuration is unchanged. Make --apply converge on enabled, running services.
  • Low: override reasons accept blank or multiline text that can forge audit lines. Require a nonblank single-line reason or structured escaped audit output.

I am preparing bounded fixes and regression coverage. Production cloud access, host setup, deployment, and secret reads were not performed. David retains merge and first-deploy ownership.

@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

Deployment failed for project darkbloom-status with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: darkbloom-status.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

davidtai and others added 2 commits October 7, 2026 05:42
The sandbox did not stub docker-credential-gcloud. On a host without it,
host-setup.sh entered its gcloud install branch, and its shell redirect wrote
to the real /etc/apt/sources.list.d before the disk-format test was reached.
Stub it with the other mutating commands.

On macOS the temp root is under a symlink (/var -> /private/var), so the
resolved deploy files looked outside the deploy root and swap.sh refused to
run. Resolve the sandbox root.

Three rollback tests need GNU ln -T, which swap.sh uses on the Ubuntu VM.
They skip with a reason where only BSD ln exists, and still run on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stubbed command answers every call. With mktemp stubbed, the calls other
than the failing one return an empty path, and a later step wrote the env
file to ./env in the repository root. Run these tests from the sandbox root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai

davidtai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@joshconverse Your fixes are merged into this branch. Head is now 983899df.

  • PR 1375 (fail-closed safety and rollback hardening) is merged at 26610cfd.
  • Two test-only commits follow it. No script changed.
    • 33d7b231 makes test-dev-deploy.py independent of the host:
      • The sandbox now stubs docker-credential-gcloud. Without it, on a host that lacks the tool, host-setup.sh entered its gcloud install branch. Its > /etc/apt/sources.list.d/google-cloud-sdk.list redirect then reached the real /etc before test_host_setup_never_formats_without_one_shot_blank_disk_authorization got to the disk check.
      • The sandbox root is now resolved. On macOS the temp root is under /var -> /private/var, so swap.sh correctly refused with "resolve outside the deploy root".
      • Three rollback tests need GNU ln -T, as on the VM. They skip with that reason on BSD ln and still run on Linux.
    • 983899df runs the temp-failure swap tests from the sandbox root. A stubbed mktemp returns an empty path for the calls that do not fail, and a later step wrote ./env (fixture values only) into the repository root.

Results on 983899df:

Host test-dev-deploy.py
Ubuntu 24.04, non-root, no gcloud tools 41 pass, 0 skipped, clean tree after the run
macOS 38 pass, 3 skipped (GNU ln -T), clean tree after the run

CI still does not reach these tests. Release Integrity stops earlier, on the inherited test-integration-ci-workflow.py failure from base 470a86d. That clears when this PR merges with current master.

Please re-review when ready. Your "changes requested" review still stands on the PR.

davidtai and others added 4 commits October 7, 2026 06:49
deploy.sh judged every unfinished check run of the candidate as pending,
including the deploy job that runs it, and failed at once without a wait.
It also counted skipped and neutral conclusions as failures, so a
path-gated required job (for example the provider lanes on a
coordinator-only commit) blocked every automatic deploy.

verify_ci now waits, bounded by CI_WAIT_S from the start of step 1, for
the required check runs to report and complete and for every status
context to leave pending. Other unfinished check runs are reported, not
awaited. success, neutral and skipped pass, as in GitHub branch
protection; every other conclusion still fails.

The empty --allow-ci-failure array is expanded with the ${a[@]+...}
form, so macOS /bin/bash 3.2 names the failing check instead of
aborting on "unbound variable". The CI-waiver audit line names the
operator with the same account and user@host as the pause override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
swap.sh removed the private database credential files after the deploy
was complete but before it set COMMITTED, so a removal failure ran the
EXIT trap rollback against a healthy deploy. The deploy is now committed
first; a removal failure adds "; private database credential cleanup
failed" to the OK line and a REPORT line, and never rolls back.

prepare_psql accepted only a query of exactly sslmode=require. It now
requires one sslmode of require, verify-ca or verify-full, accepts other
parameters, gives sslrootcert to psql, and refuses query parameters that
name another host, port, database, user, password or service.

Each deploy left an attempt directory with a full copy of the secret env
file, and old commit directories, forever. A committed deploy now
removes every attempt except its own (the one rollback-state names) and
every commit directory except the current and previous deploy files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host-setup.sh --apply restarted Caddy on every run, which dropped every
live TLS and provider websocket connection even when the Caddyfile was
unchanged. It now keeps systemctl enable --now caddy and runs systemctl
reload caddy only when it wrote a new Caddyfile and Caddy was already
running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reflow two comment blocks, split the sslrootcert count check from the
value check, state why a reported post-commit credential cleanup
failure clears PG_TMP, and name the refused passfile parameter in the
runbook. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai

davidtai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@joshconverse Review of PR 1375, by someone other than its author. Fixes are on this branch at e5086748. The 10 findings came from a high-effort code review of the PR 1375 diff. Each was reproduced with a test that fails on the PR 1375 code before it was fixed: 8 were confirmed and fixed, 2 were rejected.

# Finding Result Commit Test
1 verify_ci counted every unfinished check run, including the deploy job's own run, as pending. An automated deploy could never pass, and a human run right after a merge failed with no wait. Fixed 966fdaec test_ci_gate_does_not_wait_for_checks_outside_the_required_set, ..._waits_for_unfinished_required_checks, ..._stops_when_required_checks_do_not_finish_in_time
2 Path-skipped jobs (conclusion skipped) counted as failures. Waivers are blocked in Actions, so a docs-only commit could not deploy. Fixed 966fdaec test_skipped_and_neutral_conclusions_are_not_failures
3 The live pause gate always calls gh variable get. Rejected: PR 1374's GH_TOKEN covers it. — —
4 Empty CI_FAILURE_ALLOWLIST under set -u aborts macOS bash 3.2. It exits 0, because the EXIT trap hides the status, so the failing check is never named. Fixed 966fdaec test_unwaived_ci_failure_is_named_under_macos_bash
5 The CI-waiver audit line logged unknown. Fixed: same fallback as the pause override (gcloud account, user@host). 966fdaec test_ci_waiver_audit_names_the_operator
6 A credential-cleanup failure after the commit point rolled back a healthy deploy. Fixed: it is reported, and there is no rollback. 48d84038 test_committed_deploy_survives_a_credential_cleanup_failure
7 prepare_psql accepted only the exact query sslmode=require. Fixed: sslmode must be require, verify-ca or verify-full. Other params are allowed; host, hostaddr, port, dbname, user, password, passfile and service in the query are refused (single-host rule); sslrootcert is passed to psql. 48d84038 test_swap_requires_a_tls_single_host_database_url
8 An older 4-line rollback-state file would break rollback. Rejected: no VM was ever deployed with any version, and master has no deploy/gcp/dev. — —
9 Each deploy kept a full copy of the secret env file (attempt-*/env.before), and old deploy dirs were never pruned. Fixed: prune to what one rollback reads. 48d84038 test_committed_deploy_keeps_only_the_files_one_rollback_reads
10 host-setup.sh --apply restarted Caddy on every run and dropped live connections. Fixed: reload only when the Caddyfile changes; start an inactive Caddy. e96c909d test_host_setup_apply_reloads_caddy_only_when_the_caddyfile_changes, ..._starts_an_inactive_caddy_without_a_reload

e5086748 is the required refactor pass. It changes comments and the order of one check, and no behavior.

Two behavior changes need your decision:

  • Finding 2 reverses your choice. success, neutral and skipped now pass, as in GitHub branch protection. Your test is renamed to test_required_checks_with_a_failing_conclusion_stop, and it now also covers cancelled, timed_out, action_required, stale and startup_failure. If you want skipped to stay a failure, automation needs another way to pass docs-only commits.
  • Finding 9 keeps one rollback. A second rollback in a row now stops before it changes anything. The runbook says this.

Finding 1 design: the deploy waits up to CI_WAIT_S (default 1200 s) for the required check runs and every status context. That clock runs in parallel with the build wait, so the 45-minute job budget is unchanged. Other unfinished runs, such as the deploy job itself and E2E Integration, are listed in a REPORT line but not waited for. A completed failure of any check still blocks. --dry-run does not wait.

Validation on e5086748:

Host test-dev-deploy.py
Ubuntu 24.04, non-root, no gcloud tools 52 pass, 0 skipped
macOS 52 run, 5 skipped (GNU ln -T)
  • Each fix was reverted on the committed state, and its new test failed.
  • Also passing: test_operations_scripts.py, test-prod-env-refresh.sh, make docs-check, make docs-impact-check, bash -n (bash 3.2 and 5.2), and shellcheck -S warning.
  • The tree was clean after each run.

Not verified:

  • real GitHub timing of needs-gated check runs;
  • a Caddy reload on a real VM;
  • an empty PGSSLROOTCERT acting as unset (read in the libpq source, not tested).

PR 1374 also edits scripts/test-dev-deploy.py and docs/operations/dev-environment.md, so expect conflicts there when you rebase it.

davidtai and others added 2 commits October 7, 2026 10:02
swap.sh keeps a refresh backup that does not match env.before (the only
copy of an env change made during the deploy). A restore no longer
removes the refresh backup, so a failed removal cannot stop the restore
of the prior rollback state. The unreachable backup cleanup in rollback
is gone. A committed deploy removes each env.bak.<UTC> copy whose bytes
equal the live file or the retained env.before; the boot refresh unit
makes one at each boot. The generated-history prune is one find -delete
per directory.

seed-env.sh reports a kept post-seed refresh backup and does not fail
after the env file is in place. Both scripts read the refresh backup
through one contract file, deploy/gcp/dev/refresh-backup.sh.

deploy.sh replaces a same-commit directory whose tree differs when
neither current nor rollback-state uses it, and removes hidden staging
directories older than 60 minutes.

The Dev Deploy Safety workflow uses one YAML-anchored path list that
also covers coordinator/api/server.go and scripts/smoke-dev.sh. A test
checks that the list covers every file the suite reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor pass (subagent): STAGE_GLOB names the find pattern; in_use()
has no double negatives and states that an unreadable link or state file
counts as a use; the env backup prune comment names every source of the
copies; the refresh wrapper test helper has no sentinel argument; the
runbook paragraph on publication is three paragraphs. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this to be deleted?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. deploy/gcp/cloudbuild.yaml is the build for the old dev path, and nothing current uses it:

  • It builds for the old VM d-inference-dev in us-central1-a, pushes to the us-central1 Artifact Registry, health-checks the retired api.dev.darkbloom.xyz, and restarts the VM over SSH from inside the build.
  • Dev now builds the way production does. Trigger dev-build (darkbloom-devnet-infra terraform/cloudbuild/main.tf:23) runs deploy/gcp/cloudbuild-prod.yaml. The swap is a separate step (deploy/gcp/dev/swap.sh, through deploy.sh and deploy-dev.yml).
  • On master, only bootstrap.sh and dev-environment.md reference the file, and this PR deletes or rewrites both.
  • No Terraform in Layr-Labs/infra or darkbloom-devnet-infra creates a trigger that uses it. The one trigger known to have used it, darkbloom-dev-coordinator in the retired sepolia-ai project, was disabled by Josh on 2026-10-05 (DBLM-571).

Not verified: whether a hand-made trigger in darkbloom-dev still names the file. The old bootstrap.sh describes one. Runbook 07 lists the triggers before dev-build is created, so that check covers it.

About your PR 1096: it edits this file and the other three that this PR deletes. Do you want those edits kept somewhere, or can they go with the files?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is used for darkbloom-mainnet

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I restored deploy/gcp/cloudbuild.yaml in 683795bd, so this PR no longer deletes or changes it; the file is identical to master.

The repo says production builds from cloudbuild-prod.yaml: coordinator-deploy.md:120 checks that the prod trigger's filename is deploy/gcp/cloudbuild-prod.yaml. Also, this file pushes to darkbloom-dev and restarts d-inference-dev. But a trigger can override those substitutions, and I cannot see the mainnet triggers. So keeping it is the safe choice.

To retire it later, someone with mainnet access can run:

gcloud builds triggers list --project=darkbloom-mainnet --format='table(name,filename,disabled)'

If no trigger names deploy/gcp/cloudbuild.yaml, it can go in a separate PR. Can you clear the changes-requested state if this resolves it?

davidtai and others added 2 commits October 7, 2026 10:47
swap.sh removes an env.bak.<UTC> copy only when its bytes equal the live
env file; this attempt's env.before is removed by the next deploy, so it
is not a lasting copy. seed-env.sh removes its refresh backup only when
the backup is the file the seed wrote, else it keeps it with a REPORT
line. Both use refresh_backup_is_copy_of in refresh-backup.sh, and both
fail with the file name when that helper cannot be sourced.

deploy.sh counts a rollback-state whose line 6 is empty, missing or not
absolute as a use (none stays a first-deploy value), so it refuses to
replace the directory. When the new tree cannot be renamed into place,
it renames the old tree back and prints FAIL; when that also fails, the
FAIL line names the commit path and the directory with the old files.

The workflow path test, its comment and docs/developer/test.md now say
which inputs the test names, not every file the suite reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor pass (subagent): one module-level tree_contents() test helper
replaces two inner tree() copies; the runbook seed paragraph is rewrapped
and uses ASD-STE100 wording. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308

Copy link
Copy Markdown
Collaborator

Second review of head 84d46d74, read-only, plus the offline suites. I found no path to production: the dev scripts pin the dev project and fail closed, prod.env changes only a comment, and deploy/gcp/prod/* and cloudbuild-prod.yaml have no diff. Seven of the eight findings from the earlier review are fixed. What is left:

Needs a fix before host setup or the first automatic deploy

  1. host-setup.sh cannot pass the disk check. It runs wipefs -n --noheadings -o TYPE "$DATA_DEV". In util-linux wipefs, -o is --offset and the column flag is -O (man page). The call errors, so --apply dies with "cannot prove the existing signatures" before the disk is mounted or Caddy is configured. I checked the flags against the man page, not on a Linux host. The test stub (["wipefs", "^-n", …]) accepts any arguments, which is why the suite stays green; pinning the exact flags in the stub would catch this kind of error.

  2. The CI gate in deploy.sh refuses every commit whose Vercel statuses fail. REQUIRED_STATUSES lists five Vercel contexts, any failed status blocks, and waivers are refused under GitHub Actions. On master, the commits you authored carry failed Vercel statuses (55b5ad5a6 and 9d6730962: every context is failure, and Vercel – darkbloom-status is absent on both), while other authors' commits pass. An automatic dev deploy of those commits would always stop, and a manual one needs a waiver per context. Either the Vercel permission needs fixing or Vercel should come out of the required set.

  3. A missing container is treated as a first deploy. swap.sh sets PREVIOUS_IMAGE=none whenever docker container inspect coordinator fails, even when last-good-image and a rollback state exist. After an interrupted swap or a manual docker rm, the next deploy commits with no previous image and prunes the older fallback containers. A later rollback then stops the coordinator, starts nothing and reports OK. This affects dev availability only. Using the recorded last-good image when one exists would close it.

The open question on the deleted cloudbuild.yaml

At this head nothing in a workflow, script, Makefile or test references bootstrap.sh, cloudbuild.yaml, refresh-env.sh or vm-startup.sh; only the changelog note and two frozen reports name them. The production path is untouched. Two things remain to confirm: that no live Cloud Build trigger still points at deploy/gcp/cloudbuild.yaml, and how this lands relative to #1096, which edits all four files.

Smaller items (from reading, not reproduced)

  • deploy.sh ships git archive HEAD, not $CANDIDATE_COMMIT, after waits of up to 20 minutes. If the checkout moves, a different tree lands under the candidate's directory.
  • --migrate-only output goes to /dev/null in a --rm container, so a failed migration leaves no diagnostics, although the runbook says to read the journal.
  • The old dev env set EIGENINFERENCE_MDM_URL. No new seed source sets it, and the "differs from production" table does not mention it.
  • --override-pause is not refused under GITHUB_ACTIONS, although the docs say automation must not use it.
  • Nothing locks the VM, so a manual run can interleave with a workflow swap.

Conflicts with master

Only the Last updated lines of docs/developer/build.md and docs/developer/test.md. Taking master's side of both hunks resolves them.

What I ran

On macOS, at this head: scripts/test-dev-deploy.py (65 tests: 54 pass, 11 skipped as GNU-only), scripts/test_operations_scripts.py, scripts/run-dev-deploy-safety-ci.sh and bash -n on every script. On a local merge with master at e3575b993: scripts/test-prod-env-refresh.sh, make docs-impact-check, and the Go packages that read deploy/ files (coordinator/tests/registry, coordinator/tests/api/provider/trust). All pass. Nothing was run against a VM, GCP or GitHub.

Review assisted by Claude Code.

davidtai and others added 5 commits October 8, 2026 10:02
…cripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into devnet/dev-deploy-scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host-setup.sh reads disk signatures with wipefs -O TYPE; -o is --offset
and util-linux refuses "-o TYPE". The test stubs pin the exact lsblk and
wipefs flags and fail on any other call.

deploy.sh no longer gates on Vercel status contexts (web preview
deploys); it lists them in a REPORT line, and a commit with no status
context passes. It ships the files of the candidate commit, not HEAD,
and refuses --override-pause under GitHub Actions.

swap.sh uses last-good-image as the previous image when no coordinator
container runs, keeps the older fallbacks and images on such a run, and
refuses a rollback that names no previous image after an earlier
deploy. The --migrate-only output goes to a root-only file on the VM. A
flock on the deploy state dir lets one swap or rollback run at a time.

The runbook documents each change, and that dev takes
EIGENINFERENCE_MDM_URL from the image, as production does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor pass (subagent): the Vercel status filter is one jq definition
that single-quoted programs use; the lock and migrate-only comments state
their intent; fcntl is a module import in the tests; the runbook
paragraph on shipping and the lock is rewrapped. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed deploy that found no coordinator container restores that state,
so its own automatic rollback starts no container, as before. Only
MODE=rollback refuses a record with no previous image after an earlier
deploy. test_automatic_cleanup_reports_rollback_command_failure covers
the automatic case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacksmith-sh

This comment has been minimized.

macOS /bin/bash 3.2 exits at once when "." names a missing file, so the
"|| fail" after it never ran and the named FAIL line was lost. The CI macOS
runner uses that bash; local runs used bash 5. Test that the helper is
readable first, in seed-env.sh and swap.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai

davidtai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

@jonathan308 @joshconverse @Gajesh2007 Ready for re-review at c02fa348.

Jonathan's must-fix items

# Item Fix Commit
1 wipefs -o TYPE (-o is --offset) wipefs -O TYPE. The test stubs now pin the exact lsblk and wipefs flags and fail on any other call. Confirmed on Ubuntu 24.04, util-linux 2.39.3: -o TYPE gives "invalid offset argument" with rc 1, -O TYPE gives rc 0. 221b8d27
2 The CI gate required the five Vercel statuses Vercel is out of the deploy gate. Its contexts are listed in a REPORT line only; they are preview deploys of the web projects. 221b8d27, 99c969bf
3 A missing container was treated as a first deploy swap.sh uses last-good-image as the previous image when no coordinator container runs, and keeps the older fallbacks. An explicit rollback that would start nothing after an earlier deploy now refuses. 221b8d27, 878f6921

Smaller items

  • deploy.sh ships the candidate commit, not HEAD.
  • --override-pause is refused under GITHUB_ACTIONS.
  • --migrate-only output goes to a root-only file on the VM.
  • A flock on the deploy state directory lets only one swap or rollback run at a time.
  • EIGENINFERENCE_MDM_URL: dev takes it from the image, as production does. The runbook says so.

Also in this head

  • master merged in (6cb9ea00). The conflicts were only the Last updated stamps; master's side was taken.
  • The second-review fixes (40ab5c7a, 3e95fcf2), now with their mutation proofs and full-suite runs:
    • env backups pruned only against the live env;
    • a short rollback-state fails closed;
    • the seed keeps a backup that differs from what it wrote;
    • a failed rename restores the old tree;
    • a missing helper gives a named FAIL.
  • c02fa348: macOS /bin/bash 3.2 exits at once when . names a missing file, so || fail never ran. The CI macOS runner caught this; local runs used bash 5. The helper is now checked with [ -r ] first. Mutation-proven on bash 3.2.

@Gajesh2007: your cloudbuild.yaml question is answered in the inline thread.

CI at c02fa348:

  • Pass: Dev Deploy Safety (Ubuntu 24.04 and macOS 27), Release Integrity, Commit Signatures, Docs Lint, Docs Impact.
  • Still running: the coordinator and provider suites, which the master merge triggered.
  • Vercel previews: see Jonathan's item 2; a separate account question.

Gajesh raised in review that a darkbloom-mainnet trigger may use this
file. The repository says production builds from cloudbuild-prod.yaml
(coordinator-deploy.md checks the prod trigger filename), but a trigger
can override this file's substitutions, and mainnet triggers are not
visible from dev. Keeping the file costs nothing; deleting it could break
a production build. Retire it in a separate change after someone with
mainnet access confirms that no trigger names it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai

davidtai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Moved to Layr-Labs/darkbloom-platform#10, because coordinator development now happens there (docs/developer/platform-bootstrap.md in that repo). This PR is closed; its branch is kept.

@davidtai davidtai closed this Oct 9, 2026
@davidtai davidtai mentioned this pull request Oct 9, 2026
3 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants