fix(cli): require explicit Cloud mirror opt-in

Draft
KH
1mo ago
+164-39

Outcome

Local runs now upload to the Cloud dashboard only when the invocation explicitly requests that projection with --cloud-mirror or FLOWS_CLOUD_MIRROR=1.

A stored Cloud login remains authentication, not consent. Ordinary, named, resumed, and detached local runs remain local without the opt-in. Named-flow source lookup still works, and explicit flag/environment mirroring still reports through the existing best-effort path.

This is split from #707 so node-spawn work and the privacy fix have independent review and evidence. It does not merge, release, deploy, or mutate a customer run.

Verification

Fresh install:

$ npm ci --prefix packages/sdk --ignore-scripts --no-audit --no-fund
npm warn deprecated whatwg-encoding@3.1.1: Use @exodus/bytes instead for a more spec-conformant and faster implementation

added 196 packages in 1s

Exact post-fix gate:

$ npm run build && RELAYFLOWD_BIN=/home/khaliqgant/.relayflows-toolchain/target/4032934808/debug/relayflowd npx vitest run tests/cloud-mirror-session.test.ts tests/cloud-mirror-live.test.ts tests/observer-link.test.ts tests/named-local-run.test.ts tests/cli-detach.test.ts tests/cli-cloud-mirror-flag.test.ts tests/detached-start.test.ts tests/relay-cli-surface.test.ts --reporter=dot && npm run typecheck && npm run typecheck:tests && git diff --check

> @relayflows/sdk@2.0.65 build
> tsc && node scripts/make-cli-executable.mjs

 RUN  v2.1.9 /home/khaliqgant/Projects/AgentWorkforce/flows-cloud-mirror-optin/packages/sdk

 ✓ tests/detached-start.test.ts (5 tests) 34ms
 ✓ tests/cloud-mirror-session.test.ts (13 tests) 28ms
 ✓ tests/cli-cloud-mirror-flag.test.ts (4 tests) 4ms
 ✓ tests/cli-detach.test.ts (14 tests) 13ms
 ✓ tests/relay-cli-surface.test.ts (94 tests) 41ms
 ✓ tests/named-local-run.test.ts (10 tests) 295ms
 ✓ tests/observer-link.test.ts (49 tests) 291ms
 ✓ tests/cloud-mirror-live.test.ts (5 tests) 6554ms
   ✓ a local run on the Cloud dashboard > registers, publishes its steps and its log, and reports terminal last 528ms
   ✓ a local run on the Cloud dashboard > keeps signed-in runs local unless the invocation explicitly opts in 1247ms
   ✓ a local run on the Cloud dashboard > keeps resume and detach local, while the environment switch remains an explicit opt-in 2144ms
   ✓ a local run on the Cloud dashboard > mirrors resume and detached execution when the flag explicitly opts them in 1866ms
   ✓ a local run on the Cloud dashboard > publishes a composed authored flow as one connected dashboard DAG 690ms

 Test Files  8 passed (8)
      Tests  194 passed (194)
   Duration  7.02s

> @relayflows/sdk@2.0.65 typecheck
> tsc --noEmit && tsc -p tsconfig.type-tests.json

> @relayflows/sdk@2.0.65 typecheck:tests
> tsc -p tsconfig.tests.json

$ git diff --check
# exit 0, no output

Mutation evidence

I removed only the conditional mirror construction, leaving the rest of the change in place. The two consent regressions failed:

$ npm run build && RELAYFLOWD_BIN=/home/khaliqgant/.relayflows-toolchain/target/4032934808/debug/relayflowd npx vitest run tests/cloud-mirror-live.test.ts tests/named-local-run.test.ts -t 'keeps signed-in runs local|resolves a signed-in saved name' --reporter=verbose

 Test Files  2 failed (2)
      Tests  2 failed | 13 skipped (15)

FAIL  tests/cloud-mirror-live.test.ts > ... > keeps signed-in runs local unless the invocation explicitly opts in
AssertionError: expected ... not to contain 'Dashboard:'
Received:
Dashboard: https://127.0.0.1:44503/dashboard/workflow/live-cloud-run/runner

FAIL  tests/named-local-run.test.ts > ... > resolves a signed-in saved name without treating login as mirror consent
AssertionError: expected [ …(8) ] to deeply equal [ '/api/v1/flows/by-name/named-demo' ]
Received additional requests:
  /api/v1/workflows/local-run
  /api/v1/workflows/runs/cloud-run/events
  /api/v1/workflows/runs/cloud-run/steps/snapshot
  /api/v1/workflows/runs/cloud-run/storage/runner.log
  /api/v1/workflows/runs/cloud-run/steps
  /api/v1/workflows/callback

After restoring the production hunk byte-for-byte, the same command passed:

$ npm run build && RELAYFLOWD_BIN=/home/khaliqgant/.relayflows-toolchain/target/4032934808/debug/relayflowd npx vitest run tests/cloud-mirror-live.test.ts tests/named-local-run.test.ts -t 'keeps signed-in runs local|resolves a signed-in saved name' --reporter=verbose

 ✓ tests/cloud-mirror-live.test.ts > ... > keeps signed-in runs local unless the invocation explicitly opts in 1248ms
 ✓ tests/named-local-run.test.ts > ... > resolves a signed-in saved name without treating login as mirror consent

 Test Files  2 passed (2)
      Tests  2 passed | 13 skipped (15)

Independent review

An independent exact-diff review found no remaining issues after requiring the negative detached case to wait for the child process to exit before asserting that no Cloud request occurred. The reviewer independently reran the same eight-file 194-test gate, both TypeScript checks, leak scans, and git diff --check; all passed. No #707 node-spawn hunks are present in this branch.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Local runs no longer upload to the Cloud dashboard just because the user is signed in. A run projects to the dashboard only when the invocation explicitly requests it with --cloud-mirror or FLOWS_CLOUD_MIRROR=1.

  • A stored Cloud login is now authentication, not consent to upload; plain, named, resumed, and detached runs stay local without the opt-in.
  • Named-flow source lookup and explicit flag/environment mirroring still work through the existing best-effort path.
  • Updates docs/CLOUD.md and the hint printed when the Observer link has no workspace key.