Repository navigation
Gate idle pollers to active workspace - #6583
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 3 minutes and 12 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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesAgent Scanning Pause/Resume and Port Deduplication
Sequence Diagram(s)sequenceDiagram
participant AppDelegate
participant TerminalController
participant PortScanner
participant AgentScanTimer
TerminalController->>PortScanner: setTrackedAgentScanningPaused(!isActive)
AppDelegate->>PortScanner: setTrackedAgentScanningPaused(false) on app active
PortScanner->>AgentScanTimer: updateAgentScanTimerLocked, schedule timer
AgentScanTimer->>PortScanner: runTrackedAgentScan fires
PortScanner->>PortScanner: refreshAgentPortsLocked, mark forceAgentResultWorkspaces on PID change
PortScanner->>PortScanner: validatedAgentResults, diff lastAgentPortsByWorkspace
alt ports changed or forced
PortScanner-->>PortScanner: deliver results, update cache
else unchanged and not forced
PortScanner-->>PortScanner: suppress delivery
end
AppDelegate->>PortScanner: setTrackedAgentScanningPaused(true) on app resigned
PortScanner->>AgentScanTimer: updateAgentScanTimerLocked, cancel timer
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (2 errors, 1 warning)
✅ Passed checks (20 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Greptile SummaryThis PR gates the 2-second
Confidence Score: 5/5Safe to merge; the timer pause/resume wiring and port-diff cache are logically correct, and the two previously identified delivery-ordering issues are addressed in the current implementation. The two prior blocking findings are resolved: lastAgentPortsByWorkspace is no longer evicted before scanAgentPorts — eviction is deferred to acknowledgeAgentResults after confirmed delivery — and the trackedAgentScanWorkspaceFilter early-return path that could leave agentScanTimer live is gone, replaced by setTrackedAgentScanningPaused which directly cancels the timer. The revision-gated acknowledgment correctly handles concurrent in-flight scans. Explicit refreshAgentPortsLocked calls still deliver immediately regardless of the pause flag, preserving agent start/stop correctness while backgrounded. Sources/PortScanner.swift — complex multi-state interaction between forceAgentResultWorkspaces, lastAgentPortsByWorkspace, and the revision guard; warrants careful reading but no current defects found. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant App as AppDelegate (MainActor)
participant PS as PortScanner (queue)
participant MA as MainActor
participant WS as Workspace state
App->>PS: setTrackedAgentScanningPaused(true)
PS->>PS: cancel agentScanTimer
App->>PS: setTrackedAgentScanningPaused(false)
PS->>PS: create agentScanTimer (2s)
loop Every 2s while active
PS->>PS: runTrackedAgentScan()
PS->>MA: agentPIDsProvider(workspaceIds)
MA-->>PS: "UUID to Set<Int> map"
PS->>PS: finishTrackedAgentScan()
PS->>PS: "scanAgentPorts() -> validatedAgentResults()"
PS->>MA: "onAgentPortsUpdated(workspaceId, ports) -> Bool"
MA->>WS: "agentListeningPorts = ports"
MA-->>PS: true or false
PS->>PS: acknowledgeAgentResults()
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant App as AppDelegate (MainActor)
participant PS as PortScanner (queue)
participant MA as MainActor
participant WS as Workspace state
App->>PS: setTrackedAgentScanningPaused(true)
PS->>PS: cancel agentScanTimer
App->>PS: setTrackedAgentScanningPaused(false)
PS->>PS: create agentScanTimer (2s)
loop Every 2s while active
PS->>PS: runTrackedAgentScan()
PS->>MA: agentPIDsProvider(workspaceIds)
MA-->>PS: "UUID to Set<Int> map"
PS->>PS: finishTrackedAgentScan()
PS->>PS: "scanAgentPorts() -> validatedAgentResults()"
PS->>MA: "onAgentPortsUpdated(workspaceId, ports) -> Bool"
MA->>WS: "agentListeningPorts = ports"
MA-->>PS: true or false
PS->>PS: acknowledgeAgentResults()
end
Reviews (9): Last reviewed commit: "fix: purge stale agent port scan state" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@cmuxTests/PortScannerTests.swift`:
- Around line 10-36: The PortScannerProcessCaptureTests struct declares `@Suite`
without the .serialized trait, but the test reads process-global file descriptor
counts and performs baseline and delta assertions that can become
non-deterministic when tests run concurrently. Modify the `@Suite` annotation on
the PortScannerProcessCaptureTests struct to include the .serialized trait by
changing `@Suite` to `@Suite`(.serialized), which ensures tests in this suite
execute serially and prevents concurrent file descriptor changes from affecting
the measurements in captureStandardOutputDoesNotLeakPipeFDs.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: aa5b0431-bd14-4177-b259-3905a3346665
⛔ Files ignored due to path filters (1)
.github/swift-file-length-budget.tsvis excluded by!**/*.tsv
📒 Files selected for processing (5)
Sources/AppDelegate.swiftSources/PortScanner.swiftSources/TerminalController.swiftcmuxTests/PaneMemoryGuardrailTests.swiftcmuxTests/PortScannerTests.swift
…ottle # Conflicts: # .github/swift-file-length-budget.tsv
…e silently dropped — #6518 (terminal input after window key restore), #6508 (defer restored WebViews until visible), #6559 (avoid DevTools teardown on redock), #6583 (gate idle port scanning to active workspace), #6528 (canvas scroll-hint debug menu), #6580 (drop re-introduced sideDock promote block). #6582/#6517 deferred (see merge-deferred-gaps)
Summary
Closes #6545.
This is a focused slice of the broader poller/resource tracker in #5731 and the SwiftUI AttributeGraph saturation symptoms in #5570. The patch confirms the documented mechanism in source and reduces the timer-driven poller -> Workspace-level publish -> graph-wide invalidation chain without attempting the full #5731 rewrite.
Changes:
Mechanism confirmed
Read the issue body/comment and verified the cited source paths:
Sources/PortScanner.swifthas a 2sDispatchSourceTimerthat callsrunTrackedAgentScan()and hops throughagentPIDsProvideron the MainActor.RestorableAgentSessionIndex.load()is documented inSources/Workspace.swiftas sysctl-per-record plus disk work that can take hundreds of ms to seconds.CmuxTopProcessSnapshot.captureflows throughSources/CmuxTopProcessEnumeration.swiftand enumerates all BSD processes.SidebarGitMetadataServicedoes off-main git snapshots, then applies via MainActor. This PR does not rewrite the git/PR polling subsystem or the pane-memory process snapshot subsystem; those remain broader Master: unbounded per-workspace resource accumulation — ~30 GB memory, system-wide lag (immortal surfaces, mass agent auto-resume, unthrottled pollers) #5731 scope.Tests and limits
Added behavioral coverage for guardrail descriptors covering registered window managers and keeping background workspaces represented. Kept the touched PortScanner FD-count regression on XCTest because it samples process-global
/dev/fdstate and should not move into Swift Testing's default parallel execution model.Not unit-testable in this PR: the full five-day soak profile, SwiftUI AttributeGraph transaction cost, and the private PortScanner agent-port diff path without adding a production-only test seam. The proof here is source-level mechanism confirmation plus focused behavior tests where there is an existing runtime seam.
Local validation run:
git diff --check./scripts/lint-pbxproj-test-wiring.shpython3 scripts/swift_file_length_budget.pyPer task instruction, I did not run a local app build, reload, or bare
xcodebuild; CI is the compile/test gate before any dev build is launched.