perf: skip openclaw install and onboard when already done#34
Conversation
Saves ~60s on sandbox runs restored from snapshots by checking: - `which openclaw` before running npm install - `~/.openclaw/openclaw.json` exists before running onboard Env injection and gateway start always run since accountId may change and gateway process doesn't persist across snapshots. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughTwo OpenClaw sandbox files receive optimization enhancements: the install script now pre-checks if the OpenClaw CLI is already installed via Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/sandboxes/installOpenClaw.ts (1)
11-19: LGTM — optionally prefercommand -voverwhichfor portability.The guard is correct and the fallback is safe (any non-zero exit, including
whichitself not being available, falls through to install). As a minor nit,command -vis a POSIX shell builtin and is more portable than the externalwhichbinary.♻️ Optional: use `command -v` via `sh -c`
- const check = await sandbox.runCommand({ - cmd: "which", - args: ["openclaw"], - }); + const check = await sandbox.runCommand({ + cmd: "sh", + args: ["-c", "command -v openclaw"], + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/sandboxes/installOpenClaw.ts` around lines 11 - 19, The portability nit: replace the external "which" invocation with a POSIX-safe "command -v" call so the guard is more portable; change the sandbox.runCommand call that currently uses cmd: "which" args: ["openclaw"] to invoke the shell and run "command -v openclaw" (e.g., sandbox.runCommand with cmd "sh" and args ["-c", "command -v openclaw"]) and keep the existing check on check.exitCode === 0 and the logger.log("OpenClaw CLI already installed, skipping")/return behavior unchanged.src/sandboxes/setupOpenClaw.ts (1)
33-42:VERCEL_AI_GATEWAY_API_KEYlacks a runtime guard, creating a hard-to-diagnose failure path.
RECOUP_API_KEYis validated on lines 67-69 before use, butVERCEL_AI_GATEWAY_API_KEYis accessed with a bare non-null assertion (!). If the variable is absent at runtime:
openclawreceives the string"undefined"as the API key and will fail.- The
warn-not-throwon non-zero onboard exit (lines 53-62) swallows that failure silently.- The error only surfaces later as
"Failed to inject env vars into openclaw.json"— obscuring the real root cause.🛡️ Suggested guard — mirror the `RECOUP_API_KEY` pattern
+ if (!process.env.VERCEL_AI_GATEWAY_API_KEY) { + throw new Error("Missing VERCEL_AI_GATEWAY_API_KEY environment variable"); + } + const onboardArgs = [ "onboard", "--non-interactive", "--mode", "local", "--auth-choice", "ai-gateway-api-key", "--ai-gateway-api-key", - process.env.VERCEL_AI_GATEWAY_API_KEY!, + process.env.VERCEL_AI_GATEWAY_API_KEY,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/sandboxes/setupOpenClaw.ts` around lines 33 - 42, The code uses a non-null assertion on VERCEL_AI_GATEWAY_API_KEY when building onboardArgs and logs a redacted command via logger.log, which can pass "undefined" to openclaw and hide the real failure; mirror the RECOUP_API_KEY pattern: check process.env.VERCEL_AI_GATEWAY_API_KEY at runtime and throw or process.exit(1) with a clear error if missing, only build onboardArgs (and the redacted logger.log string) when the key is present (remove the `!`), and change the non-fatal onboard exit handling (the code that currently warns on non-zero exit) to propagate the error or exit so the underlying key-missing failure isn’t swallowed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/sandboxes/setupOpenClaw.ts`:
- Around line 22-23: The log message "OpenClaw already onboarded, skipping" is
misleading because setupOpenClaw still proceeds with env injection and gateway
start; update the message emitted in the configCheck.exitCode === 0 branch (the
logger.log call inside setupOpenClaw) to clearly state which steps are being
skipped (e.g., skipping onboarding only) and that env injection and gateway
start will still run so a reader can correlate subsequent actions.
---
Nitpick comments:
In `@src/sandboxes/installOpenClaw.ts`:
- Around line 11-19: The portability nit: replace the external "which"
invocation with a POSIX-safe "command -v" call so the guard is more portable;
change the sandbox.runCommand call that currently uses cmd: "which" args:
["openclaw"] to invoke the shell and run "command -v openclaw" (e.g.,
sandbox.runCommand with cmd "sh" and args ["-c", "command -v openclaw"]) and
keep the existing check on check.exitCode === 0 and the logger.log("OpenClaw CLI
already installed, skipping")/return behavior unchanged.
In `@src/sandboxes/setupOpenClaw.ts`:
- Around line 33-42: The code uses a non-null assertion on
VERCEL_AI_GATEWAY_API_KEY when building onboardArgs and logs a redacted command
via logger.log, which can pass "undefined" to openclaw and hide the real
failure; mirror the RECOUP_API_KEY pattern: check
process.env.VERCEL_AI_GATEWAY_API_KEY at runtime and throw or process.exit(1)
with a clear error if missing, only build onboardArgs (and the redacted
logger.log string) when the key is present (remove the `!`), and change the
non-fatal onboard exit handling (the code that currently warns on non-zero exit)
to propagate the error or exit so the underlying key-missing failure isn’t
swallowed.
Moves the conditional onboard logic (config check + early return) out of setupOpenClaw into its own file for SRP compliance. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
which openclawbefore runningnpm install -g openclaw@latest— skips if binary exists~/.openclaw/openclaw.jsonbefore runningopenclaw onboard— skips if config existsTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit