Repository navigation
Dismiss Cloud notifications everywhere at once (Cloud tree dot follows the left sidebar) #13004
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
246bf25
Test Cloud notification dismiss parity across the two sidebars
austinywang 7452629
Dismiss Cloud notifications everywhere at once
austinywang 1f99ecb
Merge branch 'main' into 13000-cloud-notification-dot-dismiss
lawrencecchen 614c3ed
Decide mute before admission and fail closed on unmapped terminals
austinywang 391110d
Merge branch 'main' into 13000-cloud-notification-dot-dismiss
lawrencecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import Foundation | ||
|
|
||
| /// What became of a row handed to the local notification store. | ||
| enum CloudNotificationDeliveryOutcome: Equatable, Sendable { | ||
| /// A local record exists; the row is consumed. | ||
| case delivered | ||
| /// Nothing here could take the row yet (no store, a placement that | ||
| /// vanished between resolution and delivery); the next fold retries it. | ||
| case declined | ||
| /// This Mac will never show the row (an admission drop, a muted | ||
| /// workspace): it is consumed and acknowledged as read at once, so no | ||
| /// indicator anywhere waits for a dismissal that cannot happen. | ||
| case suppressed | ||
| } | ||
|
|
||
| /// Turns one of a machine's notification rows into a local notification | ||
| /// record on the target the placement resolver chose. Owned by the machine's | ||
| /// provider; everything it reads arrives through closures so tests drive it | ||
| /// against the real store without a link. | ||
| @MainActor | ||
| struct CloudNotificationLocalDelivery { | ||
| let machineID: String | ||
| var store: @MainActor () -> TerminalNotificationStore? | ||
| /// The hub's admission gate, shared across every live machine. | ||
| var admit: @MainActor (CloudVMNotificationRow) -> CloudMachineNotificationGate.Decision | ||
| var machineName: @MainActor () -> String | ||
| /// The process title of a terminal from the accepted graph, for the | ||
| /// subtitle when the producer gave none. | ||
| var terminalTitle: @MainActor (_ terminalID: String) -> String? | ||
|
|
||
| func deliver(_ row: CloudVMNotificationRow, to target: CloudNotificationDeliveryTarget) -> CloudNotificationDeliveryOutcome { | ||
| guard let store = store() else { return .declined } | ||
| // Workspace mute is an admission decision of the person's own: the | ||
| // row is read here rather than left as a dot no local dismissal can | ||
| // reach. Decided before the gate so a muted row costs no budget. | ||
| let admissionWorkspaceID = store.notificationMuteAdmissionTabID( | ||
| claimedTabId: target.workspaceID, | ||
| surfaceId: target.panelID, | ||
| retargetsToLiveSurfaceOwner: target.panelID != nil | ||
| ) | ||
| guard !store.isWorkspaceNotificationsMuted(forTabId: admissionWorkspaceID) else { return .suppressed } | ||
| switch admit(row) { | ||
| case .allowed: | ||
| break | ||
| case .duplicateID, .identicalContent: | ||
| // A repeat of something this Mac already showed (or a row the | ||
| // store declined on an earlier fold). Nothing will ever show it, | ||
| // so it must not stay unread anywhere: read it now. | ||
| return .suppressed | ||
| case .machineRate, .fleetRate: | ||
| // Over budget right now. The row keeps its dot and is retried on | ||
| // the next fold, when the bucket has refilled; the burst is | ||
| // spread out, not lost. Tokens are only taken by admitted rows, | ||
| // so a retry never costs anything. | ||
| return .declined | ||
| } | ||
| let terminalTitle = row.terminalID.flatMap(terminalTitle) ?? "" | ||
| let machineName = machineName() | ||
| let subtitle: String | ||
| if let explicit = row.subtitle { | ||
| // The producer's own subtitle wins, as `cmux notify --subtitle` does locally. | ||
| subtitle = explicit | ||
| } else if terminalTitle.isEmpty { | ||
| subtitle = machineName | ||
| } else { | ||
| subtitle = String( | ||
| format: String(localized: "cloudNotification.subtitle.machine", defaultValue: "%@ on %@"), | ||
| terminalTitle, | ||
| machineName | ||
| ) | ||
| } | ||
| let recorded = store.addNotification( | ||
| tabId: target.workspaceID, | ||
| surfaceId: target.panelID, | ||
| title: row.title, | ||
| subtitle: subtitle, | ||
| body: row.body, | ||
| retargetsToLiveSurfaceOwner: target.panelID != nil, | ||
| correlationKey: CloudNotificationCorrelation.key(machineID: machineID, notificationID: row.id), | ||
| origin: .cloudVM(machineID: machineID) | ||
| ) != nil | ||
| // Any other decline is transient (the pane's live owner vanished | ||
| // between placement and delivery): the next fold re-resolves it. A | ||
| // second attempt meets the gate's duplicate-id rule and is read. | ||
| return recorded ? .delivered : .declined | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import Foundation | ||
|
|
||
| /// Which local notification records a read action covers, in the local | ||
| /// store's own terms. Mirrors `TerminalNotification.matches(tabId:surfaceId:)`: | ||
| /// `.workspace` covers every record in the workspace, `.surface` with a nil | ||
| /// surface covers only the workspace-level records, and `.all` covers | ||
| /// everything. Cloud rows are placed with the same vocabulary, so a read of a | ||
| /// target also covers the rows that would land there. | ||
| enum NotificationReadTarget: Equatable, Sendable { | ||
| case all | ||
| case workspace(UUID) | ||
| case surface(workspaceID: UUID, surfaceID: UUID?) | ||
| } | ||
|
|
||
| extension CloudNotificationDeliveryTarget { | ||
| /// Whether a read of `target` covers a row placed here, by the rule the | ||
| /// store applies to its own records. | ||
| func isCovered(by target: NotificationReadTarget) -> Bool { | ||
| switch target { | ||
| case .all: | ||
| return true | ||
| case .workspace(let workspaceID): | ||
| return self.workspaceID == workspaceID | ||
| case .surface(let workspaceID, let surfaceID): | ||
| return self.workspaceID == workspaceID && panelID == surfaceID | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A local workspace bound to a machine, as the placement resolver sees it. | ||
| struct CloudNotificationBoundWorkspace: Equatable, Sendable { | ||
| let workspaceID: UUID | ||
| let remoteWorkspaceID: String? | ||
| } | ||
|
|
||
| /// Where one of a machine's notifications lands on this Mac, resolved from the | ||
| /// catalog as it is right now, never from the placement at delivery time. The | ||
| /// same resolver answers both "where does this row go" at delivery and "which | ||
| /// rows does a read of this workspace or pane cover" at dismissal, so the two | ||
| /// can never disagree. | ||
| @MainActor | ||
| struct CloudNotificationPlacementResolver { | ||
| let machine: SurfaceMachineID | ||
| /// Local panes showing a resource of this machine. | ||
| var projections: @MainActor (SurfaceResourceID) -> [SurfaceProjection] | ||
| /// The remote workspace whose tab shows the terminal, from the accepted graph. | ||
| var remoteWorkspaceID: @MainActor (_ terminalID: String) -> String? | ||
| /// Local workspaces bound to the machine, in sidebar order. | ||
| var boundWorkspaces: @MainActor () -> [CloudNotificationBoundWorkspace] | ||
|
|
||
| /// The pane showing the terminal when one is open on this Mac, else the | ||
| /// local workspace standing for the terminal's remote workspace. A | ||
| /// terminal in a remote workspace the person has not opened here has no | ||
| /// local home: the row stays undelivered until one exists and the Cloud | ||
| /// tree dot is its indicator, instead of stacking onto whichever local | ||
| /// workspace happens to be bound to the machine (a workspace row then | ||
| /// badges the whole machine's notifications, manaflow-ai/cmux#13000). | ||
| /// Only a machine-level row (no terminal) lands on any local workspace | ||
| /// bound to the machine. A terminal the accepted graph places in no | ||
| /// workspace fails closed the same way: an unknown placement is not a | ||
| /// machine-level one. | ||
| func target(for row: CloudVMNotificationRow) -> CloudNotificationDeliveryTarget? { | ||
| let bound = boundWorkspaces() | ||
| guard let terminalID = row.terminalID else { | ||
| return bound.first.map { CloudNotificationDeliveryTarget(workspaceID: $0.workspaceID, panelID: nil) } | ||
| } | ||
| let resource = SurfaceResourceID(machine: machine, kind: .terminal, key: terminalID) | ||
| if let projection = projections(resource).first { | ||
| return CloudNotificationDeliveryTarget(workspaceID: projection.workspaceID, panelID: projection.panelID) | ||
| } | ||
| guard let remoteWorkspaceID = remoteWorkspaceID(terminalID) else { return nil } | ||
| return bound.first { $0.remoteWorkspaceID == remoteWorkspaceID } | ||
| .map { CloudNotificationDeliveryTarget(workspaceID: $0.workspaceID, panelID: nil) } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 50373
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 50373
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 50372
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 50372
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 9892
Make cloud notification admission transactional with local delivery.
CloudMachineNotificationGate.admitrecords an allowed row ID beforeCloudNotificationLocalDelivery.delivercallsstore.addNotification. If that call returnsnil, delivery returns.declined; the sync removes only its delivery bookkeeping. The next fold retries the row, receives.duplicateID, returns.suppressed, and queues an acknowledgement without creating a local record.Add a reserve, commit, and cancel gate API. Commit the reservation only after
addNotificationsucceeds. Cancel an allowed reservation before returning.declined. The gate reservation must remain the single source of truth for whether the row was consumed.🤖 Prompt for AI Agents