Skip to content

perf: skip openclaw install and onboard when already done#34

Merged
sweetmantech merged 2 commits intomainfrom
sweetmantech/myc-4291-task-conditionally-install-openclaw-and-run-openclaw
Feb 20, 2026
Merged

perf: skip openclaw install and onboard when already done#34
sweetmantech merged 2 commits intomainfrom
sweetmantech/myc-4291-task-conditionally-install-openclaw-and-run-openclaw

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Feb 20, 2026

Summary

  • Checks which openclaw before running npm install -g openclaw@latest — skips if binary exists
  • Checks ~/.openclaw/openclaw.json before running openclaw onboard — skips if config exists
  • Env injection and gateway start always run (accountId may differ, gateway doesn't persist across snapshots)
  • Saves ~60s on sandbox runs restored from snapshots

Test plan

  • Fresh sandbox (no snapshot): install and onboard both run
  • Snapshot-based sandbox: install and onboard both skip, gateway still starts

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • OpenClaw installation now skips if already installed on the system.
    • OpenClaw onboarding now skips if configuration already exists.

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 20, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📝 Walkthrough

Walkthrough

Two OpenClaw sandbox files receive optimization enhancements: the install script now pre-checks if the OpenClaw CLI is already installed via which openclaw, skipping the npm install if found; the setup script conditionally skips onboarding if the OpenClaw configuration file exists at ~/.openclaw/openclaw.json.

Changes

Cohort / File(s) Summary
Installation Pre-check
src/sandboxes/installOpenClaw.ts
Added shell command check using which openclaw to determine if OpenClaw CLI is already installed. If present (exit code 0), logs skip message and returns early; otherwise proceeds with existing npm install flow.
Setup Conditional Onboarding
src/sandboxes/setupOpenClaw.ts
Added config existence check for ~/.openclaw/openclaw.json to conditionally skip onboarding. Refactored onboarding execution into a guarded block with separate sandbox.runCommand call, capturing stdout/stderr and logging warnings on failure. Preserves downstream env injection and gateway startup logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐇 A rabbit hops through install paths so quick,
Checking if OpenClaw's there—no need for the trick!
Config exists? Skip the dance, save the time,
Early returns and guards—a logical rhyme! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf: skip openclaw install and onboard when already done' directly and clearly summarizes the main changes: adding checks to skip OpenClaw installation and onboarding when already present, improving performance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sweetmantech/myc-4291-task-conditionally-install-openclaw-and-run-openclaw

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/sandboxes/installOpenClaw.ts (1)

11-19: LGTM — optionally prefer command -v over which for portability.

The guard is correct and the fallback is safe (any non-zero exit, including which itself not being available, falls through to install). As a minor nit, command -v is a POSIX shell builtin and is more portable than the external which binary.

♻️ 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_KEY lacks a runtime guard, creating a hard-to-diagnose failure path.

RECOUP_API_KEY is validated on lines 67-69 before use, but VERCEL_AI_GATEWAY_API_KEY is accessed with a bare non-null assertion (!). If the variable is absent at runtime:

  1. openclaw receives the string "undefined" as the API key and will fail.
  2. The warn-not-throw on non-zero onboard exit (lines 53-62) swallows that failure silently.
  3. 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>
@sweetmantech sweetmantech merged commit 9546d9f into main Feb 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant