Diagnostic consent and controls
VoiceStudio treats technical diagnostics as an optional, separate data use. A user must choose to enable them before the desktop or mobile clients collect automatic failure data or send it to a configured diagnostic service. The same boundary also controls which client may change consent, which destination is valid, and which data can leave the device. See Diagnostics and observability for the wider system and Diagnostic data flow for the report path.
Consent boundary
Diagnostic consent is independent from usage analytics consent. It starts in the OFF state, and a first-run prompt or settings control records an explicit Allow or Keep off choice; viewing a self-check or saving a local bundle does not grant automatic reporting permission. The clients show the choice only when a valid destination and policy are available.
The consent state has three useful meanings:
| State | Effect |
|---|---|
| Unknown | Collection stays blocked until the saved choice is read successfully. |
| Off | Automatic capture, queued delivery, and session signals stay disabled. |
| On | Bounded technical failures may enter the local report queue and later use the configured destination. |
Analytics and diagnostics therefore need separate UI labels and separate state. Turning on analytics must not turn on diagnostics, and turning off diagnostics must not change analytics.
References: backend/…/settings.py• L1712-1752 electron/…/diagnostic-consent.tsx• L18-49 mobile/…/DiagnosticConsentView.swift• L4-31 mobile/…/MainActivity.kt• L209-221
Consent ownership
The client that owns the runtime owns the diagnostic choice. Electron normally owns desktop consent through its main process; the backend can expose the setting for local or controlled use, but it rejects a backend write when desktop control is active. Android and iOS keep consent in their app layer, including for OS-managed work that can finish after the screen closes.
This ownership prevents a renderer, paired host, or delayed worker from silently restoring an old grant. Every enabled period has a local grant epoch, which acts as a short-lived authority marker rather than report data.
References: backend/…/diagnostic_reports.py• L999-1032 backend/…/settings.py• L1735-1743 electron/…/diagnostics-ipc.ts• L6-29 mobile/…/AutomaticDiagnostics.kt• L127-220 mobile/…/AppDiagnostics.swift• L38-65
Capture authorization
Automatic capture is allowed only when consent is current, the diagnostic policy and destination are usable, and the process has not received a disable signal. A failure from work that began under an older grant cannot use a newer grant. Withdrawal closes the in-memory gate first, cancels active delivery, and removes or fences queued evidence before the UI reports the choice as complete.
The control relationship is:
flowchart LR
A[User choice] --> B{Current consent?}
B -- No --> C[No automatic capture]
B -- Yes --> D{Valid policy and destination?}
D -- No --> C
D -- Yes --> E[Capture closed technical fields]
E --> F{Grant still current?}
F -- No --> C
F -- Yes --> G[Bounded local queue]
G --> H[Send only while consent remains on]
The desktop renderer can submit only a closed set of diagnostic fields through a trusted preload and main-process bridge. Backend diagnostic writes also require an administrative action gate. The event contract accepts renderer-originated data with bounded fields and rejects extra or unsupported metadata. Remote log and crash-record reads are stricter: they require loopback access or a valid administrator credential, and a share PIN is not enough.
References: electron/…/diagnostic-reports.ts• L82-108 electron/…/diagnostic-reports.ts• L254-347 electron/…/diagnostics-ipc.ts• L12-28 backend/…/settings.py• L1718-1758 backend/…/dependencies.py• L376-404
Privacy boundary
Automatic reports contain technical classifications rather than user work. The shared policy limits values to known categories and bounded platform, version, engine, timing, resource, exit, and approved frame data. It does not carry exception messages, source text, audio, video, model content, arbitrary paths, URLs, credentials, or raw stack traces.
The privacy boundary applies again before delivery. Desktop and mobile transports map the same closed projection into an app event. A local session or install identifier supports failure grouping, but the ingest credential remains configuration data and never enters a stored report. A local diagnostic bundle is a separate, user-started export; its logs and reports are scrubbed before the user saves the file.
References: electron/…/diagnostics-schema.ts• L122-185 mobile/…/DiagnosticReports.swift• L173-207 mobile/…/DiagnosticReports.kt• L221-233 backend/…/diagnostic_bundle.py• L1-21
Destination policy
Diagnostic delivery uses a dedicated destination policy instead of the paired-host session. A configured public destination must use HTTPS; plain HTTP is accepted only for literal loopback development addresses. The diagnostic transport does not reuse paired-host cookies, authentication, redirects, or request state.
Build or environment configuration can provide the app intake identity and host. Invalid or incomplete configuration makes diagnostics unavailable rather than sending to an inferred destination. Optional session pings are also configuration-controlled and remain behind the same consent and revocation gates.
References: electron/…/diagnostics-app.ts• L64-117 mobile/…/DiagnosticAppIntake.swift• L4-26 mobile/…/DiagnosticAppIntake.kt• L5-24 mobile/…/DiagnosticTransport.swift• L182-214
Disable and withdrawal controls
The environment disable switch is a hard stop for both diagnostics and the related analytics transport. It makes reporting unavailable and triggers cleanup of stored consent and queued reports. A failed cleanup keeps the runtime closed and retries later instead of allowing an old grant to become active again.
The settings UI exposes the same boundary on each client. Electron offers a first-use choice and a privacy setting. Android shows the choice after its normal first-run consent. iOS shows it in first-run flow and Settings. A failed save shows a retry action; it does not silently treat an old or unknown permission as a new grant.
References: backend/…/diagnostic_reports.py• L984-1099 electron/…/diagnostics.ts• L396-509 mobile/…/AutomaticDiagnostics.kt• L142-227 mobile/…/AppDiagnostics.swift• L84-103 mobile/…/SettingsView.swift• L35-46
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the independent diagnostic choice aligned across the renderer or native prompt, Settings control, persisted consent, and runtime capture gate.
- Keep the grant epoch checks aligned across async work, OS recovery callbacks, IPC or API submission, and withdrawal cleanup.
- Keep destination validation aligned across desktop, Android, and iOS. Do not widen the HTTP loopback exception or allow paired-host credentials into diagnostic transport.
- Keep the closed privacy projection aligned with the shared diagnostic policy and app-intake mapping.
- Keep the backend diagnostic endpoints behind the admin-action gate and aligned with the strict renderer-only event contract.
- Keep remote log and crash-record authorization separate from diagnostic event consent.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A delayed task uses an old consent observation | A report can be created after withdrawal or under a newer grant | Compare the observed epoch with the current epoch before capture and delivery |
| Consent storage cannot be read | An old permission may be mistaken for current authority | Treat unknown consent as blocked and retry the read |
| A consent write or withdrawal cleanup fails | The UI and durable state can disagree | Keep capture closed, persist a revocation fence, and expose Retry |
| A destination uses an invalid scheme or host | Technical data could go to an unintended endpoint | Accept HTTPS or exact loopback HTTP only and fail closed on invalid config |
| A client sends extra or unsupported diagnostic fields | The event is rejected instead of entering the report path | Use the bounded renderer event contract and handle validation errors without retrying as consent |
| A remote caller requests logs with only a share PIN | Host paths and private logs could be exposed | Require loopback or a valid administrator credential |
Key files
| File | Why to read it |
|---|---|
| backend/…/diagnostic_reports.py | Backend consent state, grant epochs, privacy projection, revocation, and delivery authority |
| backend/…/settings.py | Diagnostic status, admin-action gate, and strict event API boundary |
| backend/…/dependencies.py | Authorization rules for private logs and crash records |
| electron/…/diagnostics.ts | Desktop consent authority, disable handling, and durable withdrawal behavior |
| electron/…/diagnostics-ipc.ts | Trusted renderer-to-main control boundary |
| electron/…/diagnostic-consent.tsx | Desktop prompt and privacy setting behavior |
| mobile/…/AutomaticDiagnostics.kt | Android ownership of consent and OS-work capture |
| mobile/…/AppDiagnostics.swift | iOS consent presentation, recovery gating, and MetricKit subscription control |
| mobile/…/DiagnosticTransport.swift | Isolated destination transport and network restrictions |