Skip to content

feat(v2): Firebase token attachment + WS frame tracing for cloud-brain (Switch 2-CLI)#9

Merged
LightDriverCS merged 3 commits into
mainfrom
codex/switch2-cli-bridge-cli
May 6, 2026
Merged

feat(v2): Firebase token attachment + WS frame tracing for cloud-brain (Switch 2-CLI)#9
LightDriverCS merged 3 commits into
mainfrom
codex/switch2-cli-bridge-cli

Conversation

@LightDriverCS

Copy link
Copy Markdown
Contributor

Summary

CLI-side completion of the Switch 2-CLI bridge. Pairs with the BenchAGI mono cloud bridge endpoint and the OpenClaw gateway bridge to make ADR-006 transparency real: the CLI attaches its Firebase token to `chat.send`, the gateway uses it to authenticate to the cloud bridge endpoint, and remote-brain runs flow back as normal `chat`/`agent` events.

Pairs with:

  • BenchAGI mono PR #1016
  • OpenClaw fork PR #26

What's new

  • `src/v2/auth/firebase-token.ts` — loads Firebase Direct creds from the existing keychain (V1.0-beta auth path); refreshes ID token via Firebase Identity Toolkit when one of `BENCHAGI_FIREBASE_API_KEY`, `NEXT_PUBLIC_FIREBASE_API_KEY`, or `FIREBASE_API_KEY` is set.
  • `chat-runner.ts` — `sendMessage` resolves Firebase token best-effort and adds `cloudAuth.firebaseIdToken` to chat.send. If no creds available, chat.send fires without the field; gateway falls back to local dispatch.
  • `local-gateway.ts` — passes `cloudAuth` field through chat.send param shape unchanged.
  • `cli.ts` — adds raw WS frame tracing for diagnostics:
    • `--trace-frames ` flag
    • `BENCHAGI_TRACE_FRAMES=` env
      Each frame received is appended as JSONL. Useful for correlating CLI events to `relayDirectives` during the smoke test.

Verification

  • `npm run build` — clean
  • Existing test suite still passes; no behavior change for default-local path.

Limitations / follow-ups

  • chat.send acceptance race (V1.1 ANVIL-2 P1 deferred) — still pending; separate Hammer-Anvil cycle.
  • Token refresh silently no-ops if no Firebase API key env is set; CLI users without one configured fall through to local-only even on remote-brain agents.
  • Frame trace file is append-only; no rotation.

Anvil Handoff

This PR will get one Codex Anvil pass before merge.

🤖 Generated with Claude Code

