Skip to content

fix(web): harden git checkout, run lifecycle, and branch-picker UX#98

Merged
cnjack merged 1 commit into
mainfrom
fix/git-checkout-safety-and-run-lifecycle
Jun 23, 2026
Merged

fix(web): harden git checkout, run lifecycle, and branch-picker UX#98
cnjack merged 1 commit into
mainfrom
fix/git-checkout-safety-and-run-lifecycle

Conversation

@cnjack

@cnjack cnjack commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Follow-up fixes for issues found while reviewing the (already-merged) #96. Each was reproduced against the merged code and verified; the proposed fixes from review were corrected where wrong (notably: a -- separator does not fix the checkout injection, and context.CancelFunc can't be compared — a generation counter is used instead).

Backend changes are additive or behavior-narrowing; frontend changes are guard/copy fixes. No API breakage.

🔴 HIGH

  • git checkout argv injection → silent data loss. branch flowed straight into the git argv, so {branch:"-f"} ran git checkout -f, discarding all uncommitted work and returning 200 OK. Now reject branch names beginning with - (valid git refs never do). internal/web/git.go
  • Lost-cancel race → /stop silently dead. A finishing run's defer could nil the next run's runCancel (gated only by the running CAS), leaving running=true, runCancel=nil/stop returned stopped but cancelled nothing. Now guarded by a per-run generation (Engine.runGen): a superseded defer is a no-op. internal/web/engine.go, internal/web/server.go

🟠 MEDIUM

  • Stash orphaned on failed switch. A stash-strategy checkout that fails after auto-stashing now pops the stash to restore the tree (and names the stash if pop fails) instead of leaving work in stash@{0} with no hint. git.go
  • Blocked-checkout classification. New kind (tracked|untracked) field on the blocked response so the UI can pick safe recovery options. git.go
  • setActiveEngine reclaim TOCTOU. The running check is folded into the emu-guarded block so a concurrently-starting run on the outgoing engine isn't torn down. engine.go
  • Deleting the open conversation. Resets the chat view (clearChat + blank currentSessionId) only when the deleted task is the active one, so the next message can't be sent to a dead session; background-task deletes are unaffected. Sidebar.vue

🟡 LOW

  • handleSessionDiff captures the active engine once so snapshot and pwd come from the same repo across a swap. server.go
  • handleValidatePaths reports a path missing only on confirmed not-exist, not on transient/permission stat errors that were hiding valid workspaces. server.go
  • Branch-switch copy no longer claims only "changes" and warns that discard deletes untracked files (en/zh-Hans/zh-Hant/ja/ko).
  • BranchPicker Cancel routes through reset() so a stale error no longer leaks into the branch list. BranchPicker.vue
  • ProviderIcon initial-fallback regex gains the g flag. ProviderIcon.vue

Tests

Adds internal/web/git_test.go: checkout dash-reject (asserts uncommitted work survives), blockKind tracked/untracked, and validate-paths missing detection (incl. the EACCES case the fix targets).

Deferred (own follow-up)

The kind-consuming UI (hide discard for untracked), the #9 backend porcelain classification, and a post-switch "stashed" toast — larger UX surface, out of scope for this bug-fix batch. The backend kind field ships now so that follow-up needs no API change.

Verification

go build ./... · go vet ./internal/web/... · go test -race ./internal/web/... · npm run build (type-check + vite) · oxlint + eslint on changed files — all green.

🤖 Generated with Claude Code

Follow-up fixes for issues found reviewing the merged PR #96. Backend
changes are additive or narrowing; frontend changes are guard/copy fixes.

HIGH
- git checkout: reject branch names beginning with "-" before building the
  argv, so {branch:"-f"} can no longer become `git checkout -f` and silently
  discard uncommitted work while returning 200. (A "--" separator is NOT a
  fix — it makes git treat the ref as a pathspec and breaks switching.)
- run lifecycle: guard the run-goroutine teardown with a per-run generation
  (Engine.runGen). A superseded old run's defer no longer nils the new run's
  runCancel, releases its running flag, or broadcasts a spurious idle — so a
  fast next turn on the same engine stays stoppable via /stop.

MEDIUM
- git checkout: when a stash-strategy switch fails after auto-stashing, pop
  the stash to restore the tree instead of orphaning it; name the stash if
  pop fails.
- git checkout: classify the blocked response as tracked/untracked (new
  `kind` field) so the UI can pick safe recovery options.
- setActiveEngine: fold the reclaim `running` check into the emu-guarded
  block so a concurrently-starting run is not torn down.
- sidebar: reset the chat view (clearChat + blank currentSessionId) only when
  deleting the active conversation, so the next message can't target a
  deleted session; background-task deletes are unaffected.

LOW
- handleSessionDiff: capture the active engine once so snapshot and pwd come
  from the same repo across a swap.
- handleValidatePaths: report a path missing only on confirmed not-exist, not
  on transient/permission stat errors that hid valid workspaces.
- branch-switch copy: no longer claims only "changes"; warns discard deletes
  untracked files (en/zh-Hans/zh-Hant/ja/ko).
- BranchPicker: route the confirm-dialog Cancel through reset() so a stale
  error no longer leaks into the branch list.
- ProviderIcon: add the `g` flag to the initial-fallback regex.

Adds regression tests for the checkout dash-reject, blockKind, and
validate-paths missing detection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@cnjack, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 52 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: feb3ba47-e0b4-4a0a-9275-0768257f4b42

📥 Commits

Reviewing files that changed from the base of the PR and between e697fb2 and e22e4c6.

📒 Files selected for processing (12)
  • internal/web/engine.go
  • internal/web/git.go
  • internal/web/git_test.go
  • internal/web/server.go
  • web/src/components/BranchPicker.vue
  • web/src/components/ProviderIcon.vue
  • web/src/components/Sidebar.vue
  • web/src/i18n/locales/en.ts
  • web/src/i18n/locales/ja.ts
  • web/src/i18n/locales/ko.ts
  • web/src/i18n/locales/zh-Hans.ts
  • web/src/i18n/locales/zh-Hant.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/git-checkout-safety-and-run-lifecycle

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.

@cnjack cnjack merged commit 20fa596 into main Jun 23, 2026
3 checks passed
@cnjack cnjack deleted the fix/git-checkout-safety-and-run-lifecycle branch June 23, 2026 01:20
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