Skip to content

Fix race condition in clean:build task for monorepo packages#362

Closed
Shubhrakanti wants to merge 1 commit intomainfrom
shubhra/ajs-12-fix-build-issues
Closed

Fix race condition in clean:build task for monorepo packages#362
Shubhrakanti wants to merge 1 commit intomainfrom
shubhra/ajs-12-fix-build-issues

Conversation

@Shubhrakanti
Copy link
Contributor

@Shubhrakanti Shubhrakanti commented Apr 16, 2025

Problem

When running pnpm clean:build, the build process would fail due to race conditions between interdependent packages, while pnpm build worked correctly. This occurred because the combined clean:build task would attempt to clean and rebuild packages simultaneously, causing plugins to try building before their dependencies (like the core agents package) had completed rebuilding.

Error logs (before fix)

@livekit/agents-plugin-openai:build: error TS2307: Cannot find module '@livekit/agents' or its corresponding type declarations.
@livekit/agents-plugin-silero:build: error TS2307: Cannot find module '@livekit/agents/dist/types' or its corresponding type declarations.

Solution

Modified the scripts to run clean and build sequentially rather than as a combined task. This ensures all packages are fully cleaned before any builds start.

@changeset-bot
Copy link

changeset-bot bot commented Apr 16, 2025

⚠️ No Changeset found

Latest commit: 7f234b9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Shubhrakanti Shubhrakanti changed the title Fix build issues with Turborepo's Fix race condition in clean:build task for monorepo packages Apr 16, 2025
@Shubhrakanti Shubhrakanti requested a review from nbsp April 16, 2025 00:18
@Shubhrakanti
Copy link
Contributor Author

Do I need a changes for this? No right? We don't touch any actual code?

@Shubhrakanti Shubhrakanti requested a review from lukasIO April 16, 2025 00:19
Copy link
Contributor

@lukasIO lukasIO left a comment

Choose a reason for hiding this comment

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

this looks fine.

turbo is supposed to only run tasks in parallel that do not have any inter dependencies, so wondering why this was causing you problems in the first place

@lukasIO
Copy link
Contributor

lukasIO commented Apr 16, 2025

no need for a changeset 👍

@Shubhrakanti
Copy link
Contributor Author

Yeah the error was. When you first run build it runs fine, but then let's say you make an edit. Add a random log statement or something. then run pnpm clean:build you get something like

@livekit/agents-plugin-livekit:clean:build: src/index.ts:4:33 - error TS7016: Could not find a declaration file for module '@livekit/agents'. '/Users/shubhrakantiganguly/development/agents-js/agents/dist/index.js' implicitly has an 'any' type.
@livekit/agents-plugin-livekit:clean:build:   Try `npm i --save-dev @types/livekit__agents` if it exists or add a new declaration (.d.ts) file containing `declare module '@livekit/agents';`
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 4 import { InferenceRunner } from '@livekit/agents';
@livekit/agents-plugin-livekit:clean:build:                                   ~~~~~~~~~~~~~~~~~
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: src/index.ts:9:15 - error TS2339: Property 'resolve' does not exist on type 'ImportMeta'.
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 9   import.meta.resolve('./turn_detector.js'),
@livekit/agents-plugin-livekit:clean:build:                 ~~~~~~~
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: src/turn_detector.ts:6:26 - error TS7016: Could not find a declaration file for module '@livekit/agents'. '/Users/shubhrakantiganguly/development/agents-js/agents/dist/index.js' implicitly has an 'any' type.
@livekit/agents-plugin-livekit:clean:build:   Try `npm i --save-dev @types/livekit__agents` if it exists or add a new declaration (.d.ts) file containing `declare module '@livekit/agents';`
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 6 import type { ipc } from '@livekit/agents';
@livekit/agents-plugin-livekit:clean:build:                            ~~~~~~~~~~~~~~~~~
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: src/turn_detector.ts:7:62 - error TS7016: Could not find a declaration file for module '@livekit/agents'. '/Users/shubhrakantiganguly/development/agents-js/agents/dist/index.js' implicitly has an 'any' type.
@livekit/agents-plugin-livekit:clean:build:   Try `npm i --save-dev @types/livekit__agents` if it exists or add a new declaration (.d.ts) file containing `declare module '@livekit/agents';`
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 7 import { CurrentJobContext, InferenceRunner, llm, log } from '@livekit/agents';
@livekit/agents-plugin-livekit:clean:build:                                                                ~~~~~~~~~~~~~~~~~
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: src/turn_detector.ts:8:31 - error TS2307: Cannot find module 'node:url' or its corresponding type declarations.
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 8 import { fileURLToPath } from 'node:url';
@livekit/agents-plugin-livekit:clean:build:                                 ~~~~~~~~~~
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: Found 5 errors in 2 files.
@livekit/agents-plugin-livekit:clean:build: 
@livekit/agents-plugin-livekit:clean:build: Errors  Files
@livekit/agents-plugin-livekit:clean:build:      2  src/index.ts:4
@livekit/agents-plugin-livekit:clean:build:      3  src/turn_detector.ts:6
@livekit/agents-plugin-livekit:clean:build:  ELIFECYCLE  Command failed with exit code 2.
@livekit/agents-plugin-livekit:clean:build:  ELIFECYCLE  Command failed with exit code 2.
@livekit/agents-plugin-livekit:clean:build: ERROR: command finished with error: command (/Users/shubhrakantiganguly/development/agents-js/plugins/livekit) /Users/shubhrakantiganguly/Library/pnpm/.tools/pnpm/9.7.0/bin/pnpm run clean:build exited (2)
@livekit/agents-plugin-livekit#clean:build: command (/Users/shubhrakantiganguly/development/agents-js/plugins/livekit) /Users/shubhrakantiganguly/Library/pnpm/.tools/pnpm/9.7.0/bin/pnpm run clean:build exited (2)

 Tasks:    1 successful, 3 total
Cached:    0 cached, 3 total
  Time:    2.796s 
Failed:    @livekit/agents-plugin-livekit#clean:build

 ERROR  run failed: command  exited (2)
 ELIFECYCLE  Command failed with exit code 2.

@Shubhrakanti
Copy link
Contributor Author

oh man good catch. My fix doesn't actually solve this issue.

@Shubhrakanti
Copy link
Contributor Author

Fixed by #366

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.

2 participants