Skip to content

fix: add debug logging for sandbox 400 errors#106

Open
sweetmantech wants to merge 1 commit intomainfrom
fix/debug-sandbox-400
Open

fix: add debug logging for sandbox 400 errors#106
sweetmantech wants to merge 1 commit intomainfrom
fix/debug-sandbox-400

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Mar 19, 2026

Summary

Adds error logging with sandbox context (sandboxId, cwd, command details) when sandbox.runCommand() returns a 400 error, to help diagnose the recurring clone failures.

Test plan

  • All 165 tests pass
  • Next failure will include diagnostic info in the logs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling with improved logging when command execution fails, now capturing and reporting execution context details for better debugging and error recovery.

Logs sandboxId, cwd, command details when runCommand fails
to help diagnose transient Vercel Sandbox API errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

The change adds error handling with structured logging around the sandbox command execution in runClaudeCodeAgent.ts. When command execution fails, the function logs a failure step containing error details and execution metadata before rethrowing the original error.

Changes

Cohort / File(s) Summary
Error Handling & Logging
src/sandboxes/runClaudeCodeAgent.ts
Added try/catch wrapper around sandbox.runCommand() invocation to capture and log failure events with execution metadata (sandboxId, cwd, cmd, argsLength, messageLength) before rethrowing errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 A catch for the errors that hop through the night,
With metadata logged, we'll know what went right,
The sandbox runs clean with a safety net tight,
Our agent now wiser, tracking each plight! 📋✨

🚥 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 accurately describes the main change: adding debug logging for sandbox errors. It directly relates to the core modification in the changeset.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/debug-sandbox-400
📝 Coding Plan
  • Generate coding plan for human review comments

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 (1)
src/sandboxes/runClaudeCodeAgent.ts (1)

46-48: Remove as any and use proper SDK types for commandOpts.

The properties in commandOpts (cmd, args, cwd, detached, env) all match the valid @vercel/sandbox 1.8.0 runCommand() options. Instead of declaring commandOpts as Record<string, unknown> and casting with as any, import the proper type from @vercel/sandbox (e.g., RunCommandOptions or the object parameter type) to let the compiler validate option correctness at build time. This catches contract drift earlier without sacrificing runtime behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/runClaudeCodeAgent.ts` around lines 46 - 48, Change the loose
typing on commandOpts to the real SDK type and remove the cast: import the
appropriate RunCommandOptions (or the exact parameter type name) from
`@vercel/sandbox` and declare commandOpts as that type instead of Record<string,
unknown>; then call sandbox.runCommand(commandOpts) without using "as any".
Update any related local properties (cmd, args, cwd, detached, env) to satisfy
the imported type so the compiler validates the options for sandbox.runCommand.
🤖 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/runClaudeCodeAgent.ts`:
- Around line 50-58: The catch block that reports a failed sandbox.runCommand
call should not allow logStep failures to replace the original error; wrap the
logStep(...) call in its own try/catch so logging is best-effort and any
exception thrown by logStep is swallowed or recorded separately, then rethrow
the original error variable (error) from the catch in runClaudeCodeAgent.ts;
ensure you reference the existing symbols logStep, sandbox.runCommand, and the
caught error variable so the original error is always propagated.

---

Nitpick comments:
In `@src/sandboxes/runClaudeCodeAgent.ts`:
- Around line 46-48: Change the loose typing on commandOpts to the real SDK type
and remove the cast: import the appropriate RunCommandOptions (or the exact
parameter type name) from `@vercel/sandbox` and declare commandOpts as that type
instead of Record<string, unknown>; then call sandbox.runCommand(commandOpts)
without using "as any". Update any related local properties (cmd, args, cwd,
detached, env) to satisfy the imported type so the compiler validates the
options for sandbox.runCommand.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 090fc701-681a-4acd-b3b3-34b4502d9a5b

📥 Commits

Reviewing files that changed from the base of the PR and between 5df28de and 21fca76.

📒 Files selected for processing (1)
  • src/sandboxes/runClaudeCodeAgent.ts

Comment on lines +50 to +58
logStep(`${label} - sandbox.runCommand failed`, false, {
error: error instanceof Error ? error.message : String(error),
sandboxId: sandbox.sandboxId,
cwd,
cmd: "claude",
argsLength: args.length,
messageLength: message.length,
});
throw error;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Preserve the original runCommand error if step logging fails.

Line 50 logging is inside the catch path; if logStep() throws, it can mask the root sandbox.runCommand failure. Make this diagnostics logging best-effort, then rethrow the original error.

Suggested fix
   } catch (error) {
-    logStep(`${label} - sandbox.runCommand failed`, false, {
-      error: error instanceof Error ? error.message : String(error),
-      sandboxId: sandbox.sandboxId,
-      cwd,
-      cmd: "claude",
-      argsLength: args.length,
-      messageLength: message.length,
-    });
+    try {
+      logStep(`${label} - sandbox.runCommand failed`, false, {
+        error: error instanceof Error ? error.message : String(error),
+        sandboxId: sandbox.sandboxId,
+        cwd,
+        cmd: "claude",
+        argsLength: args.length,
+        messageLength: message.length,
+      });
+    } catch {
+      // Best-effort logging only; do not mask the original failure.
+    }
     throw error;
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/runClaudeCodeAgent.ts` around lines 50 - 58, The catch block
that reports a failed sandbox.runCommand call should not allow logStep failures
to replace the original error; wrap the logStep(...) call in its own try/catch
so logging is best-effort and any exception thrown by logStep is swallowed or
recorded separately, then rethrow the original error variable (error) from the
catch in runClaudeCodeAgent.ts; ensure you reference the existing symbols
logStep, sandbox.runCommand, and the caught error variable so the original error
is always propagated.

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