Skip to content

fix(ui): implement async background analysis and thread-safe progress tracking #267#457

Open
Shubham-Gotawade wants to merge 1 commit into
agnivo988:mainfrom
Shubham-Gotawade:fix-ui-freeze-267
Open

fix(ui): implement async background analysis and thread-safe progress tracking #267#457
Shubham-Gotawade wants to merge 1 commit into
agnivo988:mainfrom
Shubham-Gotawade:fix-ui-freeze-267

Conversation

@Shubham-Gotawade

@Shubham-Gotawade Shubham-Gotawade commented Jun 5, 2026

Copy link
Copy Markdown

Contributed as part of GSSoC '26.

Problem Description

When executing long-running repository analysis tasks on massive repositories or monorepos, the intensive operations blocked the primary UI execution thread. This architectural bottleneck prevented the user interface from processing frame repaints, leading to complete UI lockups, missing execution progress metrics, and broken user feedback. Fixes #267.

Solution Implemented

  1. Thread-Safe Memory Synchronization: Introduced a strict synchronization boundary via sync.RWMutex inside internal/ui/progress.go. Re-engineered tracking accessors (NextStage, GetCurrentStage, etc.) to run thread-safe, and modified GetAllStages to return isolated deep-copy slices, completely eliminating data races during UI iteration passes.
  2. Asynchronous Command Orchestration: Decoupled the computational analysis runtime from the view lifecycle inside internal/ui/app.go by wrapping analyzeRepo and compareRepos executions into standard background Go routines handled natively via Bubble Tea's asynchronous tea.Cmd system.
  3. Dynamic View Polling System: Configured a 150ms ticking update pump (TickProgressCmd) inside the UI loop to continuously trigger non-blocking model redraws, pulling metric snapshots cleanly from the protected tracker state.
  4. Adaptive Execution Optimization: Integrated an automatic "fast-forwarding" catch-up state machine to correctly update step arrays whenever metadata is pulled instantly from local system cache blocks or skipped in Quick Mode configurations.

Verification & Test Logs

  • Synchronized model verification analysis via go build ./...: PASSED (Zero type or layout exceptions)
  • Verified concurrent safety via thread isolation: PASSED

Summary by CodeRabbit

  • Progress Tracking Improvements
    • Enhanced consistency of progress updates during repository analysis with clearer feedback at each major analysis stage.
    • Repository analysis progress is now uniformly managed across all analysis workflows and entry points.
    • Quick analysis mode now properly completes progress display before returning results.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds fine-grained, thread-safe progress tracking throughout the repository analysis pipeline to address UI freezes during large repository analysis. ProgressTracker now uses RWMutex for concurrent-safe stage reads/writes, is initialized at analysis start points, and advances explicitly at each major stage boundary (metadata, commits, contributors, languages, metrics, dependencies, vulnerabilities, hotspots, report generation). Cached and quick-mode analyses fast-forward remaining stages to keep progress feedback consistent.

Changes

Progress Tracking with Thread-Safety for Repository Analysis

Layer / File(s) Summary
Thread-Safety for ProgressTracker
internal/ui/progress.go
ProgressTracker gains sync.RWMutex field and all stage state mutations/reads are guarded with appropriate locks. NextStage acquires write locks for state changes, and GetCurrentStage/GetAllStages/GetProgress use read locks. GetAllStages now returns a copied slice to prevent external mutation of internal state.
Initialize Progress Tracker at Analysis Entry Points
internal/ui/app.go
MainModel creates a fresh ProgressTracker and wires it into the loading view at four UI entry points: starting analysis from repository input, selecting a favorite for analysis, re-analyzing history, and triggering analysis from the dashboard.
Advance Progress Through Analysis Stages
internal/ui/app.go
The analyzeRepo function advances the progress tracker at each major stage: fetching repository metadata, analyzing commits and contributors, processing languages and files, computing health metrics, analyzing dependencies, scanning vulnerabilities, identifying hotspots, generating reports, and completing analysis.
Progress Fast-Forwarding for Cached & Quick Analysis
internal/ui/app.go
For cached analysis hits, incremental analysis with no changes, and quick-mode analysis that skip stages, the tracker is fast-forwarded through remaining stages before returning results, ensuring the UI reflects completed work across all analysis paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • agnivo988/Repo-lyzer#238: Both PRs modify analyzeRepo's stage-by-stage control flow; this PR reworks progress tracking/fast-forwarding while the related PR adds context-based cancellation checks.
  • agnivo988/Repo-lyzer#393: Both PRs modify quick-mode analysis logic in analyzeRepo; this PR adds progress fast-forwarding while the related PR changes quick-mode caching/early-return behavior.

Suggested labels

type:bug, level:advanced, hard, quality:clean

Poem

🐰 A tracker hops through stages clear,
With locks held tight, no race to fear,
Each checkpoint marked as work proceeds,
Progress blooms where the rabbit reads.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly addresses the main change: implementing async background analysis and thread-safe progress tracking to fix UI freeze issues, matching the core objectives.
Linked Issues check ✅ Passed The changes fully implement all coding requirements from #267: thread-safe progress tracking via sync.RWMutex, async background analysis via goroutines, progress polling mechanism, and staged progress indicators.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing UI freeze and progress tracking issues defined in #267; no unrelated modifications detected in the analyzed files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

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

🧹 Nitpick comments (1)
internal/ui/app.go (1)

1053-1056: 💤 Low value

Fast-forward count doesn't account for already-advanced stages.

At this point, 3 stages have already been advanced (metadata, commits, contributors). The loop advances 10 more times, but only 7 are needed to reach completion. While this works due to the guard in NextStage, it's inconsistent with the cached-result fast-forward at line 971 which correctly advances from stage 0.

Consider computing the remaining stages dynamically or using a helper method like CompleteAllStages() to avoid hardcoded counts that could drift.

🤖 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 `@internal/ui/app.go` around lines 1053 - 1056, The fast-forward loop
unconditionally calls tracker.NextStage() 10 times even though some stages were
already advanced (e.g., metadata/commits/contributors), causing a hardcoded
count that can drift; update this to compute remaining stages dynamically or add
a helper like tracker.CompleteAllStages() that repeatedly calls NextStage()
until completion (use the tracker and NextStage symbols to locate the logic) so
the code advances only the needed number of stages rather than a fixed 10
iterations.
🤖 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.

Nitpick comments:
In `@internal/ui/app.go`:
- Around line 1053-1056: The fast-forward loop unconditionally calls
tracker.NextStage() 10 times even though some stages were already advanced
(e.g., metadata/commits/contributors), causing a hardcoded count that can drift;
update this to compute remaining stages dynamically or add a helper like
tracker.CompleteAllStages() that repeatedly calls NextStage() until completion
(use the tracker and NextStage symbols to locate the logic) so the code advances
only the needed number of stages rather than a fixed 10 iterations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f8fd3c1-fee6-4541-b3eb-36ff34352647

📥 Commits

Reviewing files that changed from the base of the PR and between 6d6fa89 and 703a04c.

📒 Files selected for processing (2)
  • internal/ui/app.go
  • internal/ui/progress.go

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: Large Repository Analysis Causes UI Freeze and Missing Progress Feedback

1 participant