🤖 fix: branch SSH workspaces from upstream source#3267
Open
ethanndickson wants to merge 1 commit into
Open
Conversation
Fresh SSH/Coder workspace creation now treats the selected source branch as the upstream remote-tracking branch when available, leaving refs/mux-bundle/* as a local snapshot fallback only.\n\n---\n\n_Generated with `mux` • Model: `openai:gpt-5.5` • Thinking: `xhigh` • Cost: `3.34`_\n\n<!-- mux-attribution: model=openai:gpt-5.5 thinking=xhigh costs=13.34 -->
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ 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
Fresh SSH/Coder workspaces now treat the selected Source Branch as the upstream remote-tracking branch when it is available, instead of letting the synced local snapshot in
refs/mux-bundle/*override it.Issue
A newly-created Coder workspace on an SSH runtime could immediately show as hundreds of commits behind
origin/maineven when the UI's Source Branch was set tomain. In the reported case, the workspace was created onpog2.coderwith Source Branchmain, and the UI showed it as 236 commits behindorigin/mainright after creation. That is surprising because selectingmainshould mean the fresh workspace starts from upstreamorigin/main, so the initial behind count should be zero.Why it happened
The SSH worktree refactor split the remote VM's shared bare repo into two different kinds of refs:
refs/mux-bundle/mainis the user's local laptopmainuploaded as a transport snapshot, whilerefs/remotes/origin/mainis the actual upstream branch fetched on the SSH host. Fresh workspace creation still treated the uploaded local snapshot as eligible to define the new workspace base. Specifically, it only choseorigin/<source>if the local snapshot ref could fast-forward to upstream; if localmainwas stale, ahead, diverged, or the origin fetch path failed, mux fell back torefs/mux-bundle/main. A background fetch could then updateorigin/mainto the real upstream tip, making the newly-created workspace appear immediately behind even though the user explicitly selected Source Branchmain.How this fixes it
Fresh SSH checkout now uses a remote-first source selection policy. It fetches the selected source branch into an explicit remote-tracking ref, verifies that
refs/remotes/origin/<source>exists, and bases the new worktree onorigin/<source>whenever that upstream source is available.refs/mux-bundle/*remains as a transport/local-snapshot cache and is used only as an explicit fallback when the upstream source branch cannot be fetched. The existing fast-forward safety check is preserved for existing workspace re-init paths, where protecting local workspace state still matters.Implementation
The fresh SSH checkout path now fetches with an explicit refspec like
+refs/heads/main:refs/remotes/origin/main, resolves the fresh workspace base withorigin/<source>first, and logs when it has to fall back to the local snapshot. Tests cover the upstream-first selection, explicit fallback behavior, and the new fetch refspec.Risks
This changes fresh SSH/Coder workspace initialization semantics when a local branch is ahead of or diverged from upstream. That is intentional for the Source Branch selector, but users relying on local
maindrift as the implicit fresh-workspace base will now need to create from that local branch explicitly or rely on the logged fallback when upstream is unavailable.Generated with
mux• Model:openai:gpt-5.5• Thinking:xhigh• Cost:$13.34