Skip to content

fix(parse_git_status): fix false-positive detached HEAD when upstream name contains 'detached'#1374

Open
devteamaegis wants to merge 1 commit into
e2b-dev:mainfrom
devteamaegis:fix/logic-error-wrong-output-false-positive-detached-head-detection
Open

fix(parse_git_status): fix false-positive detached HEAD when upstream name contains 'detached'#1374
devteamaegis wants to merge 1 commit into
e2b-dev:mainfrom
devteamaegis:fix/logic-error-wrong-output-false-positive-detached-head-detection

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

parse_git_status in packages/python-sdk/e2b/sandbox/_git/parse.py returns detached=True and leaves current_branch and upstream empty for a repository that is not in detached HEAD mode. This happens whenever the upstream tracking branch name contains the word detached — for example, a branch main tracking origin/detached-work. The porcelain line ## main...origin/detached-work causes raw_branch to equal "main...origin/detached-work", and the condition "detached" in raw_branch on line 129 fires, sending execution into the detached-HEAD code path and returning completely wrong state.

Why it happens

The "detached" in raw_branch sub-check is a substring match against the full branch...upstream string, not just the branch name, so it matches any upstream whose name contains the word detached.

Fix

Remove the "detached" in raw_branch sub-check from line 128–130. The raw_branch.startswith("HEAD (detached at ") check already covers real detached HEAD, and the subsequent normalized_branch.startswith("HEAD") check on line 130 catches HEAD (no branch) and similar HEAD variants.

Test

Added tests/bugs/test_parse_git_status_detached.py which feeds ## main...origin/detached-work into parse_git_status and asserts detached=False, current_branch="main", and upstream="origin/detached-work".

Fixes #1373

…pstream name

The broad `"detached" in raw_branch` sub-check matched any upstream
tracking ref containing the word "detached" (e.g. `origin/detached-work`),
causing `parse_git_status` to return `detached=True` and empty
`current_branch`/`upstream` for repos that are not in detached HEAD mode.

Remove the sub-check; `raw_branch.startswith("HEAD (detached at ")` already
covers the real detached-HEAD case and the subsequent
`normalized_branch.startswith("HEAD")` covers `HEAD (no branch)` variants.

Fixes e2b-dev#1373
@cla-bot

cla-bot Bot commented May 31, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Aegis Dev.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@changeset-bot

changeset-bot Bot commented May 31, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f3b7326

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3b7326ed9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

is_detached = raw_branch.startswith("HEAD (detached at ") or (
"detached" in raw_branch
)
is_detached = raw_branch.startswith("HEAD (detached at ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply the detached fix to the JS SDK too

This change fixes parse_git_status only for Python, but the JS SDK still has the same rawBranch.includes('detached') check in packages/js-sdk/src/sandbox/git/utils.ts:392-394, so parseGitStatus('## main...origin/detached-work\n') still reports a detached HEAD for JS users. The repo instructions say SDK changes should be applied to both JS and Python implementations, and this leaves the same user-visible status bug in one of the shipped SDKs.

Useful? React with 👍 / 👎.

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.

BUG: parse_git_status returns detached=True when upstream branch name contains the word 'detached'

1 participant