codeburn/app/renderer/components/CliErrorPanel.tsx
iamtoruk d4b7b48dc8 fix(app): no-output watchdog replaces fixed timeouts; graceful kills; cold floor everywhere; orphan serve reaping
The desktop app capped every read at 45s of TOTAL runtime, so a slow machine's
warm `optimize` (52.5s on 0.9.20, 39.6s on main) was SIGKILLed mid-parse and the
panel painted a red "timed out" that a 60s poll then reproduced forever.

- cli.ts: the read timeout is now a no-output watchdog. The window restarts on
  every byte the child writes (serve: every frame carrying that request's id),
  so only a genuinely silent child times out. A 15-minute absolute ceiling still
  reaps a livelocked child. Every read spawn sets CODEBURN_PROGRESS=1 so a long
  parse heartbeats through it; progress lines are stripped from any surfaced
  stderr so they can never become the error message.
- cli.ts: a timed-out child gets SIGTERM first and SIGKILL only after a 5s
  grace, on both the spawn and the serve branch. That lets the CLI's signal
  cleanup publish its partial parse and release the cross-process refresh lock
  instead of leaving both stale.
- main.ts: the 10-minute cold floor now covers EVERY read while the first
  hydration is still running, not just the overview. Sections start polling the
  moment `ready` flips (which an overview error also does), and a 45s section
  spawn queued behind the cold parse was killed on arrival.
- main.ts/renderer: a timeout raised while the hydration is still running is
  flagged `cold`, and the renderer keeps its indexing splash (and keeps the
  sections gated) instead of latching ready and painting CliErrorPanel. Only
  timeouts are flagged; a permission or nonzero failure still surfaces.
- cli.ts/main.ts: the resident serve child's pid is recorded under userData and
  a serve orphaned by a previous crash is reaped at launch, after `ps` confirms
  the pid still belongs to a codeburn serve.
- src/main.ts: `codeburn serve` exits explicitly once its stdin closes, so a
  handle outliving the transport cannot keep the child alive as an orphan.
2026-08-22 09:22:38 -07:00

72 lines
2.5 KiB
TypeScript

import { Panel } from './Panel'
import type { CliError } from '../lib/types'
export function isPermissionCliError(error: CliError | null): boolean {
return error?.kind === 'nonzero' && /permission|full disk access|eacces/i.test(error.message)
}
/** A failure the main process attributed to a still-running cold hydration. The
* data is coming, so nothing here is broken — never paint it red. */
export function isColdHydrating(error: CliError | null): boolean {
return error?.cold === true
}
export function cliErrorDisplay(error: CliError): { title: string; message: string; tone: 'amber' | 'red' | 'muted' } {
if (isColdHydrating(error)) {
return {
title: 'Still indexing',
message: 'Reading your usage history for the first time. This can take a few minutes.',
tone: 'muted',
}
}
if (error.kind === 'not-found') {
return {
title: 'Locate the codeburn CLI',
message: 'Install it with npm i -g codeburn, then reopen this window.',
tone: 'muted',
}
}
if (isPermissionCliError(error)) {
return {
title: 'Permission denied',
message: 'permission denied; grant Full Disk Access',
tone: 'amber',
}
}
return { title: "Couldn't read data", message: error.message, tone: 'red' }
}
function colorForTone(tone: 'amber' | 'red' | 'muted'): string {
if (tone === 'amber') return 'var(--warn)'
if (tone === 'red') return 'var(--bad)'
return 'var(--mut2)'
}
export function CliErrorText({ error }: { error: CliError }) {
const display = cliErrorDisplay(error)
return <p style={{ color: colorForTone(display.tone), margin: 0, fontSize: 12 }}>{display.message}</p>
}
export function CliErrorPanel({ error, subject = 'usage' }: { error: CliError; subject?: string }) {
const display = cliErrorDisplay(error)
if (error.kind === 'not-found') {
return (
<Panel title={display.title}>
<p style={{ color: 'var(--mut)', margin: '0 0 6px', fontSize: 12.5 }}>
CodeBurn Desktop reads {subject} by running the{' '}
<code style={{ fontFamily: 'var(--mono)', color: 'var(--accent)' }}>codeburn</code> command, but it isn&apos;t
on your PATH yet.
</p>
<p style={{ color: colorForTone(display.tone), margin: 0, fontSize: 11.5 }}>
Install it with <code style={{ fontFamily: 'var(--mono)', color: 'var(--accent)' }}>npm i -g codeburn</code>,
then reopen this window.
</p>
</Panel>
)
}
return (
<Panel title={display.title}>
<CliErrorText error={error} />
</Panel>
)
}