LightDriverCS and others added 3 commits May 6, 2026 13:03
Writes `scripts/cloud-brain-smoke.mjs` per V2 runbook §"Validation
script". Exercises the cloud-brain end-to-end path once Phase 1B
merges (BenchAGI #872 W1 + #874 W4 + #878 W2 + #988 relay +
openclaw#24 W3) and an agent's deployment is flipped to
runtime: 'remote-brain'.

What the script does:
- Lists known agents from the local openclaw gateway.
- Queries Firestore (admin REST + gcloud token per the documented
  recipe) for `agentDeployments/{instanceId}_{agentId}.runtime`.
- For each agent with `runtime === 'remote-brain'`, spawns
  `benchagi --agent <name> --liveness off "respond: smoke-ok"`
  with stdout captured and a 60s timeout.
- Asserts: exit 0, non-empty stdout, no error markers, latency
  under 60s.
- Emits JSON summary; exits 0 only if all tested agents passed.

Required env: INSTANCE_ID. Optional: GCP_PROJECT (default
benchagi-8ea90), SMOKE_AGENT_FILTER, SMOKE_PROMPT, SMOKE_TIMEOUT_MS.

Gated on cloud-brain Phase 1B merging + a deployment flipped to
remote-brain. Until then, the script reports "no remote-brain
agents found — Phase 1B may not be merged + flipped yet" and exits
0 (not a failure).

Stays as a draft PR until Cory merges Phase 1B and flips at least
one deployment, at which point we run the smoke + capture the
transcript for ANVIL-5.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codex Anvil 4 finding: HOLD. Two P0s + two P1s + a missing-test
flag.

Most important: Codex couldn't find a readable local gateway path
that routes chat.send through cloud-brain when an agent's
deployment has runtime: 'remote-brain'. Without that dispatch
bridge, the smoke script will pass on local execution without
exercising cloud-brain at all. The bridge MAY be in W2 (#878)
which Codex couldn't see in full diff via the connector; needs
verification.

Other findings:
- P1: bench-cli's chat.history call expects events/frames but the
  readable OpenClaw chat.history handler returns transcript
  messages and ignores sinceSeq. V1.1 reconnect replay is
  best-effort no-op until this contract is reconciled.
- P1: Firestore doc id format assumption in the smoke
  (instances/{instanceId}/agentDeployments/{instanceId}_{agentId})
  may not match real W1 backfill output if deploymentIds differ.
- P2: Firestore failures recorded as skips can produce false
  exit-0 if no agents tested.
- P2: smoke assumes repo-root cwd.

Stronger smoke proposed: assert directive artifacts in Firestore
(relayDirectives doc with directiveType: llm_turn), assert directive
reaches completed, AND assert CLI saw normal chat/agent.lifecycle
frames. That proves both halves of ADR-006 transparency.

Doesn't change the smoke script in this commit — the structural
concern (missing dispatch bridge) needs resolution first. The
smoke script is preserved as-is (P0 #2 acknowledged as a review
finding) so Cory can decide which path to take.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…n (Switch 2-CLI)

Pairs with the BenchAGI mono cloud bridge endpoint + the OpenClaw
gateway bridge to enable transparent cloud-brain dispatch from the
CLI. The CLI side is small: attach the user's Firebase ID token to
chat.send so the gateway can authenticate to the cloud bridge.

## What's new

- `src/v2/auth/firebase-token.ts` — loads Firebase Direct creds
  from the existing keychain. Refreshes ID token using the public
  Firebase Identity Toolkit when one of these is set:
    BENCHAGI_FIREBASE_API_KEY
    NEXT_PUBLIC_FIREBASE_API_KEY
    FIREBASE_API_KEY
- `src/v2/chat-runner.ts` — sendMessage now resolves the Firebase
  token (best-effort) and adds `cloudAuth.firebaseIdToken` to the
  chat.send request. If no creds are available, chat.send fires
  without the field and the gateway falls back to local dispatch
  per ADR-006's transparency contract.
- `src/v2/transport/local-gateway.ts` — accepts the cloudAuth field
  in chat.send param shape; passes through unchanged.
- `src/v2/cli.ts` — adds raw WS frame tracing for diagnostics:
    --trace-frames <path>
    BENCHAGI_TRACE_FRAMES=<path>
  Each WS frame the CLI receives is appended as a JSONL line to
  the file. Useful for correlating CLI events to relayDirectives
  during the smoke test.

## Verification

- `npm run build` — clean
- Existing test suite still passes (no behavior change for the
  default-local path; only adds the cloudAuth field when a token
  is available).

## Limitations / follow-ups

- chat.send acceptance race (V1.1 ANVIL-2 P1 deferred) — still not
  fixed in this PR. Re-issuing chat.send on reconnect with same
  idempotencyKey is a separate cycle.
- Token refresh path silently no-ops if no Firebase API key env
  var is set. CLI users who don't have one configured will fall
  through to local-only dispatch even on remote-brain agents
  (which is the safe default).
- Frame trace file is append-only; no rotation. Each smoke run
  should use a fresh path.

## Pairs with

- BenchAGI mono PR [#1016](BenchAGI/BenchAGI_Mono_Repo#1016) — cloud bridge endpoint
- OpenClaw fork PR [#26](BenchAGI/openclaw#26) — gateway-side dispatch + polling
@LightDriverCS LightDriverCS added the anvil Queue for Codex Anvil smoke testing (Hammer-Anvil PR handoff) label May 6, 2026
@LightDriverCS
LightDriverCS merged commit ee42181 into main May 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anvil Queue for Codex Anvil smoke testing (Hammer-Anvil PR handoff)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant