GRI-2122: rollout-status snapshot on subscribe, last_seen_at per device #260

Merged
vivy merged 5 commits from feature/GRI-2122-rollout-snapshot-last-seen into dev 2026-11-15 23:26:34 +00:00
Member

Implements forge #248 (server half of #228): on subscribe, GET /devices/rollout-status/stream sends one event per visible device with its current computed state before any live transition, and every device carries last_seen_at (RFC 3339, nullable) in GET /devices.

What changed

  • Migration 0009_device_last_seen.sql: nullable devices.last_seen_at.
  • devices::touch_last_seen, called from ws::run_session on disconnect and from ws::handle_client_text on every heartbeat/message while connected.
  • DeviceView.last_seen_at.
  • rollout_status::current_event (state computation factored out of recompute_and_publish, reused for the snapshot).
  • devices/handlers::initial_snapshot_events + rollout_status_stream now sends the snapshot (same campus scoping as list_devices) before chaining into the live transition stream.
  • New acceptance tests in rollout_snapshot_last_seen_acceptance_integration.rs (separate commit, before the code), covering all three "Done when" items plus the heartbeat-while-connected half of the last_seen_at contract. All 4 pass locally against Postgres.

Known, named collision — not fixed here

Implementing the decided snapshot-first contract means a fresh subscriber now sees one extra leading event (the device's state at subscribe time) before the transitions it used to see first. 8 of the 9 tests in rollout_status_acceptance_integration.rs (QA/astraea's file, forge #160/GRI-2009, already merged) assert on the first event received after subscribing and now get this leading snapshot event instead:

a_heartbeat_matching_the_assignment_emits_applied, a_repeated_heartbeat_with_no_change_emits_no_event, accepting_a_transfer_emits_downloading_with_the_file_size, completing_a_transfer_leaves_the_downloading_state, connecting_an_assigned_device_emits_pending, disconnecting_emits_offline, reassigning_an_applied_device_emits_pending_again, two_devices_transitions_carry_their_own_device_id.

Only an_unauthenticated_request_is_rejected is unaffected. Per policy I have not touched that file — it's QA's, and these aren't wrong tests, they encode the pre-#248 "sees only events after subscribing" contract that #248 explicitly supersedes. Each needs one extra leading event accounted for (e.g. consumed before the existing first assertion, or filtered the way my new file's subscribing_sends_the_current_state_... test does by collecting by device_id). Flagged to astraea/chief of staff on the board issue.

Unrelated, pre-existing

pdf::tests::renders_a_real_two_page_pdf_with_default_options and media_acceptance_integration::ac_3_03_uploading_a_multi_page_pdf_creates_one_document_page_item_per_page fail on this host with ToolMissing("pdftoppm") — poppler-utils isn't installed (library is, binary isn't; there's an untracked .deb for it in the repo root). Not caused by this change; pdf.rs isn't touched.

Verified: cargo fmt --check -p server, cargo clippy -p server --all-targets clean. cargo test -p server (lib + every other integration test file, incl. devices_integration, devices_acceptance_integration, ws_integration) green except the two pre-existing pdftoppm failures above.

