Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

log lastAliveAt and suspendedAt on crash-detection.boot (PRD-8234) (#3771)

Andrew Mikofalvy3f17f67efc7d
diff --git a/.changeset/crash-boot-liveness-timestamps.md b/.changeset/crash-boot-liveness-timestamps.md
new file mode 100644
index 000000000..1515a4640
--- /dev/null
+++ b/.changeset/crash-boot-liveness-timestamps.md
@@ -0,0 +1,7 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Crash reports from the desktop app now record when the previous session was last known alive, and whether the machine ended it. When the app finds that a session ended without shutting down cleanly it offers to send a report, and until now that report said a crash had happened but never said when. The app already refreshes a liveness timestamp about once a minute while it runs, which dates the death to within roughly a minute, but that timestamp only ever reached the log on the path where the prompt is suppressed and no report is produced. Without it the only bound on when a session died was the gap between its last log line and the next launch, which routinely runs to hours, so readings as different as "it died hours ago and the relaunch was late" and "it stayed hung until the moment it relaunched" were equally consistent with the report, while pointing at completely different problems.
+
+Reports now also carry the two markers that say the machine ended the session rather than the app failing: whether it was asleep, and whether the operating system was shutting down. When a session leaves a crash dump behind, the separate log line that would otherwise have recorded those is never written, so the report is the only record, and their absence used to be indistinguishable from an ordinary crash. All of these are written as explicitly empty when a session's file predates them, so "we could not tell" stays distinguishable from a value that went missing. Nothing new is collected about you or your documents: all three are timestamps the app already kept for its own restart handling.
diff --git a/packages/desktop/src/main/crash-detection.test.ts b/packages/desktop/src/main/crash-detection.test.ts
index 1276bb4c2..f6271c5cd 100644
--- a/packages/desktop/src/main/crash-detection.test.ts
+++ b/packages/desktop/src/main/crash-detection.test.ts
@@ -1625,6 +1625,145 @@ describe('the version a boot invitation attributes the crash to', () => {
});
});
+/**
+ * When the dead session was last known alive, and whether the machine ended it
+ * rather than the app failing — asleep, or mid-shutdown. The arming breadcrumb
+ * is what a dirty-shutdown report gets reconstructed from, and on the path
+ * where a fresh dump routes a machine-level death here it is the only record.
+ * So a crash it cannot date leaves the death anywhere in the gap between the
+ * session's last log line and the next launch, and one whose machine-level
+ * cause it cannot name reads as an ordinary crash.
+ */
+describe('when a boot invitation says the dead session stopped', () => {
+ test('the boot breadcrumb dates the dead session to its last heartbeat', () => {
+ // Without this the line names a crash but never says when it happened, so
+ // the window the session could have died in is the whole gap between its
+ // last log line and this launch. The heartbeat refreshes the value every
+ // SENTINEL_HEARTBEAT_INTERVAL_MS, which narrows that window to a minute —
+ // and the readings it separates ("died early, the relaunch was late" vs
+ // "hung until the relaunch") point at completely different bugs.
+ const rig = makeRig();
+ const dying = createCrashDetection(rig.deps);
+ dying.detectBootCrash();
+ rig.advance(5 * 60_000);
+ dying.noteAlive();
+ const lastAliveAt = readSentinel(rig).lastAliveAt;
+ expect(lastAliveAt).toBeDefined();
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb?.lastAliveAt).toBe(lastAliveAt);
+ expect(breadcrumb?.suspendedAt).toBeNull();
+ expect(breadcrumb?.pendingOsShutdownAt).toBeNull();
+ });
+
+ test('a sentinel written before the liveness fields existed logs them as null', () => {
+ // Logged even when null, for the same reason the version beside them is:
+ // "we could not tell" is itself the finding, and an old-format sentinel and
+ // a torn write otherwise reach the report identically. A field that
+ // vanished here would be indistinguishable from a build predating the line.
+ const rig = makeRig();
+ mkdirSync(dirname(rig.deps.sentinelPath), { recursive: true });
+ writeFileSync(
+ rig.deps.sentinelPath,
+ `${JSON.stringify({ bootId: '1784494925550', startedAt: '2026-07-09T21:02:05.550Z' })}\n`,
+ );
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ createCrashDetection(rig.deps).detectBootCrash();
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb).toHaveProperty('lastAliveAt');
+ expect(breadcrumb).toHaveProperty('suspendedAt');
+ expect(breadcrumb).toHaveProperty('pendingOsShutdownAt');
+ expect(breadcrumb?.lastAliveAt).toBeNull();
+ expect(breadcrumb?.suspendedAt).toBeNull();
+ expect(breadcrumb?.pendingOsShutdownAt).toBeNull();
+ });
+
+ test('a dump-driven arming after a death asleep carries the suspend marker', () => {
+ // The one path a non-null suspend marker reaches this line: a fresh dump
+ // overrides the died-asleep suppression, so the session is reported as the
+ // process dying rather than the machine ending it. The marker is then the
+ // only thing telling a reader the crash happened with the lid shut, which
+ // is the difference between a renderer fault and a power-loss artifact.
+ const rig = makeRig();
+ const dying = createCrashDetection(rig.deps);
+ dying.detectBootCrash();
+ dying.noteSuspend();
+ const { lastAliveAt, suspendedAt } = readSentinel(rig);
+ expect(suspendedAt).toBeDefined();
+ expect(lastAliveAt).toBeDefined();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick());
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ // Pin the routing the premise above depends on. Both branches forward
+ // these two fields identically, so a refactor that dropped the suspend
+ // marker from `machineLevelDeath` would fall through to the ordinary
+ // dirty-shutdown branch and nothing here would notice.
+ expect(armed.eventId).toMatch(/^boot:dump:/);
+ expect(armed.context.dirtyShutdown).toBe(false);
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb?.suspendedAt).toBe(suspendedAt);
+ expect(breadcrumb?.lastAliveAt).toBe(lastAliveAt);
+ expect(breadcrumb?.pendingOsShutdownAt).toBeNull();
+ });
+
+ test('a dump-driven arming after an announced OS shutdown carries that marker', () => {
+ // The third witness the suppression predicate is built from, and it reaches
+ // this line under the same dump override as the suspend marker. Without it
+ // a reader seeing no suspend marker cannot separate an ordinary crash from
+ // one the OS killed mid-quit, because on this path the suppression
+ // breadcrumb that would have said so is never emitted at all.
+ const rig = makeRig();
+ const dying = createCrashDetection(rig.deps);
+ dying.detectBootCrash();
+ dying.noteOsShutdown();
+ const pendingOsShutdownAt = readSentinel(rig).pendingOsShutdownAt;
+ expect(pendingOsShutdownAt).toBeDefined();
+ seedMinidump(rig, 'pending/native.dmp', rig.tick());
+
+ const infoLines: Array<Record<string, unknown>> = [];
+ rig.deps.logger = {
+ info: (payload: Record<string, unknown>) => {
+ infoLines.push(payload);
+ },
+ warn: () => {},
+ };
+ const armed = bootInvite(createCrashDetection(rig.deps).detectBootCrash());
+
+ expect(armed.eventId).toMatch(/^boot:dump:/);
+ expect(armed.context.dirtyShutdown).toBe(false);
+
+ const breadcrumb = infoLines.find((line) => line.event === 'crash-detection.boot');
+ expect(breadcrumb?.pendingOsShutdownAt).toBe(pendingOsShutdownAt);
+ expect(breadcrumb?.suspendedAt).toBeNull();
+ });
+});
+
/**
* Dumps that were captured without a fault.
*
diff --git a/packages/desktop/src/main/crash-detection.ts b/packages/desktop/src/main/crash-detection.ts
index 4f99ab256..dea6ee6f2 100644
--- a/packages/desktop/src/main/crash-detection.ts
+++ b/packages/desktop/src/main/crash-detection.ts
@@ -855,6 +855,26 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
detectedAt: detectedAt.toISOString(),
dirtyShutdown: !dumpDriven,
newMinidumps: newDumps.length,
+ // When the dead session was last known alive, and whether it
+ // was asleep at the time. The heartbeat refreshes `lastAliveAt`
+ // every `SENTINEL_HEARTBEAT_INTERVAL_MS`, so it dates the death
+ // to within a minute; without it the only bound is the gap
+ // between the session's last log line and this launch, which
+ // runs to hours, leaving "died early, the relaunch was late"
+ // and "hung until the relaunch" equally consistent with the
+ // report while pointing at different bugs.
+ //
+ // The suspend and OS-shutdown markers are the other two
+ // witnesses the suppression predicate is built from, and a
+ // fresh dump routes their sessions here instead, where that
+ // breadcrumb is never emitted. Carrying only some of them
+ // would let their absence read as "no machine-level death"
+ // when it only means "not the one we happened to log". All
+ // three are logged even when null, for the same reason the
+ // version below is.
+ lastAliveAt: prevLastAliveAt,
+ suspendedAt: prevSuspendedAt,
+ pendingOsShutdownAt: prevPendingOsShutdownAt,
// Logged even when null: this line is what an incident gets
// reconstructed from, and "we could not tell" is itself the
// finding when the two sources both come up empty.