Skip to content

Run account switching asynchronously - #18

Merged
letmutex merged 2 commits into
mainfrom
feat/async-account-loader
Jul 19, 2026
Merged

letmutex merged 2 commits into
mainfrom
feat/async-account-loader

Conversation

@letmutex

@letmutex letmutex commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added an animated loading indicator during account switching and other longer-running terminal operations.
  • Bug Fixes
    • Improved account-switching reliability by completing authentication before applying Git configuration changes.
    • Prevented partial configuration updates when authentication is canceled or fails.
    • Added clearer status feedback when switching succeeds or is aborted.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The account switch flow now clones the selected account, gates Git configuration on token availability, and performs credential and configuration updates inside a background loader. A new terminal helper animates progress while blocking work runs on a separate thread.

Changes

Account switch flow

Layer / File(s) Summary
Background loader helper
src/tui.rs
Adds raw_with_loader, which runs blocking work on a background thread, animates terminal output, clears the loader, and returns the result.
Authenticated switch application
src/commands/list.rs, src/utils.rs
Updates account ownership and token gating, wraps credential approval and Git configuration changes in the loader operation, centralizes success and failure handling, and removes credential rejection support.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant handle_switch
  participant apply_switch
  participant raw_with_loader
  participant GitCredentials
  participant GitConfig
  handle_switch->>apply_switch: pass cloned account
  apply_switch->>raw_with_loader: run authentication and configuration closure
  raw_with_loader->>GitCredentials: approve credentials when token exists
  raw_with_loader->>GitConfig: update account and credential settings
  raw_with_loader-->>apply_switch: return closure result
  apply_switch-->>handle_switch: render success or aborted status
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: account switching now runs with a background loader and asynchronous work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/async-account-loader

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/list.rs`:
- Around line 492-495: Update the token-handling branch around
git_credential_reject and git_credential_approve to preserve the existing
credential until the replacement succeeds. Use an overwrite-safe approval flow,
or only reject the old credential after successful approval; if rejection must
happen first, restore it on approval failure before propagating the error.

In `@src/tui.rs`:
- Around line 87-101: Update the worker join handling in the TUI loop so panics
from the background operation do not unwind past run_loop and bypass
exit_cleanup. Replace both join().expect calls with thread::Result propagation
or equivalent panic capture, render an error for a failed worker, and ensure the
function returns through normal cleanup that restores terminal state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39287907-5a1b-4612-b0af-08949fd5d69e

📥 Commits

Reviewing files that changed from the base of the PR and between 60967b4 and 7032161.

📒 Files selected for processing (2)
  • src/commands/list.rs
  • src/tui.rs

Comment thread src/commands/list.rs Resolved
Comment thread src/tui.rs Resolved

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tui.rs (1)

80-97: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix terminal layout corruption from frame wrapping.

When frame wraps back to 0 (after 10 iterations), frame > 0 evaluates to false. This passes 0 as prev_count to raw_render_lines, skipping the cursor movement and printing the loader on a new line. Over longer background operations, this permanently leaves duplicated lines on the screen and corrupts the TUI layout.

Use a dedicated boolean flag to track whether it's the first render instead of relying on the frame index.

🐛 Proposed fix
-    let mut frame = 0;
+    let mut frame = 0;
+    let mut rendered = false;
     let started_at = Instant::now();
 
     while !handle.is_finished() && started_at.elapsed() < SHOW_DELAY {
         thread::sleep(Duration::from_millis(10));
     }
 
     if handle.is_finished() {
         return handle.join();
     }
 
     let shown_at = Instant::now();
 
     while !handle.is_finished() || shown_at.elapsed() < MIN_VISIBLE_DURATION {
         let line = format!("  {} {}", FRAMES[frame].cyan(), message);
-        raw_render_lines(&mut stdout, &[line], usize::from(frame > 0));
+        raw_render_lines(&mut stdout, &[line], usize::from(rendered));
+        rendered = true;
         frame = (frame + 1) % FRAMES.len();
         thread::sleep(FRAME_INTERVAL);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tui.rs` around lines 80 - 97, Update the loader rendering loop around
raw_render_lines to track first-render state with a dedicated boolean flag
rather than deriving prev_count from frame > 0. Initialize the flag before the
loop, pass the appropriate previous-line count on every render including after
FRAMES wraps, then clear the flag after the first render while preserving frame
advancement.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/tui.rs`:
- Around line 80-97: Update the loader rendering loop around raw_render_lines to
track first-render state with a dedicated boolean flag rather than deriving
prev_count from frame > 0. Initialize the flag before the loop, pass the
appropriate previous-line count on every render including after FRAMES wraps,
then clear the flag after the first render while preserving frame advancement.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aabfd096-981f-4306-b9cb-0265091b275b

📥 Commits

Reviewing files that changed from the base of the PR and between 7032161 and 2d90252.

📒 Files selected for processing (3)
  • src/commands/list.rs
  • src/tui.rs
  • src/utils.rs
💤 Files with no reviewable changes (1)
  • src/utils.rs

@letmutex
letmutex merged commit 8dced08 into main Jul 19, 2026
2 checks passed
@letmutex
letmutex deleted the feat/async-account-loader branch July 19, 2026 00:30
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