Diagnostic capture and reporting
Diagnostic reporting turns failures and process exits into small, consent-gated technical records. Backend, Electron, Android, and iOS code project local failures into the same closed event shape, keep each record owned by the consent state that allowed it, store it until delivery is safe, and leave the product usable when storage or network work fails.
Diagnostic event model
Technical event projection
An event is a bounded description of a failure rather than a copy of the failure itself. The shared policy limits categories, stages, error codes, platforms, device classes, and approved frame locations, then adds a stable fingerprint and an occurrence count for grouping. Raw messages, user content, arbitrary paths, and credentials do not enter the automatic event path. config/diagnostics.json• L1-16 config/diagnostics.json• L23-38 config/diagnostics.json• L241-257 electron/…/diagnostics-schema.ts• L48-115 electron/…/diagnostics-schema.ts• L151-186
Each boundary rebuilds the technical projection from allowed values. Electron accepts only a small renderer input shape, reduces errors to known types and approved frames, and sanitizes records again before they enter or leave durable storage. The backend applies the same closed-field rule and derives the fingerprint from the sanitized fields rather than accepting a caller-supplied identity. electron/…/diagnostics-schema.ts• L117-148 electron/…/diagnostics-schema.ts• L189-209 backend/…/diagnostic_reports.py• L188-219
The event keeps enough context to compare failures across runtimes. Backend and client sources use the same categories such as generation_failed, model_load_failed, install_failed, and crash classes. A platform adapter maps that closed record to the remote intake form and marks crashes as fatal while treating handled failures as errors. backend/…/diagnostic_app_transport.py• L74-98 mobile/…/DiagnosticAppIntake.kt• L30-55 mobile/…/DiagnosticAppIntake.swift• L42-84
References: config/diagnostics.json• L1-16 config/diagnostics.json• L23-38 config/diagnostics.json• L241-257 electron/…/diagnostics-schema.ts• L48-115 electron/…/diagnostics-schema.ts• L117-148 electron/…/diagnostics-schema.ts• L151-209 backend/…/diagnostic_reports.py• L188-219 backend/…/diagnostic_app_transport.py• L74-98 mobile/…/DiagnosticAppIntake.kt• L30-55 mobile/…/DiagnosticAppIntake.swift• L42-84
Consent epoch
Consent is an explicit grant with an epoch: a fresh opaque value that identifies one active grant. Capture, queued records, delayed callbacks, storage writes, and sends must still match that epoch. Turning reporting off closes the in-memory gate first, so work that finishes later cannot use an older choice. electron/…/diagnostics.ts• L247-273 electron/…/diagnostics.ts• L396-509 mobile/…/DiagnosticReports.kt• L304-355 mobile/…/DiagnosticReports.swift• L163-235
Backend async work carries only the observed grant authority across await and executor boundaries. A callback that has no clear owner does not gain permission from a later opt-in, and a callback that belongs to an older grant is rejected before it enters the capture queue. backend/…/diagnostic_reports.py• L38-128 backend/…/diagnostic_reports.py• L410-447
The renderer uses the same rule before it sends a failure to Electron or the backend. It records a local consent observation with the current revision and epoch, checks that observation again after async work, and aborts pending requests when the user withdraws consent. electron/…/diagnostic-reports.ts• L82-108 electron/…/diagnostic-reports.ts• L118-146 electron/…/diagnostic-reports.ts• L162-215 electron/…/diagnostic-reports.ts• L329-361
An unread consent file is different from a confirmed opt-out. The reporters stop new collection and delivery while they retry the read. A confirmed withdrawal writes a revocation marker and removes stored reports, with a bounded retry if the write or cleanup fails. electron/…/diagnostics.ts• L302-343 electron/…/diagnostics.ts• L584-620 mobile/…/DiagnosticReports.kt• L385-430 mobile/…/DiagnosticReports.swift• L328-370 mobile/…/DiagnosticReports.swift• L411-437
References: electron/…/diagnostics.ts• L247-273 electron/…/diagnostics.ts• L302-343 electron/…/diagnostics.ts• L396-509 backend/…/diagnostic_reports.py• L38-128 backend/…/diagnostic_reports.py• L410-447 electron/…/diagnostic-reports.ts• L82-108 electron/…/diagnostic-reports.ts• L118-146 electron/…/diagnostic-reports.ts• L162-215 mobile/…/DiagnosticReports.kt• L304-355 mobile/…/DiagnosticReports.kt• L385-430 mobile/…/DiagnosticReports.swift• L163-235 mobile/…/DiagnosticReports.swift• L328-370
Runtime capture paths
Backend capture
The backend captures a failure by projecting it into memory and placing it on a bounded intake queue. A single worker owns consent reads, sanitization, durable storage, and delivery. This keeps an error path short and prevents diagnostic work from retaining an exception or delaying the operation that failed. backend/…/diagnostic_reports.py• L1-5 backend/…/diagnostic_reports.py• L410-457 backend/…/diagnostic_reports.py• L949-985
The backend keeps capture optional even when projection or storage sees an unexpected value. It drops an uninspectable event instead of reading a raw error message or allowing the reporting path to interrupt the product operation. backend/…/diagnostic_reports.py• L238-285 backend/…/diagnostic_reports.py• L410-457
The backend has two delivery roles. A standalone backend can own its outbox and send reports. A desktop-managed backend writes sanitized records to an Electron inbox instead; Electron then owns the final durable queue and network send. This split prevents two processes from competing for one delivery record. backend/…/diagnostic_reports.py• L329-379 backend/…/diagnostic_reports.py• L616-665 backend/…/diagnostic_reports.py• L867-918
Fatal backend evidence starts outside normal exception handling. The fault handler writes native traceback data to the process error stream, while exit forensics adds a short reason for silent exits and thread failures. Electron consumes that stream and can turn the next startup into a bounded crash event. backend/…/crash_diagnostics.py• L18-31 backend/…/crash_diagnostics.py• L53-110 electron/…/crash-journal.ts• L91-111 electron/…/crash-journal.ts• L160-207
References: backend/…/diagnostic_reports.py• L1-5 backend/…/diagnostic_reports.py• L38-128 backend/…/diagnostic_reports.py• L238-285 backend/…/diagnostic_reports.py• L329-379 backend/…/diagnostic_reports.py• L410-457 backend/…/diagnostic_reports.py• L616-665 backend/…/diagnostic_reports.py• L867-918 backend/…/diagnostic_reports.py• L949-985 backend/…/crash_diagnostics.py• L18-31 backend/…/crash_diagnostics.py• L53-110 electron/…/crash-journal.ts• L91-111
Electron capture
Electron is the desktop authority for renderer, main-process, and managed-backend reports. Renderer code sends only a validated technical projection through trusted IPC or a bounded backend request, while main-process hooks observe uncaught exceptions, rejected promises, backend status failures, and unexpected process exits. electron/…/diagnostics-ipc.ts• L6-29 electron/…/diagnostics-capture.ts• L117-201 electron/…/diagnostic-reports.ts• L272-361
Renderer capture starts with a consent observation and produces only typed fields such as a known error type, approved frames, and a known error code. It ignores cancellation and routine client failures, limits concurrent requests, and swallows reporting errors so a failed diagnostic request cannot create another renderer failure. electron/…/diagnostic-reports.ts• L218-252 electron/…/diagnostic-reports.ts• L254-323 electron/…/diagnostic-reports.ts• L329-361
Electron status observation turns backend setup verdicts into one bounded event per attempt. It reports real stalls and classified launch or crash failures, but does not restart work, inspect arbitrary service names, or report expected exits. Each setup attempt keeps the grant owner from the operation that started it, including an explicit disabled state, or observes the current grant when no operation owner exists. electron/…/diagnostics-capture.ts• L24-115 electron/…/diagnostics-capture.ts• L164-201
Electron also owns the boundary between backend work and delayed callbacks. An operation receives the grant epoch that was current when it started. Promise and async-resource tracking carries that owner to the actual consumer of a rejected result, or refuses attribution when ownership is ambiguous. Main-process fatal hooks use this owner rather than a fresh consent read, while an unowned strict-mode rejection is not given permission by the hook. This prevents a later opt-in from authorizing an older task. electron/…/diagnostic-operation.ts• L84-118 electron/…/diagnostic-operation.ts• L143-203 electron/…/diagnostic-operation.ts• L206-233 electron/…/diagnostics-capture.ts• L117-161
Electron process-exit evidence follows a closed set of reasons and child-process types. Expected exits and unknown reasons are ignored. Unexpected renderer exits become renderer crash events, while main-process exits use fixed codes for GPU, utility, or other child processes instead of recording a free-text service name. electron/…/diagnostics-capture.ts• L164-201
The renderer has a separate user-report path for issues that a person chooses to submit. It adds scrubbed environment facts, a bounded error section, and recent action names. Breadcrumbs stay in memory and contain action names only; they are not part of automatic diagnostic intake. electron/…/breadcrumbs.js• L1-14 electron/…/bugReportDocument.js• L24-104
References: electron/…/diagnostics-ipc.ts• L6-29 electron/…/diagnostics-capture.ts• L24-115 electron/…/diagnostics-capture.ts• L117-201 electron/…/diagnostic-reports.ts• L82-108 electron/…/diagnostic-reports.ts• L218-252 electron/…/diagnostic-reports.ts• L254-323 electron/…/diagnostic-reports.ts• L329-361 electron/…/diagnostic-operation.ts• L143-203 electron/…/diagnostic-operation.ts• L206-233 electron/…/breadcrumbs.js• L1-14 electron/…/bugReportDocument.js• L24-104
Android capture
Android exposes one application-owned reporter to feature work. A feature takes a local observation of the active grant before starting work and passes it to delayed or remote failure handlers. The handler records only failures that still match that observation, so a consent change cannot authorize a result from an earlier task. mobile/…/AutomaticDiagnostics.kt• L234-258 mobile/…/StudioViewModel.kt• L84-103
Android process recovery uses the system exit history. On a later launch, the app reads the small process summary written while reporting was enabled and maps native crashes, crashes, hangs, and startup failures into records with the original time and app version. Expected exits are ignored. mobile/…/AutomaticDiagnostics.kt• L260-300
References: mobile/…/AutomaticDiagnostics.kt• L127-180 mobile/…/AutomaticDiagnostics.kt• L234-258 mobile/…/AutomaticDiagnostics.kt• L260-300 mobile/…/StudioViewModel.kt• L84-103
iOS capture
iOS uses the same reporter contract through an app-owned controller. Feature failures are mapped from known client error keys and stages to the shared diagnostic classes. A captured observation stays tied to the user-started operation, including delayed recording and companion work. mobile/…/AppDiagnostics.swift• L149-177 mobile/…/AppDiagnosticPolicy.swift• L1-19
iOS also accepts delayed OS evidence from MetricKit and background work. MetricKit payloads are reduced to grouped counts and closed fields, then accepted only when the full diagnostic window began after the grant. The app does not place OS payload objects, messages, paths, or resource details into the durable report. mobile/…/AppDiagnostics.swift• L218-263 mobile/…/AppDiagnosticPolicy.swift• L39-45
References: mobile/…/AppDiagnostics.swift• L38-65 mobile/…/AppDiagnostics.swift• L149-177 mobile/…/AppDiagnostics.swift• L218-263 mobile/…/AppDiagnosticPolicy.swift• L1-19 mobile/…/AppDiagnosticPolicy.swift• L39-45
Durable delivery
Outbox ownership
Each runtime separates fast capture from slow work. Capture places a sanitized record into bounded memory. A worker then restores the durable queue, merges new records, writes the queue atomically, and only after successful publication attempts network delivery. Records have stable IDs, timestamps, a grant epoch, and occurrence counts so a restart can replay them without losing identity or counting the same failure repeatedly. electron/…/diagnostics.ts• L631-720 mobile/…/DiagnosticReports.kt• L645-708 mobile/…/DiagnosticReports.swift• L482-545
Desktop-managed backend records use a handoff directory rather than the desktop outbox. Electron imports each committed file, keeps the producer ID, and removes the source only after its own queue has durably accepted the record. A failed read keeps that source file for a later bounded retry. electron/…/diagnostics.ts• L865-912 electron/…/diagnostics.ts• L1233-1267
References: electron/…/diagnostics.ts• L631-720 electron/…/diagnostics.ts• L762-777 electron/…/diagnostics.ts• L865-912 electron/…/diagnostics.ts• L1233-1267 mobile/…/DiagnosticReports.kt• L645-708 mobile/…/DiagnosticReports.swift• L482-545
Network delivery
The sender uses a dedicated diagnostic destination and a short request limit. It sends bounded batches and retries temporary failures with backoff. A successful or otherwise terminal response marks the record complete; a timeout, connection error, server error, or rate limit keeps the record for a later retry. A 401 pauses app intake for the run instead of repeatedly sending with an invalid destination. backend/…/diagnostic_app_transport.py• L137-165 backend/…/diagnostic_app_transport.py• L222-301 electron/…/diagnostics.ts• L991-1043
App intake has a stricter acknowledgement rule than ordinary delivery. The client accepts a batch only when the response gives a valid result for every event. Accepted and terminally dropped events can be removed; rate-limited or unclear results stay durable. This avoids deleting evidence because a collector response was incomplete or malformed. backend/…/diagnostic_app_transport.py• L119-134 mobile/…/DiagnosticAppIntake.kt• L59-90 mobile/…/DiagnosticAppIntake.swift• L95-127
References: backend/…/diagnostic_app_transport.py• L137-165 backend/…/diagnostic_app_transport.py• L222-301 electron/…/diagnostics.ts• L1053-1231 mobile/…/DiagnosticAppIntake.kt• L59-90 mobile/…/DiagnosticAppIntake.swift• L95-127
Failure recovery
Storage errors do not become empty queues. A transient read or write failure leaves the last known durable evidence in place, closes collection or delivery when permission is unknown, and schedules one bounded retry. Confirmed malformed or oversized data can be discarded, but unread data is preserved until the system can inspect it. electron/…/diagnostics.ts• L681-720 mobile/…/DiagnosticReports.kt• L645-679 mobile/…/DiagnosticReports.swift• L486-513
The backend follows the same separation between unread storage and proven bad data. Its worker keeps an intake item in place when durable IO fails, then retries storage without sending memory-only reports. It removes only records that fail validation or exceed known limits. backend/…/diagnostic_reports.py• L619-668 backend/…/diagnostic_reports.py• L744-763
Delivery cleanup follows the same rule. The sender records completion before removing a producer inbox file or shrinking the outbox. If cleanup fails, the completed identity remains known and is retried later, which prevents a successful event from being imported and counted again. electron/…/diagnostics.ts• L1233-1267 mobile/…/DiagnosticReports.kt• L817-835 mobile/…/DiagnosticReports.swift• L634-641
References: electron/…/diagnostics.ts• L681-720 electron/…/diagnostics.ts• L1233-1267 backend/…/diagnostic_reports.py• L619-668 backend/…/diagnostic_reports.py• L670-763 mobile/…/DiagnosticReports.kt• L645-679 mobile/…/DiagnosticReports.kt• L817-835 mobile/…/DiagnosticReports.swift• L486-513 mobile/…/DiagnosticReports.swift• L634-641
Crash recovery and local reports
Process session recovery
An enabled process writes a small active-session marker. An orderly shutdown retires its own marker. If the next launch finds an active marker from the same grant and the prior process is no longer alive, it creates one bounded unclean-exit event using the old timestamp and identity. The marker and event identity prevent replaying the same crash on every launch. electron/…/diagnostics.ts• L1282-1382 backend/…/diagnostic_reports.py• L762-813
The crash journal and session marker have different jobs. The journal keeps a short local native-crash view for desktop support and UI display. The session marker proves that automatic reporting was enabled for the failed run. A journal row alone cannot upgrade an old or unrelated failure into a newly authorized automatic event. electron/…/crash-journal.ts• L113-197 electron/…/diagnostics.ts• L1304-1355
References: electron/…/diagnostics.ts• L1282-1382 backend/…/diagnostic_reports.py• L762-813 electron/…/crash-journal.ts• L113-207
Diagnostic bundle
The diagnostic bundle is a user-started local report, not automatic intake. It gathers a self-check result, recent error and render summaries, and bounded log tails into a ZIP file. Each text member is scrubbed before it leaves the machine, and a missing or unreadable log becomes a note so the bundle can still be saved. backend/…/diagnostic_bundle.py• L1-20 backend/…/diagnostic_bundle.py• L40-91
The Electron bug-report link is another user-reviewed path. It keeps the report within a URL size limit and places the most useful facts before longer log sections, so truncation loses detail before it loses the report itself. electron/…/bugReportDocument.js• L5-21 electron/…/bugReportDocument.js• L77-105
References: backend/…/diagnostic_bundle.py• L1-20 backend/…/diagnostic_bundle.py• L40-91 electron/…/bugReportDocument.js• L5-21 electron/…/bugReportDocument.js• L77-105
Change checklist
When these files or sections are changed, remember to consider these:
- Keep config/diagnostics.json aligned with every platform projector and every receiver-side event mapping. A new enum or frame path must be accepted consistently.
- Preserve the grant epoch through renderer consent observations, renderer IPC, Electron async ownership, backend executor callbacks, mobile observations, durable records, and recovery callbacks. Do not replace it with a fresh read at callback time.
- Keep backend-managed inbox IDs stable across Electron import, durable acknowledgement, and source-file removal. A change in any one step can create duplicate reports.
- Keep app-intake acknowledgement rules aligned across backend, Electron, Android, and iOS. Partial or rate-limited results must not delete retained records.
- If queue limits or record fields change, update the local storage bound and the network batch bound together. The sender must never create a request larger than the receiver contract.
- Keep crash-session recovery tied to the same consent epoch and evidence time. A startup marker must not replay an old journal row or extend its retention window.
- Keep Electron's status-attempt ownership and process-exit filters aligned with the backend status contract. A setup event must not lose an explicit disabled owner or admit an expected or unknown process exit.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Consent storage cannot be read | New capture and delivery stop while existing evidence waits for a bounded retry | Treat unknown permission as closed, but preserve the unread file and queue |
| User withdraws consent while a send or callback is active | A late result could otherwise publish under the old grant | Invalidate the epoch before asynchronous storage or network work continues |
| A renderer or backend callback has no clear grant owner | A later opt-in could authorize an older failure | Require a matching local observation or bound authority before capture |
| Backend inbox file is read but not removed | The same backend event could be imported again | Retain a completed ID until durable acknowledgement and cleanup both succeed |
| Collector returns an unclear batch response | Evidence could be deleted without proof of acceptance | Require a complete, valid per-event acknowledgement |
| Process exits without normal shutdown | The failure may be invisible after restart | Use the active-session marker and OS or stderr crash evidence to create one bounded recovery event |
| Diagnostic projection throws or sees an unexpected object | Failure reporting could damage the product operation | Catch projection failures and drop the optional report |
| Electron sees an expected or unknown process-exit reason | Normal shutdowns or unsafe free-text labels could create false reports | Accept only the closed reason set and fixed child-process codes |
Key files
| File | Why to read it |
|---|---|
| config/diagnostics.json | Shared event vocabulary, approved frame locations, and queue or delivery limits |
| backend/…/diagnostic_reports.py | Backend capture, async grant ownership, consent, managed inbox handoff, persistence, and delivery lifecycle |
| backend/…/diagnostic_app_transport.py | App-intake event mapping, batch limits, and acknowledgement handling |
| backend/…/crash_diagnostics.py | Backend fatal traceback and silent-exit evidence |
| electron/…/diagnostics.ts | Desktop authority, durable outbox, inbox import, retry behavior, and crash-session recovery |
| electron/…/diagnostics-capture.ts | Main-process failure sources, backend status ownership, process-exit mapping, and expected-exit filtering |
| electron/…/diagnostics-schema.ts | Closed event projection, record validation, frame filtering, and durable size limits |
| electron/…/diagnostic-operation.ts | Async ownership and rejection attribution |
| electron/…/main-error-journal.ts | Local scrubbed evidence for fatal Electron-main failures and detached rejected work |
| electron/…/crash-journal.ts | Local native-crash evidence and bounded journal persistence |
| electron/…/diagnostic-reports.ts | Renderer consent observations, typed error projection, and safe dispatch |
| electron/…/diagnostics.test.ts | Cross-checks for consent races, sanitization, recovery, queue bounds, and delivery failures |
| mobile/…/DiagnosticReports.kt | Android consent, outbox, transport, retry, and app-intake flow |
| mobile/…/AutomaticDiagnostics.kt | Android feature ownership and OS process-exit recovery |
| mobile/…/DiagnosticReports.swift | iOS reporter, actor-owned durable work, retry, and recovery flow |
| mobile/…/AppDiagnostics.swift | iOS app control, feature observations, MetricKit projection, and background recovery |
| backend/…/diagnostic_bundle.py | User-started scrubbed diagnostic bundle |
| electron/…/bugReportDocument.js | User-reviewed GitHub report composition and size limits |