fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Android: Fleet agent not installed when profile reconciler moves device to host policy before setup experience job runs

Open terry-kwok-code opened this issue 1 month ago • 0 comments

Fleet versions

  • Discovered: main
  • Reproduced: rc-minor-fleet-v4.94.0

Web browser and operating system: N/A (server-side). Devices: Google Pixel (fully managed / company-owned), Samsung Galaxy SM-A376U1 (BYOD work profile)


💥  Actual behavior

When the fleet has at least one Android configuration profile, a newly enrolled Android device sometimes never gets the Fleet agent app (com.fleetdm.agent). The device enrolls, profiles apply, and self-service apps show up, but the agent is never installed and never checks in. It stays that way; nothing retries.

It's timing-dependent, so the same steps sometimes pass. In one session the Galaxy (BYOD) got the agent and the Pixel (fully managed) didn't.

🛠️ Expected behavior

The Fleet agent is installed on every enrolled Android device, regardless of whether the fleet has configuration profiles or of background job timing.

🧑‍💻  Steps to reproduce

These steps:

  • [ ] Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
  • [x] Describe the workflow that led to the error, but have not yet been reproduced in multiple Fleet instances.
  1. Turn on Android MDM.
  2. Make sure the fleet has at least one Android configuration profile (Controls → OS settings → Custom settings). The contents and number don't matter. Without any Android profiles, the profile reconciler doesn't touch new hosts and the race can't happen.
  3. Enroll an Android device that has not previously enrolled in this Android Enterprise (or turn Android MDM off and on first to start with a fresh enterprise). Reproduced with a Pixel enrolled as fully managed / company-owned.
  4. Wait several minutes and check the device and the server logs.
  5. The Fleet agent isn't installed, and there's no /api/fleet/orbit/enroll request from the device.

Tip for reproducing: the run_android_setup_experience job is picked up by the integrations cron about once a minute (at a fixed second offset, visible as msg="processing job" cron=integrations in the logs). Finishing enrollment just after that tick makes the job wait almost a full minute, so the profile reconciler (every 30s) and the device's status report almost always beat it.

🕯️ More info (optional)

Likely cause

Two background jobs both set up the host-specific policy after enrollment:

  1. Profile reconciler (mdm_android_profile_manager, every 30s) only picks up hosts with applicable Android profiles (ListMDMAndroidProfilesToSend). It creates/patches enterprises/.../policies/<host_uuid> with the fleet's profiles (excluding apps) and moves the device onto it. It doesn't add the Fleet agent.
  2. run_android_setup_experience (worker cron, about every 1 min) calls ensureHostSpecificPolicyIsApplied (server/worker/software_worker.go), which only runs BuildAndSendFleetAgentConfig when the host's applied policy is still the default (policyID == "1").

If the device reports its host-specific policy (updating applied_policy_id) before the setup job runs, the job skips the agent step. Nothing retries it afterward.

Failing case: Pixel, fully managed, 3 Android profiles, first enrollment in this enterprise

Time (UTC) Event
17:51:28 Enrollment received; run_android_setup_experience job 79 queued
17:51:48 Profile reconciler processed host (profile_count=3), patched host policy + device
17:51:50 Device status report on host-specific policy, applied_policy_version=1
17:52:22 Job 79 processed; agent step skipped (no errors logged)
19:12:48 Device still on host policy version 1; agent never installed

Passing case (timing): Galaxy, BYOD, same session, 3 Android profiles

Time (UTC) Event
17:44:16 Enrollment received; job 78 queued
17:44:17 Profile reconciler processed host
17:44:22 Job 78 processed while DB still showed default policy, so agent was added
17:44:35 Device status report on host-specific policy
17:44:46 Agent enrolled (/api/fleet/orbit/enroll)

Confirmed: doesn't reproduce without Android configuration profiles

Same Pixel, same fully managed enrollment, after removing all 3 Android configuration profiles from the fleet:

Time (UTC) Event
19:48:10 Enrollment received; job 80 queued
19:48:22 Job 80 processed while device was still on the default policy, so agent was added
19:48:26 Device status report on host-specific policy (version 3)
19:49:41 Agent enrolled (/api/fleet/orbit/enroll)

No profile reconciler activity for the host during enrollment.

Masked on re-enrollment

The host-specific policy is named after the device's enterprise-specific ID and survives host deletion in Fleet. If a previous enrollment already added the agent to that policy, the reconciler's patch (which excludes apps) keeps it, so the agent still installs even when the reconciler wins the race.

Galaxy (BYOD), deleted from Fleet and re-enrolled, 2 Android profiles:

Time (UTC) Event
20:12:28 Enrollment received; job 81 queued
20:12:51 Profile reconciler processed host (profile_count=2), moved device to host policy
20:12:55 Device status report on host-specific policy (version 7)
20:13:01 Agent enrolled, from the agent entry left in the policy by the earlier enrollment
20:13:23 Job 81 processed, after the agent was already installed

This is likely why turning Android MDM off/on made the issue reproduce reliably: a new enterprise has no existing host policies.

Related: #54447 handled the reverse ordering (setup job's policy patch overwriting profiles the reconciler already delivered) but not the skipped agent step.

Also noticed:

  • If AddFleetAgentToAndroidPolicy fails in BuildAndSendFleetAgentConfig and the host has no certificate templates, the error is only logged ("Not a critical failure") and never retried. That's a separate path to the same symptom.
  • After a device moves to its host-specific policy, every status report logs level=error msg="policy request not found" policy_request_uuid="" along with a warning no matching policy request UUID found for non-compliance verification. Seen on both the Pixel and the Galaxy. It didn't block anything, but it's noisy at error level.

terry-kwok-code avatar Oct 13 '26 20:10 terry-kwok-code