feat: report devices appearing in a fleet - #6060
Open
simplesagar wants to merge 2 commits into
Open
Conversation
Contributor
🦋 Changeset detectedLatest commit: 9392ab5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Running ultrareview automatically — This changes the MDM upsert to rely on Postgres xmax to distinguish inserts from updates, and a subtle bug here could break stale-sync detection and merge stale inventory into new configs, risking data integrity.. I'll post findings when complete. |
This comment has been minimized.
This comment has been minimized.
Contributor
There was a problem hiding this comment.
Ultrareview completed in 4m 51s
All reported issues were addressed across 8 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
simplesagar
force-pushed
the
grw-66-pr4-devices
branch
from
September 4, 2026 04:09
5c3a9cd to
ad1b9d8
Compare
simplesagar
force-pushed
the
grw-66-pr4-devices
branch
from
September 4, 2026 04:13
ad1b9d8 to
b59591d
Compare
simplesagar
force-pushed
the
grw-66-pr4-devices
branch
from
September 4, 2026 04:24
b59591d to
db9fdf2
Compare
This was referenced Sep 4, 2026
Emits `device_first_seen` when an MDM snapshot inserts a device the inventory has not held before. Detecting that at all needed a query change. The upsert returned the same row count on insert and on update, so a first sighting and a re-sighting were indistinguishable; it now returns `(xmax = 0)`, which is zero only on a freshly inserted row. The config-guard case, which previously showed up as a zero row count, is now no row at all and maps to the same stale sync outcome as before. Two guards keep this from flooding the channel. A config that has never completed a sync is being backfilled, so its first snapshot inserts the whole existing fleet and reports none of it. Later syncs report at most ten devices, because a fleet that doubles overnight is worth one glance at the dashboard rather than hundreds of notifications. Reporting happens only once the snapshot is durable. Emitting inside the loop would announce devices for a run that later aborts as stale. These activities are organization-scoped: no MDM table carries a project. Temporal actions/month: 0 (no schedules, workflows or activities added; this rides the existing device-integration sync). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01761VcQZ1sW4TFb16AoozTA
…owner Three findings from review. The MDM-assigned user is a device's owner, not the actor. Reporting them as the actor attributed the sighting to them and attached it to their PostHog person, when nobody performed it: a scheduled sync observed it. The owner now travels as `device_owner_email`. The guard-refusal regression test asserted the old contract. A refused write used to be a zero row count and is now no row at all, so the test asserts `pgx.ErrNoRows`. Documents that reporting is at-most-once. A sync that inserts rows and then fails on a later page has already committed them, so the retry sees them as existing and reports nothing. Persisting pending sightings would buy durability for an ops notification at the cost of a table and its own failure modes; the devices are in the inventory either way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01761VcQZ1sW4TFb16AoozTA
simplesagar
force-pushed
the
grw-66-pr4-devices
branch
from
September 4, 2026 19:33
db9fdf2 to
9392ab5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Stacked PR — merge bottom-up. Each PR targets the one above it, so its Files tab shows only its own diff.
Merging #6057 retargets #6058 to
mainautomatically, and so on down the stack.GRW-66
Fourth of a five-PR stack. Targets #6059, review that first.
Summary
Emits
device_first_seenwhen an MDM snapshot inserts a device the inventory has not held before.Detecting that at all required a query change.
UpsertMdmDevicereturned the same row count on insert and on update, so a first sighting and a re-sighting were indistinguishable. It now returns(xmax = 0), which is true only on a freshly inserted row. The config-guard case, which previously surfaced as a zero row count, is now no row at all and maps to the same stale-sync outcome as before, so that behaviour is unchanged.Two guards keep this from flooding the channel:
last_poll_success_atis the signal, newly exposed onGetSyncTarget.Reporting happens only after the snapshot is durable. Emitting inside the loop would announce devices for a run that later aborts as stale, and every abort path returns before the emit.
These activities are organization-scoped, because no MDM table carries a project id.
Motivation
Devices were the riskiest item on the ticket precisely because none of the three device ingest paths could tell that a row was new, and the bulk-sync shape meant a naive implementation would announce an entire fleet the first time an integration was connected.
Temporal actions/month: 0, scales with fixed. No schedules, workflows or activities are added; this rides the existing device-integration sync.
Summary by cubic
Emits
device_first_seenwhen an MDM snapshot inserts a device the inventory hasn't held before, covering the devices scope of GRW-66. The upsert previously returned the same row count on insert and update, so a first sighting and a re-sighting were indistinguishable.UpsertMdmDevicenow returns(xmax = 0), true only on a freshly inserted row; the config-guard case is now no row at all and maps to the same stale-sync outcome as before.last_poll_success_at, newly exposed onGetSyncTarget), and later syncs report at most ten devices.device_owner_emailproperty rather than the actor, so the sighting isn't attached to the owner's PostHog person.Written for commit 9392ab5. Summary will update on new commits.