fix(traffic): give the one-box canary its secrets #477

Merged
gmackie merged 4 commits from fix/traffic-lifecycle-recovery into main 2026-08-27 21:07:38 +00:00
Owner

Root cause of a live control-plane incident: forgegraf.com served from forgegraph-onebox, a Worker with zero secrets, so every bearer request 401d and all 7 node agents went offline for ~30 minutes.

The enable path comments that the one-box target "shares secrets" with the stage. True for a node service (env file from stage secrets each deploy); false for a Worker, where Cloudflare scopes secrets per worker name. The canary is created with none, deploying code adds none, and they cannot be copied off the primary because Worker secrets are write-only. They must be pushed from our encrypted store. putWorkerSecret already existed with exactly one caller, none in the one-box path.

Why it is worse than a degraded canary: verifyBearerTokenWithDB returns invalid when FG_API_TOKEN is unset, before the DB is consulted. A canary owning the production hostname denies all machine auth platform-wide, and the deploy meant to replace it needs that same auth to finish, so it cannot self-recover.

enable now pushes stage secrets to the canary and refuses to enable if any fail, naming them. Half-configured is the dangerous state.

Root cause of a live control-plane incident: forgegraf.com served from forgegraph-onebox, a Worker with **zero secrets**, so every bearer request 401d and all 7 node agents went offline for ~30 minutes. The enable path comments that the one-box target "shares secrets" with the stage. True for a node service (env file from stage secrets each deploy); false for a Worker, where Cloudflare scopes secrets per worker *name*. The canary is created with none, deploying code adds none, and they cannot be copied off the primary because Worker secrets are write-only. They must be pushed from our encrypted store. `putWorkerSecret` already existed with exactly one caller, none in the one-box path. Why it is worse than a degraded canary: `verifyBearerTokenWithDB` returns invalid when FG_API_TOKEN is unset, *before* the DB is consulted. A canary owning the production hostname denies all machine auth platform-wide, and the deploy meant to replace it needs that same auth to finish, so it cannot self-recover. enable now pushes stage secrets to the canary and refuses to enable if any fail, naming them. Half-configured is the dangerous state.
Author
Owner

Preview environment is live: https://pr-477-forgegraph.forgegraf.com

Deployed f27bd9f1 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-477-forgegraph.forgegraf.com Deployed `f27bd9f1` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Preview environment is live: https://pr-477-forgegraph.forgegraf.com

