turbo icon indicating copy to clipboard operation
turbo copied to clipboard

[turborepo] Scripts execution order broken

Open arthurgubaidullin opened this issue 3 years ago • 7 comments

What version of Turborepo are you using?

1.6.2

What package manager are you using / does the bug impact?

npm, Yarn v1

What operating system are you using?

Mac

Describe the Bug

Script doesn't run when dependent script result is changed and replayed.

Spent hours to understand why the result of script execution is unpredictable! This literally renders the task dependency graph useless.

Expected Behavior

Script must run when dependent script result is changed and replayed.

To Reproduce

With repro project do:

  1. Assume content of file packages/lib-a/src/index.ts in state S1
  2. Run yarn run deploy
  3. Change content of file packages/lib-a/src/index.ts to another state S2
  4. Run yarn run deploy
  5. Change content of file packages/lib-a/src/index.ts to state S1
  6. Run yarn run deploy
  7. Change content of file packages/lib-a/src/index.ts to state S2
  8. Run yarn run deploy
  9. Check content of file deploy/a/lib/index.js. Must be in state S2

Reproduction Repo

https://github.com/arthurgubaidullin/turborepo-bug-repro-scripts-execution-order-broken

arthurgubaidullin avatar Oct 29 '22 10:10 arthurgubaidullin

Thanks for the repro. Can you specify at which step in the repro steps the issue occurs and what the expected behavior is? Also, just to make sure, you're toggling the contents of lib-a between two versions, correct?

chris-olszewski avatar Oct 31 '22 17:10 chris-olszewski

@chris-olszewski The problem occurs at step 8. I expect the depoy script to run if the build script's output has changed, even if it's replayed.

Yes, I switch between versions in repro. But in fact it may have more versions.

arthurgubaidullin avatar Nov 01 '22 09:11 arthurgubaidullin

image

arthurgubaidullin avatar Nov 01 '22 10:11 arthurgubaidullin

I think Turbo is behaving as expected. Since the deploy directory isn't in the outputs section for the deploy task, Turbo doesn't know that it should update those files from cache on a hit.

chris-olszewski avatar Nov 01 '22 21:11 chris-olszewski

@chris-olszewski How can output of the deploy command affect the work of the build command?

I want to build script execution chains. First, the build script must be executed, then the deploy.

The build script puts the output in the lib. Deploy script takes input from lib.

Why, if there is an old version of the build in the cache, does the deploy script not run at all?

arthurgubaidullin avatar Nov 02 '22 06:11 arthurgubaidullin

This use case is broken. For understanding.

arthurgubaidullin avatar Nov 02 '22 07:11 arthurgubaidullin

How can output of the deploy command affect the work of the build command?

It's not affecting the result of the build command. From what I've observed in your repro build is correctly producing the artifacts in lib. The issue comes when deploy, seeing that it's inputs are in the cache, is a cache hit and replays the logs, but doesn't update the content of deploy since Turbo doesn't know that there are outputs that need updating.

This use case is broken

The case works, but using the task name deploy might be bad due to people generally not wanting that task to be cached e.g. rolling back a deploy

chris-olszewski avatar Nov 02 '22 18:11 chris-olszewski