[chat] Fire-and-forget sandbox setup on login#1564
Conversation
After POST /api/account succeeds, trigger sandbox provisioning via POST /api/sandboxes/setup. The handler is idempotent so redundant calls are no-ops. This ensures customers always have a ready sandbox. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughIntroduces automatic sandbox provisioning when users are fetched. A new utility function triggers a fire-and-forget API request to provision sandbox environments for accounts. The integration hooks into the user data fetch flow, initiating setup whenever an account ID is available. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3cbe6dfd2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * @param accountId - The account ID to provision a sandbox for | ||
| */ | ||
| export function triggerSandboxSetup(accountId: string): void { | ||
| fetch("/api/sandboxes/setup", { |
There was a problem hiding this comment.
Call sandbox setup through an existing API path
This POST targets "/api/sandboxes/setup", but in this commit tree there is no matching Next.js handler under app/api and no rewrite in next.config.mjs/vercel.json to forward that path, so the request will return 404 on login and provisioning will never be triggered. Because fetch only .catches network failures (not non-2xx responses), this fails silently and defeats the new pre-warm behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/sandbox/triggerSandboxSetup.ts (1)
7-12: Consider adding input validation foraccountId.The function accepts any string, including empty strings or whitespace, which would still fire a POST request to the API. Adding a guard clause would prevent unnecessary network calls.
🛡️ Proposed validation
export function triggerSandboxSetup(accountId: string): void { + if (!accountId?.trim()) return; + fetch("/api/sandboxes/setup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ account_id: accountId }), }).catch(() => {}); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/sandbox/triggerSandboxSetup.ts` around lines 7 - 12, The triggerSandboxSetup function currently sends a POST for any accountId string; add input validation at the top of triggerSandboxSetup to guard against empty or whitespace-only values (e.g., if (!accountId || accountId.trim().length === 0) return;) so the fetch("/api/sandboxes/setup", ...) is not invoked for invalid input; ensure you reference the accountId parameter and keep the existing fetch call unchanged otherwise (optionally log or warn before returning).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/sandbox/triggerSandboxSetup.ts`:
- Around line 7-12: The triggerSandboxSetup function currently sends a POST for
any accountId string; add input validation at the top of triggerSandboxSetup to
guard against empty or whitespace-only values (e.g., if (!accountId ||
accountId.trim().length === 0) return;) so the fetch("/api/sandboxes/setup",
...) is not invoked for invalid input; ensure you reference the accountId
parameter and keep the existing fetch call unchanged otherwise (optionally log
or warn before returning).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9b18f606-0130-4294-a118-ea8558485457
⛔ Files ignored due to path filters (1)
lib/sandbox/__tests__/triggerSandboxSetup.test.tsis excluded by!**/*.test.*and included bylib/**
📒 Files selected for processing (2)
hooks/useUser.tsxlib/sandbox/triggerSandboxSetup.ts
|
Closing — superseded by the post-cutover work in chat#1747. This PR targets the pre-cutover The intent — front-load sandbox provisioning so the user doesn't wait at the chat input — is now tracked as a new open item in chat#1747: "defer bootstrap wait from spinner to send button". A fresh PR will reanimate the pattern against the new flow. |
Summary
Trigger sandbox provisioning on every login so customers always have a ready sandbox by the time they first use
prompt_sandbox.Changes
lib/sandbox/triggerSandboxSetup.ts— fire-and-forget POST to/api/sandboxes/setuphooks/useUser.tsx— calltriggerSandboxSetup()after account data loadslib/sandbox/__tests__/triggerSandboxSetup.test.ts(2 tests)Notes
promptSandboxStreamingLinear
MYC-4419
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes