Skip to content

Fixed Android hosts being auto-deleted by host expiry - #45471

Merged
getvictor merged 1 commit into
mainfrom
victor/45258-zero-time
May 14, 2026
Merged

getvictor merged 1 commit into
mainfrom
victor/45258-zero-time

Conversation

@getvictor

@getvictor getvictor commented May 14, 2026 •

Copy link
Copy Markdown
Member

Related issue: Resolves #45258

The change to zero time is conventionally consistent with the rest of the codebase, and produces zero observable behavior differences anywhere I could find except for the cleanup SQL (which is the bug being fixed).

Decided not to do a migration since we do not expect hosts to actually stick around with the 1970-01-02 value, and we have not heard about this issue from customers.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

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

Testing

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where hosts were being automatically deleted and re-enrolled repeatedly when host expiry cleanup was enabled.

Review Change Stack

@getvictor
getvictor marked this pull request as ready for review May 14, 2026 14:22
@getvictor
getvictor requested a review from a team as a code owner May 14, 2026 14:22
Copilot AI review requested due to automatic review settings May 14, 2026 14:22

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an hourly enroll/delete loop for re-enrolled Android hosts when host expiry is enabled. EnrollOrbit (and EnrollOsquery) previously initialized timestamp columns to 1970-01-02 00:00:00, but CleanupExpiredHosts only nullifies the canonical 2000-01-01 00:00:00 sentinel — causing fresh rows to be treated as last-seen in 1970 and immediately deleted. The PR switches both enroll paths to use common_mysql.GetDefaultNonZeroTime() (2000-01-01 UTC), which matches the sentinel CleanupExpiredHosts already recognizes (and is consistent with the Android setTimesToNonZero path).

Changes:

  • Replace time.Unix(0, 0).Add(24 * time.Hour) with common_mysql.GetDefaultNonZeroTime() in EnrollOrbit and EnrollOsquery.
  • Add a user-visible changes note describing the fix.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
server/datastore/mysql/hosts.go Use canonical 2000-01-01 sentinel for newly inserted enroll rows so cleanup SQL's NULLIF recognizes them.
changes/45258-android-host-expiry-loop Release note for the bug fix.

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

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aad18df5-874d-48f2-b682-a3736531c6f4

📥 Commits

Reviewing files that changed from the base of the PR and between 057e161 and 8c0bd03.

📒 Files selected for processing (2)
  • changes/45258-android-host-expiry-loop
  • server/datastore/mysql/hosts.go

Walkthrough

This PR fixes a host expiry issue where Android devices re-enrolled after their Fleet host record was deleted would be immediately deleted again by the cleanup cron, creating an indefinite hourly loop. The fix updates both EnrollOrbit and EnrollOsquery in server/datastore/mysql/hosts.go to initialize newly inserted host timestamp fields using the canonical "never" sentinel value (2000-01-01 UTC via common_mysql.GetDefaultNonZeroTime()) instead of the previous 1970-01-02 UTC value. This ensures the cleanup logic's NULLIF clause correctly recognizes the sentinel and does not treat the host as having been seen in 1970, which would trigger deletion on the next cleanup tick. The changelog documents this fix.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main bug fix: Android hosts being auto-deleted by host expiry. It directly reflects the central issue being resolved.
Description check ✅ Passed The description includes the related issue number, a checklist with checked items for changes file and manual QA, and rationale for not including a migration. However, it lacks details about security, testing scope, and database considerations mentioned in the template.
Linked Issues check ✅ Passed The PR addresses the root cause of issue #45258 by normalizing the zero-time sentinel from 1970-01-02 to the canonical 2000-01-01, fixing the mismatch that caused Android host auto-deletion during cleanup. This aligns with the recommended fix option (option 1) from the linked issue.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the sentinel timestamp mismatch: documentation, EnrollOrbit initialization, and EnrollOsquery initialization. No unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch victor/45258-zero-time

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.

var host fleet.Host
err := ds.withRetryTxx(ctx, func(tx sqlx.ExtContext) error {
zeroTime := time.Unix(0, 0).Add(24 * time.Hour)
zeroTime := common_mysql.GetDefaultNonZeroTime()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this for consistency? (Or is there "osquery" API enrollment in Android?)

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.73%. Comparing base (326844b) to head (8c0bd03).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #45471      +/-   ##
==========================================
+ Coverage   66.71%   66.73%   +0.02%     
==========================================
  Files        2734     2736       +2     
  Lines      218832   218850      +18     
  Branches    10820    10820              
==========================================
+ Hits       145987   146047      +60     
+ Misses      59625    59597      -28     
+ Partials    13220    13206      -14     
Flag Coverage Δ
backend 68.58% <100.00%> (+0.02%) ⬆️

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 merged commit 77a2916 into main May 14, 2026
55 of 57 checks passed
@getvictor
getvictor deleted the victor/45258-zero-time branch May 14, 2026 15:02

This branch was previously deployed

1 inactive deployment
Docker Hub — 8c0bd033 Deployed May 14, 2026 by getvictor via publish #89130
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 hosts deleted prematurely by host expiry: EnrollOrbit writes a different "never seen" sentinel than CleanupExpiredHosts recognizes

3 participants