fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Patch policies: Prompt end users before app updates on macOS

Open noahtalerman opened this issue 9 months ago • 21 comments

  • @noahtalerman: Let's also try to address the feedback in this request:
    • https://github.com/fleetdm/fleet/issues/44672

Goal

User story
As an IT admin patching software on macOS,
I want to notify end users that app will close to update, 1hr and 5 minutes before update happens.
so that I give my end users time to save their work.

Changes

Product

  • [x] UI changes: Figma
  • [x] CLI (fleetctl) usage changes: No changes
  • [x] YAML changes: #50678
  • [x] REST API changes: #50677
  • [x] Fleet's agent (fleetd) changes: No changes
  • [x] Fleet server configuration changes: No changes
  • [x] Exposed, public API endpoint changes: No changes
  • [x] fleetdm.com changes: No changes
  • [x] GitOps mode UI changes: Specified in Figma above.
  • [x] GitOps generation changes: Include new field notify_before_patching in generated YAML files under Fleet-maintained apps.
  • [x] Activity changes: #50679
  • [x] Permissions changes: "Add, edit, and delete software" already defined in permissions table.
  • [x] Changes to paid features or tiers: Fleet Premium
  • [x] My device and fleetdm.com/better changes: My device changes specified in Figma.
  • [x] Usage statistics: No changes
  • [x] Other reference documentation changes: No changes.
  • [x] First draft of test plan added
  • [x] Once shipped, requester has been notified
  • [x] Once shipped, dogfooding issue has been filed. @marko-lisica dogfooded: #55134
    • Image

Engineering

The delivery half of this story is built as a reusable platform, end_user_notifications, rather than as patch-specific code. Core handles enqueue, dispatch to Fleet Desktop, delivery confirmation, failure causes, and retry. A kind owns what to say, when, and what happens next. notify_before_patching is the first kind. #44672 and #39176 are both funded consumers.

