Skip to content

feat(devnet): bind dev-installed providers to their coordinator and add seed data - #1330

Merged
Gajesh2007 merged 9 commits into
masterfrom
feat/devnet-env-bound-provider
Oct 6, 2026
Merged

Gajesh2007 merged 9 commits into
masterfrom
feat/devnet-env-bound-provider

Conversation

@davidtai

@davidtai davidtai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR prepares the DevNet: a dev coordinator plus Macs that stay bound to it, so the team can test database migrations and account erasure before production. Linear: DBLM-552.

  1. Installer binds the provider to the coordinator that served it. Before this change, an installer served by https://api.dev.darkbloom.xyz downloaded the dev release, but the provider then connected to production: the provider default is wss://api.darkbloom.dev/ws/provider and install.sh never wrote a URL. Now bind_provider_coordinator in scripts/install.sh always binds the provider to the serving coordinator, and keeps every other line of ~/.config/darkbloom/provider.toml:
    • Any other coordinator (dev, local): writes url = "wss://<host>/ws/provider" under [coordinator] (ws:// only for http://localhost / http://127.0.0.1), and creates the file if it is missing. The host must be a bare host[:port]; anything else stops the install.
    • Production (https://api.darkbloom.dev): removes any url line under [coordinator], so the provider uses its built-in production default. It does not create the file, and a file without that line stays byte-for-byte unchanged. Running the production installer therefore moves a dev Mac back to production.
  2. coordinator/cmd/devnet-seed fills an empty database with fake data (seed-<n>@example.invalid, did:privy:seed-<n>, serials SEED00000001, model IDs devnet-seed/*) through the same store methods the coordinator uses. It refuses to run when users has any row, and it checks this before any migration runs. The default scale is small; the runbook gives flags for production-like volume.
  3. Dev docs and deploy fixes. The runbook now describes the binding correctly, says that bootstrap creates only 10 secrets, says that the R2 CDN URL is not templated into install.sh, and adds a DevNet checklist of the steps that need a person. The comment in bootstrap.sh said the console runs on Cloud Run; it runs on Vercel. vm-startup.sh now sets EIGENINFERENCE_IPAPI_KEY, as refresh-env.sh already did (the env lines of the two files now match).

Paths that read the bound URL

I checked every CLI path. start (and the LaunchAgent plist it writes), login, update, doctor, enroll, models and the watchdog all read config.coordinator.url from provider.toml. No Swift code change was needed. ServiceDrain falls back to the production URL when no daemon state exists, but it uses that URL only to take a local update lock, not to make a network call.

Before / After

flowchart LR
  subgraph Before
    direction TB
    B1(["curl api.dev…/install.sh | bash"]):::user --> B2["install.sh<br/>downloads dev release"]:::code
    B2 --> B3[("provider.toml<br/>(no coordinator url)")]:::data
    B3 --> B4["darkbloom start / login / update<br/>default url"]:::code
    B4 --> B5{{"wss://api.darkbloom.dev<br/>PRODUCTION"}}:::bad
  end
  subgraph After
    direction TB
    A1(["curl api.dev…/install.sh | bash"]):::user --> A2["install.sh<br/>downloads dev release"]:::code
    A2 --> A3["bind_provider_coordinator<br/>COORD_URL ≠ production: write url"]:::new
    A3 --> A4[("provider.toml<br/>[coordinator] url = wss://api.dev…")]:::data
    A4 --> A5["darkbloom start / login / update<br/>LaunchAgent, watchdog"]:::code
    A5 --> A6{{"wss://api.dev.darkbloom.xyz<br/>DEV"}}:::good
    P1(["prod install.sh"]):::user --> P2["bind_provider_coordinator<br/>COORD_URL = production:<br/>remove [coordinator] url"]:::new
    P2 --> P3[("provider.toml<br/>other lines kept")]:::data
    P3 --> P4{{"wss://api.darkbloom.dev<br/>built-in default"}}:::good
  end
  classDef user fill:#dbeafe,stroke:#1d4ed8,color:#0b1b3a
  classDef code fill:#f3f4f6,stroke:#4b5563,color:#111827
  classDef new fill:#dcfce7,stroke:#15803d,color:#052e16
  classDef data fill:#fef9c3,stroke:#a16207,color:#422006
  classDef bad fill:#fee2e2,stroke:#b91c1c,color:#450a0a
  classDef good fill:#dcfce7,stroke:#15803d,color:#052e16
Loading
flowchart LR
  subgraph Before
    direction TB
    S1(["empty dev database"]):::data --> S2["no seed tool:<br/>data only from real use"]:::bad
  end
  subgraph After
    direction TB
    T1(["devnet-seed --accounts N ..."]):::user --> T2{"users table<br/>has rows?"}:::new
    T2 -- "yes" --> T3["refuse<br/>(before migrations)"]:::bad
    T2 -- "no" --> T4["store.NewPostgres<br/>(migrations)"]:::code
    T4 --> T5["CreateUser, CreateAPIKey"]:::code
    T5 --> T6["UpsertProvider +<br/>Open/Touch/CloseProviderSession"]:::code
    T6 --> T7["Credit deposit, Debit charge,<br/>RecordUsage, CreditProviderAccount"]:::code
    T7 --> T8[("users, api_keys, providers,<br/>provider_sessions, usage,<br/>ledger_entries, balances")]:::data
  end
  classDef user fill:#dbeafe,stroke:#1d4ed8,color:#0b1b3a
  classDef code fill:#f3f4f6,stroke:#4b5563,color:#111827
  classDef new fill:#dcfce7,stroke:#15803d,color:#052e16
  classDef data fill:#fef9c3,stroke:#a16207,color:#422006
  classDef bad fill:#fee2e2,stroke:#b91c1c,color:#450a0a
Loading

Legend: blue = person, grey = existing code, green = new code or good outcome, yellow = stored data, red = wrong or refused outcome.

Test plan

  • python3 scripts/test-install-coordinator-binding.py: 11 tests pass. Production: creates no file, removes only the [coordinator] url (other sections, including [coordinator.extra] and [provider] url keys, kept), leaves a file without that url byte-identical, and dev-then-production restores the original file. Other coordinators: missing file, url replacement, section without url, file without the section, url keys in other tables left alone, localhost http:// → ws://, and bad URLs (remote http://, paths, quotes, user@) failing without a write.
  • ./scripts/test-install-atomic.sh (now also runs the test above): passes.
  • go test ./coordinator/api -run 'TestServedInstallerBindsProviderToServingCoordinator|TestInstallScriptTemplating|TestEmbeddedInstaller': passes. The new test runs the installer exactly as a dev and a prod coordinator serve it: dev creates or extends the file; production creates no file and removes the dev url from an existing one.
  • DATABASE_URL=<disposable postgres:17> go test ./coordinator/cmd/devnet-seed: 4 tests pass. Row counts for users, api_keys, providers, provider_sessions, usage, provider_earnings, balances and ledger_entries; balance totals; a second run is refused; a database with users is refused before migrations.
  • swift test --filter "InstallerCoordinatorBindingTests|RuntimeSnapshotConfigTests" (with DEVELOPER_DIR set to Xcode, --build-system native): 8 tests pass. The new suite runs the real installer step and reads the result through loadRuntimeSnapshot, loadUpdateConfig and Watchdog.settings, checks that a fully serialized config keeps every other setting, and checks that dev then production returns the config to its original values with the production default URL.
  • golangci-lint run ./coordinator/cmd/... ./coordinator/api/... (v2.1.6, as CI): 0 issues. gofmt -l: clean. ./scripts/test-install-atomic.sh: passes.
  • scripts/sync-install-embed.sh check, make docs-impact-check BASE=origin/master, make docs-check, git diff --check: pass.
  • Note: coordinator/cmd/payout-audit TestPostgresAuditAndApprovedRefund failed locally against Postgres 17. This PR does not change that package or coordinator/store.

Components touched

  • coordinator (Go): new cmd/devnet-seed, installer embed, test
  • provider-swift (Swift CLI): tests only
  • infra / CI / release: scripts/install.sh, deploy/gcp/*, deploy/provider-fleet/update-fleet.sh
  • docs

Protocol / interface changes

  • No protocol changes. The installer now writes the existing [coordinator] url config key. scripts/install.sh and coordinator/api/install.sh are identical (sync-install-embed.sh check). release-swift.yml and LatestProviderVersion are not changed. No version bump.

Documentation impact

  • Canonical documentation updated: docs/operations/dev-environment.md (steps 1, 2, 9, new step 10, DevNet checklist), docs/provider/installation.md, docs/provider/cli-reference.md, docs/operations/provider-release.md, docs/developer/test.md, CHANGELOG.md (Unreleased — DevNet).

Limitations

  • Dev and production on the same Mac are out of scope: the last installer that ran decides the coordinator.
  • A provider that is already running keeps its old coordinator until the next darkbloom start. darkbloom restart reuses the existing LaunchAgent arguments.
  • devnet-seed refuses as soon as anyone has signed in to the database, so run it on a fresh dev database. It does not seed billing sessions, withdrawals or Global Payouts rows.
  • The dev env scripts do not set the EIGENINFERENCE_STRIPE_GLOBAL_PAYOUTS_* variables. This is listed in the checklist and not changed here.

🤖 Generated with Claude Code

Refactor Pass

A dedicated refactor subagent reviewed the diff against the AGENTS.md structure, clean-code and refactor rules. Outcome: one cleanup commit, 813c561.

  • cmd/devnet-seed/main.go: in requireEmptyDatabase, one bool served two checks. It is now two bools, usersTableExists and hasUsers. The queries, their order and the error text are unchanged.
  • scripts/test-install-coordinator-binding.py: the --bind-coordinator-test call was copied in two places. Both now use one helper, run_binding(coordinator, config). All 11 tests and their assertions are unchanged.
  • The installer (scripts/install.sh and its copy in coordinator/api/install.sh), seed.go, the deploy scripts and the docs are unchanged. scripts/sync-install-embed.sh check reports that the two installer copies match.

Validation on the final tree: the Python binding tests (11 OK), go vet, gofmt -l, golangci-lint v2.1.6 (0 issues), go test -count=1 ./cmd/devnet-seed (4 PASS, including the two Postgres tests on local postgres:16), make docs-impact-check, and make docs-check (330 OK) all pass.

Needs a port before merge: master c5552d3 moved coordinator/api/install_sh_test.go to coordinator/tests/api/, and TestCoordinatorTestsAreIsolated rejects test files outside that directory. Both of this PR's Go test files would fail that check. cmd/devnet-seed/main_test.go is a package main test of unexported functions, so it needs to be rewritten as well as moved. There are also conflicts in CHANGELOG.md, tests/api/releases/contracts/install_test.go and docs/developer/test.md.

For the author: the DevNet checklist in docs/operations/dev-environment.md has point-in-time status ("timed out on 2026-10-03", "Agents cannot do them") that may belong in this PR body instead.

Port to master, c4c9556, 83bed15 and 7337d9b (follow-up): merged master. The devnet-seed logic moved into the production package coordinator/internal/command/devnetseed/ (Run, ParseOptions, Seed), following master's cmd/payout-audit → internal/command/payoutaudit layout. cmd/devnet-seed/main.go is now only the entry point. The tests moved to coordinator/tests/cmd/devnet-seed/ with the same assertions. The installer test lives in tests/api/releases/contracts/install_test.go, next to the helpers it uses. The dated session status in the dev-environment checklist is removed. Build, vet, lint (0), the layout guard, test-coordinator-tests.py (20), the tests/api, releases and cmd tests, the devnet-seed tests on Postgres 16 with -race, sync-install-embed.sh check and the installer-binding tests (11) pass. Not repeated on the merged tree: the Swift InstallerCoordinatorBindingTests. Master changed no provider-swift files this test touches.


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

… data

An installer served by any coordinator other than production now writes
that coordinator's [coordinator] url into provider.toml and keeps the
file's other lines. Before this, a Mac installed from the dev coordinator
connected to production, because the provider default is production and
install.sh never wrote the URL. The production installer leaves the file
unchanged.

Add coordinator/cmd/devnet-seed, which fills an empty dev database with
fake accounts, API keys, provider sessions, usage, ledger entries and
balances through the store package. It refuses a database whose users
table has rows, before any migration runs.

Fix the dev runbook and deploy comments: bootstrap creates only 10
secrets, the console runs on Vercel, the R2 CDN URL is not templated into
install.sh, and vm-startup.sh now sets EIGENINFERENCE_IPAPI_KEY like
refresh-env.sh. Add a DevNet checklist of the steps that need a person.

Refs DBLM-552.

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

vercel Bot commented Oct 3, 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

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 660b3e4283b0 against base dccc9ee03333.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
normal spending limit reached; remaining coverage deferred

LOW: Installer now persists the serving coordinator URL, extending Host-header-injection impact (T-040)

coordinator/api/install.sh:28 · T-040

Previously, a coordinator URL injected into the installer through Host or X-Forwarded-Proto (T-040) affected only the one-shot download. With this PR the installer's bind_provider_coordinator writes COORD_URL into ~/.config/darkbloom/provider.toml as `[coordinator] url`, after validating only that it is a syntactically valid https://host\[:port\] (or localhost http). The provider's start, login, update and LaunchAgent all use that URL. If the coordinator derives COORD_URL from request headers (baseURL unset) and a cache or proxy serves the poisoned installer, the victim's provider stays bound to the attacker's host. Later `darkbloom login` tokens and provider traffic then go to that host, and updates are fetched from it. A malicious installer could already run arbitrary code, but the persistent rebinding is new. Fix: require baseURL to be configured in production so install.sh never reflects request headers. Optionally allowlist the hosts the installer may write, and have the provider warn when its coordinator differs from the production default.

Raised by: anthropic/claude-sonnet-5.5

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

Coverage: 26/120 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.4236 reported, $0.0000 reserved with unknown cost; 5 paid request(s), 2 reused batch(es), 100485 provider cache-hit tokens.

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

The served COORD_URL is written into provider.toml, so accept only a bare
host[:port] (letters, digits, dots, hyphens) and refuse paths, quotes and
other characters that could change the TOML. Plain http:// (ws://) is
accepted only for localhost and 127.0.0.1, so a remote coordinator cannot
be bound over a cleartext channel.

Addresses the threat-model review finding on #1330.

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

vercel Bot commented Oct 3, 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 3, 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 3, 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

davidtai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Disposition for the threat-model review finding (MEDIUM, installer persists an unvalidated coordinator URL):

  • Injection into TOML / awk: valid, fixed in a3367bd. provider_websocket_url now accepts only https://<host>[:port], with the host limited to A-Za-z0-9.-. Paths, quotes, backslashes, user@ and any other characters stop the install before anything is written. scripts/test-install-coordinator-binding.py has new cases for each of these (8 tests pass), and I also checked it under macOS /bin/bash 3.2.
  • Cleartext ws://: valid, fixed in a3367bd. http:// is accepted only for localhost and 127.0.0.1, which a local development coordinator uses. A remote http:// coordinator is refused (test case http://192.0.2.10:8080).
  • Host-header fallback / explicit confirmation / allowlist: not changed. The URL comes from the same coordinator response as the script the user runs. Anyone who can change that text can already change the whole script, so a check inside the script adds no protection against that. Production and dev both set EIGENINFERENCE_BASE_URL (deploy/environments/prod.env, deploy/gcp/refresh-env.sh), so resolveBaseURL does not use the request Host there. A domain allowlist would block local and future dev coordinators, and curl | bash cannot prompt. The installer prints the coordinator URL it wrote.

The installer now persists the substituted coordinator URL, so a
Host-derived URL would rebind later provider traffic. Record this, the
host validation, and that production and dev both configure the base URL.

Addresses the LOW threat-model review findings on #1330.

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

davidtai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Disposition for the two LOW threat-model findings on a3367bd (Host-header-derived URL persisted into provider.toml):

  • Persistence is real: documented in 082a3c3. docs/threat-model.yaml T-040 now lists scripts/install.sh and records that the binding persists the substituted URL, the host validation from a3367bd, and that the bound URL is printed.
  • Production exposure: not reachable. Production requires EIGENINFERENCE_BASE_URL (deploy/gcp/prod/required-env-keys.txt) and dev sets it (deploy/gcp/refresh-env.sh). With it set, resolveBaseURL returns the configured URL and never reads Host or X-Forwarded-Proto. Also, the production installer never writes provider.toml.
  • Allowlist or opt-in flag: not added. An allowlist would block local coordinators and new dev hosts, and the URL comes from the same response as the script the user runs. Removing the Host fallback from resolveBaseURL is a coordinator change outside this PR; the existing open T-040 mitigation tracks it.

The installer now always binds the provider to the coordinator that
served it. The production installer removes any url line under
[coordinator] and keeps every other line, so the provider falls back to
its built-in production default; it does not create the file when it is
missing, and it leaves a file without that url byte-for-byte unchanged.
Before this, a Mac bound to dev stayed on dev after the production
installer ran. Other coordinators keep the existing behaviour.

Update the installer, Go and Swift tests, and the docs that described
the old limitation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 4 commits October 4, 2026 16:14
…ng test runner

requireEmptyDatabase no longer reuses one bool for "table exists" and "has rows".
The coordinator-binding Python test runs the installer hook through one helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve CHANGELOG.md (keep both sides), docs/developer/test.md (master
header) and the installer binding test, which follows master's move of the
templating tests to coordinator/tests/api/releases/contracts/install_test.go.
devnet-seed opens PostgreSQL through store/postgres.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tests/cmd

Master keeps every coordinator test under coordinator/tests/ in an external
package. Follow payout-audit: cmd/devnet-seed is a thin main that calls
devnetseed.Run, and the package exports ParseOptions, Seed and Run. The
tests move to coordinator/tests/cmd/devnet-seed (package devnetseed_test)
unchanged in their assertions and use store/memory for the in-memory store.

Docs: point docs/developer/test.md at the moved tests, and remove the dated
VM status from the DevNet checklist in docs/operations/dev-environment.md;
the procedure stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs-impact requires a canonical owner entry for the new
coordinator/internal/command/devnetseed package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidtai davidtai mentioned this pull request Oct 5, 2026
3 of 5 tasks
Port onto master dccc9ee. Conflicts: CHANGELOG.md keeps master's
"provider service replacement" section and this PR's "DevNet" section;
the three doc stamps take master's later dates.

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 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

@Gajesh2007
Gajesh2007 merged commit 2763aca into master Oct 6, 2026
23 of 32 checks passed
@Gajesh2007
Gajesh2007 deleted the feat/devnet-env-bound-provider branch October 6, 2026 20:28

This branch was successfully deployed

No deployments
benchmarks — 660b3e42 Deployed Oct 6, 2026 by davidtai via E2E Benchmarks #2330
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.

2 participants