Skip to content

environment management overhaul #62

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 4 commits into from
Jun 18, 2025
Merged

environment management overhaul #62

merged 4 commits into from
Jun 18, 2025

Conversation

aluzzardi
Copy link
Member

@aluzzardi aluzzardi commented Jun 12, 2025

This overhauls how state and environments are managed.

  • Environments are "resumed" from state each and every time, rather than keeping the state hanging in memory. This makes resuming safe (whether it's the same session later on, a different agent, etc)
  • Repository contains CRUD operations around environments
  • All the git logic is stashed in there. Environment can only operate on a given worktree

@aluzzardi aluzzardi marked this pull request as draft June 12, 2025 22:57
return homedir.Expand(filepath.Join(cuRepoPath, normalizedOrigin))
}

func normalizeGitURL(endpoint string) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This boilerplate was copied from dagger, which in turn was copied from Go.

It simply normalizes e.g. https://github.com/dagger/container-use.git and [email protected]:dagger/container-use.git both to github.com/dagger/container-use

@aluzzardi aluzzardi force-pushed the env-management branch 5 times, most recently from a5a003f to 87775df Compare June 16, 2025 21:02
Signed-off-by: Andrea Luzzardi <[email protected]>
Copy link
Collaborator

@cwlbraa cwlbraa left a comment

Choose a reason for hiding this comment

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

directionally this looks right to me, accomplishes the more immediate goals of #59 without trying to dot every i and cross every t.

imo we need to get this and #65 onto main ASAP to clear a path for more incremental work... eg i wanna get the "real" #11 environment resume working. with this PR plus the tests, the impl will be much cleaner (although it'll still involve similar dirty tricks with worktree .git pointers)

parts of my Remote refactor will fit in here as a sub-package of Repository, i think.

func (env *Environment) Export(ctx context.Context) (rerr error) {
_, err := env.container.Directory(env.Config.Workdir).Export(
ctx,
env.Worktree,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a bit of a hole in the abstraction. not a problem for now but a good thing to noodle on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed.

I was thinking it's not that bad because the interface of environments is pretty straightforward: worktree in (New, Load), worktree out (Export). The rest is out of scope for the environment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the hard part, and a big part of why #59 felt like boiling the ocean, is eventually it'd great to point these at a network remote and these lil abstraction violations will prevent us from doing that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I actually kept #59 in mind while doing this -- I was kinda hoping that this would be compatible. 1) Keep the environment dumb (load stuff , dump stuff ). 2) All that logic moved as-is (for now) in a layer above 3) Eventually Repository could use the Remote abstraction (e.g. rather than integrating Remote in all of Environment, we could integrate it into Repository only?)

Just realized that maybe I'm missing something. I assumed we'd still use local storage as a staging area, even for other storage implementation, but I see now you meant to be able to avoid doing that and going straight to the alternative storage without stopping by local disk?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assumed we'd still use local storage as a staging area, even for other storage implementation, but I see now you meant to be able to avoid doing that and going straight to the alternative storage without stopping by local disk?

yep, that's the eventual goal. honestly it's very cart-before-horse to be trying to break your assumption right now, but that's where I started with #59. We'll get there eventually, but we also need to upstream some Git apis into dagger first anyways.

Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
Copy link
Collaborator

@cwlbraa cwlbraa left a comment

Choose a reason for hiding this comment

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

lgtm!

),
mcp.WithString("source",
mcp.WithString("environment_source",
Copy link
Collaborator

Choose a reason for hiding this comment

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

one day we're gonna have evals so we can make these changes on more than just vibes XD

Comment on lines +440 to +442
if resp, err := updateRepo(); err != nil {
return resp, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

noting here that in the case where we fail to update the repo, we discard runErr.

i think that's fine for now, in theory the "failed to update repo" is the more violent and important error. it may be hard to debug without logs from environment.Run, but that failure mode is also mostly theoretical for right now.

same thing exists below for the !background case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah went back and forth between the 2. My thinking was that a failed command "happens", it's just the model iterating. However, failing to update the repo is an urgent error that needs to be brought forward to the user (something is very wrong)

@aluzzardi aluzzardi merged commit e7bd753 into main Jun 18, 2025
1 check passed
@aluzzardi aluzzardi deleted the env-management branch June 18, 2025 18:46
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