Skip to content

Fix comment on workdir (very confusing) #3181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2025
Merged

Fix comment on workdir (very confusing) #3181

merged 2 commits into from
May 31, 2025

Conversation

ekzhang
Copy link
Member

@ekzhang ekzhang commented May 24, 2025

Extremely confusing field called workdir on ImageMetadata which is not actually used by any of our systems, ImageManifest.workdir is the actual workdir. This is wrong in 99% of images.

@mwaskom
Copy link
Contributor

mwaskom commented May 27, 2025

Not sure I know the initial intention here or exactly the nature of the confusion, but I think this is meant to convey what the workdir state would be for subsequent builder tasks, (i.e. so that we can know where .add_local_* layers would put their files with a relative remote location. @freider might know more.

@ekzhang
Copy link
Member Author

ekzhang commented May 27, 2025

Yeah there's a somewhat confusing issue in that image.manifest.workdir and image.workdir are different. image.manifest.workdir is the actual workdir, and it's read by tasks on startup:

  • runner tasks: uses manifest.workdir, otherwise /root if not set
  • builder tasks: uses manifest.workdir, otherwise / if not set
  • sandbox tasks: uses sandbox.workdir, otherwise manifest.workdir if not set, otherwise / if not set

Meanwhile image.workdir is not read by anything in the runtime and is a duplicate metadata value that is measured by builder.

The issue is that for the vast majority of tasks, manifest.workdir is not set, but in the internal lookup and database for images, we see workdir: / observed by this metadata process. Which is misleading — it's actually not set, and the runtime code treats it as not set.

@mwaskom
Copy link
Contributor

mwaskom commented May 29, 2025

I'm not sure I'm completely following, but is it right that what's confusing here is that we have a different default workdir for builder tasks vs runner tasks?

@ekzhang
Copy link
Member Author

ekzhang commented May 31, 2025

I'm not sure I'm completely following, but is it right that what's confusing here is that we have a different default workdir for builder tasks vs runner tasks?

That's not quite it, the confusing but is that this field is just useless and not used anywhere. The correct field is manifest.workdir. I can update the comment to make that clearer

@ekzhang
Copy link
Member Author

ekzhang commented May 31, 2025

@prbot approve freider

@modal-pr-review-automation
Copy link

Please request a reviewer to follow up with a post-merge review.

@ekzhang ekzhang requested a review from freider May 31, 2025 05:10
Copy link

@modal-pr-review-automation modal-pr-review-automation bot left a comment

Choose a reason for hiding this comment

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

Approved 👍. @freider will follow-up review this.

@ekzhang ekzhang merged commit f926ded into main May 31, 2025
21 of 22 checks passed
@ekzhang ekzhang deleted the ekzhang/workdir branch May 31, 2025 05:10
@ekzhang
Copy link
Member Author

ekzhang commented May 31, 2025

See https://github.com/modal-labs/modal/pull/22955 for comment in other location of the code

@freider
Copy link
Contributor

freider commented May 31, 2025

The context here is that for some planned future work the client needs to receive the image workdir in the response data from images. We need to fill this metadata field with whatever the best information available - be that from the manifest or otherwise.

Also, why is it wrong for 99% of images? (disregarding that we override it for runner tasks)

@ekzhang
Copy link
Member Author

ekzhang commented May 31, 2025

Thanks for the insight @freider, I can update the comment / document better what it means when manifest.workdir is missing. The missing value is actually semantic versus a / value.

I think for now any workdir should return a PurePosixPath | None or str | None value determining whether it is set, since None is meaningful (and it's the case for 99% of images mentioned above) — overriding as /root only applies when None. Does that make sense? Just from a runtime perspective.

Either way I think we shouldn't have two different workdir on the backend -- for client code it's up for discussion! In the backend, the source of truth is the manifest in all cases.

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.

3 participants