feat: report devices appearing in a fleet - #6060
Conversation
🦋 Changeset detectedLatest commit: a6b662d 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 |
|
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.
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
5c3a9cd to
ad1b9d8
Compare
ad1b9d8 to
b59591d
Compare
b59591d to
db9fdf2
Compare
db9fdf2 to
9392ab5
Compare
9392ab5 to
10325de
Compare
There was a problem hiding this comment.
Auto-approved: review:bypass label applied by @simplesagar. Required status checks still gate this merge.
10325de to
66ee708
Compare
66ee708 to
930649e
Compare
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
930649e to
a6b662d
Compare
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 a6b662d. Summary will update on new commits.