Diagnostics and observability
Diagnostics and observability provide an opt-in way to learn why VoiceStudio operations fail across desktop, mobile, and backend runtimes. The system records small technical reports, keeps them safe and bounded, links asynchronous failures to the operation that owns them, and sends accepted reports to the diagnostic service without delaying the user’s work.
System purpose
Operational failure reports
The diagnostic system turns failures into a shared set of technical facts. A report can describe a crash, setup problem, model or engine failure, download failure, or other failed operation. It uses fixed categories, stages, error codes, safe error types, bounded stack locations, and coarse timing or resource buckets. A technical fingerprint groups close repeats and an occurrence count represents them without flooding the queue. This lets maintainers compare failures without receiving exception text, user content, or arbitrary paths. The shared policy in config/diagnostics.json defines the vocabulary and limits used by the clients and backend.
References: config/diagnostics.json• L1-14 config/diagnostics.json• L16-38 electron/…/diagnostics-schema.ts• L48-125 electron/…/diagnostics-schema.ts• L151-196 electron/…/diagnostics.ts• L632-692
Failure-safe reporting
Reporting is a side path to the product operation. Capture makes a bounded in-memory enqueue and returns without waiting for disk, consent reads, or network work. If projection or reporting fails, the original operation continues. Process hooks and backend error paths follow the same rule so they do not create a second failure while they describe the first one.
References: backend/…/diagnostic_reports.py• L410-457 backend/…/diagnostic_reports.py• L971-985 electron/…/diagnostics-capture.ts• L117-161
Diagnostic lifecycle
Report flow
The system moves a report through capture, safe projection, local protection, durable storage, delivery, and acknowledgement. Consent and its grant epoch remain attached to the lifecycle as authority. They are not report content. A report is removed only after the receiving service gives a terminal result.
The following diagram shows the common path from a product failure to a diagnostic service. The delivery step can use a shared event endpoint or an app-intake endpoint.
flowchart LR
F[Product failure] --> C[Client capture]
C --> P[Closed technical projection]
P --> A{Consent still valid?}
A -- No --> X[Drop or purge]
A -- Yes --> Q[Bounded durable queue]
Q --> D[Diagnostic transport]
D --> R{Terminal result?}
R -- No --> Q
R -- Yes --> K[Commit acknowledgement and cleanup]
For the detailed record, consent, queue, and transport rules, see diagnostic data flow.
References: electron/…/diagnostics-schema.ts• L235-267 electron/…/diagnostics.ts• L885-932 electron/…/diagnostics.ts• L933-1064 electron/…/diagnostics.ts• L1073-1251 backend/…/diagnostic_reports.py• L670-728 backend/…/diagnostic_reports.py• L826-921
Consent and control boundaries
Diagnostic collection requires an explicit opt-in. The desktop shell owns consent when the backend runs under desktop control. A standalone backend or mobile client can own its own choice. Turning reporting off closes capture and delivery first. It then removes or fences stored evidence. A kill switch also forces reporting off. An unread consent store is treated as unknown authority rather than permission.
The renderer exposes status and the consent control, but the trusted desktop boundary makes the final decision. The backend rejects attempts to change consent when the desktop owns it. See diagnostic consent and controls for the full boundary model.
References: backend/…/diagnostic_reports.py• L463-482 backend/…/diagnostic_reports.py• L1002-1102 backend/…/diagnostic_reports.py• L1194-1203 electron/…/diagnostics.ts• L245-301 electron/…/diagnostics.ts• L397-511
Protected report data
Before a report leaves a client, the system rebuilds it from allowed fields and the shared policy. It rejects unknown values, limits size and age, keeps only app-owned frame locations, and derives a technical fingerprint from safe fields. It does not send exception messages, raw stacks, credentials, URLs, or user media and text. Manual diagnostic bundles follow a separate support path and scrub their logs before the user shares them.
References: electron/…/diagnostics-schema.ts• L117-196 electron/…/diagnostics-schema.ts• L235-312 backend/…/diagnostic_reports.py• L188-231
Client roles
Desktop client
The Electron main process is the desktop diagnostic authority and durable outbox. It receives safe renderer events through trusted IPC, observes backend status, captures main and renderer process failures, and records backend startup, install, and operation failures. Python uses a managed inbox when it runs under the desktop. The desktop then decides consent and owns external delivery through the configured event or app-intake transport. See Electron desktop for the wider desktop boundary.
The renderer reads status through IPC when available and through the backend settings API when it is not. This lets the settings view show consent before the packaged Python service is ready without making the renderer the authority.
References: electron/…/diagnostics-capture.ts• L33-115 electron/…/diagnostics-capture.ts• L117-200 electron/…/diagnostics-schema.ts• L199-210 electron/…/diagnostics.ts• L231-301 electron/…/diagnostics.ts• L964-1064 electron/…/diagnostics.ts• L1073-1251 backend/…/diagnostic_reports.py• L332-346
Mobile clients
The mobile diagnostic library provides the same high-level contract for mobile runs: explicit consent, a bounded local queue, safe projection, crash recovery, and delayed delivery. Mobile clients report failures from local work and asynchronous tasks such as uploads and companion jobs. They keep task ownership with the task identity so a later retry does not lose the failure’s source or report it under the wrong operation. See mobile clients for the client lifecycle around this contract.
The mobile transport can use the shared event endpoint or the app-intake endpoint. The app-intake form supports session correlation and per-event results. This lets a client retain only events that the service has not finished.
References: mobile/…/DiagnosticReports.swift• L125-200 mobile/…/DiagnosticAppIntake.swift• L42-127 mobile/…/BackgroundUpload.swift• L81-177
Backend runtime
The backend captures failures from request handlers, model work, setup work, streams, and worker tasks. It can run as a standalone reporter or as a desktop-managed producer. In the managed case, Python writes local diagnostic records to the Electron inbox. It does not make the consent decision or send the report itself.
The backend also maps known request stages to closed diagnostic categories and ignores expected refusals and cancellations. This keeps normal control flow out of failure reports without retaining request paths or raw error context.
References: backend/…/diagnostic_reports.py• L1129-1245 backend/…/diagnostic_reports.py• L332-346 backend/…/diagnostic_reports.py• L826-921
Ownership and correlation
Asynchronous operation ownership
An operation owner is the consent grant that was valid when asynchronous work began. The system carries that owner through tasks, thread workers, awaited work, streams, and retries. A failure can therefore be reported only for the grant that started the work. A later opt-out or new opt-in cannot authorize an old continuation.
This ownership is separate from request data. It uses local context and a grant epoch rather than copied user input. Desktop status observation applies the same rule: a setup attempt keeps the owner that was active when the attempt began. Backend hooks also refuse to infer permission for unbound work.
References: backend/…/diagnostic_reports.py• L38-128 backend/…/diagnostic_reports.py• L1135-1151 electron/…/diagnostics-capture.ts• L42-114 electron/…/diagnostic-operation.ts• L1-220
Session correlation
Session correlation groups failures from one enabled app run so maintainers can relate a startup or operation failure to the run that produced it. It is local run state. It does not revive an old grant or attach restored records to a new session. When consent changes, the correlation is retired with the old grant.
References: backend/…/diagnostic_reports.py• L378-385 backend/…/diagnostic_reports.py• L765-805 backend/…/diagnostic_reports.py• L923-925 electron/…/diagnostics.ts• L346-358 electron/…/diagnostics.ts• L1302-1402
Delivery and support outputs
Remote diagnostic delivery
Clients deliver technical events over short, bounded requests. They retry transient failures while retaining the durable record and stop delivery for an invalid or unauthorized app-intake configuration. Batch responses identify accepted, dropped, and rate-limited events. A record becomes locally complete only after a terminal result, and that completion state is never sent as report data. Ambiguous responses do not acknowledge evidence. The backend API also exposes local status, consent, and renderer event intake for managed clients.
References: electron/…/diagnostics.ts• L994-1063 electron/…/diagnostics.ts• L1073-1251 backend/…/diagnostic_reports.py• L873-921 backend/…/diagnostic_reports.py• L927-947 backend/…/diagnostic_app_transport.py• L119-165 backend/…/settings.py• L1729-1750
Local diagnostic bundles
Automatic reports are small remote events. A diagnostic bundle is a user-requested support package for cases that need local context. It combines a self-check report, recent classified errors, render timings, and scrubbed log tails into a zip file that the user can attach to a support issue. It does not replace consent-based automatic reporting.
References: backend/…/diagnostic_bundle.py• L1-21 backend/…/diagnostic_bundle.py• L53-91
Change checklist
When these files or sections are changed, remember to consider these:
- Keep config/diagnostics.json aligned with the TypeScript, Python, and Swift projections. A new category, stage, or error code must be accepted by every client that can produce it.
- Preserve the grant epoch checks across IPC, backend API intake, task context, retries, and transport callbacks. A delayed callback must not use a newer consent choice.
- Keep the app-intake event shape and per-index acknowledgement rules aligned between desktop, Python, iOS, and the receiving service.
- Preserve the managed desktop boundary. Backend settings must not silently become a second consent authority when Electron owns the run.
- If report fields change, review both automatic event sanitization and manual bundle scrubbing. These paths have different data purposes.
- Keep the per-fingerprint queue budget aligned with deduplication and terminal acknowledgement. A repeat flood must not evict unrelated evidence or leave completed producer records able to re-enter delivery.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Consent read fails while a grant is stored | Capture and delivery stop while durable evidence remains for a later bounded retry | Treat unread authority as unknown and keep the old evidence unchanged |
| User withdraws consent during an active send | The in-flight request may finish locally but must not publish or retain the old grant’s report | Close the memory gate first and cancel the transport |
| App-intake response is malformed or incomplete | Events remain pending and can be retried; evidence is not falsely acknowledged | Require a valid per-index result for the whole batch |
| Durable queue or inbox reaches its bound | New reports can be dropped and counted instead of growing without limit | Enforce record, byte, and age limits before admission |
| One failure repeats faster than other failures | Repeated evidence can crowd out distinct failures | Coalesce close repeats and cap each fingerprint family before applying the global queue bound |
| Asynchronous work finishes after its owner changes | A late failure could be attributed to the wrong consent choice | Carry and compare the owner’s grant epoch |
| Diagnostic projection throws while handling a product failure | The original product operation could be masked by reporting | Keep capture best effort and discard uninspectable diagnostic input |
Key files
| File | Why to read it |
|---|---|
| config/diagnostics.json | Shared report vocabulary, frame allowlist, and size and age limits |
| electron/…/diagnostics.ts | Desktop consent authority, durable queue, recovery, completion state, and delivery lifecycle |
| electron/…/diagnostics-capture.ts | Desktop observation of backend, renderer, and process failures |
| electron/…/diagnostics-schema.ts | Closed report shape, safe projection, frame filtering, and queue limits |
| electron/…/diagnostic-reports.ts | Renderer consent observation and safe event dispatch |
| backend/…/diagnostic_reports.py | Backend capture, ownership propagation, managed inbox, and standalone delivery |
| backend/…/diagnostic_app_transport.py | App-intake event mapping, batching, and acknowledgement handling |
| mobile/…/DiagnosticReports.swift | Mobile consent, recovery, queue, correlation, and delivery lifecycle |
| mobile/…/DiagnosticAppIntake.swift | Mobile app-intake event shape and result rules |
| backend/…/diagnostic_bundle.py | User-requested local support bundle and log scrubbing boundary |
| electron/…/diagnostics.test.ts | Guarantees for consent, safe projection, crash recovery, queue limits, and delivery |
| electron/…/diagnostics-storage.test.ts | Guarantees for durable storage, cleanup races, recovery, and acknowledgement persistence |