Skip to content

Keep an Android host's disk space when a re-enrollment reports none - #52639

Open
Dhvanit41 wants to merge 1 commit into
fleetdm:mainfrom
Dhvanit41:fix-52605-android-disk-space-reenroll
Open

Keep an Android host's disk space when a re-enrollment reports none#52639
Dhvanit41 wants to merge 1 commit into
fleetdm:mainfrom
Dhvanit41:fix-52605-android-disk-space-reenroll

Conversation

@Dhvanit41

@Dhvanit41 Dhvanit41 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #52605

After an Android host re-enrolls, its disk space on Host details changes from a real value to "Not supported," while total disk space stays correct.

AMAPI only sends memory events on status reports, so an enrollment payload carries none. calculateAndroidStorageMetrics reads that as "measurement not supported" and returns its -1 sentinel, and updateHost writes that over a measurement Fleet already had.

The fix skips the assignment when the calculation comes back not supported. The fields stay zero, so UpdateAndroidHost's existing != 0 guard skips host_disks and the stored measurement survives until a report brings a new one. A device that genuinely never measures still records the sentinel when it first enrolls — that is the create path, which isn't touched.

What this trades away

host_disks is written as one row, so preserving the available space means skipping the whole write. Two consequences, both confined to hosts that report no measurement:

  • A host that was measuring and permanently stops keeps its last known value instead of turning into "Not supported."
  • A host that only ever sends EXTERNAL_STORAGE_DETECTED no longer refreshes its total on later reports. Measured against the same scenario, main moves a 110.29 GB total to 160.29 GB when 50 GB of external storage appears; with this change it stays at 110.29 GB. Such a host already displays "Not supported" for free space.

Keeping the total fresh while preserving free space would mean teaching the datastore to update the columns independently. That seemed like the wrong trade for a released bug where the visible symptom is a correct value being replaced by a wrong one, but I'm happy to take it further if you'd rather have it.

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.

Testing

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

TestAndroidStorageExtraction gains two update-path cases: a re-enrollment payload with no memory events must leave the stored values alone, and one that does carry measurements must still update them. Its three existing cases all cover the create path and are unchanged.

Checked by reverting the fix: the first new case then fails on Should be zero, but was -1, and everything else passes either way. go test ./server/mdm/android/... -race is green.

Manual QA

Local Fleet server with Android MDM enabled and an enrolled Android host, driving the Pub/Sub endpoint with AMAPI enrollment and status-report payloads. Same database and build flags for both columns; every push carries a fresh messageId so nothing is dropped by the duplicate check.

Payload Before After
Enrollment with a storage measurement 95.28 GB free, 86.39%, 110.29 GB total same
Re-enrollment, no memory events -1 (Not supported), total kept 95.28 GB, 86.39% kept
Later status report, new measurement 80.00 GB, 72.54% 80.00 GB, 72.54%
Measured report of a full disk (0 bytes free) 0.00 GB, 0% 0.00 GB, 0%
New device, only EXTERNAL_STORAGE_DETECTED -1 (Not supported) -1 (Not supported)

Row 2 is the reported bug. The rest are the checks that the fix is narrow: a later measurement still lands, a genuinely full disk still records 0 rather than being mistaken for "no data," and a device that truly can't measure still reports "Not supported" instead of having the symptom hidden. Values read from host_disks.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved previously reported Android storage values when updated device reports do not include supported storage measurements.
    • Ensured storage metrics are refreshed when valid measured storage events are available during re-enrollment.

AMAPI only sends memory events on status reports, so an enrollment
payload calculates as "storage measurement not supported" and updateHost
wrote the -1 sentinel over a measurement Fleet already had. A host that
re-enrolled showed "Not supported" on Host details, with its total disk
space still correct, until the next status report arrived.

Skip the assignment when the calculation comes back not supported. The
fields stay zero, so UpdateAndroidHost's guard skips host_disks and the
stored measurement survives. A device that genuinely never measures
still records the sentinel when it first enrolls, which is a different
path, and a later status report with a measurement still updates.
@Dhvanit41
Dhvanit41 requested a review from a team as a code owner September 6, 2026 03:53
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: c11ff6c1-b8e9-4582-9952-0c180de4bf94

📥 Commits

Reviewing files that changed from the base of the PR and between 658ea38 and 81d96d6.

⛔ Files ignored due to path filters (1)
  • changes/52605-android-disk-space-preserved-on-reenroll.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • server/mdm/android/service/pubsub.go
  • server/mdm/android/service/pubsub_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

Android host updates now preserve existing storage metrics when enrollment data lacks measured memory events. The update path writes storage values only when calculated available space is non-negative. Tests add re-enrollment setup and cover payloads both without measured events and with measured events.

Merge Risk: ⚪ Minimal · up to 81d96

Android re-enrollment no longer replaces stored disk-space measurements with “Not supported” when a payload lacks storage metrics, and later measured reports still update those values. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #52605 by preserving existing Android disk-space measurements when re-enrollment lacks storage events. Tests also confirm that later measured reports still update the values …
Out of Scope Changes check ✅ Passed The production change, automated tests, and documented changes file are directly related to preserving Android disk-space values during re-enrollment. No unrelated code changes are shown.
Title check ✅ Passed The title clearly identifies the main change: preserving Android host disk-space data when re-enrollment reports no measurement.
Description check ✅ Passed The description explains the issue, root cause, fix, trade-offs, testing, and manual QA results. It includes the related issue and relevant checklist items. Non-applicable template sections are omitte…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.92%. Comparing base (626dd26) to head (81d96d6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #52639   +/-   ##
=======================================
  Coverage   75.91%   75.92%           
=======================================
  Files        4102     4102           
  Lines      247984   247987    +3     
  Branches    14100    14100           
=======================================
+ Hits       188266   188283   +17     
+ Misses      59542    59528   -14     
  Partials      176      176           
Flag Coverage Δ
backend 77.60% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@Dhvanit41

Copy link
Copy Markdown
Contributor Author

@noahtalerman
This one is ready whenever you get sometime

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.

Android host disk space shows "Not supported" after re-enrollment

1 participant