feat(setup): R2-optional deploys + headless service key generation (CLA-107)#37
Conversation
…LA-107)
Two first-run convenience gaps bundled because both live in setup-time
ergonomics:
* Image storage (R2) is now optional. The wrangler.toml.example ships
[[r2_buckets]] commented out, setup.sh prompts the operator, and
the worker detects the missing IMAGES binding at runtime —
remember_with_image and recall_image are hidden from the MCP tools
listing when R2 is absent, and return a clean error if a stale
client calls them anyway. This unblocks deploys on truly free CF
accounts (R2 is the one stack component that needs billing
enabled, even within its 10GB free tier).
* setup.sh prompts whether to mint a starter rover service key. If
yes, runs the existing keygen subcommand (with new --quiet flag
for scripting), captures the raw key + env entry from stdout,
pushes the hash to ONEIRO_API_KEYS, and surfaces the raw key in
the final summary with a "store now, unrecoverable" warning. The
orient hook (CLA-105), rover, and any non-interactive caller now
work out of the box from a fresh deploy.
Incidental cleanup: removed ONEIRO_ADMIN_KEY generation, display, and
secret push from setup.sh + wrangler.toml.example. CLA-103 retired the
/restore admin endpoint that was its only consumer; the secret has
been dead weight since.
CLA-112 (backlog) tracks the deeper fix for multi-key UX: moving the
hash list out of the wrangler secret and into a D1 table so add /
list / revoke are first-class DB operations.
📝 WalkthroughWalkthroughOptional R2 image storage is now opt-in in setup; keygen gains a machine-friendly ChangesOptional R2 and API Key Provisioning
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/setup.sh`:
- Around line 366-380: The script currently treats any non-zero result from the
command `wrangler r2 bucket create` (whose output is captured in R2_OUT) as
“likely already exists” and proceeds to enable the `IMAGES` binding; change this
so you inspect R2_OUT for an explicit “already exists” (or equivalent) message
and only proceed with the awk block that enables the `[[r2_buckets]]`/binding
`IMAGES` when that text is present or when the create succeeded; otherwise call
`warn` with the full R2_OUT and exit non-zero to fail fast on real errors
(billing/auth/permission), i.e., update the if/else around `wrangler r2 bucket
create` and gate the awk mv step on that check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d9dc5578-4ba8-4958-a0b7-4566c437b113
📒 Files selected for processing (5)
scripts/setup.shsrc/api_key.rssrc/main.rssrc/worker_mcp.rswrangler.toml.example
…lready-exists (CLA-107) PR #37 review (CodeRabbit): the previous code treated every non-zero exit from `wrangler r2 bucket create` as "likely already exists" and fell through to uncomment the IMAGES binding. That silently masked the failure mode CLA-107 is specifically designed to handle — billing not enabled on the Cloudflare account — by enabling the binding anyway and surfacing the failure two steps later as a confusing wrangler deploy error. Now three outcomes: success → proceed, already-exists (detected by explicit grep on R2_OUT) → proceed with a warning, anything else → print the full R2_OUT, point at the common causes (billing, R2 permissions), exit 1. The binding-uncomment + ok message only fire when create actually succeeded or the bucket was already there.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/setup.sh (1)
551-558:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winDiscarding stderr hides keygen failures.
Line 551 redirects stderr to
/dev/null, so if keygen fails (compilation error, runtime panic, missing dependency), the operator sees only "keygen produced no output" with no diagnostic. Consider capturing stderr or letting it pass through:- if KEYGEN_OUT=$(cargo run --quiet --bin oneiro -- keygen --role rover --quiet 2>/dev/null); then + if KEYGEN_OUT=$(cargo run --quiet --bin oneiro -- keygen --role rover --quiet 2>&1); then RAW_API_KEY=$(printf '%s\n' "$KEYGEN_OUT" | sed -n '1p') API_KEY_ENTRY=$(printf '%s\n' "$KEYGEN_OUT" | sed -n '2p') + else + err "keygen failed:" + printf '%s\n' "$KEYGEN_OUT" | sed 's/^/ /' + exit 1 fiAlternatively, let stderr flow to the terminal (
2>&2) and keep stdout capture separate.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/setup.sh` around lines 551 - 558, The script hides keygen errors by redirecting stderr to /dev/null when running "cargo run --bin oneiro -- keygen --role rover" into KEYGEN_OUT; change the invocation so stderr is preserved or captured (e.g., allow stderr to flow to the terminal or capture it into a separate variable/file) and include those stderr contents in the failure path that logs the error, so when RAW_API_KEY or API_KEY_ENTRY are empty you can print the actual keygen stderr output alongside the "keygen produced no output" message; update the block that sets KEYGEN_OUT and the error branch that calls err and exit to reference KEYGEN_OUT/stderr capture accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@scripts/setup.sh`:
- Around line 551-558: The script hides keygen errors by redirecting stderr to
/dev/null when running "cargo run --bin oneiro -- keygen --role rover" into
KEYGEN_OUT; change the invocation so stderr is preserved or captured (e.g.,
allow stderr to flow to the terminal or capture it into a separate
variable/file) and include those stderr contents in the failure path that logs
the error, so when RAW_API_KEY or API_KEY_ENTRY are empty you can print the
actual keygen stderr output alongside the "keygen produced no output" message;
update the block that sets KEYGEN_OUT and the error branch that calls err and
exit to reference KEYGEN_OUT/stderr capture accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f747aa02-ae99-4f81-b1c4-acb59242cde8
📒 Files selected for processing (1)
scripts/setup.sh
Summary
wrangler.toml.exampleships[[r2_buckets]]commented out,setup.shprompts the operator, and the worker detects the missingIMAGESbinding at runtime —remember_with_image/recall_imageare hidden from the MCP tools listing when R2 is absent, and return a clean error if a stale client somehow still calls them. Unblocks deploys on truly free CF accounts (R2 is the only stack component that needs billing enabled, even within its 10GB free tier).setup.shmints a starter service key on request. New optional Step 4 prompt runs the existingkeygensubcommand (with new--quietflag for scripting), captures the raw key + env entry from stdout, pushes the hash toONEIRO_API_KEYS, and surfaces the raw key in the final summary with a "store now, unrecoverable" warning. Orient hook (CLA-105), rover, and any non-interactive caller work out of the box from a fresh deploy.ONEIRO_ADMIN_KEYgeneration/display/push from setup + the wrangler example (CLA-103 retired its only consumer, the/restoreadmin endpoint).CLA-112 tracks the deeper multi-key UX fix (move the hash list to a D1 table so add/list/revoke are first-class DB ops).
Test plan
cargo test(127 tests pass — 78 + 49)cargo check --target wasm32-unknown-unknown --libcleanworker-build --releaseproduces the wasm bundle (28KB)bash -n scripts/setup.shsyntax checksetup.sh --dry-rundecline-both path (R2 skipped, no service key, noONEIRO_API_KEYSpush)setup.sh --dry-runaccept-both path (R2 bucket created +[[r2_buckets]]uncommented in wrangler.toml, service key generated,ONEIRO_API_KEYSpushed, raw key block displayed before summary)cargo run --bin oneiro -- keygen --role rover --quiet— emits raw key + env entry as two parseable stdout linesCloses CLA-107.
Summary by CodeRabbit
New Features
Behavior Changes
Bug Fixes
Chores