Skip to content

fix(python): use unique module paths to avoid uv cache conflict - #8245

Merged
sipsma merged 1 commit into
dagger:mainfrom
jedevc:python-runtime-fix-uv-clash-conflict
Aug 31, 2024
Merged

sipsma merged 1 commit into
dagger:mainfrom
jedevc:python-runtime-fix-uv-clash-conflict

Conversation

@jedevc

@jedevc jedevc commented Aug 27, 2024

Copy link
Copy Markdown
Contributor

Attempts to fix #7662, follow-up to #8051.

I think #8051 was the right approach - however, the tests weren't the issue. The paths in the tests aren't actually part of the uv cache key, so the underlying issue remains.

The real fix for this needs to be in the python sdk runtime, where we can correctly set these paths - based on the module id (or some other "unique enough" id, that can guarantee that we're not going to get weird horrible conflicts).

cc @sipsma @helderco

@jedevc
jedevc requested a review from a team as a code owner August 27, 2024 16:05
@jedevc

jedevc commented Aug 27, 2024

Copy link
Copy Markdown
Contributor Author

My theory for how this affected CI more than local environments is related to disk throughput - I suspect with heavily busy enough engines, the disk could be maxed out, and we might end up having some read/write operations interleaved. This means that potentially with all these parallel python tests, we might end up with some of the calls to uv and python interleaved weirdly, which may not have happened locally.

Comment thread sdk/python/runtime/main.go Outdated
Comment on lines +173 to +178
id, err := m.Discovery.ModSource.ID(ctx)
if err != nil {
return nil, err
}
h := sha256.New()
fmt.Fprint(h, id)
idHex := hex.EncodeToString(h.Sum(nil))
m.SourcePath = path.Join(ModSourceDirPath, idHex)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, this isn't the right stable ID to use - it should be related to the context directory I think?

For git sources, maybe we could use the commit ID? And for local sources, the Digest? Maybe we want a ModuleSource.digest property more generally for things like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we want a ModuleSource.digest property more generally for things like this.

I've found the need for a unique ID per module to use as a key for a cache volume, for node_modules and .venv, but was able to avoid it (just not creating a cache volume for it). So I agree that it can be useful in general.

We'll soon have isolated/namespaced cache volumes per module though. Even though that'll apply to the runtime module itself and not the target module, maybe the same approach that @sipsma is going for can be reused here, even if just the part that uniquely identifies a modules. Not sure if it's a simple namespace based on the module's name (like type namespaces) though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isolated cache volumes for each SDK instance would I think solve this issue, but the problem then is that we wouldn't be able to cache any legitimately shared dependencies if they were entirely separated 😢

I guess the uv cache is just not designed to be shared across multiple hosts, so, we need some little trick just for those paths 😢

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I know, I was saying maybe you can reuse some part of it, in order to get the unique value for the mount. Unless the idea for the namespaced cache valumes is to just use the module name.

@jedevc jedevc Aug 27, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh right I see 🎉 🎉 (time for more coffee)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ended up implementing Directory.digest and ModuleSource.digest so I could have a better way of doing this.

For some reason, the ID kept changing, I'm guessing normalizeCallerLoadedSource isn't helping here? Having a Digest helps keep things a bit more consistent and content-based.

@jedevc

This comment was marked as resolved.

@jedevc
jedevc force-pushed the python-runtime-fix-uv-clash-conflict branch from 6ba1889 to b4057c8 Compare August 27, 2024 17:46
@jedevc
jedevc requested a review from sipsma August 27, 2024 17:46
@jedevc jedevc added area/ci area/engine About dagger core engine area/sdk/python and removed area/engine About dagger core engine labels Aug 27, 2024
@sipsma

sipsma commented Aug 27, 2024

Copy link
Copy Markdown
Contributor

Gonna merge this now, let's see if this chunk of flakes is officially squashed! 🤞

@jedevc

jedevc commented Aug 28, 2024

Copy link
Copy Markdown
Contributor Author

Looks like this wasn't merged - I'm gonna hold it till after the release later today.

@jedevc
jedevc force-pushed the python-runtime-fix-uv-clash-conflict branch from b4057c8 to 05324b7 Compare August 28, 2024 12:55
@jedevc
jedevc requested a review from a team as a code owner August 28, 2024 12:55
@jedevc
jedevc marked this pull request as draft August 28, 2024 12:55
@jedevc
jedevc force-pushed the python-runtime-fix-uv-clash-conflict branch 3 times, most recently from 68ccb9f to 22e75df Compare August 28, 2024 14:36
@jedevc
jedevc requested a review from TomChv August 28, 2024 14:38
@sipsma

sipsma commented Aug 28, 2024

Copy link
Copy Markdown
Contributor

Looks like this wasn't merged - I'm gonna hold it till after the release later today.

I'm so confused, I swear I pressed merge... 😵‍💫

@jedevc

jedevc commented Aug 28, 2024

Copy link
Copy Markdown
Contributor Author

😱 okay, all the test failures are either flakes, or... the issue that the linter gets very sad when trying to codegen a feature in sdk/python/runtime that hasn't actually been released.

This is annoying, two options:

  • Just go back to doing ID hashing, but I didn't love that very much
  • Exclude sdk/python/runtime from the linter

@helderco

Copy link
Copy Markdown
Contributor

😱 okay, all the test failures are either flakes, or... the issue that the linter gets very sad when trying to codegen a feature in sdk/python/runtime that hasn't actually been released.

Probably would need to release the new digests in the API first, and then use it in the runtime right?

However, I'm good with either options you provided until next release. Excluding from the linter is just easier though, but temporary anyway.

@jedevc
jedevc force-pushed the python-runtime-fix-uv-clash-conflict branch from 22e75df to 1d4e6ea Compare August 30, 2024 15:04
@jedevc

jedevc commented Aug 30, 2024 •

Copy link
Copy Markdown
Contributor Author

Decided to revert to the older approach, and just deferred adding the .Digest API for later, split that out to #8282.

@jedevc
jedevc marked this pull request as ready for review August 30, 2024 15:05
@jedevc
jedevc force-pushed the python-runtime-fix-uv-clash-conflict branch from 1d4e6ea to 3b054ae Compare August 30, 2024 15:10
@jedevc
jedevc requested a review from helderco August 30, 2024 15:17
@sipsma
sipsma merged commit 134a8aa into dagger:main Aug 31, 2024
@jedevc
jedevc deleted the python-runtime-fix-uv-clash-conflict branch September 18, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test: TestPythonProjectLayout - The "main" module could not be found

3 participants