Skip to content

mac Phase 4 Batch T: opt-in telemetry (R4) - #1249

Merged
iamfatness merged 6 commits into
mainfrom
mac-control-phase4-telemetry
Nov 26, 2026
Merged

iamfatness merged 6 commits into
mainfrom
mac-control-phase4-telemetry

Conversation

@iamfatness

@iamfatness iamfatness commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Force-pushed 2026-11-26: rebased onto origin/main 103604c0. Conflicts:

  • the ShellTests.swift case line;
  • the idle-quit hold in AppModel.handleQuitRequest, where main now also holds for a connected social review. The merged hold keeps main's condition (comms.inMeeting || socialReview connected), the session-end wait, and the review fix's quit-gate phase.

CI fixes:

  • native-shell-windows: TelemetryFixtureExportTests.FixtureIsCurrent failed because System.Text.Json's indented preview uses \r\n on Windows. The exporter now normalises it to \n; the fixture is unchanged.
  • native-metal-macos: a corevideo-native-tests SEGFAULT in the virtual-camera helper tests. This PR changes no native code, so it's re-run on this push.

After the rebase: telemetry 190, quit 116, comms 268, social 287, leftovers 46, control 1882 (only the known filtered-run state-stream-event-tracking failure).

Phase 4 control lane, Batch T (R4): opt-in telemetry, per docs/superpowers/plans/2026-11-22-mac-control-telemetry-leftovers-phase4.md Tasks 7-9. Draft. #1233 is merged, so this PR now targets main directly. Do not merge without the owner's OK.

Key handling (open owner decision D-T1)

The API key is read only from COREVIDEO_TELEMETRY_API_KEY in the process environment. No key is embedded or committed. With no key, telemetry is quietly disabled: the heartbeat timer isn't even scheduled, and the card says so. The key is never logged; the start-up line names only the endpoint host and whether a key is present. A Finder- or Dock-launched app inherits no shell environment, so no customer Mac sends anything until a key channel is decided.

What's here

  • Task 7: contracts/telemetry.fixtures.json, written by a new MediaCore test from the real Windows telemetry code. Core sync responses go through the live parse path (TryParseWireState + MapNativeWireStateToSnapshot). It covers config, machine class (mac-arm64-cpu<N>-ram<N>gb, RAM rounded half to even, Apple M-series tier) and the payload, whose keys match Windows' order and which carries no names, ids, keys, URLs or paths. The consent store reads absent, corrupt, locked or unreadable files as OFF; a revoke always lands.

  • Task 8: the event client (POST /v1/events, Bearer; Accepted / RetryLater / Rejected) and the service:

    • the 24 h heartbeat runs only if configured at start, and only it honours Retry-After;
    • session-end is sent once, with a 2 s cap;
    • the exact wire JSON is logged before each POST.
    • Quit: with consent and a key, an idle quit waits at most 2 s for session-end; otherwise it's unchanged.
    • Every interval and timeout runs on an injected clock.
  • Task 9: the "Diagnostics & telemetry" card at the bottom of the Zoom pane, with Windows' copy and order and a "Preview what's sent" that works with consent off.

  • Rebase merge: main's Comms release-first quit (macOS Comms page and release triggers (Phase 4, Tasks 9-10) #1236) and this PR's session-end both hold an idle quit. They now run side by side and the quit replies once, after both.

  • Independent review fixes:

    • the API key appears in no log line;
    • the POST body equals the logged wire;
    • a blank key counts as no key (with a Windows fixture row);
    • the heartbeat is pinned (no stale timer, no drift);
    • a held quit sets the gate to finishing, so there's no second quit and no output start;
    • redirects are refused, there's a hard total timeout, and the User-Agent is neutral.

