Skip to content

Commit 5a77759

Browse files
committed
experiment: trace fatal main-process errors (do not merge)
1 parent e08ee97 commit 5a77759

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎.github/workflows/desktop-e2e.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163

164164
- name: Run Playwright _electron smoke suite
165165
working-directory: apps/desktop
166-
run: bun run ../../scripts/desktop-e2e.ts ${{ matrix.shard }}/${{ strategy.job-total }}
166+
run: bunx playwright test e2e/terminal-cancel.spec.ts --grep "the launch after|survives a quit" --repeat-each=15 --reporter=line,json
167167
env:
168168
PLAYWRIGHT_JSON_OUTPUT_FILE: test-results/desktop-smoke.json
169169

@@ -175,6 +175,15 @@ jobs:
175175
path: apps/desktop/test-results
176176
retention-days: 7
177177

178+
- name: Upload fatal trace
179+
if: always()
180+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
181+
with:
182+
name: fatal-trace-${{ matrix.shard }}
183+
path: /tmp/sim-fatal-trace.log
184+
if-no-files-found: ignore
185+
retention-days: 7
186+
178187
- name: Upload smoke coverage and timings
179188
if: always()
180189
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2

‎apps/desktop/src/main/observability.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export interface MainProcessFailureObserverDeps {
7474

7575
const FAILURE_DEDUPE_MS = 5_000
7676

77+
function experimentTrace(line: string): void {
78+
const entry = `[fatal-trace pid=${process.pid} ${new Date().toISOString()}] ${line}\n`
79+
process.stdout.write(entry)
80+
try {
81+
appendFileSync('/tmp/sim-fatal-trace.log', entry)
82+
} catch {}
83+
}
84+
7785
/**
7886
* Records native child-process failures and gives a fatal main-process error a
7987
* single native recovery surface. Error text is deliberately excluded from
@@ -120,6 +128,11 @@ export function installMainProcessFailureObservers({
120128
name: 'main_unhandled_rejection' | 'main_uncaught_exception',
121129
value: unknown
122130
): void => {
131+
experimentTrace(
132+
`fatal ${name} quitStarted=${quitStarted} open=${fatalRecoveryOpen}\n${
133+
value instanceof Error ? `${value.name}: ${value.message}\n${value.stack}` : String(value)
134+
}`
135+
)
123136
if (fatalRecoveryOpen) return
124137
fatalRecoveryOpen = true
125138
events.record(name, { valueType: value instanceof Error ? 'Error' : typeof value })
@@ -165,6 +178,11 @@ export function installMainProcessFailureObservers({
165178
app.on('child-process-gone', onChildProcessGone)
166179
app.on('before-quit', onQuitStarted)
167180
app.on('will-quit', onQuitStarted)
181+
app.on('before-quit', () => experimentTrace('before-quit'))
182+
app.on('will-quit', () => experimentTrace('will-quit'))
183+
app.on('quit', () => experimentTrace('quit'))
184+
process.on('exit', () => experimentTrace('process exit'))
185+
experimentTrace('observers installed')
168186
processSource.on('unhandledRejection', onUnhandledRejection)
169187
processSource.on('uncaughtException', onUncaughtException)
170188
}

0 commit comments

Comments
 (0)