Skip to content

real container resume redux#115

Closed
cwlbraa wants to merge 2 commits intomainfrom
real-container-resume-redux
Closed

real container resume redux#115
cwlbraa wants to merge 2 commits intomainfrom
real-container-resume-redux

Conversation

@cwlbraa
Copy link
Contributor

@cwlbraa cwlbraa commented Jun 20, 2025

we incidentally got a bunch of the "real" container resume logic working when @aluzzardi reworked state storage into git.

this PR shores up a hole in that resume: we weren't saving run commands into the ongoing container state.

the other hole is run_background... maybe that should just call AddService? does that make sense to you @aluzzardi?

this also includes minor fixes to env.container concurrency safety.

cwlbraa added 2 commits June 20, 2025 11:23
Signed-off-by: Connor Braa <connor@dagger.io>
Signed-off-by: Connor Braa <connor@dagger.io>
@cwlbraa cwlbraa marked this pull request as draft June 20, 2025 18:45
@cwlbraa
Copy link
Contributor Author

cwlbraa commented Jun 20, 2025

switching back to draft. there's something fishy going on here. been testing with this one liner [[ -f .ran ]] && exit 1 || touch .ran and things don't work quite how we should expect them to.

@cwlbraa cwlbraa closed this Jun 24, 2025
cwlbraa added a commit that referenced this pull request Jun 26, 2025
this PR implements "real" container resume where we store each Run WithExec in the container LLB definition and shores up the base of that container by saving off InitialSourceDir in state. InitialSourceDir is a made consistent and re-hydratable by using dag.Host().Directory(forkRepoPath).AsGit().Ref(initialWorktreeHead).Tree(). because we can rely on that SHA always pointing at the exact right base content and the forkRepo always having that SHA, we can source the base of sourcedir without keeping a copy of the first commit on disk.

6/25: this PR does have a big piece of "magic" in it. we template in the .git file to be gitdir: repos/name/worktrees/id so that, on export, we don't constantly override reset the git history.

Other stuff buried in here:

env.apply no longer takes arguments that give the false impression it's gonna make a commit. it just takes newState (the container)
env.run calls apply
run_background still doesn't. to make those restore we gotta do some additional thinking around how we data model service persistence.
additionally on 6/25 cc @aluzzardi:

better error handling in the event of failed commands. we now no longer fail the withexec for failed commands, but still propagate error information to the git notes and the tool responses. this is necessary for
better prompt engineering around endpoints. the agent was getting confused and using localhost to try to talk to things it had run_backgrounded.
closes #115.


* working

Signed-off-by: Connor Braa <connor@dagger.io>

* cleanup

Signed-off-by: Connor Braa <connor@dagger.io>

* clean up apply

Signed-off-by: Connor Braa <connor@dagger.io>

* shore up error handling in run command

Signed-off-by: Connor Braa <connor@dagger.io>

* assorted fixes:

- stop saving initialSourceDir - its saved in the llb.
- have environment_update rebuild the base from workdir
- improve prompt engineering around internal/external ports
- improve run_command error handling so that failed commands can be saved into the container state

Signed-off-by: Connor Braa <connor@dagger.io>

* resolve build failure post-merge

Signed-off-by: Connor Braa <connor@dagger.io>

* make tests pass

Signed-off-by: Connor Braa <connor@dagger.io>

* shoutout guillaume's tests, i totally forgot about this part of the magic

Signed-off-by: Connor Braa <connor@dagger.io>

* remove unnecessary git notes initialization

Signed-off-by: Connor Braa <connor@dagger.io>

---------

Signed-off-by: Connor Braa <connor@dagger.io>
@aluzzardi aluzzardi deleted the real-container-resume-redux branch June 26, 2025 20:27
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.

1 participant