fix: throttle agent detection loop against detect_reset notify storms#4
Draft
wkentaro wants to merge 1 commit into
Draft
fix: throttle agent detection loop against detect_reset notify storms#4wkentaro wants to merge 1 commit into
wkentaro wants to merge 1 commit into
Conversation
The per-pane agent detection loop wakes on its normal 300-500ms tick or when detect_reset is notified. tokio::Notify coalesces to a single stored permit, so a sustained notify source (full-lifecycle authority re-asserted on every app event, repeated report_agent_session, or agent-state churn across many panes) let the loop re-probe /proc and re-emit with no sleep, pegging a CPU core per affected pane and starving the single-threaded server loop so client handshakes timed out and the session froze. Bound both detection loops to a 50ms minimum interval between work iterations so a detect_reset storm cannot drive them faster than the fastest legitimate tick, while keeping reset responsiveness well under the normal tick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Throttle the per-pane agent-detection loop so a burst of
detect_resetnotifications can't drive it into a high-CPU spin.Why
Each pane runs an agent-detection task shaped like:
detect_resetfires whenever the pane's foreground process group changes. An agent that rapidly toggles its foreground pgid produces a storm of notifications, each of which wakes the loop immediately and bypasses the intendedsleeptick. The detection work then runs back-to-back with no spacing, spinning the task at high CPU (and adding load that can make the UI lag).Fix
Add a minimum interval between detection iterations: if the previous iteration finished less than
DETECTION_LOOP_MIN_INTERVALago, sleep the remainder before running again. Adetect_resetstorm now collapses into at most one iteration per interval instead of an unbounded spin. Covered by unit tests for the throttle helper plus an integration test that fires adetect_resetstorm and asserts the loop stays throttled.Scope
Independent fix, unrelated to the
ui.pane_borders = "minimal"feature (#1). Related in spirit to the 0.6.10 detection-reset-loop fix (ogulcancelik#560, ogulcancelik#565) but a distinct path (the notify storm bypassing the loop's own throttle).