Skip to content

Conversation

@issuetopr-dev
Copy link

@issuetopr-dev issuetopr-dev bot commented Dec 2, 2025

Summary

  • After copying a repository into a running agent container, automatically start a dev server inside that container.
  • Adds a reusable utility startDevServerInContainer that:
    • Detects the package manager (pnpm > yarn > npm) by lockfiles
    • Runs installation with an appropriate command (frozen/ci when possible)
    • Launches the dev script in the background via nohup
    • Writes logs to .dev.log and PID to .dev.pid under the repo root (default /workspace)
  • Updates the /api/playground/copy-repo endpoint to trigger the dev server after the copy completes.

Why

  • Next.js supports HMR, so we can preview the app while the agent is making edits.
  • The workflow asked for pnpm i and pnpm dev (or relevant scripts) to run as soon as the code is in the container.

Implementation details

  • Utility added in lib/utils/container.ts: startDevServerInContainer
    • Uses execInContainerWithDockerode to run a shell script that:
      • Selects pm by checking for pnpm-lock.yaml, then yarn.lock, else npm
      • Chooses the best install command (pnpm install --frozen-lockfile || pnpm install, yarn install --frozen-lockfile || yarn install, npm ci || npm i)
      • Starts the dev server backgrounded with nohup, storing logs/PID
  • API route app/api/playground/copy-repo/route.ts updated to call the new helper after copying the repo.
    • Returns HTTP 202 if the copy succeeds but starting the dev server fails, so the user still gets feedback and can inspect .dev.log.

Notes

  • The container image already includes pnpm (via corepack) and the needed tooling.
  • This change is additive and isolated to the playground flow; no impact on other workflows.

Checks

  • Linted the repository: next lint passed with no warnings or errors.

Closes #1374


Note

Automatically starts a background dev server in the container after copying a repo, with package manager auto-detect, install, and logging.

  • API:
    • Update POST /api/playground/copy-repo to call startDevServerInContainer after copyRepoToExistingContainer and return 202 if dev start fails (copy still succeeds).
  • Container Utils:
    • Add startDevServerInContainer in lib/utils/container.ts and shared/src/lib/utils/container.ts:
      • Detects pnpm/yarn/npm via lockfiles.
      • Runs install (prefers frozen/ci) then dev in background with nohup.
      • Writes logs to .dev.log and PID to .dev.pid under mountPath (default /workspace).

Written by Cursor Bugbot for commit 9b162c1. This will update automatically on new commits. Configure here.

…\n\n- Add startDevServerInContainer helper to run install and dev in background based on lockfiles\n- Update copy-repo API route to trigger dev server startup post-copy\n\nThis enables previewing the Next.js app via HMR as soon as the code is copied into the container.
@issuetopr-dev issuetopr-dev bot added the AI generated AI-generated Pull Requests label Dec 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

{ error: `Copied repo but failed to start dev server: ${err}` },
{ status: 202 }
)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Exit code ignored, failures return success incorrectly

The try-catch wrapping startDevServerInContainer won't catch script execution failures because execInContainerWithDockerode returns { stdout, stderr, exitCode } instead of throwing exceptions on non-zero exit codes. The PR description states this endpoint should return HTTP 202 when dev server startup fails, but the returned exitCode is never checked. The endpoint will return HTTP 200 with { success: true } even when the shell script fails. Other callers of execInContainerWithDockerode in the codebase properly check exitCode === 0 to determine success.

Fix in Cursor Fix in Web

// - backgrounds the process with nohup and stores logs/pid
const script = [
"set -e",
`cd ${mountPath}`,
Copy link

Choose a reason for hiding this comment

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

Bug: Unquoted shell path breaks on paths with spaces

The mountPath parameter is interpolated directly into the shell command without quotes in cd ${mountPath}. While currently hardcoded to /workspace, the function interface accepts any string. If mountPath contained spaces (e.g., /my workspace), the cd command would receive multiple arguments and fail. Paths containing shell metacharacters like semicolons could also cause unexpected behavior. The path should be quoted like cd "${mountPath}" to handle paths safely.

Additional Locations (1)

Fix in Cursor Fix in Web

@vercel vercel bot temporarily deployed to Preview – issue-to-pr-storybook December 2, 2025 19:09 Inactive
@vercel vercel bot temporarily deployed to Preview – issue-to-pr-realtime December 2, 2025 19:09 Inactive
// Start dev in background after install completes
'nohup sh -c "$INSTALL && "$PM" run -s dev" > .dev.log 2>&1 & echo $! > .dev.pid',
'echo "Dev server starting with $PM. Logs: .dev.log, PID: $(cat .dev.pid)"',
].join(" && ")
Copy link

Choose a reason for hiding this comment

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

Bug: Broken quoting prevents dev server start

The nohup sh -c ... command string has mismatched quotes around $INSTALL and $PM, which makes the shell command syntactically invalid. This likely causes the nohup launch to fail, so the dev server never starts and .dev.pid/.dev.log may not reflect a running process.

Additional Locations (1)

Fix in Cursor Fix in Web

@vercel vercel bot temporarily deployed to Preview – issue-to-pr-realtime December 30, 2025 02:34 Inactive
@vercel vercel bot temporarily deployed to Preview – issue-to-pr-storybook December 30, 2025 02:34 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI generated AI-generated Pull Requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start dev server in container after code copy

2 participants