Upload pending crash reports as opt-in telemetry

A crash report is worth nothing sitting on the player's disk. On startup, drain
the crash_report_*.txt files the handler left behind to the endpoint named by
CRASH_TELEMETRY_URL in Ja2 Settings; an empty or absent key turns the feature off
entirely. The first launch asks the player once and remembers the answer in
telemetry.consent -- declined means the reports simply keep accumulating locally.

This lands in its own translation unit rather than in more of debug_win_util.cpp.
Everything in that file runs inside a faulting thread and may not allocate;
everything here runs at startup with a healthy heap and is ordinary code. Two
files keep the no-heap rule easy to see and easy to hold.

The draining runs on a detached thread. The uploads are synchronous WinHttp calls
with seconds-long timeouts, and this sits on the startup path, so on the main
thread an unreachable endpoint is a stall the player watches before the splash
screen. Nothing waits on the result: if the player quits first the process exits
from under the thread, which costs nothing, since an interrupted upload leaves the
file on disk and it goes out next launch. The consent prompt stays on the main
thread on purpose -- it is a question, and a question has to be asked before
anything is sent.

Which reports get deleted is chosen so that a mistake cannot destroy them. A file
goes away on 2xx, and on 400/413/415, i.e. content the server will never accept.
Everything else keeps it: no connection, 5xx, and notably the 403/404 of a
mistyped CRASH_TELEMETRY_URL, which would otherwise silently eat every player's
crash history. Bounds all round: every WinHttp phase has a timeout, a report over
256 KB is not one of ours and never goes on the wire, at most 20 uploads per
launch so a crash-looping build cannot turn startup into an upload session, and
reports older than 30 days are dropped unsent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-28 10:25:47 -03:00
committed by majcosta
co-authored by Claude Opus 5
parent 71cc553a07
commit f5782dccbd
5 changed files with 187 additions and 0 deletions
+6
View File
@@ -69,6 +69,12 @@ namespace sgp
// stamp into crash reports, so a report can be tied to whoever raises it with
// us on Discord. Empty or unset simply omits the field. Call once at startup.
void setCrashUserHandle(const wchar_t* handle);
// Startup crash-telemetry pass (heap is healthy here — never call from a
// crash handler). If url is empty the feature is off. On first run, asks the
// player for consent (native dialog) and remembers it; if granted, POSTs each
// pending crash_report_*.txt to url and deletes the ones that upload cleanly.
void processCrashTelemetry(const wchar_t* url);
}
#endif // BASE_DEBUG_UTIL_H_