Repository navigation
fix(terminal): damp park-verdict churn that is too slow to burst - #20851
Conversation
The cold-park verdict flip damper only engaged on a burst: 3 flips inside a 1s
window, a threshold derived from React's 50-commit nested-update bail. The
notice limit — 12 flips in 60s — was explicitly breadcrumb-only, on the
reasoning that churn that slow was never near React's bail and damping it would
spend a mounted pane's memory for no crash-safety gain.
The field disagrees about the cost, though not for the reason first recorded.
WHAT THE BUNDLE SHOWS
Bundle Nz4kzIG_NwLd8KObgjJDKA (v1.4.201, win32) carries 52 park-verdict churn
crumbs. They are two unrelated episodes across four launches, not one run:
L3 09-14 00:53 35 crumbs, 1 tab, 46.9 min, 34 window + 1 burst
L4 09-14 17:07 17 crumbs, 4 tabs, 8.9 min, 17 window + 0 burst
L3's 46.9 min counts a lone trailing burst; the window-triggering run itself is
35.2 min, with an 11.7 min quiet gap before that final burst.
Per-flip cadence is elapsedMs / (NOTICE_LIMIT - 1), not / NOTICE_LIMIT: the
window opens ON a flip, so the 12th sits 11 intervals later. L3 runs 3.19s /
4.63s / 5.44s per flip (min/median/max); L4 runs 3.19 / 3.20 / 5.01.
Across 321 field bundles, 24 carry this churn and all 24 burst at least once —
though those 24 are roughly 17 devices, and 23 of them are burst-only, so the
load-bearing fact is narrower than it sounds: this install is the ONLY one that
ever tripped the window rule, and that is what ran undamped.
WHAT IT COSTS, STATED ACCURATELY
Each flip remounts the pane. A remount does NOT reconnect a terminal: parking
deliberately keeps the PTY alive (terminal-parked-tab-watchers runs a pane-less
byte watcher), SSH restores from main's snapshot, and a remote runtime
re-subscribes a stream on a per-environment multiplexer that outlives the pane.
The cost is a remount each time, indefinitely.
The user who filed wrote "The connection closes, reconnects and again and again
and again all the time. Is a cycle." An earlier draft of this change took that
as the mechanism. It is not: the bundle carries no remote-terminal stream-stall
recovery crumbs, no daemon session churn inside either churn window, and one
pane-recovery remount two hours earlier. And the report was filed in L4, 12.3
minutes AFTER that launch's churn had already stopped. The churn is real and
worth damping on its own terms; the causal link to that sentence is not
established, and this change should not be read as proving it.
THE FIX
The notice limit now engages the same unpark pin the burst does, backing off ×2
per consecutive notice window to an 8-minute ceiling, clearing once a full
window closes below the limit.
Measured closed-loop — driving the pin back into the verdict the way
useTerminalParkVerdictPin does — over 47 simulated minutes, counting pane
remounts, which is the user-visible quantity:
per flip transitions before -> after ceiling reached
3193 ms 884 -> 96 (9.2x fewer) 8x
4627 ms 610 -> 96 (6.4x fewer) 8x
4800 ms 588 -> 96 (6.1x fewer) 8x
5000 ms 564 -> 126 (4.5x fewer) 8x
5442 ms 519 -> 156 (3.3x fewer) 8x
These count verdict TRANSITIONS; a mount/unmount cycle is two, so actual pane
mounts are half each figure. The ratios are unaffected. The harness applies the
pin in the same commit cascade as the flip that caused it, which is what the
hook does and what three rounds of review showed an open-loop harness cannot
see.
TRADE-OFFS AND LIMITS, NONE OF THEM HIDDEN
- This does not fix the driver. Whatever keeps re-proposing the park is still
unidentified; the pin masks the rendered verdict and the driver resumes when
each pin lapses. This caps the remount rate of an oscillation; it does not end
one.
- A pinned pane stays mounted and holds its memory, re-armed while churn
persists. One oscillating per-worktree flag flips every tab in that worktree
in the same pass, so all of them can pin at once. The merged verdict includes
the retention-budget force-park, so a churn-pinned pane can stay mounted
through memory reclamation that was trying to free it — and the reclaimer
records success either way, because its only anomaly breadcrumb fires on a
different condition.
The honest number is a duty cycle, not a ceiling. Measured per cadence:
89.7% of wall time pinned at 3193ms/flip, 84.3% at 4627, 83.9% at 4800,
77.8% at 5000, 69.1% at 5442, with a peak contiguous pin of ~480s. Before this
change none of these cadences pinned at all, so blocked reclamation goes from
roughly 0% to 69-90%. Repo-stated cost is ~2.5MB per mounted pane at the 5k
scrollback default and ~19MB at 50k. This is the strongest form of the
original "memory is not free" objection and the change does not answer it.
- Only the notice path backs off; a burst still takes a flat one-window pin.
The corpus supports leaving it: repeat bursts arrive a median 673s apart
(n=29, grouped by bundle/launch/tab; 356s if physical pairs are deduped), and
1 of those 29 inter-arrivals falls in the band that would mean re-firing the
instant a pin lapsed. That margin is thin — the next gap above the band is
75.3s, 0.3s outside it.
- One hard edge, geometric: reaching 12 flips takes 11 intervals, so churn
slower than 60s/11 = 5454.5ms per flip never reaches the limit at all. The
field's slowest observed episode runs 5441.8ms, 12.7ms inside it. Past roughly
4.7s per flip each window only barely makes the limit, so damping engages
later and the win shrinks from 9.2x to 3.3x — but the back-off reaches the
8-minute ceiling at every cadence measured.
- Crumb volume drops by roughly 6x, a loss of
telemetry sensitivity for the very corpus scan that found this. The surviving
'window' crumbs carry sustainedPinCount, which discriminates sustained churn
better than raw volume did; 'burst' crumbs do not carry it. The detection
method changes either way.
REVIEW: TWO ROUNDS, AND BOTH FOUND THE FIX ITSELF
Round 1 found the back-off never left 1x in production. While a tab is pinned
the hook subtracts it from the rendered verdict, so no flip is recorded and
windowStartMs never advances; by the time a pin lapsed, windowStartMs was always
older than a full window, so the quiet branch wiped sustainedPinCount on the
first pass after EVERY pin. Closed-loop, that shipped 3.6x the remounts
intended. The 24 tests then in the file passed either way, because the harness
was open-loop. A second lens found five wrong claims in the commit message,
including a per-flip divisor of 12 where the code uses 11 — which made the
stated safety margin 37x too generous — and a reconnect mechanism the source
contradicts.
Round 2 attacked round 1's fix and found two more:
- The back-off RATCHETED. The flip path cleared it on `flips < noticeLimit`,
and the notice path leaves `flips` at exactly noticeLimit, so a window
reopening after hours of silence did not clear it. Four isolated episodes
six hours apart reached the 8-minute ceiling — the precise behaviour the
code comment claimed was impossible.
- And it was INERT above ~4.7s per flip, because a lapsing pin knocks the next
window out of alignment so it closes at 11 of 12, which that same
`flips < noticeLimit` test read as the churn easing. At the field's slowest
observed cadence round 1's fix changed nothing at all: 519 -> 346 both with
and without it.
Both come from one wrong question. The reset now asks whether the tab has been
genuinely quiet — a full window with no flip and no live pin, tracked on an
explicit lastFlipMs — or whether the closing window held fewer than half the
notice limit. A window closing at 11 of 12 is neither.
Round 3 found the defect inside round 2's fix, and it was one line. Engaging the
pin IS a rendered verdict transition: the hook drops the tab from the parked
set, the effect re-runs on the changed dep, and that flip lands while the pin is
live — overwriting the future deadline with the current time. The back-off then
cleared one window after the pin STARTED rather than one window after it ended.
Round 3 also showed the residual slow-cadence weakness was this bug and not the
geometry the round-2 message blamed, and that reverting to round 2's threshold
still passed all 31 tests. `lastFlipMs` no longer moves backwards off a live
deadline, and a closed-loop test that records a flip inside a live pin now kills
both that clobber and round 2's threshold.
Round 4 found no defect inside round 3's fix and judged it mergeable. It did
find that the eased-flip clause was itself untested — four mutations of it,
including reverting to round 2's threshold, passed every test — and that the
test whose comment claimed to cover it was satisfied by the other disjunct. A
sparse-churn test (three flips per window, indefinitely: eased but never silent)
now separates the two and kills all four.
Also from the review rounds: two separate dead clauses in this function, one
added by each of the previous two rounds, are gone; the burst-interval median in
the shipped comment was one row off (673s, not 732s) and n is 29, not 30. That
median is grouping-fragile — 702.7s by (bundle,tab), 356.1s deduped — but the
facts it supports are not: 1 value in the 59-75s band under every grouping, and
the next gap above it is 75.3s.
Known and not fixed: a tab churning continuously at 6-10 flips per window sits
in the gap between both reset conditions and holds its back-off indefinitely, so
the next notice after it speeds up pins for the ceiling rather than one window.
Stated rather than fixed: because quiet is measured from the pin deadline, a tab
at the 8-minute ceiling needs roughly nine minutes of real silence before the
back-off clears, not one window. The record's doc says so.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughTerminal park flip telemetry now tracks sustained churn and applies exponentially increasing pin durations up to a configured maximum. Activity uses flip and pin deadlines, and sustained state resets after quiet or reduced-churn windows. Force-parking disables sustained pins while retaining burst protection. Tests cover cadence thresholds, closed-loop churn, back-off, maximum duration, isolated episodes, reset behavior, and force-parking. A test helper now supplies the required Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No identified issue blocks merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Longer-lived pins can keep terminal panes mounted outside the ordinary eviction budget, and their combined memory cost is unknown. Forced eviction overrides these new pins. No new cross-service access or verified security issue is established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the user impact, mechanism, rationale, testing, limitations, and compatibility considerations. However, it does not provide the required linked issue, and it does not provide the required visual proof or the exact permitted N/A statement for this behavior change. Resolution Link a tracked issue in the Linked Issue section. Add before-and-after visual proof, or explain why there is truly no visual or interaction change using exactly
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
ℹ️ No critical issues — two documentation nits inline. I independently re-ran the changed suites (38 tests, green), typecheck, and lint, and reproduced the closed-loop damping claims below the window cliff.
Reviewed changes
- Sustained-churn damping — the notice limit (12 flips/60s) now engages the unpark pin instead of only breadcrumbing, with exponential back-off (
60s → 8min) tracked bysustainedPinCount. - Quiet-activity tracking — new required
lastFlipMsrecords a flip or a suppressing pin's deadline, so the back-off resets only after a genuinely quiet window and cannot ratchet across isolated episodes. - Pin-clobber fix —
lastFlipMs = max(nowMs, pinnedUntilMs)keeps a flip that lands inside a live pin (pin engagement is itself a transition) from overwriting the deadline and clearing the back-off a window early. - Test coverage — added an open-loop regression guard plus a closed-loop harness that feeds the pin back into the rendered verdict, pinning the clobber, the alignment cliff, the 8× ceiling, and both reset conditions.
I verified the state machine independently: a 47-minute closed-loop run at the 5442 ms/flip slow end reaches the ceiling (sustainedPinCount 7, max pin 480000), and a 2000-5454 ms sweep in 20 ms steps found no cadence where the back-off stays at the first 60s pin. The documented cliff sits between 5442 and 5460 ms.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Sustained pins now yield to retention force-parking —
allowSustainedPinis threaded fromuseTerminalTabColdParking(!isForceParked) through the pin hook intorecordParkVerdictFlips, where a live'window'pin is released at the top of the per-tab loop. A newpinTriggerfield lets'burst'pins survive the eviction. - Hook-level regression coverage —
terminal-retention-churn-pins.test.tsxexercises release-on-force (with the live-shell exemption intact), no re-arming while forced, damping resuming after force ends, and burst-deadline preservation across both initial force-park states. - Two prior nits resolved in
4ee8fe21— the stale burst-corpus stats were removed andquietSinceMswas renamed tolastFlipMs.
I re-ran the three changed suites (42 tests, green) and mutation-checked the new hook tests for teeth: forcing allowSustainedPin always true fails the release/no-re-arm tests, and releasing burst pins alongside window pins fails the burst-preservation test. The release path and its 'window'-only guard are both genuinely covered. This approval covers the new code only — the retained-memory verification item the PR body already tracks remains the author's merge gate.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Eight-minute ceiling regression test — drives the hook to the 8× sustained pin, parks the pane, and asserts it stays mounted until exactly the pin deadline lapses before the watchers are re-synced back to parked, then disposes the timer on unmount.
- Unmount cleanup regression test — asserts a live sustained-pin timer is cleared when the worktree unmounts.
I re-ran terminal-retention-churn-pins.test.tsx (6/6 green, tree clean) and mutation-checked both new tests for teeth: neutering the disposal effect fails the unmount test, and flattening pinnedForMs to a single window fails the ceiling test. The two prior documentation nits remain resolved. This approval covers the new tests only; the retained-memory verification item the PR body already tracks remains the author's merge gate. No fresh rendered-app verification was claimed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Some terminal panes repeatedly unload and rebuild every three to five seconds. Keep an affected pane mounted temporarily so it rebuilds less often, while allowing retention-budget eviction to take priority.
What Changed
Twelve parking transitions within one minute now trigger the existing keep-mounted mechanism. Repeated episodes increase the delay from one to two, four, then eight minutes; a quiet window resets it. The existing rapid-loop protection remains unchanged.
A retention force-park cancels sustained pins, including pins earned before eviction, and prevents rearming while forced. Live-shell exemptions and watcher synchronization are preserved. Regression tests exercise actual hook behavior, including an earned eight-minute pin expiring without another input change and disposal of its timer on unmount.
Why
The existing three-transitions-in-one-second protection misses the slower repeated remounts recorded in crash bundles. Extending that mechanism reduces remounts without introducing another parking policy. Closed-loop simulations at the recorded cadences produce 3.3–9.2 times fewer transitions over 47 simulated minutes.
This is a mitigation, not a root-cause or memory-leak fix. Each pin has a deadline and renewal needs fresh churn after expiry. Continued churn can keep ordinary panes mounted longer; there is no new global count or byte limit. The existing fallback retention budget applies to worktrees ordinary parking cannot handle, and its forced evictions override these sustained pins.
Linked Issue
Crash bundle
Nz4kzIG_NwLd8KObgjJDKA(Windows 1.4.201), referenced in the crash-scan reports. No separate issue is linked. The bundle establishes sustained churn, not that remounts caused the reported connection loss.Visual Proof
No fresh rendered before/after capture. The automated hook regressions and closed-loop simulations verify parking transitions and watcher handover; they do not reproduce the user's connection-loss symptom or measure production memory usage.
Testing
Local macOS validation: 71 cases across nine churn, parking and retention suites passed across the focused runs, including all six final hook integration cases. Two eviction regressions fail before the correction. Web typecheck, targeted lint, formatting, whitespace and changed-code quality pass.
Full PR Checks passed the verification jobs on production head
a7f619f624: all eight test shards, relay integration, static analysis, types, macOS/Windows packaging and applicable changed E2E specs. The final commit adds only two regression tests; its six-case suite, web types and quality checks also pass locally. No fresh Windows, Linux or SSH rendered-app run is claimed.Review
Independent review found no concrete remaining blocker for this mitigation. Verified deadline expiry and cleanup; sustained pins yield to forced eviction while preserving existing burst protection. The root oscillation and fleet memory impact remain unproven.
Agent skill upstream boundary
Notes
The renderer policy covers local, SSH and paired-host panes. It does not change remote messages or the execution host's terminal lifecycle. Parking leaves the PTY alive.
Checklist