Skip to content

fix(api-service): run seed script API from build folder instead of dev mode#10415

Draft
LetItRock wants to merge 1 commit intonextfrom
cursor/seed-script-api-build-7371
Draft

fix(api-service): run seed script API from build folder instead of dev mode#10415
LetItRock wants to merge 1 commit intonextfrom
cursor/seed-script-api-build-7371

Conversation

@LetItRock
Copy link
Copy Markdown
Contributor

What changed? Why was the change needed?

The seed-agent-data.mjs script was using pnpm start:api:dev (which runs nest start --watch) to start the API server temporarily for seeding. This caused intermittent failures because the dev server triggers a double build on startup, and the API could restart mid-seeding — leading to fetch failed errors (specifically during the "set active organization" step).

Changes:

  • Replaced pnpm start:api:dev with node dist/main.js to run the API directly from the pre-built output, eliminating file watching and rebuild-related restarts
  • Added build output validation — the script now checks that dist/main.js exists and throws a clear error if the API hasn't been built yet
  • Added ensureDistEnvFile() to copy src/.env to dist/.env when missing, since the NestJS env loader resolves .env relative to the dist directory
  • Added stability checks — after the initial health check passes, the script performs 3 consecutive health checks over 6 seconds to confirm the API won't restart before proceeding with seeding

Screenshots

N/A — script-only change, no visual impact.

Expand for optional sections

Special notes for your reviewer

This was identified from a cloud agent environment setup failure where the API restarted between the first and second build triggered by nest start --watch, causing the seed to fail at the "set active organization" step. Running from the build folder avoids this entirely since there's no file watching or recompilation.

Slack Thread

Open in Web Open in Cursor 

…v mode

- Replace 'pnpm start:api:dev' (nest start --watch) with 'node dist/main.js'
  to avoid double-build restarts that caused 'fetch failed' during seeding
- Add build output validation before starting the API
- Copy src/.env to dist/.env when missing to ensure env config is available
- Add stability checks (3 consecutive health checks) after initial readiness
  to confirm the API won't restart mid-seeding

Co-authored-by: Paweł Tymczuk <LetItRock@users.noreply.github.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 20, 2026

Deploy Preview for dashboard-v2-novu-staging failed. Why did it fail? →

Name Link
🔨 Latest commit a3fa663
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/69bd19a8aa1a9300082815e7

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db749094-8080-42a9-a336-462c209ce83e

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 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.

@github-actions
Copy link
Copy Markdown
Contributor

Hey there and thank you for opening this pull request! 👋

We require pull request titles to follow specific formatting rules and it looks like your proposed title needs to be adjusted.

Your PR title is: fix(api-service): run seed script API from build folder instead of dev mode

Requirements:

  1. Follow the Conventional Commits specification
  2. As a team member, include Linear ticket ID at the end: fixes TICKET-ID or include it in your branch name

Expected format: feat(scope): Add fancy new feature fixes NOV-123

Details:

PR title must end with 'fixes TICKET-ID' (e.g., 'fixes NOV-123') or include ticket ID in branch name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants