Skip to content

Return Windows Enrollment Status Page (ESP)#43454

Merged
getvictor merged 34 commits intomainfrom
victor/42843-esp-status
Apr 28, 2026
Merged

Return Windows Enrollment Status Page (ESP)#43454
getvictor merged 34 commits intomainfrom
victor/42843-esp-status

Conversation

@getvictor
Copy link
Copy Markdown
Member

@getvictor getvictor commented Apr 13, 2026

Related issue: Resolves #42843

This change shows Windows Enrollment Status Page (ESP) during OOBE enrollment. It does not track/update the status of that page, so the end user does not actually see any progress on it. Its purpose is to block the user from proceeding to desktop until all the profiles have been sent to the device. Software apps are not being tracked/blocked in this PR.

This is what the final ESP screen looks for this PR before it takes the user to set up Windows Hello:
image

Checklist for submitter

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • New Features

    • Enrollment Status Page (ESP) support for Windows Autopilot: sends hold/release commands and advances enrollment states during setup.
    • Scoped profile installation checks per host and a default ESP timeout (3 hours).
  • Bug Fixes

    • Clears prior profile delivery state during reenrollment cleanup to avoid stale delivery state.
    • Safer state transitions for "awaiting configuration" with guarded compare-and-swap updates.
  • Tests

    • New unit and integration tests validating ESP flows and awaiting-configuration transitions.

@getvictor
Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the first pass of Windows Autopilot Enrollment Status Page (ESP) support in the Windows MDM management checkin flow, enabling Fleet to initialize ESP tracking and subsequently return ongoing ESP status updates on later checkins.

Changes:

  • Add ESP command generation to the Windows MDM management response path, including an init phase (enqueue) and an active phase (inline status updates).
  • Introduce SyncML builders for DMClient/EnrollmentStatusTracking CSP nodes used by ESP, plus status mapping helpers.
  • Add datastore support for host-scoped Windows profile queries and updating awaiting_configuration, with mocks + tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
server/service/microsoft_mdm.go Adds ESP decision logic to management checkins and implements pending/active ESP flows.
server/service/microsoft_mdm_test.go Adds unit tests covering ESP command behavior across awaiting states and grace period scenarios.
server/mock/datastore_mock.go Extends datastore mock with new ESP-related methods.
server/mdm/microsoft/esp_csp.go Adds SyncML templates/builders for ESP init + status update commands and status mapping.
server/mdm/microsoft/esp_csp_test.go Adds tests validating ESP SyncML generation and XML escaping.
server/fleet/datastore.go Extends datastore interface for SetMDMWindowsAwaitingConfiguration and host-scoped profile listing.
server/datastore/mysql/microsoft_mdm.go Implements new datastore methods for awaiting-config updates and host-scoped Windows profile selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service/microsoft_mdm.go
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/mdm/microsoft/esp_csp.go Outdated
Comment thread server/mdm/microsoft/esp_csp.go Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds Windows Autopilot ESP (Enrollment Status Page) support and related datastore APIs and tests. Changes include: service logic to generate ESP/DMClient SyncML commands and manage awaiting_configuration transitions (Pending→Active→None) with timeout handling; datastore additions SetMDMWindowsAwaitingConfiguration (compare-and-swap) and ListMDMWindowsProfilesToInstallForHost (host-scoped profile query); extended reenrollment cleanup to remove per-host Windows profile rows; exported ESPTimeoutSeconds constant; unit and integration tests for ESP command flows.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive Implementation covers awaiting_configuration state transitions (Pending→Active→None), ESP/DMClient SyncML commands, profile querying, timeout setup, but lacks 10-minute orbit registration check and some edge-case handling. Verify that orbit registration timestamp validation (10-minute wait logic) is implemented and that all profile-delivery terminal states are properly handled.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarizes the main feature: implementing Windows Enrollment Status Page (ESP) display during OOBE.
Description check ✅ Passed Description covers related issue, key implementation detail (blocking user until profiles sent), includes manual QA confirmation, but lacks database/security/compatibility checklist items.
Out of Scope Changes check ✅ Passed All code changes align with ESP feature scope: datastore methods for Windows MDM state/profiles, ESP/DMClient command generation, mock updates, and integration tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch victor/42843-esp-status

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/service/microsoft_mdm.go (1)

1945-1952: ⚠️ Potential issue | 🟠 Major

This can't satisfy the first-checkin ESP requirement.

getPendingMDMCmds runs before handleESPInitial, and handleESPInitial only persists the new command before returning nil. The first post-orbit response therefore can't include the freshly generated ESP/DMClient init payload; it only becomes deliverable on the next management session.

Also applies to: 1954-1967, 2084-2103

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/microsoft_mdm.go` around lines 1945 - 1952, The code fetches
pending MDM commands via getPendingMDMCmds before calling handleESPInitial, so a
newly-persisted ESP/DMClient init command created in handleESPInitial won't be
included in the same first post-orbit response; fix by calling handleESPInitial
first (when requestAuthState == RequestAuthStateTrusted and when handling
first-checkin scenarios), ensure handleESPInitial persists any generated
commands, and only then call getPendingMDMCmds to populate resPendingCmds so the
freshly created ESP/DMClient init payload is delivered immediately; apply the
same reorder/flow change in the other affected blocks referenced (around lines
1954-1967 and 2084-2103).
🧹 Nitpick comments (2)
server/service/microsoft_mdm_test.go (2)

1099-1104: Isolate datastore mocks per subtest to prevent state leakage

ds/svc are shared across all t.Run cases, so function overrides from one case can affect later cases and hide unintended calls. Build a fresh store/service inside each subtest (or reset all function fields) for deterministic coverage.

Suggested test-setup refactor
 func TestGetESPCommands(t *testing.T) {
 	ctx := t.Context()
-	ds := new(mock.Store)
-	logger := slog.New(slog.DiscardHandler)
-	svc := &Service{ds: ds, logger: logger}
+	newSUT := func() (*mock.Store, *Service) {
+		ds := new(mock.Store)
+		logger := slog.New(slog.DiscardHandler)
+		return ds, &Service{ds: ds, logger: logger}
+	}

 	deviceID := "test-device-id"
 	hostUUID := "test-host-uuid"
 	now := time.Now()

 	t.Run("no awaiting configuration", func(t *testing.T) {
+		ds, svc := newSUT()
 		ds.MDMWindowsGetEnrolledDeviceWithDeviceIDFunc = func(ctx context.Context, mdmDeviceID string) (*fleet.MDMWindowsEnrolledDevice, error) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/microsoft_mdm_test.go` around lines 1099 - 1104, The test
shares ds and svc across subtests causing mock function overrides to leak;
inside TestGetESPCommands create a fresh mock.Store and Service for each t.Run
(or explicitly reset all mock function fields on ds before each subtest) so that
mock methods on mock.Store and the Service{ds: ds, logger: logger} are isolated
per case and deterministic.

1175-1176: Assert host-scoped method input to lock in the core ESP behavior

These stubs ignore hUUID. Since host-scoped filtering is a key requirement, assert hUUID == hostUUID so regressions in argument wiring are caught.

Suggested assertion hardening in stubs
 ds.ListMDMWindowsProfilesToInstallForHostFunc = func(ctx context.Context, hUUID string) ([]*fleet.MDMWindowsProfilePayload, error) {
+	require.Equal(t, hostUUID, hUUID)
 	return nil, nil
 }
 ds.ListMDMWindowsProfilesToInstallForHostFunc = func(ctx context.Context, hUUID string) ([]*fleet.MDMWindowsProfilePayload, error) {
+	require.Equal(t, hostUUID, hUUID)
 	return []*fleet.MDMWindowsProfilePayload{
 		{ProfileUUID: "prof-1", ProfileName: "WiFi Config"},
 		{ProfileUUID: "prof-2", ProfileName: "SCEP Cert"},
 	}, nil
 }

Also applies to: 1222-1223

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/microsoft_mdm_test.go` around lines 1175 - 1176, The stub for
ds.ListMDMWindowsProfilesToInstallForHostFunc ignores the host UUID argument;
update the stub to assert that the incoming hUUID equals the test's hostUUID
(e.g., using the test assertion helper or require.Equal) so host-scoped wiring
is validated, and apply the same assertion pattern to the other identical
stub(s) in this file that accept hUUID to ensure all host-scoped methods check
hUUID == hostUUID (reference the ds.ListMDMWindowsProfilesToInstallForHostFunc
and any other stubs taking hUUID).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/datastore/mysql/microsoft_mdm.go`:
- Around line 879-886: The UPDATE in SetMDMWindowsAwaitingConfiguration
unconditionally flips awaiting_configuration and can race; change the SQL in
function SetMDMWindowsAwaitingConfiguration to a compare-and-swap UPDATE that
includes the current expected awaiting_configuration (e.g., "... WHERE
mdm_device_id = ? AND awaiting_configuration = ?") or otherwise targets the
specific enrollment row, execute with both mdmDeviceID and expected status, then
inspect and return the RowsAffected (or an error if 0 rows were changed) so
callers can detect whether the transition actually succeeded.

In `@server/mdm/microsoft/esp_csp.go`:
- Around line 67-126: In the espInitialCommandTmpl template change the
BlockInStatusPage item metadata to use Format int (not bool) and update its Data
value from the boolean "true" to an integer (e.g., 1 for enabled, 0 for
disabled) so the declared Format matches the value; locate the BlockInStatusPage
block inside the espInitialCommandTmpl template (the Replace block with Target
LocURI containing FirstSyncStatus/BlockInStatusPage) and replace the Meta Format
and Data accordingly.

In `@server/service/microsoft_mdm_test.go`:
- Around line 1288-1290: The loop that builds rawParts ignores the error from
xml.Marshal (xml.Marshal(cmd)) so a marshal failure could be silently ignored;
update that loop to check the error returned by xml.Marshal and fail the test on
error (e.g., use t.Fatalf/t.Fatalf-style assertion or require.NoError) when
marshaling a cmd into rawParts, referencing the cmds loop and rawParts variable
so the test fails immediately if xml.Marshal returns an error.

In `@server/service/microsoft_mdm.go`:
- Around line 2007-2010: The grace timer starts before HostUUID is present: when
device.HostUUID is empty you return early, but AwaitingConfigurationAt (the
grace-window timestamp) is measured from MDM enrollment and can expire while the
host is still unassociated. Fix by resetting or initializing
device.AwaitingConfigurationAt at the moment you attach/set device.HostUUID (or
by basing the wait logic on the actual Orbit enrollment timestamp instead of
AwaitingConfigurationAt). Locate the code paths that set device.HostUUID and
update them to set device.AwaitingConfigurationAt = now() (or switch the check
to use the Orbit enrollment time field) and apply the same change for the
similar checks around the other block that touches AwaitingConfigurationAt (the
checks in the 2028–2036 region).
- Around line 1954-1967: The ESP commands are fetched unconditionally which can
append/enqueue ESP actions for unauthenticated requests; wrap the
svc.getESPCommands call and subsequent append of espCmds behind a check that the
request's auth state equals RequestAuthStateTrusted (the same auth state used in
processIncomingMDMCmds). Concretely, only call svc.getESPCommands(ctx, deviceID)
and append espCmds to allCmds when reqMsg (or the local authState variable used
in processIncomingMDMCmds) == RequestAuthStateTrusted; otherwise skip
fetching/appending ESP so createResponseSyncML and createResponseSyncML do not
include ESP for untrusted requests.

---

Outside diff comments:
In `@server/service/microsoft_mdm.go`:
- Around line 1945-1952: The code fetches pending MDM commands via
getPendingMDMCmds before calling handleESPInitial, so a newly-persisted
ESP/DMClient init command created in handleESPInitial won't be included in the
same first post-orbit response; fix by calling handleESPInitial first (when
requestAuthState == RequestAuthStateTrusted and when handling first-checkin
scenarios), ensure handleESPInitial persists any generated commands, and only
then call getPendingMDMCmds to populate resPendingCmds so the freshly created
ESP/DMClient init payload is delivered immediately; apply the same reorder/flow
change in the other affected blocks referenced (around lines 1954-1967 and
2084-2103).

---

Nitpick comments:
In `@server/service/microsoft_mdm_test.go`:
- Around line 1099-1104: The test shares ds and svc across subtests causing mock
function overrides to leak; inside TestGetESPCommands create a fresh mock.Store
and Service for each t.Run (or explicitly reset all mock function fields on ds
before each subtest) so that mock methods on mock.Store and the Service{ds: ds,
logger: logger} are isolated per case and deterministic.
- Around line 1175-1176: The stub for
ds.ListMDMWindowsProfilesToInstallForHostFunc ignores the host UUID argument;
update the stub to assert that the incoming hUUID equals the test's hostUUID
(e.g., using the test assertion helper or require.Equal) so host-scoped wiring
is validated, and apply the same assertion pattern to the other identical
stub(s) in this file that accept hUUID to ensure all host-scoped methods check
hUUID == hostUUID (reference the ds.ListMDMWindowsProfilesToInstallForHostFunc
and any other stubs taking hUUID).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 52eecd15-e796-4bb3-a370-f728b7c4baa3

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1a51e and ff3ae91.

📒 Files selected for processing (7)
  • server/datastore/mysql/microsoft_mdm.go
  • server/fleet/datastore.go
  • server/mdm/microsoft/esp_csp.go
  • server/mdm/microsoft/esp_csp_test.go
  • server/mock/datastore_mock.go
  • server/service/microsoft_mdm.go
  • server/service/microsoft_mdm_test.go

Comment thread server/datastore/mysql/microsoft_mdm.go Outdated
Comment thread server/mdm/microsoft/esp_csp.go Outdated
Comment thread server/service/microsoft_mdm_test.go Outdated
Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 72.00000% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.82%. Comparing base (75f79dc) to head (7c1fa6d).
⚠️ Report is 294 commits behind head on main.

Files with missing lines Patch % Lines
server/service/microsoft_mdm.go 71.56% 15 Missing and 14 partials ⚠️
server/datastore/mysql/microsoft_mdm.go 73.91% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #43454      +/-   ##
==========================================
- Coverage   66.91%   66.82%   -0.09%     
==========================================
  Files        2600     2617      +17     
  Lines      208643   210848    +2205     
  Branches     9305     9192     -113     
==========================================
+ Hits       139608   140902    +1294     
- Misses      56327    57116     +789     
- Partials    12708    12830     +122     
Flag Coverage Δ
backend 68.57% <72.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@getvictor getvictor changed the title Initial implementation Return Windows Enrollment Status Page (ESP) tracking commands on checkins Apr 13, 2026
Base automatically changed from 41379-eua-orbit to main April 13, 2026 21:19
# Conflicts:
#	client/orbit_client_eua_test.go
#	orbit/pkg/packaging/windows_eua_test.go
Comment thread server/service/microsoft_mdm.go
Comment thread server/service/microsoft_mdm.go
Comment thread server/service/microsoft_mdm.go
Autopilot-enrolled devices now receive ESP hold commands (Replace/Add)
alongside fleetd install commands. Update TestWindowsAutomaticEnrollmentCommands
and TestWindowsAzureInitiatedEnrollmentAndMapping to find fleetd commands
by GUID rather than asserting exact command counts. Fix ineffassign lint
error on unused cmds variable.
The SendResponse ack for Autopilot devices now includes ESP hold
commands alongside the Status command. Update assertions to check
for Status presence rather than exact command count.
@getvictor getvictor marked this pull request as ready for review April 22, 2026 16:15
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@getvictor
Copy link
Copy Markdown
Member Author

@ksykulev I forgot to set this one ready for review yesterday

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/service/microsoft_mdm.go`:
- Around line 2119-2126: Capture both return values from
svc.ds.SetMDMWindowsAwaitingConfiguration into (changed, err) and use them: if
err != nil return nil, err (or wrap and return) so DB/CAS failures are surfaced
instead of silently sending releaseCmds; if err == nil and changed == false
treat as benign (already released) and return nil, nil (or no releaseCmds) to
avoid re-emitting commands; only proceed to log "releasing device" and return
releaseCmds when changed == true. Reference: SetMDMWindowsAwaitingConfiguration
and the surrounding release logic that produces releaseCmds (e.g.,
handleESPRelease).
- Line 2023: The code is sending ESPTimeoutSeconds (seconds) to the DMClient
TimeOutUntilSyncFailure (which expects minutes); update the newSyncMLCmdInt call
that sets
"./Device/Vendor/MSFT/DMClient/Provider/%s/FirstSyncStatus/TimeOutUntilSyncFailure"
to pass ESPTimeoutSeconds converted to minutes (divide by 60), then clamp the
resulting minutes into the CSP-required range (60–1440) before formatting;
locate the call to newSyncMLCmdInt and the microsoft_mdm.ESPTimeoutSeconds
symbol and replace the raw seconds value with the converted-and-clamped minutes
value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53b1dfac-bbbc-41f4-bea0-00ea08610eaa

📥 Commits

Reviewing files that changed from the base of the PR and between 84c1d16 and 5a15fbd.

📒 Files selected for processing (3)
  • server/service/integration_mdm_test.go
  • server/service/microsoft_mdm.go
  • server/service/microsoft_mdm_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/service/integration_mdm_test.go

Comment thread server/service/microsoft_mdm.go Outdated
Comment thread server/service/microsoft_mdm.go
Comment thread server/datastore/mysql/microsoft_mdm.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
server/service/microsoft_mdm.go (1)

2037-2052: ⚠️ Potential issue | 🟠 Major

Send the ESP initialization payload before completing DevicePreparation.

This path flips PendingActive and only returns DevicePreparation/InstallationState=3. It never registers the expected profile policies or ESP tracking entries for the host, so the ESP has no initialized DeviceSetup baseline before preparation is marked complete. Build the full ESP/DMClient initialization commands here, or keep the device in the hold state until that payload is sent.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/microsoft_mdm.go` around lines 2037 - 2052, The current path
flips awaiting state to Active via SetMDMWindowsAwaitingConfiguration and
immediately returns a single DevicePreparation/InstallationState=3 dpCmd without
sending the ESP/DMClient initialization payloads (profiles, policy registration
and ESP tracking entries); update the logic so that before setting
InstallationState=3 you construct and return the full ESP initialization command
set (e.g., DMClient registration and profile/policy payloads and ESP tracking
entries) using the same newSyncMLCmdInt/mdm_types.SyncMLCmd pattern, and only
then mark DevicePreparation complete (or alternatively do NOT call
SetMDMWindowsAwaitingConfiguration/return InstallationState=3 and keep the
device in hold until those initialization commands are successfully queued);
reference SetMDMWindowsAwaitingConfiguration, dpCmd, newSyncMLCmdInt and
DevicePreparation/InstallationState in your changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/service/microsoft_mdm.go`:
- Around line 2072-2104: The current readiness check uses replica-backed
ListMDMWindowsProfilesToInstallForHost and the UI helper
GetHostMDMWindowsProfiles, which can miss just-queued or reserved install rows;
replace this with a writer/transaction-backed datastore query scoped to the
specific device.HostUUID/current enrollment that returns all install-profile
rows that must block ESP release (including Fleet-reserved profiles). Implement
or call a new datastore method (e.g. GetMDMWindowsProfilesForESPRelease or a
transactional variant) that runs under the writer/transaction, includes reserved
profiles, filters by OperationType == fleet.MDMOperationTypeInstall, and checks
Status for terminal states; use that method in place of the two existing calls
in the ESP release logic.
- Around line 2121-2133: The code currently flips the device ESP state from
fleet.WindowsMDMAwaitingConfigurationActive to
fleet.WindowsMDMAwaitingConfigurationNone by calling
svc.ds.SetMDMWindowsAwaitingConfiguration before the release command
(releaseCmds) is actually acknowledged; change this so the DB still records the
pending release and the device remains in Active until delivery is confirmed:
persist the outgoing release command (e.g., via a datastore method like
CreatePendingMDMCommand or extend svc.ds with a SavePendingRelease) tied to
device.MDMDeviceID and return releaseCmds, and only call
svc.ds.SetMDMWindowsAwaitingConfiguration(...,
fleet.WindowsMDMAwaitingConfigurationNone) when the agent explicitly
acknowledges ServerHasFinishedProvisioning on a subsequent checkin; ensure
subsequent checkins detect the pending release record and resend the idempotent
release command instead of skipping ESP, and keep logging with
svc.logger.InfoContext as before.

---

Duplicate comments:
In `@server/service/microsoft_mdm.go`:
- Around line 2037-2052: The current path flips awaiting state to Active via
SetMDMWindowsAwaitingConfiguration and immediately returns a single
DevicePreparation/InstallationState=3 dpCmd without sending the ESP/DMClient
initialization payloads (profiles, policy registration and ESP tracking
entries); update the logic so that before setting InstallationState=3 you
construct and return the full ESP initialization command set (e.g., DMClient
registration and profile/policy payloads and ESP tracking entries) using the
same newSyncMLCmdInt/mdm_types.SyncMLCmd pattern, and only then mark
DevicePreparation complete (or alternatively do NOT call
SetMDMWindowsAwaitingConfiguration/return InstallationState=3 and keep the
device in hold until those initialization commands are successfully queued);
reference SetMDMWindowsAwaitingConfiguration, dpCmd, newSyncMLCmdInt and
DevicePreparation/InstallationState in your changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e0110e87-2c05-42e1-bacc-adf7522f804a

📥 Commits

Reviewing files that changed from the base of the PR and between 5a15fbd and b29dfa2.

📒 Files selected for processing (2)
  • server/datastore/mysql/microsoft_mdm.go
  • server/service/microsoft_mdm.go

Comment thread server/service/microsoft_mdm.go
Comment thread server/service/microsoft_mdm.go Outdated
@getvictor getvictor marked this pull request as draft April 24, 2026 14:38
@getvictor getvictor marked this pull request as ready for review April 28, 2026 15:58
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@getvictor getvictor merged commit c0ecbfc into main Apr 28, 2026
51 checks passed
@getvictor getvictor deleted the victor/42843-esp-status branch April 28, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WCS (phase 2): Return current ESP status on checkins from Windows devices awaiting configuration

3 participants