Fleet Desktop already ships the notify command and the toast window from #49325 (PR #50211), so this story needs no Swift changes.

  • [x] Test plan is finalized
  • [x] Contributor API changes: No changes. The new endpoints are device-authenticated, not contributor API.
  • [x] Feature guide changes: A new guide is required at https://fleetdm.com/learn-more-about/patching-end-user-experience. The End user experience link in the UI points there, so a missing page ships a dead link. Owned by #50918.
  • [x] Database schema migrations: Four, across three sub-issues. policies.notify_before_patching TINYINT(1) NOT NULL DEFAULT 0 (#50911); end_user_notifications (#50910); patch_notifications and patch_notification_apps (#50912).
  • [x] Load testing: Yes. A new cron runs every minute, which is what an accurate 5-minute reminder needs. idx_eun_dispatch (status, next_attempt_at) keeps the sweep cheap on an empty table. Measure the sweep against a fleet-sized end_user_notifications table.
  • [x] Pre-QA load test: Yes. The cron is a permanent, always-on addition to the load profile, so measure it before QA rather than during.
  • [x] Load testing/osquery-perf improvements: osquery-perf needs to produce app-open skips at scale, meaning hosts that report a failing patch policy and an empty pre-install query output. Without that the notification tables stay empty and the load test measures nothing.
  • [x] This is a premium only feature: Yes

Open engineering questions

Marko answered most of these on 2026-08-11, in comments above and in Slack. What is left:

  1. How the device token reaches the notification script. Interpolating a host's device auth token into script_contents stores a live credential and breaks if the token rotates mid-countdown. Blocks #50910. Decides: Jonathan, Lucas.
  2. The deferred exit code number is not published. Marko added a notify error for "another notification is displayed" on 2026-08-11 but has not stated the value. Blocks #50910 and #50915. Decides: Marko.
  3. Fleet Desktop version dependency. The catalog manifest is pinned at 1.4.0, Info.plist says 1.5.0, and the deferred exit code needs a release beyond that. Three versions in play against a 2026-09-11 milestone. Decides: Marko, release.
  4. Boolean is provisional. Marko chose notify_before_patching: bool pending Rachael Shaw. If it becomes an enum, #50911, #50914, and #50917 all change field names.
  5. #49106 names two fields wrong, and it is merged. Answering Marko's Slack question: the payload field is install_skipped_when_app_open and the policy field is patch_when_closed. skipped_install did ship, but as the frontend display status derived from the flag, not as a payload field. patch_only_when_closed never existed in code. So it is a doc fix, not a code rename, and 4.91 has not shipped yet. Handled in #50918.

Notification outcomes in the UI

No reason field. The activity carries script_execution_id, and the details modal calls GET /api/v1/fleet/scripts/results/{execution_id} for the exit code and output, picking its copy from the exit code (Figma dev note 5582:46519).

A deferral, where another toast was already on screen, arrives two ways. The binary reports the new exit code Marko added on 2026-08-11, with a script_execution_id. When the dispatcher catches it first no script runs at all, so absence of script_execution_id identifies it. That is unambiguous only because this kind sets no expiry, making a dispatcher-caught deferral the only outcome that emits an activity without a script run. Both render the same sentence.

The app-open skip keeps using installed_software with the skip flag for both options, told apart by pre_install_query_output.

Validation rules

Marko specified the exact user-facing text in a dev note on #50678. All three apply to the API and to fleetctl gitops.

Rule Message
Both flags true Only one of "patch_when_closed" or "notify_before_patching" can be set to true
Explicit continuous_automations_enabled: false If "notify_before_patching" is true, "continuous_automations_enabled" can't be set to false.
Windows Fleet-maintained app "notify_before_patching" is available for macOS Fleet-maintained apps. It's coming soon to Windows.

The second rejects an explicit false rather than overriding it silently. Omitting the field still auto-sets it. This mirrors patch_when_closed at server/service/global_policies.go:259 and pkg/spec/gitops.go:2082.

Dependency

Fleet Desktop 1.5.0 or newer is required on the host. The Fleet-maintained app manifest at ee/maintained-apps/outputs/fleet-desktop/darwin.json is still pinned at 1.4.0. The catalog has to pick up 1.5.0 before this feature works for anyone.

ℹ️  Please read this issue carefully and understand it. Pay special attention to UI wireframes, especially "dev notes".

Risk assessment

  • Requires testing in a hosted environment: No. Everything reproduces on a local Fleet with one enrolled Mac.
  • Requires load testing: Yes.
  • Risk level: High
  • Risk description: Three reasons. First, a new cron on a one-minute interval permanently changes the load profile. Second, the feature can quit an application the end user is working in, so a bug in either verify pass or in the per-app dedup guard closes an app without warning, or closes one the end user already updated. Third, it extends the app-open skip path added by #39962, so a regression there affects patch_when_closed as well as this story. server/service/orbit_test.go:1368 is the guard test to watch.

Test plan

Make sure to go through the list and consider all events that might be related to this story, so we catch edge cases earlier.

Core flow

  • [ ] Add a Fleet-maintained app with notify before patching enabled. With the host online, the app open, and the policy failing, confirm the end user gets the 1 hour notification, then the 5 minute reminder, and the app closes and updates after that.
  • [ ] Same setup but with the app closed. Confirm it updates straight away and the end user is never notified.
  • [ ] Add three patch policies with notify before patching enabled and all three apps open. Confirm the end user gets one notification listing all three, not three separate ones.
  • [ ] Get the 1 hour notification, then go offline for a few hours. Confirm nothing updates while offline, and that a fresh 1 hour notification appears when the host comes back rather than the apps updating unannounced. Cycle is repeated 1hr notification, 5min reminder, install.
  • [ ] Get the notification, then update one of the listed apps yourself through My device > Self-service. Confirm it drops out of the 5 minute reminder and is not installed, while the others still update.
  • [ ] Get the notification, then update all the listed apps yourself. Confirm no 5 minute reminder appears, and nothing is installed.
  • [ ] While one notification's hour timer is still running, add a patch policy for another app and refetch the host. Confirm the new app gets its own separate notification and its own hour, and that the first apps still update on its original schedule.
  • [ ] Lock the screen, then refetch the host. Confirm no notification appears, nothing is installed, and the notification arrives on a later attempt once unlocked.
  • [ ] Log out entirely, then refetch the host. Confirm nothing is installed, and the notification arrives after logging back in.
  • [ ] Uninstall Fleet Desktop, then refetch the host. Confirm nothing is installed and Fleet reports it could not notify.
  • [ ] Confirm the countdown starts when the notification actually appears on screen, not when Fleet decided to send it.
  • [ ] Add a patch policy without notify before patching. Confirm it installs straight away with no notification, alongside policies that do notify.
  • [ ] With a notification on screen, click the Fleet Desktop icon in the Dock. Confirm the self-service window comes to the front and there is only one Fleet Desktop icon in the Dock.
  • [ ] Get 1 hour notification, click Update now, make sure that only Hide button is available in the toast. Install progress is visible. Timer is canceled, no 5 minute reminder.
  • [ ] Make sure the toast window notification UI respects the system theme set in macOS settings (dark / light mode).

Edge cases

  • TODO

Supplemental testing

Testing notes

Confirmation

  1. [ ] Engineer: Added comment to user story confirming successful completion of test plan (include any special setup, test data, or configuration used during development/testing if applicable).
  2. [ ] QA: Added comment to user story confirming successful completion of test plan.
  3. [ ] QA: Determined whether this story needs Playwright automation.
    • Needs automation: Yes / No
    • If yes, filed a follow-up issue in the :help-qa project with status "Needs automation":

noahtalerman avatar Feb 02 '26 19:02 noahtalerman

Putting S since this type of time based agent work can be tedious to test / dev

georgekarrv avatar Feb 20 '26 22:02 georgekarrv

@noahtalerman What if we lean more towards opening it the day it's due, and then only opening it once every 10 minutes once it is overdue? Also, I think we need to be more explicit than just opening the window. Would it open with a modal of some kind telling me what to do? This is a time to be explicit about what the end user should expect and what they need to do

mikermcneil avatar May 05 '26 23:05 mikermcneil

User story
As an IT admin patching software,
I want to programmatically open Fleet Desktop w/ an easy to understand message about all the apps my end users need to update at their deadline, and then only opening it once every 10 minutes after the deadline (only if the app is open, if it's not update it)
so that I nudge end users to update open software.

@mikermcneil sounds good and agreed! Updated the user story.

FYI @marko-lisica

noahtalerman avatar May 06 '26 14:05 noahtalerman

@noahtalerman - Clarification from customer-panoramix, they would need this not only for patch policies, but be configurable for any policies they've created. If it shows in Self service, it should be able to have a push notification configured.

kc9wwh avatar Jun 16 '26 17:06 kc9wwh

Flow

sequenceDiagram
    autonumber
    participant F as Fleet
    participant H as Host
    participant U as End user

    Note over F,H: Host refetched, policies evaluated
    H->>F: 1Password, Slack, Docker Desktop failing
    Note over F: All 3 have notify_before_patching

    F->>H: Queue all 3 installs, each gated on the app not running
    Note over H: Slack is closed, so it installs straight away<br/>1Password and Docker Desktop are open, so their installs are skipped
    H->>F: Slack installed. The other two were skipped because the app was open.
    Note over F: Only apps the end user is actually using need a notification

    F->>U: Notification listing 1Password and Docker Desktop<br/>These apps will close to update in 1 hour
    Note over F: The hour starts once the notification is displayed.<br/>If it could not be displayed, nothing installs.

    Note over U: End user updates 1Password themselves

    Note over F,H: 5 minutes before the update
    Note over F: VERIFY each app still needs updating<br/>1Password is up to date now, so it is dropped
    F->>U: Reminder listing Docker Desktop

    Note over F,H: The hour is up
    Note over F: VERIFY each app still needs updating<br/>Anything updated in the meantime is skipped
    F->>H: Install Docker Desktop, closing it if it is still open

Decisions

flowchart TD
    A["Policies evaluated<br/>notify-policy failing"] --> B{"End user already notified<br/>about this app?"}
    B -- YES --> B1["Wait<br/><br/>Nothing to do"]
    B -- NO --> C{"Is the app running<br/>on the host?"}
    C -- NO --> C1["Install now<br/><br/>Nothing to interrupt,<br/>so no notification"]
    C -- YES --> D["Do NOT install yet<br/>Show one notification listing<br/>the apps that are open"]
    D --> E{"Notification<br/>displayed?"}
    E -- NO --> E1["Try again later<br/><br/>Nothing installs until<br/>the end user is notified"]
    E -- YES --> F["Start the 1 hour countdown"]
    F --> G["5 minutes before the update"]
    G --> H{"VERIFY<br/>still needs updating?"}
    H -- NO --> H1["Drop it from the reminder"]
    H -- YES --> I["Show reminder"]
    H1 --> J["The hour is up"]
    I --> J
    J --> K{"VERIFY<br/>still needs updating?"}
    K -- NO --> K1["Do NOT install<br/><br/>End user already handled it"]
    K -- YES --> L["Install<br/><br/>Closes the app if still open -<br/>the end user was warned"]

Two countdowns at once

A policy added while another countdown is running gets its own notification and its own hour. The two run independently.

sequenceDiagram
    autonumber
    participant F as Fleet
    participant H as Host
    participant U as End user

    Note over F,H: 1:00pm - 1Password and Slack failing
    F->>U: Notification A - 1Password and Slack
    Note over F: Countdown A runs to 2:00pm

    Note over F,H: 1:34pm - Admin adds a Docker Desktop patch policy<br/>and refetches the host
    H->>F: All 3 failing
    Note over F: 1Password and Slack - already notified, countdown A running<br/>Docker Desktop - not notified yet
    F->>U: Notification B - Docker Desktop only
    Note over F: Countdown B runs to 2:35pm, independent of A

    Note over F,U: If a notification is already on screen, the second one waits<br/>rather than covering it. Nothing installs until it has been shown.

    Note over F,H: 1:55pm - VERIFY, then reminder for A
    F->>U: Reminder - whichever of A still needs updating
    Note over F,H: 2:00pm - VERIFY, then install for A
    F->>H: Install 1Password and Slack

    Note over F,H: 2:30pm - VERIFY, then reminder for B
    F->>U: Reminder - Docker Desktop
    Note over F,H: 2:35pm - VERIFY, then install for B
    F->>H: Install Docker Desktop

What the design requires

  • Only open apps are notified about. When a policy fails, Fleet checks whether the app is running. If it is closed there is nothing to interrupt, so it installs straight away and the end user is never notified.
  • Installs are skipped for open apps. The end user is notified first, and nothing is installed until they have been.
  • One notification covers all the apps if multiple patch policies w/ notification enabled fails at the same time.
  • The countdown starts when the notification is displayed, not when Fleet decided to send it.
  • Verify twice — before the 5 minute reminder, and before installing. An app that no longer needs updating is dropped from the reminder and patch is not installed.
  • A newly added policy gets its own notification and its own hour, even while other countdowns are running.

marko-lisica avatar Aug 06 '26 15:08 marko-lisica

Suggestion for a notification script that invokes a toast notification window.

#!/bin/bash

APP="/Applications/Fleet Desktop.app"
BIN="$APP/Contents/MacOS/FleetDesktop"
PLIST="$APP/Contents/Info.plist"

if [ ! -x "$BIN" ]; then
  echo "Fleet Desktop is not installed."
  exit 100
fi

# Check if the installed Fleet Desktop supports notifications.
if ! plutil -extract FleetDesktopCapabilities.notify raw -o - "$PLIST" >/dev/null 2>&1; then
  version=$(plutil -extract CFBundleShortVersionString raw -o - "$PLIST" 2>/dev/null)
  echo "Fleet Desktop ${version:-unknown} does not support notifications."
  exit 101
fi

# Get the user logged in at the GUI.
console_user=$(stat -f "%Su" /dev/console)
if [[ "$console_user" == "root" || "$console_user" == "loginwindow" || "$console_user" == "_mbsetupuser" ]]; then
  echo "No user is logged in at the GUI."
  exit 40
fi

console_uid=$(id -u "$console_user")

# Run the binary as the logged-in user.
launchctl asuser "$console_uid" sudo -u "$console_user" \
  "$BIN" notify --url "$PATCH_NOTIFICATION_URL"

Suggested exit codes:

Code Meaning Reported by What to do
0 Notification displayed binary —
2 Bad invocation — missing or invalid --url, unknown flag or subcommand binary Fix the script. Effectively a Fleet bug.
20 Could not resolve configuration. Specific cause is in the output. binary Check the host's Fleet configuration
30 Page did not load before the deadline binary Check connectivity and that Fleet is reachable
31 Page returned HTTP >= 400, or Fleet's error page (e.g. an expired token) binary Check the URL and the device token
40 Nobody logged in at the GUI script Nothing — retry later
41 Screen is locked binary Nothing — retry later
42 No display attached binary Nothing — this host cannot show notifications
70 Internal error — watchdog fired, or the toast process died without reporting binary Bug report
100 Fleet Desktop is not installed script Deploy Fleet Desktop
101 Fleet Desktop is installed but too old for notify script Upgrade Fleet Desktop to 1.5.0 or newer

marko-lisica avatar Aug 10 '26 15:08 marko-lisica

  1. One activity type or two? #50679's description promises notified_end_user_before_patching and failed_to_notify_end_user_before_patching, but its diff adds one type with a status field. Blocks #50912 merging. Decides: Marko, Noah.

@cdcme I forgot to update the issue description. I decided to have one activity, similar to installed_software.

  1. force_patch_at or install_at in the activity payload? #50679's field list and its example disagree. Decides: Marko.

I think let's go with install_at to be consistent with other endpoints.

  1. Boolean or enum? #50677 documents notify_before_patching: bool. #39176 and #44672 both add options to the same dropdown later. Affects the API, YAML, and GitOps names permanently. Decides: Noah, Marko.

I think let's go with boolean, but I'll ask Rachael Shaw for her opinion as well.

  1. Host offline at the deadline: reset the notification record, or create a new UUID? Decides: Marko.

I think it's probably worth keeping the same record, because that way you can follow the whole patch process. User notified > offline > notified again > 5 min reminder > offline > notified again, etc. Wdyt @cdcme?

  1. Usage statistics: count policies with notify_before_patching enabled, alongside #48005? Decides: Noah.

In #48005, we track FMAs that have patch policy and automation enabled. I don't think we need to track what option is selected (silent install when closed or notification). We want to see an increase in patch policy + software automation enabled for the app.

marko-lisica avatar Aug 11 '26 10:08 marko-lisica

The delivery half of this story is built as a reusable platform, end_user_notifications, rather than as patch-specific code. Core handles enqueue, dispatch to Fleet Desktop, delivery confirmation, failure causes, and retry. A kind owns what to say, when, and what happens next. notify_before_patching is the first kind. https://github.com/fleetdm/fleet/issues/44672 is the next consumer.

@cdcme we will also consume notifications as part of the "deadline" story. #39176

marko-lisica avatar Aug 11 '26 10:08 marko-lisica

@cdcme heads up, I did few small updates to API and YAML PRs. Also I added this comment to the API PR: https://github.com/fleetdm/fleet/pull/50678/changes#r3757351674

marko-lisica avatar Aug 11 '26 11:08 marko-lisica

@marko-lisica re Host offline agreed, same record. Updated #50913.

One activity is great, but we'll still need reason in the activity payload. The details modals show a different sentence per cause, and status can't pick between them. Should I add it to #50679?

Generic /patch page: launchd won't work yet. notify needs a full --url with the device token, and nothing hands a script that token. Fix is a --path flag so the binary resolves its own URL, but that needs a Fleet Desktop release. Let's take the follow-up story.

Also, your API PR updates caught two things I'd missed, the update package endpoint and the skip output text. Both are now included in #50911.

cdcme avatar Aug 11 '26 14:08 cdcme

Generic /patch page: launchd won't work yet. notify needs a full --url with the device token, and nothing hands a script that token. Fix is a --path flag so the binary resolves its own URL, but that needs a Fleet Desktop release. Let's take the follow-up story.

We decided to cut this and file a follow-up story.

marko-lisica avatar Aug 11 '26 16:08 marko-lisica

One activity is great, but we'll still need reason in the activity payload. The details modals show a different sentence per cause, and status can't pick between them. Should I add it to https://github.com/fleetdm/fleet/pull/50679?

We will use script output for details modal to show a dedicated copy for certain exit codes.

marko-lisica avatar Aug 11 '26 16:08 marko-lisica

Moving the expected milestone to 93 since it's not likely to finish before RC next week

georgekarrv avatar Aug 20 '26 16:08 georgekarrv

Test plan results: notify before patching (#39178) — 14/15 pass on 4.93.0 RC ✅

Environment: 4.93.0-rc.2609262124 (rev 1f30f3ad, rc-minor-fleet-v4.93.0), on a real ADE-enrolled Mac mini with fleetd. Fleet Desktop 1.5.1 was built from the same RC, because the published Fleet Desktop doesn't have the notify capability yet. Apps: KeepingYouAwake, 010 Editor and LocalSend.

# Test plan item Result
1 Open app, policy failing → 1 hour → 5 minutes → app closes and updates ✅ Real policy skip → 1 hour notice → 5 minute reminder on the real clock → install at the deadline quit KeepingYouAwake, updated it and relaunched it
2 App closed → updates straight away, no notification ✅ Installed right away, 0 notifications
3 3 apps open → one notification listing all 3 ✅ The three skips came in about 30 s apart and all joined one notification. One toast listed all 3
4 1 hour notice, then offline → nothing updates, fresh 1 hour notice on return, cycle repeats ✅ The deadline passed while the Mac was offline and nothing installed. On return the toast said 1 hour again with a new 1 hour deadline, then the reminder and install followed. Offline for about 8 minutes, not hours
5 Update one listed app yourself → it drops out of the reminder, others still update ✅ LocalSend was updated outside Fleet. The reminder listed only the other 2, LocalSend wasn't reinstalled, and the other 2 updated. Not through My device → Self-service, because LocalSend isn't offered there. Updating an app through Fleet while the reminder is open hits #54149
6 Update all listed apps → no reminder, nothing installed ✅ With 1 app: already current at the 5 minute point → notification closed quietly, no reminder
7 New policy while an hour is running → own notification, own hour, first keeps its schedule ⚠️ The separate notification and its own hour pass. The first notification's schedule can move an hour → #54172
8 Screen locked → nothing shown or installed, arrives after unlock ✅ Exit 41, 1 activity, 0 installs. The next attempt after unlock displayed
9 Logged out → nothing installed, arrives after login ✅ Exit 40 ×15, 1 activity, 0 installs. The first attempt after login displayed. The row has no reason → #54173
10 Fleet Desktop missing → nothing installed, "could not notify" ✅ Exit 100, "Fleet Desktop app is required…", 1 hour retry, 0 installs. The app was renamed, not uninstalled
11 Countdown starts when the toast appears ✅ install_at = display time + 3600 s every time, including after offline and locked
12 Policy without notify installs straight away, alongside notify policies ✅ Same refetch: Patch immediately quit/relaunched and updated the open app with no toast. The notify policy skipped and notified
13 Dock click with a toast up → self-service in front, one Dock icon ✅ One icon. Self-service opens behind the toast, which floats above other windows by design
14 1 hour notice → Update now → only Hide, progress shown, no 5 minute reminder ✅ Hide only, Updating... → Updated. With the deadline moved inside 5 minutes, there was no reminder and no second install
15 Toast follows macOS light/dark mode ✅ Light, Dark and Auto all match the system. It switches live

Filed from this run:

  • #54149: an app updated during the 5 minute reminder makes the reminder 500 and close
  • #54170 (~released): a Fleet-maintained app that refuses to quit gets replaced anyway, and the running copy's files are deleted
  • #54172: a second notification can push the first past its deadline and restart its hour
  • #54173: "Failed to notify" shows no reason when no one is logged in

Also worth knowing:

  • Closing a toast early doesn't release the 10 minute hold. The next notification waited 8m40s with nothing on screen. Noted on #53381, not filed.
  • The End user experience link (learn-more-about/patching-end-user-experience) returns 404 until #53984 merges.

Brajim20 avatar Sep 28 '26 04:09 Brajim20

@shc-sync @kellykroening @andreasn-work @kc9wwh @pintomi1989 Can you notify your customers this feature has shipped in 4.93.0?

ddribeiro avatar Oct 13 '26 16:10 ddribeiro

Notified panoramix, spartacus and sanchez at release. 🖖

kc9wwh avatar Oct 13 '26 16:10 kc9wwh

customer-coelestina & customer-dreyfus have been notified.

andreasn-work avatar Oct 13 '26 17:10 andreasn-work

Notified customer-universitas

shc-sync avatar Oct 14 '26 22:10 shc-sync

customer-lea has been notified

kellykroening avatar Oct 16 '26 14:10 kellykroening

customer-numa notified, closing

pintomi1989 avatar Oct 19 '26 18:10 pintomi1989