Deployed 66180854 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-477-forgegraph.forgegraf.com Deployed `66180854` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Reviewed. The diagnosis is right and this is not superseded — git grep listWorkerSecretNames|syncSecretsToCanary|assertCanaryCanServeTraffic against main returns nothing, and the three traffic commits that landed since (82d29c2d #475, d2af6f91 #479, 849263f3 #482) all address hostname stealing, a different facet of the same incident.

The red CI is not this PR's fault. Task 23991 failed in Vet and test Go agent on a transient module-proxy error:

github.com/klauspost/cpuid/v2@v2.2.11: read "https://proxy.golang.org/…zip":
stream error: stream ID 99; INTERNAL_ERROR; received from peer

The same log reports test | passed | 1151 passed / 0 failed / 10 skipped. A re-run should go green.


The blocker: this would stop deploys fleet-wide, including forgegraf.com

assertCanaryCanServeTraffic fires in shiftAndBake, which every one-box deploy passes through. But the only thing that ever pushes secrets to a canary is syncSecretsToCanary, called from exactly one place — the enable mutation in packages/api/src/routers/traffic.ts:303. Nothing re-syncs on deploy.

I checked the production control-plane DB:

select enabled, count(*) from traffic_splits group by 1;
 f | 1
 t | 22

All 22 enabled splits — calzone, controlsfoundry, creator, crucible, daily-dose, driftport, fabforge, festigram, forgegraph, fryos, habit-app, insure, jobs-pulse, latchflow, linear-clone, netcontrol, omnidat-app, playtrek, streamconductor, test-dojo, trip, veritas — were enabled before this code existed, so none of their canaries has ever received a secret push. On merge, each one's next production deploy throws at the shift step, and re-running enable is the only remediation.

It is worse for ForgeGraph itself: the PR body notes 26 of the primary's 41 secrets were set out-of-band with wrangler secret put and are not in the store, so even a disable/re-enable would fail the strict parity check. That is a self-blocking condition on the platform's own deploy path.

Suggested shape: land the enable-time sync now, but either put the parity guard behind a flag / warn-only mode, or add a shift-time sync before the shift-time assert, so an already-enabled split self-heals instead of dead-ending. The 26 out-of-band secrets need backfilling into the store before a strict check goes live either way.

Two smaller issues

  1. listWorkerSecretNames fails in opposite directions. It returns [] whenever data.success is false and never checks resp.ok. A CF API error on the primary lookup therefore makes the guard silently pass (fails open, defeating it); the same error on the canary lookup reports every primary secret as missing and blocks the deploy (fails closed, spuriously).
  2. The deploymentTargets select in shiftAndBake runs before the workerName check, so every shift pays a DB roundtrip even on node-platform lanes. Cosmetic.

Not merging — the guard's rollout needs a decision, not a patch.

Reviewed. **The diagnosis is right and this is not superseded** — `git grep listWorkerSecretNames|syncSecretsToCanary|assertCanaryCanServeTraffic` against main returns nothing, and the three traffic commits that landed since (`82d29c2d` #475, `d2af6f91` #479, `849263f3` #482) all address hostname stealing, a different facet of the same incident. **The red CI is not this PR's fault.** Task `23991` failed in `Vet and test Go agent` on a transient module-proxy error: ``` github.com/klauspost/cpuid/v2@v2.2.11: read "https://proxy.golang.org/…zip": stream error: stream ID 99; INTERNAL_ERROR; received from peer ``` The same log reports `test | passed | 1151 passed / 0 failed / 10 skipped`. A re-run should go green. --- ## The blocker: this would stop deploys fleet-wide, including forgegraf.com `assertCanaryCanServeTraffic` fires in `shiftAndBake`, which every one-box deploy passes through. But the only thing that ever *pushes* secrets to a canary is `syncSecretsToCanary`, called from exactly one place — the `enable` mutation in `packages/api/src/routers/traffic.ts:303`. **Nothing re-syncs on deploy.** I checked the production control-plane DB: ```sql select enabled, count(*) from traffic_splits group by 1; f | 1 t | 22 ``` All 22 enabled splits — `calzone`, `controlsfoundry`, `creator`, `crucible`, `daily-dose`, `driftport`, `fabforge`, `festigram`, **`forgegraph`**, `fryos`, `habit-app`, `insure`, `jobs-pulse`, `latchflow`, `linear-clone`, `netcontrol`, `omnidat-app`, `playtrek`, `streamconductor`, `test-dojo`, `trip`, `veritas` — were enabled **before this code existed**, so none of their canaries has ever received a secret push. On merge, each one's next production deploy throws at the shift step, and re-running `enable` is the only remediation. It is worse for ForgeGraph itself: the PR body notes 26 of the primary's 41 secrets were set out-of-band with `wrangler secret put` and are not in the store, so even a disable/re-enable would fail the strict parity check. That is a self-blocking condition on the platform's own deploy path. **Suggested shape:** land the enable-time sync now, but either put the parity guard behind a flag / warn-only mode, or add a shift-time *sync* before the shift-time *assert*, so an already-enabled split self-heals instead of dead-ending. The 26 out-of-band secrets need backfilling into the store before a strict check goes live either way. ## Two smaller issues 1. **`listWorkerSecretNames` fails in opposite directions.** It returns `[]` whenever `data.success` is false and never checks `resp.ok`. A CF API error on the **primary** lookup therefore makes the guard silently pass (fails open, defeating it); the same error on the **canary** lookup reports every primary secret as missing and blocks the deploy (fails closed, spuriously). 2. The `deploymentTargets` select in `shiftAndBake` runs before the `workerName` check, so every shift pays a DB roundtrip even on node-platform lanes. Cosmetic. Not merging — the guard's rollout needs a decision, not a patch.
gmackie force-pushed fix/traffic-lifecycle-recovery from 64ceead063
Some checks failed
CI / gitleaks (pull_request) Successful in 6s
CI / storybook (pull_request) Successful in 1m23s
forgegraph/ci CI failed
CI / ci (pull_request) Failing after 9m46s
to d975761077
All checks were successful
CI / gitleaks (pull_request) Successful in 7s
CI / storybook (pull_request) Successful in 1m47s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 11m47s
2026-08-27 20:42:51 +00:00
Compare
Author
Owner

Preview environment is live: https://pr-477-forgegraph.forgegraf.com

Deployed d9757610 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-477-forgegraph.forgegraf.com Deployed `d9757610` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Sign in to join this conversation.
No description provided.