Repository navigation
Cap sidebar status/metadata dictionaries to bound the sidebar view-graph livelock (#5845) #5855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e9bef7a
8a12328
71e9eae
0c8a7ee
f81f895
91e1505
6a713b3
df18b8a
8e2f1e5
d6e0e23
9588405
40f34e4
1b675fa
efeac54
2a5e2e0
76a896d
ce0fa83
c77521c
8f357b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10776,8 +10776,12 @@ final class Workspace: Identifiable, ObservableObject { | |
| @Published private(set) var tmuxWorkspaceFlashReason: WorkspaceAttentionFlashReason? | ||
| @Published private(set) var tmuxWorkspaceFlashToken: UInt64 = 0 | ||
| var manualUnreadMarkedAt: [UUID: Date] = [:] | ||
| @Published var statusEntries: [String: SidebarStatusEntry] = [:] | ||
| @Published var metadataBlocks: [String: SidebarMetadataBlock] = [:] | ||
| @Published var statusEntries: [String: SidebarStatusEntry] = [:] { | ||
| didSet { trimSidebarStatusEntriesIfNeeded() } | ||
| } | ||
| @Published var metadataBlocks: [String: SidebarMetadataBlock] = [:] { | ||
| didSet { trimSidebarMetadataBlocksIfNeeded() } | ||
| } | ||
| @Published private(set) var latestConversationMessage: String? | ||
| @Published private(set) var latestSubmittedMessage: String? | ||
| @Published private(set) var latestSubmittedAt: Date? | ||
|
|
@@ -14455,6 +14459,56 @@ final class Workspace: Identifiable, ObservableObject { | |
| } | ||
| } | ||
|
|
||
| /// Upper bound on retained sidebar status pills / metadata blocks per | ||
| /// workspace. The sidebar `status`/`metadata` socket API lets agents and CI | ||
| /// scripts insert entries under arbitrary caller-chosen keys. Without a cap, | ||
| /// a long-running or verbose integration (e.g. ~30 live agent sessions over | ||
| /// hours, https://github.com/manaflow-ai/cmux/issues/5845) grows these | ||
| /// `@Published` dictionaries without bound, which both leaks memory and makes | ||
| /// the per-tick `removeDuplicates` equality check and the | ||
| /// `sidebarStatusEntriesInDisplayOrder()` / `sidebarMetadataBlocksInDisplayOrder()` | ||
| /// sorts that feed the sidebar view graph progressively more expensive on the | ||
| /// main thread. The bound is generous enough that no realistic integration | ||
| /// (the collapsed sidebar shows at most a handful of pills) is affected; | ||
| /// it only clamps pathological growth. Mirrors the `logEntries` cap above. | ||
| static let maxSidebarStatusEntries = 200 | ||
| static let maxSidebarMetadataBlocks = 200 | ||
|
|
||
| /// Evicts the lowest-priority, then oldest, status entries once the cap is | ||
| /// exceeded so retention matches `sidebarStatusEntriesInDisplayOrder()`: | ||
| /// high-priority and recent entries (the ones actually shown) survive. | ||
| private func trimSidebarStatusEntriesIfNeeded() { | ||
| guard statusEntries.count > Self.maxSidebarStatusEntries else { return } | ||
| let keptKeys = statusEntries.values | ||
| .sorted { lhs, rhs in | ||
| if lhs.priority != rhs.priority { return lhs.priority > rhs.priority } | ||
| if lhs.timestamp != rhs.timestamp { return lhs.timestamp > rhs.timestamp } | ||
| return lhs.key < rhs.key | ||
| } | ||
| .prefix(Self.maxSidebarStatusEntries) | ||
| .map(\.key) | ||
| let kept = Set(keptKeys) | ||
| // Reassigning re-enters didSet, but the next pass sees count <= cap and | ||
| // returns immediately, so recursion terminates at depth two. | ||
| statusEntries = statusEntries.filter { kept.contains($0.key) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Practical impact is negligible, so I left the ranking as priority/timestamp. The structured-agent-hook keys are a fixed 16-key allowlist ( — Claude Code
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an insert pushes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping the single whole-dictionary reassignment. The second — Claude Code
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your analysis is correct on all three counts. The reassign and per-key paths produce the same notification count on the single-entry overflow path (1 insert notification + 1 trim notification either way), the reassign is strictly fewer notifications than per-key removal on the bulk-assign path, and the overflow path itself is the bounded pathological case the cap exists to contain. I'll retract the concern — the current approach is the right choice here. |
||
| } | ||
|
|
||
| /// Mirror of `trimSidebarStatusEntriesIfNeeded()` for metadata blocks, | ||
| /// matching `sidebarMetadataBlocksInDisplayOrder()` retention. | ||
| private func trimSidebarMetadataBlocksIfNeeded() { | ||
| guard metadataBlocks.count > Self.maxSidebarMetadataBlocks else { return } | ||
| let keptKeys = metadataBlocks.values | ||
| .sorted { lhs, rhs in | ||
| if lhs.priority != rhs.priority { return lhs.priority > rhs.priority } | ||
| if lhs.timestamp != rhs.timestamp { return lhs.timestamp > rhs.timestamp } | ||
| return lhs.key < rhs.key | ||
| } | ||
| .prefix(Self.maxSidebarMetadataBlocks) | ||
| .map(\.key) | ||
| let kept = Set(keptKeys) | ||
| metadataBlocks = metadataBlocks.filter { kept.contains($0.key) } | ||
| } | ||
|
|
||
| // MARK: - Panel Operations | ||
|
|
||
| private func seedTerminalInheritanceFontPoints( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.