fix(tui): show Conns: 1 for single-connection downloads#315
fix(tui): show Conns: 1 for single-connection downloads#315SuperCoolPencil merged 1 commit intoSurgeDM:mainfrom
Conversation
When a download is active with speed > 0 but reports 0 connections (SingleDownloader, range requests not supported), display 1 instead of 0. An active download with speed must have at least one connection. Fixes SurgeDM#287
| if isActive { | ||
| connStr := "0" | ||
| if d.Connections > 0 { | ||
| connStr = fmt.Sprintf("%d", d.Connections) | ||
| conns := d.Connections | ||
| if conns == 0 { | ||
| conns = 1 // Single-connection download (range requests not supported) | ||
| } | ||
| connStr := fmt.Sprintf("%d", conns) | ||
| leftColItems = append(leftColItems, lipgloss.JoinHorizontal(lipgloss.Left, StatsLabelStyle.Width(7).Render("Conns:"), StatsValueStyle.Render(connStr))) | ||
| } |
There was a problem hiding this comment.
Consider fixing at the source rather than the display layer
This compensates for the missing ActiveWorkers increment in SingleDownloader.Download(). Patching the display layer means any other consumer of ProgressState.GetProgress() (e.g. remote service, polling events) still sees 0 connections for single-connection downloads. Incrementing ActiveWorkers at the start of Download() and decrementing it on return would fix the value at the source and remove the need for this view-layer special case.
Rule Used: # Code Review Rule: Suggest Architectural Improvem... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/tui/view.go
Line: 911-918
Comment:
**Consider fixing at the source rather than the display layer**
This compensates for the missing `ActiveWorkers` increment in `SingleDownloader.Download()`. Patching the display layer means any other consumer of `ProgressState.GetProgress()` (e.g. remote service, polling events) still sees 0 connections for single-connection downloads. Incrementing `ActiveWorkers` at the start of `Download()` and decrementing it on return would fix the value at the source and remove the need for this view-layer special case.
**Rule Used:** # Code Review Rule: Suggest Architectural Improvem... ([source](https://app.greptile.com/review/custom-context?memory=4d82344e-33c4-4e14-bbc7-81d79af11b7e))
How can I resolve this? If you propose a fix, please make it concise.| if isActive { | ||
| connStr := "0" | ||
| if d.Connections > 0 { | ||
| connStr = fmt.Sprintf("%d", d.Connections) | ||
| conns := d.Connections | ||
| if conns == 0 { | ||
| conns = 1 // Single-connection download (range requests not supported) | ||
| } | ||
| connStr := fmt.Sprintf("%d", conns) | ||
| leftColItems = append(leftColItems, lipgloss.JoinHorizontal(lipgloss.Left, StatsLabelStyle.Width(7).Render("Conns:"), StatsValueStyle.Render(connStr))) | ||
| } |
There was a problem hiding this comment.
No test coverage for this render path
view_test.go exists but has no test for renderFocusedDetails with Connections == 0 && Speed > 0. Adding a case there would prevent a future regression where someone removes the guard and the UI silently reverts to showing "Conns: 0".
Rule Used: What: All code changes must include tests for edge... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/tui/view.go
Line: 911-918
Comment:
**No test coverage for this render path**
`view_test.go` exists but has no test for `renderFocusedDetails` with `Connections == 0 && Speed > 0`. Adding a case there would prevent a future regression where someone removes the guard and the UI silently reverts to showing "Conns: 0".
**Rule Used:** What: All code changes must include tests for edge... ([source](https://app.greptile.com/review/custom-context?memory=2b22782d-3452-4d55-b059-e631b2540ce8))
How can I resolve this? If you propose a fix, please make it concise.
SuperCoolPencil
left a comment
There was a problem hiding this comment.
Hi @mvanhorn, Thanks for the PR!
I would love if as suggested by AI reviewer, we could fix the problem at source rather than TUI layer so that the problem is mitigated in future user layers as well.
Also, some tests that prevent against future regressions would be really appreciated.
|
Appreciate the merge, @SuperCoolPencil. |
|
Thanks for contributing 🚀 |
Summary
When a download doesn't support range requests (SingleDownloader), the TUI shows "Conns: 0" even though there's an active connection transferring data.
Why this matters
Showing 0 connections while a download is actively running with nonzero speed is confusing. The SingleDownloader uses one connection but the
ActiveWorkersatomic counter doesn't track it, soProgressState.GetProgress()returns 0 for the connections field.Changes
internal/tui/view.go(line 912): When a download is active (speed > 0) and reports 0 connections, display 1 instead. An active download with speed must have at least one connection.Testing
d.Connectionsd.Connections == 0AND the download is activeFixes #287
This contribution was developed with AI assistance (Claude Code).
Greptile Summary
This PR fixes a TUI cosmetic issue where single-connection downloads (served by
SingleDownloader, which never incrementsActiveWorkers) displayed "Conns: 0" during an active transfer. The fix adds a display-layer fallback inrenderFocusedDetails: whenisActiveis true andd.Connections == 0, the rendered value is coerced to 1.Confidence Score: 5/5
isActivecheck and cannot over-report connections for multi-connection downloads.Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[renderFocusedDetails] --> B{isActive?\nnot done, not paused,\nSpeed > 0} B -- No --> C[Skip Conns row] B -- Yes --> D{d.Connections == 0?} D -- No --> E[conns = d.Connections\nfrom ActiveWorkers] D -- Yes --> F["conns = 1\n(SingleDownloader fallback)"] E --> G[Render 'Conns: N'] F --> G subgraph Root Cause H[SingleDownloader.Download] --> I[ActiveWorkers never\nincremented/decremented] I --> J[GetProgress returns\nconnections = 0] J --> D endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(tui): show Conns: 1 for single-conne..." | Re-trigger Greptile
Context used (3)