Tests: telemetry/* 190, quit/* 116, comms 268, all passing. Every named mutation turned red. No test touches the network (a URLProtocol stub is used).

🤖 Generated with Claude Code

@iamfatness
iamfatness force-pushed the mac-control-phase4-telemetry branch from 74a6161 to ad7205c Compare November 25, 2026 19:23
@iamfatness
iamfatness changed the base branch from mac-control-phase4 to main November 25, 2026 23:21
John Wallace and others added 6 commits November 26, 2026 16:03
… machine class

Task 7 of docs/superpowers/plans/2026-11-22-mac-control-telemetry-leftovers-phase4.md.

- contracts/telemetry.fixtures.json, written by the new MCT
  TelemetryFixtureExportTests from the REAL Windows telemetry code
  (COREVIDEO_REWRITE_TELEMETRY_FIXTURES=1). It holds payloads, ram bands,
  half-to-even RAM rounding, consent files and config resolution.
  - The payload inputs are core sync responses parsed on the LIVE path:
    CoreProtocolParser.TryParseWireState + MapNativeWireStateToSnapshot, as
    MediaCoreSupervisor does on a real core (confirmed). The direct
    TryParseSyncSnapshot branch is the stub path.
  - Participants come from the core's own participants node there; no Zoom
    merger on that path.
  - Three inputs: the secret-laden snapshot re-expressed as core JSON
    (stream key, guest name, recording folder, meeting URL, passphrase);
    engine off; NDI-only.
- TelemetryConfig: endpoint https://telemetry.corevideo.io, overridden by a
  non-blank COREVIDEO_TELEMETRY_ENDPOINT. The key comes ONLY from
  COREVIDEO_TELEMETRY_API_KEY (D-T1); nothing is embedded. Enabled = a key
  plus an absolute http(s) URL. The description never prints the key.
- MachineClassProbe (D-T2): mac-arm64-cpu<N>-ram<N>gb, RAM rounded half to
  even, Windows bands, gpuTier apple-m<gen>[-pro|-max|-ultra] from
  machdep.cpu.brand_string. No model code, serial or name.
- TelemetryPayloadBuilder: counts and on/off from the core snapshot, keys in
  Windows' order, a nil gpuTier omitted. Builder returns an ordered
  TelemetryPayload struct instead of a JSONObject, because a dictionary cannot
  keep the wire order.
- TelemetryConsentStore: the Windows JSON (DateTimeOffset "+00:00"),
  temp-file + rename, bounded 20 x 25 ms retry with the sleep injected.
  Absent, empty, corrupt, locked or unreadable files, and a directory at the
  path, all read OFF. A revoke lands on an unreadable file; a grant and
  markSent throw instead.
- TelemetryCrashCount and CrashReportRecord (Task 10 reuses it).

Tests (telemetry/*, 111 checks): payload-matches-windows (object-equal AND
key order at every level, all three inputs, no secret in the wire),
ram-bands, ram-rounding-half-even, machine-label, config-matches-windows,
consent-defaults-off (including the same store reading a file that turns
corrupt or locked), consent-file-shape (object- and text-equal),
revoke-lands-when-unreadable, marksent-never-revokes, crash-count. The MCT
exporter: 2/2.

Mutations (all red): RAM rounded half away from zero (8.5 GiB); gpuTier
always emitted (engine-off); streaming read from activeSenderCount instead
of sender status (ndi-only); a corrupt or locked file returning the last
in-memory value (same-store case); two payload keys swapped (order).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Task 8 of the Phase 4 control plan. Ports of Windows TelemetryEventClient
and TelemetryEventService.

- TelemetryEventClient: POST {endpoint}/v1/events (the absolute path
  replaces a base path, as Windows new Uri(endpoint, "/v1/events")),
  Authorization: Bearer, Content-Type: application/json. Outcomes: 2xx
  Accepted (reportId read); 429 or >= 500 RetryLater (Retry-After as delta
  seconds or an HTTP date relative to the injected now); anything else
  Rejected; a network error is RetryLater. Error bodies are cut to 300
  characters.
- TelemetryService: the heartbeat every 24 h (first after 24 h) is scheduled
  ONLY when configured at start, and sends only with consent at fire time,
  15 s timeout. Only a heartbeat RetryLater with Retry-After moves the next
  fire. Session-end is sent once per process with a 2 s timeout and never
  honours Retry-After. The exact wire JSON is logged before every POST, then
  "accepted (reportId=...)" or "not accepted (<Status>, http=<n|n/a>): ...".
  An accepted send records markSent(now). Every interval and timeout runs on
  an injected TelemetryClock (RealTelemetryClock = main-queue scheduling,
  which fires during .terminateLater).
- AppModel (D-T4): with consent and a key, an idle quit returns
  .terminateLater and replies when session-end finishes or 2 s pass,
  whichever is first, exactly once. Without either, the quit is .terminateNow
  as before. confirmQuit fires session-end first so it runs alongside output
  teardown. startTelemetry() reads the key only from
  COREVIDEO_TELEMETRY_API_KEY, logs only the endpoint host and whether a key
  is present, and never runs in the test harness.

Tests (telemetry/* 152, quit/* 105, all pass): client-classify,
client-request-shape (a URLProtocol stub, no network), no-send-without-
consent, no-send-without-key (no timer scheduled), session-end-once,
heartbeat-cadence (manual clock: 24 h, consent off at 30 h, Retry-After
600 s), audit-log-precedes-send, marks-sent-only-on-accept,
quit/idle-waits-for-session-end (run against a transport that honours its
timeout AND one that ignores it, rule 9; the reply comes at exactly 2 s),
quit/idle-unchanged-without-consent, quit/idle-replies-when-send-finishes
(0.3 s).

Mutations (all red): session-end honours Retry-After (a timer moved);
heartbeat scheduled without a key; quit replies only when the send finishes
(the never-returning transport never replies); log written after the POST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Task 9 of the Phase 4 control plan (placement D-T3: the bottom of the Zoom
pane, after "Zoom status").

- TelemetryCard, in Windows' order and words (SettingsPage.xaml:187-221,
  SettingsViewModel.cs:140-152):
  - title "Diagnostics & telemetry";
  - toggle "Share anonymous health data" (Off/On);
  - the what-is-sent copy, verbatim;
  - a 12 pt accent status line: "Telemetry endpoint and API key configured."
    or Windows' missing-key sentence;
  - a ghost "Preview what's sent" button;
  - a bordered, monospaced, selectable, scrolling (max 320) preview of the
    indented session-end payload.
- The toggle loads the stored consent WITHOUT re-persisting it, persists only
  on the operator's change, and logs "telemetry: consent ENABLED/disabled by
  operator". The preview works with consent off and sends nothing.
- Diagnostics.swift header: "nothing in this file sends a byte off the
  machine; uploads live in Telemetry*.swift and CrashReport*.swift and need
  consent".
- Tab snapshot: COREVIDEO_SHELL_TAB_SNAPSHOT_TELEMETRY=1 seeds an open
  preview. It is opt-in, so other lanes' Zoom snapshots are unchanged. The
  capture was reviewed against the XAML order.

Tests: telemetry/card-copy (every string verbatim),
telemetry/toggle-persists-not-on-load (load writes nothing, a flip writes
once and logs, a repeat writes nothing), telemetry/preview-without-consent.
telemetry/* 167/167.

Mutations (all red): persist during the initial load; preview gated on
consent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n replies once

Rebasing Batch T onto main brought in #1236, which also defers an idle quit
(the Comms release-all in a meeting). Both holds now run side by side, and
finishIdleQuit replies exactly once, when the release has finished (its own
bound) AND session-end has finished or hit its 2 s cap. With neither hold
the quit is .terminateNow, as before.

quit/idle-waits-for-comms-and-session-end: released but session-end in
flight -> no reply; session-end done at 0.3 s -> one reply; never a second.
Mutation (red): mark telemetry done up front, so the reply comes after the
release alone. telemetry/* 167, quit/* 110, comms 268, all passing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ank key, heartbeat pin, quit window, transport hardening

The independent Batch T review found no blocking defect, and all 11 plan
mutations went red. Its gaps, each now fixed with a test that is red without
the fix:

1. The harness uses a distinctive API key, and the audit test asserts it is
   in NO log line (adding log(apiKey) used to stay green).
2. The fake transport's POST body equals the logged wire, byte for byte.
3. A blank or whitespace key is NO key (TelemetryConfig.resolve returns nil).
   New Windows exporter row (null, " ") in contracts/telemetry.fixtures.json:
   Windows reports enabled=false for it too.
4. Heartbeat pinned: after a RetryLater retry exactly one timer is armed, and
   the next 25 h hold exactly one more fire (a stale, uncancelled timer is
   red). New telemetry/heartbeat-no-drift: a send that takes 10 s does not
   push the next fire (cadence runs from the fire, as Windows' Timer period).
5. A held idle quit (session-end and/or the Comms release-all) sets the quit
   gate to .finishing (QuitGate.beginDeferredQuit) and quitFinishing, so a
   second quit is ignored (.terminateCancel) and no output can start in the
   window (canSetOutputs). The test first proves outputs COULD start, so the
   check cannot pass vacuously (a first version did, and was caught by its
   own mutation).
6. Transport:
   - redirects are refused by a session delegate, so the Bearer key never
     reaches another host and the 3xx is Rejected;
   - a HARD total timeout (timeoutIntervalForResource, one ephemeral session
     per send, no cookies or cache), as Windows' HttpClient.Timeout;
   - a neutral User-Agent "CoreVideoPro-Telemetry/1" with no OS build.
   Tested with the URLProtocol stub: one host contacted on a 302, the UA, a
   hung server ending at 0.5 s, and the resource timeout.

Mutations (all red): log the key; POST a body different from the log; keep a
blank key; leave the old heartbeat timer armed; reschedule after the send
(drift); no quit-gate phase; leave outputs open in the window; follow the
redirect; the default User-Agent; idle-only timeout.
telemetry/* 190, quit/* 116, comms 268, MCT exporter 2/2, all passing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…matches on Windows

System.Text.Json's indented output uses Environment.NewLine (\r\n on
Windows), so FixtureIsCurrent failed on the Windows CI job. The fixture is
unchanged (it was written with \n on macOS).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamfatness
iamfatness force-pushed the mac-control-phase4-telemetry branch from 596cb02 to b225eb4 Compare November 26, 2026 21:06
@iamfatness
iamfatness marked this pull request as ready for review November 26, 2026 21:33
@iamfatness
iamfatness merged commit 294e4b7 into main Nov 26, 2026
18 checks passed
@iamfatness
iamfatness deleted the mac-control-phase4-telemetry branch November 26, 2026 21:33
iamfatness pushed a commit that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

# Conflicts:
#	mac-shell/Sources/CoreVideoProShell/ShellTests.swift
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.

1 participant