Error handling improvements for /api/v1/fleet/os_versions endpoint
Fleet versions
- Discovered: 4.90.0
- Reproduced: 4.90.0
Web browser and operating system: N/A
π₯ Β Actual behavior
As discovered on #35075, there are a couple incorrect or incomplete error responses from the /os_verisons endpoint, as described below:
- [ ] Providing an invalid platform for
/os_versions?platform=notrealplatformresponds with a count of zero, rather than an error about the platform being invalid.- Response:
{ "meta": { "has_next_results": false, "has_previous_results": false }, "count": 0, "counts_updated_at": "2026-07-17T15:10:56Z", "os_versions": [] }
- Response:
- [ ] Similarly, when providing an invalid id like
/os_versions/99999, the response does not give an error message, just the standard json response full of nulls, blanks, and zeroes.- Response:
{ "counts_updated_at": null, "os_version": { "os_version_id": 0, "hosts_count": 0, "name": "", "name_only": "", "version": "", "platform": "", "vulnerabilities": null, "vulnerabilities_count": 0 } }
- Response:
- [ ] When providing an invalid max_vunerabilities such as /os_versions?max_vulnerabilities=-5, there is an unencoded character in the reason:
"reason": "max_vulnerabilities must be \u003e= 0"
π οΈ Expected behavior
As with the other error message provided by these endpoints, expected an error state and a reason for each, with characters encoded correctly.
π§βπ» Β Steps to reproduce
These steps:
- [x] Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
- [ ] Describe the workflow that led to the error, but have not yet been reproduced in multiple Fleet instances.
- See examples in Actual Behavior section
I have an open PR for this: #49899 β all checks are passing. Could I be assigned so it doesn't get picked up twice while it sits in Ready?
One decision is needed before it can merge. The single-version handler previously swallowed the datastore's not-found error and returned an empty result on purpose, with the comment "It is possible the os version exists, but the aggregation job has not run yet." My PR removes that so an unknown id returns 404.
@noahtalerman @sharon-fdm could you confirm 404 is the behaviour you want here, or should the empty result be preserved for the not-yet-aggregated case? Happy to adjust either way.
Also worth flagging: two of the three fixes change responses that were previously 200 into 422 and 404, so this is a breaking change for any client relying on the old shape.
could you confirm 404 is the behaviour you want here, or should the empty result be preserved for the not-yet-aggregated case? Happy to adjust either way.
Thanks @Dhvanit41!
Up to @rachaelshaw
cc @sharon-fdm
@rachaelshaw PR looks good. Leaving this in Waiting until we are g2g with the decision on returning 404 on /os_versions/<NON_EXISTENT_ID> (which makes sense to me).
Branch: rc-minor-fleet-v4.91.0 Β· Server: 4.91.0-rc.2608181727 Β· Validated: 2026-08-18
Fix: PR #49899 (commit a6b541d029), merged to main 2026-08-06; commit confirmed on rc-minor-fleet-v4.91.0.
Method: code review (server/service/hosts.go) + live API reproduction of all 3 cases + positive regression checks + unit test.
Fix summary (verified in source):
OSVersions/OSVersioninserver/service/hosts.go: added platform allow-list validation; reworded negativemax_vulnerabilitiesmessage to avoid the HTML-escaped>; removed the not-found swallow in the single-version handler so a missing id now surfaces the datastore not-found error.
Live reproduction (running RC server)
| # | Case | Before (reported) | Expected | Actual | Result |
|---|---|---|---|---|---|
| 1 | GET /os_versions?platform=notrealplatform |
200, count: 0 |
validation error listing platforms | 422 β platform: Invalid platform: must be one of "darwin", "windows", "linux", "chrome", "ios", "ipados", or "android". |
β |
| 2 | GET /os_versions/99999 |
200, null/zero object |
not-found error | 404 β "Resource Not Found" / "OSVersion was not found in the datastore" |
β |
| 3 | GET /os_versions?max_vulnerabilities=-5 |
reason contained escaped \u003e= |
readable, correctly-encoded reason | 422 β max_vulnerabilities cannot be negative (no escaped char) |
β |
| 4 | Positive: ?platform=darwin |
β | still 200 |
200 |
β |
| 5 | Positive: ?max_vulnerabilities=5 |
β | still 200 |
200 |
β |
| 6 | Unit test TestOSVersionsErrorHandling (server/service) |
β | pass | ok (all 3 cases covered) |
β |
| 7 | Fix in RC branch | β | commit on rc-minor-fleet-v4.91.0 |
a6b541d029 contained |
β |
Verdict: Fixed and shipping in 4.91.0. All three invalid inputs now return proper error states with correct status codes (422/404/422) and clean messages; valid requests unaffected.
Requests crash on rocks clear error messages guide them safe harbor awaits