Skip to content

fix: fall back to local mode for empty repos with no commits#2150

Open
alecramos-sudo wants to merge 3 commits into
pingdotgg:mainfrom
alecramos-sudo:t3code/fix-empty-repo-crash
Open

fix: fall back to local mode for empty repos with no commits#2150
alecramos-sudo wants to merge 3 commits into
pingdotgg:mainfrom
alecramos-sudo:t3code/fix-empty-repo-crash

Conversation

@alecramos-sudo

@alecramos-sudo alecramos-sudo commented Apr 17, 2026

Copy link
Copy Markdown

What Changed

resolveSendEnvMode() now checks branch availability alongside isGitRepo. When the user's default env mode is "worktree" but the repo has no branch (i.e. an empty repo with zero commits), it falls back to "local" mode instead of proceeding into a guaranteed crash.

Three files changed, 28 lines added, 3 removed:

  • ChatView.logic.ts — added optional branch param to resolveSendEnvMode; returns "local" when worktree is requested but branch === null
  • ChatView.tsx — passes gitStatusQuery.data?.branch at the call site
  • ChatView.logic.test.ts — 3 new test cases (empty repo fallback, local-on-empty, backward compat when branch not provided)

Why

Empty git repositories (git init, no commits) report isRepo: true but branch: null — the status line reads # branch.head (initial), parsed as null in GitCore.ts. In worktree mode this triggers a crash:

  1. resolveSendEnvMode sees isGitRepo=true → keeps "worktree" mode
  2. Bootstrap calls git worktree add → fails (no commits to branch from)
  3. Error handler dispatches thread.delete → draft is cleared
  4. User is stranded on a dead route: "Select an existing thread or create a new one"

The fix is the smallest correct change: detect the missing branch client-side and fall back to local mode before the bootstrap ever runs. No server changes needed.

Fixes #2148

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes — N/A (no UI changes, behavioral fix only)
  • I included a video for animation/interaction changes — N/A

Note

Low Risk
Small client-side guard in chat send env resolution with tests; no server or auth changes.

Overview
Fixes empty git repos defaulting to worktree and crashing during bootstrap when git worktree add has no commits to branch from.

resolveSendEnvMode now accepts optional branch from git status: branch === null (empty repo) forces local when worktree was requested; undefined (status still loading) leaves the requested mode unchanged. ChatView passes gitStatusQuery.data?.branch into that helper. Unit tests cover empty-repo fallback, explicit local, and callers that omit branch.

Reviewed by Cursor Bugbot for commit 36672fc. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fall back to local mode in resolveSendEnvMode for empty git repos with no commits

When a git repo has no commits, branch is null and worktree mode is not meaningful. resolveSendEnvMode in ChatView.logic.ts now returns "local" in this case. When branch is undefined (still loading), the requested mode is preserved unchanged. ChatView.tsx passes gitStatusQuery.data?.branch to resolveSendEnvMode to enable this behavior.

Macroscope summarized 36672fc.

Empty git repositories (git init, no commits) report isRepo=true but
branch=null. In worktree mode this caused an instant crash: git worktree
add fails without commits, the bootstrap cleanup deletes the thread, and
the user gets stranded on a dead route with "select a thread."

resolveSendEnvMode now checks branch availability and falls back to local
mode when worktree mode is requested but no branch exists.

Fixes pingdotgg#2148
@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1ff9e92e-4a96-4706-8f3d-7794dc5eb643

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Apr 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d99c628. Configure here.

Comment thread apps/web/src/components/ChatView.tsx Outdated
@macroscopeapp

macroscopeapp Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

A small, well-tested bug fix that gracefully handles empty git repositories (initialized but no commits) by falling back to local mode instead of failing. The change is backward compatible with clear documentation and comprehensive test coverage.

You can customize Macroscope's approvability policy. Learn more.

Drop `?? null` from the branch call site so `undefined` (git status
query still loading) is not conflated with `null` (empty repo, no
commits). This prevents worktree users from being incorrectly
downgraded to local mode while the query resolves.

Update the type signature to explicitly accept `undefined` to satisfy
exactOptionalPropertyTypes.
@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Apr 18, 2026
@juliusmarminge juliusmarminge enabled auto-merge (squash) June 12, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Creating a thread in an empty git repository (no commits) crashes with "select a thread"

2 participants