Repository navigation
fix(ports): stop live-port indicator flickering (scan debounce + re-init loop) - #5510
Conversation
…lures A worktree's plug icon renders only when it has ports. The scanner polls each execution host every 30s and, on a transient failure (SSH/IPC latency), substituted an empty "unavailable" scan — dropping that host's ports for the cycle and blinking the affected row's live-port indicator off, then on again next poll. Debounce per-host failures: reuse the host's last good scan until failures reach a tolerance, so a single dropped poll no longer zeroes the row. A reachable host reporting no ports has no unavailableReason, so a genuine port close still clears immediately. Logic extracted to a pure helper with tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The scan poll effect depended on the `refresh` callback identity, which gets a fresh reference whenever repos/settings are replaced (frequent in a busy workspace). Each change re-ran the effect, which reset the scan to null and kicked an immediate re-scan — a tight ~600ms loop that blinked the plug icon off/on even though the scanned ports never changed. Drive the poll and advertised-url effects off the latest refresh via a ref and key them on stable value-signatures (enable state, active scan key, host-set signature, runtime kind) instead of the callback identity. Incidental store churn no longer re-inits the scanner; it still polls every 30s, reacts to advertised-url events, and rescans on a real host-set or runtime change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Ready to review this PR? Stage has broken it down into 3 individual chapters for you:
Chapters generated by Stage for commit a78046c on Jun 16, 2026 4:50pm UTC. |
- Prune the per-host failure counter for failed-only hosts that disappear, not just hosts present in lastGood — avoids an unbounded failures map and a stale failure streak if the host reappears - Canonicalize scanTargetsSignature by sorting so a reordered-but-unchanged host set does not re-init the scan and reintroduce flicker Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughA new
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/renderer/src/components/ports/WorkspacePortScanner.tsx (1)
67-69: ⚡ Quick winMake
scanTargetsSignatureorder-insensitive.This signature is treated as a host-set key, but
join('|')is order-sensitive. If host ordering changes with the same hosts, the effect will still re-initialize and can reintroduce null→rescan churn.Proposed fix
const scanTargetsSignature = useMemo( - () => scanTargets.map(workspacePortScanKeyForTarget).join('|'), + () => scanTargets.map(workspacePortScanKeyForTarget).sort().join('|'), [scanTargets] )src/renderer/src/lib/workspace-port-scan-debounce.test.ts (1)
126-140: ⚡ Quick winAdd a regression that prunes
state.failuresfor failure-only keys.Current pruning coverage exercises keys present in
lastGood, but not keys that only ever failed. Add that case to lock behavior and prevent stale failure streak reuse.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6437ac6c-dbe8-475a-8819-0a9cd2d9195c
📒 Files selected for processing (3)
src/renderer/src/components/ports/WorkspacePortScanner.tsxsrc/renderer/src/lib/workspace-port-scan-debounce.test.tssrc/renderer/src/lib/workspace-port-scan-debounce.ts
|
Both nitpicks from the latest CodeRabbit review (reviewed at
|
AmethystLiang
left a comment
There was a problem hiding this comment.
Thanks — rebased and resolved against current main.
- Keeps the last good per-host port scan through one transient failure, while a reachable empty result still clears immediately.
- Limits host-change and advertised-URL refreshes to the affected host, avoiding unnecessary remote scan work.
- Adds coverage for retention, host changes/removal, hidden-window resumption, and scan-state stability.
#8174) launch-agent-in-new-tab.ts crossed the 300-line oxlint max-lines limit (303 counted lines) after #5510 and #7944 both grew it; verify only runs on PRs, so the over-limit state landed on main via a merge race and now fails lint for every open PR. Move the web-runtime host launch branch (stale-local-tab pruning plus createWebRuntimeSessionTerminal call) into launch-agent-web-host-tab.ts. No behavior change; the i18n key is kept so locale catalogs are untouched. Co-authored-by: Brennan Benson <[email protected]>
…nit loop) (stablyai#5510) * fix(ports): stop live-port indicator flickering on transient scan failures A worktree's plug icon renders only when it has ports. The scanner polls each execution host every 30s and, on a transient failure (SSH/IPC latency), substituted an empty "unavailable" scan — dropping that host's ports for the cycle and blinking the affected row's live-port indicator off, then on again next poll. Debounce per-host failures: reuse the host's last good scan until failures reach a tolerance, so a single dropped poll no longer zeroes the row. A reachable host reporting no ports has no unavailableReason, so a genuine port close still clears immediately. Logic extracted to a pure helper with tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(ports): stop port scan re-init loop that flickered live-port icons The scan poll effect depended on the `refresh` callback identity, which gets a fresh reference whenever repos/settings are replaced (frequent in a busy workspace). Each change re-ran the effect, which reset the scan to null and kicked an immediate re-scan — a tight ~600ms loop that blinked the plug icon off/on even though the scanned ports never changed. Drive the poll and advertised-url effects off the latest refresh via a ref and key them on stable value-signatures (enable state, active scan key, host-set signature, runtime kind) instead of the callback identity. Incidental store churn no longer re-inits the scanner; it still polls every 30s, reacts to advertised-url events, and rescans on a real host-set or runtime change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Address PR review feedback (stablyai#5510) - Prune the per-host failure counter for failed-only hosts that disappear, not just hosts present in lastGood — avoids an unbounded failures map and a stale failure streak if the host reappears - Canonicalize scanTargetsSignature by sorting so a reordered-but-unchanged host set does not re-init the scan and reintroduce flicker Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(ports): keep host scans targeted and stable * test(ports): cover scan debounce state --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Jinjing <[email protected]>
stablyai#8174) launch-agent-in-new-tab.ts crossed the 300-line oxlint max-lines limit (303 counted lines) after stablyai#5510 and stablyai#7944 both grew it; verify only runs on PRs, so the over-limit state landed on main via a merge race and now fails lint for every open PR. Move the web-runtime host launch branch (stale-local-tab pruning plus createWebRuntimeSessionTerminal call) into launch-agent-web-host-tab.ts. No behavior change; the i18n key is kept so locale catalogs are untouched. Co-authored-by: Brennan Benson <[email protected]>
What
The live-port "plug" icon on a worktree row flickers off/on instead of staying solid. Two independent causes in the workspace port scanner, both surfaced while testing the live ports UI.
Cause 1 — transient scan failures drop ports for a cycle
WorkspacePortScannerpolls each execution host every 30s. On a transient failure (SSH/IPC latency), the catch substituted an emptyunavailablescan, so that host's ports vanished from the merged result for the cycle → the affected worktree'sports.lengthhit 0 → the plug icon unmounted, then reappeared next poll.Fix: debounce per-host failures — reuse the host's last good scan until failures reach a tolerance (2). A reachable host reporting zero ports has no
unavailableReason, so a genuine port close still clears immediately. Logic extracted to a pure helper (workspace-port-scan-debounce.ts) with unit tests.Cause 2 — scanner re-init loop (~600ms)
Diagnostics showed scans repeating roughly every 600ms with identical results and no advertised-URL events — the scanner was re-initializing in a tight loop:
refreshcallback's identity.refreshgets a new identity wheneverrepos/settingsare replaced in the store (frequent in a busy workspace).setWorkspacePortScan(null)(plug disappears) andinstallWindowVisibilityIntervalscans immediately on install (plug reappears) → a ~600msnull → rescanblink even though the ports never changed.Fix: call the latest
refreshthrough a ref and key the poll/advertised-URL effects on stable value-signatures (enabled state, active scan key, host-set signature, runtime kind) instead of the churning callback identity. Incidental store churn no longer re-inits the scanner; it still polls every 30s, reacts to advertised-URL events, and rescans on a real host-set/runtime change.Tests
workspace-port-scan-debounce.test.ts— 6 cases: single-failure tolerance, drop-after-tolerance, immediate clear on a real (reachable) empty scan, failure-streak reset, per-host isolation, and state pruning.oxlintclean; existingWorktreeCardPortstest passes.Notes
Split out of #5501 (the touch-visibility icon fix) — these port-scanner fixes are independent of that change. A possible follow-up: the underlying
repos/settingsreference churn (~600ms) is a separate minor perf item; it no longer affects the port scanner but may cause extra re-renders elsewhere.