🤖 feat: devcontainer git parity for worktrees on managed hosts#2799
Open
ethanndickson wants to merge 3 commits intomainfrom
Open
🤖 feat: devcontainer git parity for worktrees on managed hosts#2799ethanndickson wants to merge 3 commits intomainfrom
ethanndickson wants to merge 3 commits intomainfrom
Conversation
Type-safe bind mounts, gitdir resolution for worktrees, and credential env forwarding across the container boundary. - BindMount type ensures mount strings are formatted only at the CLI boundary (prevents Docker-only options like readonly from leaking) - resolveGitdirMount: follows .git files to the real gitdir so worktree-based workspaces can fetch/commit inside the container - resolveHostCredentialEnv: forwards GIT_ASKPASS, GIT_SSH_COMMAND, CODER_*, and git identity vars into the container - resolveCoderAgentMount: bind-mounts /.coder-agent when present - SSH agent socket forwarding via resolveSshAgentForwarding - getContainerEnv() on Runtime interface for ptyService integration
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fdb143473c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Devcontainer workspaces running inside Coder now automatically receive the host's credential environment — git authentication, SSH proxying, git identity, and the
/.coder-agent/coderbinary — without any manualdevcontainer.jsonworkarounds.Closes #2767
Background
When Mux runs inside a Coder workspace and uses devcontainers, the Coder agent sets up critical environment variables (
GIT_ASKPASS,GIT_SSH_COMMAND,CODER_*, git identity) and mounts/.coder-agent/coderon the host. These were not being forwarded into the devcontainer, breaking OIDC git auth, SSH-based git operations, and commit identity for both agent commands and terminal sessions.Additionally, worktree-based workspaces broke inside the container because git's
.gitfile references agitdirpath outside the mounted workspace — the parent.git/directory was not bind-mounted.Users had to manually configure
mountsandcontainerEnvindevcontainer.jsonas workarounds.Implementation
Credential forwarding (
credentialForwarding.ts)New pure utility module (no runtime imports) with structured resolvers:
resolveHostCredentialEnv()— scansprocess.envfor an allowlist of credential-related vars (GIT_ASKPASS,GIT_SSH_COMMAND,CODER_*prefix, git identity vars) and returns them as a record.resolveCoderAgentMount()— returns aBindMountfor/.coder-agent/if the directory exists on the host.resolveGitdirMount(workspacePath)— follows.gitfiles (worktree indicator) to resolve the parent.git/directory and returns aBindMountfor it.resolveSshAgentForwarding()— returns structured SSH socket paths whenSSH_AUTH_SOCKexists.Type-safe bind mounts (
BindMount)BindMount = { source, target }is defined alongside the producers. The single formatting point (type=bind,source=...,target=...) lives indevcontainerCli.tswhere--mountargs are serialized. This makes it type-impossible to add Docker-only options (likereadonly) that the devcontainer CLI rejects.Deterministic env hydration (
DevcontainerRuntime.ts)Container requirements (mounts + env) are derived runtime state, hydrated at every entry boundary:
setCurrentWorkspacePath()now callsrefreshContainerRequirements()immediately — this is the terminal creation path.getContainerEnv()self-heals with a lazy refresh if workspace path exists but cache is empty.postCreateSetup()andensureReady()both use the samerefreshContainerRequirements()wrapper.This ensures terminal sessions get identical credential env as agent
exec()commands, regardless of lifecycle ordering.PTY integration (
ptyService.ts)The devcontainer terminal branch reads
runtime.getContainerEnv()and forwards each entry as--remote-envflags todevcontainer exec. No changes needed here — the relay was already correct; the fix was upstream in the runtime.Validation
dev.pog2.me.coder):env | grep -E '^(GIT_|CODER_)'shows all expected varsgit fetch originsucceeds with OIDC auth/.coder-agent/coderis mounted and executableRisks
setCurrentWorkspacePath()now does I/O (checking/.coder-agentexistence, reading.gitfiles). These are synchronousfscalls on local paths — fast and already present in theensureReady()path.null/{}when Coder env vars and paths don't exist. Non-Coder devcontainer workflows are unaffected.Generated with
mux• Model:anthropic:claude-opus-4-6• Thinking:xhigh• Cost:$37.33