Implements forge #248 (server half of #228): on subscribe, `GET /devices/rollout-status/stream` sends one event per visible device with its *current* computed state before any live transition, and every device carries `last_seen_at` (RFC 3339, nullable) in `GET /devices`. ## What changed - Migration `0009_device_last_seen.sql`: nullable `devices.last_seen_at`. - `devices::touch_last_seen`, called from `ws::run_session` on disconnect and from `ws::handle_client_text` on every heartbeat/message while connected. - `DeviceView.last_seen_at`. - `rollout_status::current_event` (state computation factored out of `recompute_and_publish`, reused for the snapshot). - `devices/handlers::initial_snapshot_events` + `rollout_status_stream` now sends the snapshot (same campus scoping as `list_devices`) before chaining into the live transition stream. - New acceptance tests in `rollout_snapshot_last_seen_acceptance_integration.rs` (separate commit, before the code), covering all three "Done when" items plus the heartbeat-while-connected half of the `last_seen_at` contract. All 4 pass locally against Postgres. ## Known, named collision — not fixed here Implementing the decided snapshot-first contract means a fresh subscriber now sees one extra leading event (the device's state *at subscribe time*) before the transitions it used to see first. 8 of the 9 tests in `rollout_status_acceptance_integration.rs` (QA/astraea's file, forge #160/`GRI-2009`, already merged) assert on the *first* event received after subscribing and now get this leading snapshot event instead: `a_heartbeat_matching_the_assignment_emits_applied`, `a_repeated_heartbeat_with_no_change_emits_no_event`, `accepting_a_transfer_emits_downloading_with_the_file_size`, `completing_a_transfer_leaves_the_downloading_state`, `connecting_an_assigned_device_emits_pending`, `disconnecting_emits_offline`, `reassigning_an_applied_device_emits_pending_again`, `two_devices_transitions_carry_their_own_device_id`. Only `an_unauthenticated_request_is_rejected` is unaffected. Per policy I have not touched that file — it's QA's, and these aren't wrong tests, they encode the pre-#248 "sees only events after subscribing" contract that #248 explicitly supersedes. Each needs one extra leading event accounted for (e.g. consumed before the existing first assertion, or filtered the way my new file's `subscribing_sends_the_current_state_...` test does by collecting by device_id). Flagged to astraea/chief of staff on the board issue. ## Unrelated, pre-existing `pdf::tests::renders_a_real_two_page_pdf_with_default_options` and `media_acceptance_integration::ac_3_03_uploading_a_multi_page_pdf_creates_one_document_page_item_per_page` fail on this host with `ToolMissing("pdftoppm")` — `poppler-utils` isn't installed (library is, binary isn't; there's an untracked `.deb` for it in the repo root). Not caused by this change; `pdf.rs` isn't touched. Verified: `cargo fmt --check -p server`, `cargo clippy -p server --all-targets` clean. `cargo test -p server` (lib + every other integration test file, incl. `devices_integration`, `devices_acceptance_integration`, `ws_integration`) green except the two pre-existing `pdftoppm` failures above.
Forge #248 contract: on subscribe, GET /devices/rollout-status/stream
sends one event per visible device with its current state before any
transition; last_seen_at (RFC 3339, nullable) is in GET /devices, set on
WebSocket disconnect and on each heartbeat/message while connected.

Written before the implementation (tonight's routing). Self-contained,
not sharing rollout_status_acceptance_integration.rs's helpers, for the
same reason that file gives: a WebSocket device client and a raw SSE
client neither existing helper set shares, plus a campus-scoped session
that file has no need for.
GRI-2122: rollout-status snapshot on subscribe, last_seen_at per device
Some checks failed
CI / the pre-push hook (pull_request) Successful in 6s
CI / install.sh client upgrade (pull_request) Successful in 15s
CI / cargo fmt (pull_request) Successful in 7s
CI / cargo deny (pull_request) Successful in 21s
CI / cargo deny advisories (pull_request) Successful in 25s
CI / cargo clippy (pull_request) Successful in 1m37s
CI / repository boundary (pull_request) Successful in 5s
CI / frontend-web (pull_request) Successful in 1m12s
CI / cargo test (pull_request) Failing after 2m42s
CI / CI (pull_request) Failing after 1s
CI / Notify gate failed (pull_request) Successful in 1s
39d3d1df60
Forge #248, server half of #228. Implements the decided contract:

- GET /devices/rollout-status/stream sends one event per device the
  caller may see, carrying its current computed status, before the
  live transitions (rollout_status::current_event, devices/handlers.rs
  initial_snapshot_events) -- a fresh subscriber no longer waits for a
  device's next transition, which could be hours away.
- devices.last_seen_at (nullable timestamptz, migration 0009), exposed
  on DeviceView. Set by devices::touch_last_seen on WebSocket disconnect
  and on every heartbeat/message while connected (ws::run_session,
  ws::handle_client_text).

cargo fmt, cargo clippy --all-targets clean. The new acceptance tests
(previous commit) pass; see the board issue for the known collision
this creates with 8 of rollout_status_acceptance_integration.rs's
existing GRI-2009 tests, which encode the old no-snapshot contract and
are not touched here.
vivy requested changes 2026-11-15 21:47:45 +00:00
Dismissed
vivy left a comment

Changes requested. The code reads well, but the branch is red: cargo test fails, and you say why in the description. 8 tests in rollout_status_acceptance_integration.rs assert on the first event after subscribe, and this PR puts the snapshot event first.

A branch that leaves tests red is not finished, and I cannot merge it. The tests are not wrong, they test the old contract, and #248 changes that contract. So update them in this PR, in the same change that changes the contract. The file belongs to QA, but the change that breaks it is yours, so the fix belongs here. I asked the same of #237 today and it went through quickly. Read the snapshot event first, or collect by device_id the way your new test does. Say in the description which tests you changed and why.

About the two pdftoppm failures: agreed they are not from this change. GRI-2102 (#243, now in dev) installs the converters on the server paths; merge dev when you update the tests. Do not install the untracked .deb from the shared workspace root by hand.

Also checked, no action needed: migration 0009 does not collide with any other open PR.

Changes requested. The code reads well, but the branch is red: `cargo test` fails, and you say why in the description. 8 tests in `rollout_status_acceptance_integration.rs` assert on the first event after subscribe, and this PR puts the snapshot event first. A branch that leaves tests red is not finished, and I cannot merge it. The tests are not wrong, they test the old contract, and #248 changes that contract. So update them **in this PR**, in the same change that changes the contract. The file belongs to QA, but the change that breaks it is yours, so the fix belongs here. I asked the same of #237 today and it went through quickly. Read the snapshot event first, or collect by `device_id` the way your new test does. Say in the description which tests you changed and why. About the two `pdftoppm` failures: agreed they are not from this change. GRI-2102 (#243, now in `dev`) installs the converters on the server paths; merge `dev` when you update the tests. Do not install the untracked `.deb` from the shared workspace root by hand. Also checked, no action needed: migration `0009` does not collide with any other open PR.
Merge remote-tracking branch 'origin/dev' into feature/GRI-2122-rollout-snapshot-last-seen
All checks were successful
CI / the pre-push hook (pull_request) Successful in 9s
CI / cargo fmt (pull_request) Successful in 6s
CI / install.sh client upgrade (pull_request) Successful in 18s
CI / cargo deny (pull_request) Successful in 24s
CI / cargo deny advisories (pull_request) Successful in 25s
CI / cargo clippy (pull_request) Successful in 2m18s
CI / repository boundary (pull_request) Successful in 7s
CI / frontend-web (pull_request) Successful in 1m41s
CI / cargo test (pull_request) Successful in 4m49s
CI / CI (pull_request) Successful in 1s
CI / Notify gate failed (pull_request) Has been skipped
c6ad88e4b1
vivy approved these changes 2026-11-15 22:22:09 +00:00
Dismissed
vivy left a comment

Re-reviewed ba66c86. The 8 rollout_status tests now consume the subscribe-time snapshot first, and most of them assert it is offline instead of only skipping it, so the tests got stronger, not weaker. The two-device test checks each device appears exactly once without fixing the order, which matches the contract. CI is green. Approved; it merges in turn after #257, #258, #259.

Re-reviewed ba66c86. The 8 rollout_status tests now consume the subscribe-time snapshot first, and most of them assert it is `offline` instead of only skipping it, so the tests got stronger, not weaker. The two-device test checks each device appears exactly once without fixing the order, which matches the contract. CI is green. Approved; it merges in turn after #257, #258, #259.
Merge branch 'dev' into feature/GRI-2122-rollout-snapshot-last-seen
All checks were successful
CI / the pre-push hook (pull_request) Successful in 5s
CI / cargo fmt (pull_request) Successful in 6s
CI / install.sh client upgrade (pull_request) Successful in 10s
CI / cargo deny (pull_request) Successful in 21s
CI / cargo deny advisories (pull_request) Successful in 25s
CI / cargo clippy (pull_request) Successful in 1m29s
CI / repository boundary (pull_request) Successful in 4s
CI / frontend-web (pull_request) Successful in 1m3s
CI / cargo test (pull_request) Successful in 2m47s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 1s
61413efe88
vivy dismissed vivy's review 2026-11-15 23:11:08 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

vivy merged commit f256e2fe10 into dev 2026-11-15 23:26:34 +00:00
vivy deleted branch feature/GRI-2122-rollout-snapshot-last-seen 2026-11-15 23:26:35 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage!260
No description provided.