Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ If the browser-backed checks fail in CI or a container, install Chromium during

The error message says `ghostty-web crashed while it replayed this session's output.` The Chromium page of the `ghostty-web` renderer died while it replayed the event log. `screenshot` (also with `--renderer libghostty-vt`, because its screenshot replays the log in a `ghostty-web` page) and `snapshot --renderer ghostty-web` fail with `REPLAY_ERROR` (exit `10`, `retryable: false`), on a live session and on an exited one. `record export --format webm` fails with `EXPORT_ERROR` (exit `7`). The message ends with the Playwright text, `(page.evaluate: Target crashed)`.

One known cause is a bug in ghostty-web 0.4.0. After a full reset (`ESC c`), `CSI ? 47 h` and `CSI ? 1047 h` show the old cells on the alternate screen. Output over a cell that holds a combining mark or another grapheme cluster then crashes the page. The shortest input has 12 bytes: `a`, U+0301, `ESC c`, `ESC [ ? 4 7 h` and `o`. `CSI ? 1049 h` is not affected.
The crash is a bug in the WASM module of ghostty-web 0.4.0. Several different inputs trigger it. Some need no reset, no resize and no alternate screen: a plain print of many lines that hold combining marks also crashes the page.

Running the command again does not help, because each run replays the same log and the page crashes again. The session itself keeps running, and the host stays up. A render `wait` with `--renderer ghostty-web` stops with the same error after 10 failed polls. These commands do not use the page, so they still work on such a session:
One known cause is [coder/ghostty-web#215](https://github.com/coder/ghostty-web/issues/215). After a full reset (`ESC c`), `CSI ? 47 h` and `CSI ? 1047 h` show the old cells on the alternate screen. Output over a cell that holds a combining mark or another grapheme cluster then crashes the page. The shortest input has 12 bytes: `a`, U+0301, `ESC c`, `ESC [ ? 4 7 h` and `o`. `CSI ? 1049 h` is not affected.

Running the command again does not help, because each run replays the same log and the page crashes again. The session itself keeps running, and the host stays up. A render `wait` with `--renderer ghostty-web` stops at the first crash with the same error. These commands do not use the page, so they still work on such a session:

- `snapshot` and `wait` with the `libghostty-vt` renderer, which is the default when its native package is available
- `record export --format svg` and `record export --format asciicast`
Expand Down
4 changes: 2 additions & 2 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ On timeout, a standalone `wait` exits `11` and prints an error envelope: `ok: fa

A render wait reads the session's event log. When that log has stopped at its limit (see [the event log limit](TROUBLESHOOTING.md#a-recording-ends-early-or-an-export-names-the-event-log-limit)), a timed-out render wait adds `The event log stopped at seq 41 (byte limit), so output after it is not seen.` to its message, with and without `--json`, and `error.details.eventLogStop` holds `{ "reason": "bytes", "seq": 41 }`. The host reports the stop with its timeout result, so a wait that times out at the moment the log stops names it too. A `batch` `wait` step adds the same sentence to its message. On an exited session, `wait` replays the stored log, and a wait that the replayed screen does not satisfy fails with `REPLAY_ERROR`. Its message ends with the same sentence, and `error.details.eventLogStop` carries the same facts. `reason` is `unknown` when the stop marker names no limit, and the sentence then reads `(reason unknown)`. `--idle-ms` and `--exit` waits do not read the log, so they add nothing. A wait that matches is not changed.

`WAIT_TIMEOUT` only means that the timeout ran out. When 10 render polls in a row fail (about 3 s, for example because the renderer cannot start), a render `wait` stops with the renderer's error instead, also with `--timeout 0`: the same `error.code` and exit code that `snapshot` gives for that failure, usually `RPC_ERROR` (exit `9`, `retryable: true`), and no `result`. A `batch` `wait` step fails with that code, and its step record has no `timedOut`. Fewer failed polls in a row are retried.
`WAIT_TIMEOUT` only means that the timeout ran out. When 10 render polls in a row fail (about 3 s, for example because the renderer cannot start), a render `wait` stops with the renderer's error instead, also with `--timeout 0`: the same `error.code` and exit code that `snapshot` gives for that failure, usually `RPC_ERROR` (exit `9`, `retryable: true`), and no `result`. A `batch` `wait` step fails with that code, and its step record has no `timedOut`. Fewer failed polls in a row are retried. The one failure that is not retried is a crash of the `ghostty-web` page: the `wait` stops at the first crash with `REPLAY_ERROR` (exit `10`, `retryable: false`), as `snapshot` does.

### Echo-Match

Expand Down Expand Up @@ -259,7 +259,7 @@ The Wait Baseline fixes stale-match only. It does **not** fix echo-match: a whol

## Screenshots And Recording Exports

Screenshots and WebM export use the `ghostty-web` reference visual renderer through Playwright/Chromium. When its page crashes during a replay, the error message says `ghostty-web crashed` and names a known cause (see [Troubleshooting](TROUBLESHOOTING.md#a-command-says-ghostty-web-crashed)).
Screenshots and WebM export use the `ghostty-web` reference visual renderer through Playwright/Chromium. When its page crashes during a replay, the error message says `ghostty-web crashed`, says that several inputs do this and names one known cause (see [Troubleshooting](TROUBLESHOOTING.md#a-command-says-ghostty-web-crashed)).
Semantic `snapshot`, screen-hash, and render-backed `wait` paths prefer `libghostty-vt` when the optional native package is available and fall back to `ghostty-web` otherwise. Run `doctor --json` first in new environments.

On a session that has printed nothing yet, `snapshot` returns an empty screen of the session's size and `screenshot` returns a blank image. `record export` gives a header-only asciicast, a blank WebM or a blank SVG of the session's size, with `durationMs: 0`. An animated SVG of such a session reports `durationMs: 1000`, the hold of its one blank frame. All of them report `capturedAtSeq: -1`, and the default files are named `screenshot--1-<profile>.png`, `recording--1-<format>.<ext>` and `recording--1-svg-<profile>[-animated].svg`.
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This directory holds one handler module per agent-tty CLI command. `src/cli/main
- `wait` rejects a mix of legacy flags (`--exit`, `--idle-ms`) and render flags. `--text` and `--regex` are mutually exclusive. The default timeout is `DEFAULT_WAIT_TIMEOUT_MS` (30,000 ms), which the `main.ts` help text names. An `--idle-ms` at or above the effective timeout (explicit or default), or a `--screen-stable-ms` whose `screenStableMinimumMs` is not shorter than it, throws `INVALID_DURATION`. `--timeout 0` skips the check. [wait.ts:runWaitCommand] [wait.ts:assertWindowFitsTimeout] [main.ts:main]
- A timed-out `wait` throws `WAIT_TIMEOUT` with the wait result attached, so its error envelope keeps `result`. Without `--json`, and only when the wait lasted its whole timeout (`timeoutMs > 0`, measured by the CLI), the message names the timeout and, for the default, how to change it. With `--json`, the message stays `Wait timed out before its condition was met.` The host sends `eventLogStop` with the result of a render wait that timed out. When it does, in both modes the message ends with `The event log stopped at seq <n> (<byte limit|event limit|reason unknown>), so output after it is not seen.` and `details.eventLogStop` carries `{ reason, seq }`. The CLI never rereads the event log for a wait. `--idle-ms` and `--exit` waits carry no stop. When the host is unreachable, `wait` replays the stored log. A wait that the replayed screen does not satisfy fails with `REPLAY_ERROR`, and its message and `details.eventLogStop` carry the stop that `findEventLogStop` finds in the replayed events. [wait.ts:throwIfTimedOut] [wait.ts:timeoutMessage] [wait.ts:buildOfflineRenderWaitResult]
- `snapshot` and `screenshot` try the live RPC only when the manifest status is `running`. They fall back to offline replay only on `HOST_UNREACHABLE` and rethrow other errors. [snapshot.ts:runSnapshotCommand] [screenshot.ts:runScreenshotCommand]
- `record export` accepts only the formats in `RecordExportFormatSchema` (`asciicast`, `webm`, `svg`). `--animate` needs `svg`, and `svg` refuses `--timing`. An event log over the size limit fails with `EXPORT_ERROR` in every format, a message that names the log size and the limit, and `eventLogBytes` and `maxEventLogBytes` in `details`. A `webm` replay whose renderer makes no progress for the stall window fails with `EXPORT_ERROR`, a message that names the window and the last event that the replay reached, and `stallWindowMs`, `lastSeq` and `timingMode` in `details`. A `GhosttyWebCrashedError` from a WebM export fails with `EXPORT_ERROR` and adds its message to the fixed message. [record-export.ts:runRecordExportCommand]
- `record export` accepts only the formats in `RecordExportFormatSchema` (`asciicast`, `webm`, `svg`). `--animate` needs `svg`, and `svg` refuses `--timing`. An event log over the size limit fails with `EXPORT_ERROR` in every format, a message that names the log size and the limit, and `eventLogBytes` and `maxEventLogBytes` in `details`. A `webm` replay whose renderer makes no progress for the stall window fails with `EXPORT_ERROR`, a message that names the window and the last event that the replay reached, and `stallWindowMs`, `lastSeq` and `timingMode` in `details`. Any other failure of an export fails with `EXPORT_ERROR` and a message that ends with the cause, cut to its first line and at most 300 characters (`summarizeError`). A `GhosttyWebCrashedError` from a WebM export fails with `EXPORT_ERROR` and adds its message to the fixed message. [record-export.ts:runRecordExportCommand]
- `batch` parses the whole plan with `parseBatchPlan` before it resolves the session target. [batch.ts:runBatchCommand]
- `create` polls readiness with an `inspect` RPC every `READINESS_POLL_INTERVAL_MS` (100 ms) for as long as the host process that it spawned runs (`hostRuns`). A probe that fails with `HOST_UNREACHABLE`, `HOST_TIMEOUT` or an `RPC_ERROR` whose cause is `EPIPE` (the host closed its server as the probe connected, as a host does whose program has already exited) counts as not ready yet (`isClosedByHost`). `create` rethrows that last error as soon as the host process has exited, and after `READINESS_DEADLINE_MS` (30 s) in any case. Any other error ends the wait at once. It checks the host process before it reads the manifest, so a session that exited before the host did is a result, not an error. [create.ts:waitForReadyHost]
- `doctor` reports the `node-runtime` check as failed when the Node version is outside the `engines.node` range of `package.json`. It keeps running the other checks, reports `ok: false` and sets `process.exitCode = 1`. [doctor.ts:runNodeRuntimeCheck] [doctor.ts:runDoctorCommand]
Expand Down
9 changes: 6 additions & 3 deletions src/cli/commands/record-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
} from '../../storage/outputPath.js';
import { eventLogPath, manifestPath } from '../../storage/sessionPaths.js';
import { invariant } from '../../util/assert.js';
import { summarizeError } from '../../util/errorSummary.js';
import { loadPackageMetadata } from '../../util/packageMetadata.js';

const RecordExportFormatSchema = z.enum(['asciicast', 'webm', 'svg']);
Expand Down Expand Up @@ -617,10 +618,12 @@ export async function runRecordExportCommand(
});
}

const reason =
error instanceof GhosttyWebCrashedError
? `. ${error.message}`
: `: ${summarizeError(error)}`;
throw makeCliError(ERROR_CODES.EXPORT_ERROR, {
message: `Failed to export session "${options.sessionId}" as ${format}.${
error instanceof GhosttyWebCrashedError ? ` ${error.message}` : ''
}`,
message: `Failed to export session "${options.sessionId}" as ${format}${reason}`,
details: {
sessionId: options.sessionId,
format,
Expand Down
2 changes: 1 addition & 1 deletion src/host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- `normalizeExitSignal(signal)` maps a PTY exit signal number to a string, or `null` for `null` and 0. [hostMain.ts:normalizeExitSignal]
- `isSessionCommandable(state)` and `assertSessionCommandable(state)` check that the session status is commandable. The assert throws `SESSION_NOT_RUNNING`. [hostMain.ts:isSessionCommandable] [hostMain.ts:assertSessionCommandable]
- `resolveHostRendererName(input?)` picks the renderer name from the input, then `AGENT_TTY_HOST_RENDERER`, then `AGENT_TTY_RENDERER`, then `DEFAULT_RENDERER_NAME` (from `src/renderer/names.ts`). It throws `INVALID_INPUT` for an unknown renderer name. [hostMain.ts:resolveHostRendererName]
- `MAX_CONSECUTIVE_POLL_FAILURES` (10) is the number of failed polls in a row after which a `waitForRender` wait rejects with the last poll error. A `CliError` keeps its code. The RPC server sends any other error as an RPC error, which the CLI reports as `RPC_ERROR`. [hostMain.ts:MAX_CONSECUTIVE_POLL_FAILURES]
- `MAX_CONSECUTIVE_POLL_FAILURES` (10) is the number of failed polls in a row after which a `waitForRender` wait rejects with the last poll error. Every failure of a poll counts, for example a browser that does not launch, because the next poll can pass. The one exception is the error of a crashed ghostty-web page (`isReplayCrashError`): the next poll replays the same output into a new page and crashes it again, so the wait rejects with that error at the first poll, with code `REPLAY_ERROR`, as a live `snapshot` does. [renderer.ts:isReplayCrashError] A `CliError` keeps its code. The RPC server sends any other error as an RPC error, which the CLI reports as `RPC_ERROR`. [hostMain.ts:MAX_CONSECUTIVE_POLL_FAILURES]
- `allocateSession(config, launch)` validates an `AllocateConfig`, creates the session directory, calls `launch(sessionId)`, writes `host.json` for the launched host when `captureHost` can read it, and writes the first `running` manifest with the returned PID as `hostPid`. It returns an `AllocateResult` with `sessionId` and `sessionDirectory`. [lifecycle.ts:allocateSession] [lifecycle.ts:AllocateConfig] [lifecycle.ts:AllocateResult]
- `launchHost(config)` spawns the host process for a `LaunchHostConfig` and returns a `LaunchedHost`: its PID and a `stop()` that sends the host SIGTERM through the `ChildProcess` handle, and nothing once the host has exited. `create` calls it from the `launch` callback of `allocateSession`, and calls `stop()` on any error after `allocateSession` returned, such as a give-up on the host. [lifecycle.ts:launchHost] [lifecycle.ts:LaunchHostConfig] [lifecycle.ts:LaunchedHost] [src/cli/commands/create.ts:runCreateCommand]
- `removeSocketDirectoryIfEmpty(socketFile)` removes the Home's socket directory with `rmdir`. A directory that still holds a socket (`ENOTEMPTY` or `EEXIST`) or is already gone (`ENOENT`) stays as it is. `destroySession` and `reconcileSession` call it after they unlink a socket. The host's shutdown and `doctor`'s socket check call `removeSocketDirectoryBestEffort`, which logs any other `rmdir` error at debug level instead of throwing it. [lifecycle.ts:removeSocketDirectoryIfEmpty] [lifecycle.ts:removeSocketDirectoryBestEffort]
Expand Down
11 changes: 9 additions & 2 deletions src/host/hostMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
writeProgramRecord,
} from './programGroup.js';
import { buildReplayInput } from './replay.js';
import { HostRendererManager } from './renderer.js';
import { HostRendererManager, isReplayCrashError } from './renderer.js';
import { RpcServer, type MethodHandler } from './rpcServer.js';
import {
RunCompletionCoordinator,
Expand Down Expand Up @@ -1173,7 +1173,14 @@ export async function runHost(
}

consecutiveFailures += 1;
if (consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES) {
// Another poll replays the same output into a new page, so a
// crash of the ghostty-web page ends the wait at once. Any other
// failure can pass (a browser that fails to launch under load),
// so those get MAX_CONSECUTIVE_POLL_FAILURES polls in a row.
if (
isReplayCrashError(pollError) ||
consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES
Comment on lines +1181 to +1182

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve retries for unclassified Chromium crashes

When Chromium reports Target crashed because of a transient page/process failure such as resource pressure, describeReplayFailure classifies it as GhosttyWebCrashedError even though it cannot establish that the session output hit the deterministic WASM bug. The backend's crash handler marks it unbooted, so a later poll can recreate the page and recover, but this new branch now aborts on the first failure as a non-retryable REPLAY_ERROR; retain the existing retry allowance unless the failure can actually be tied to a deterministic input fault.

Useful? React with 👍 / 👎.

) {
reject(
pollError instanceof Error
? pollError
Expand Down
12 changes: 12 additions & 0 deletions src/host/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mkdirSync } from 'node:fs';
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';

import { CliError } from '../cli/errors.js';
import { ERROR_CODES, makeCliError } from '../protocol/errors.js';
import type { RendererBackend } from '../renderer/backend.js';
import type { RendererName } from '../renderer/names.js';
Expand Down Expand Up @@ -43,6 +44,17 @@ function rethrowCrashAsReplayError(error: unknown): never {
throw error;
}

// True for the error that `withBackend` throws when a ghostty-web page
// crashed. The same output crashes the page again on every later call, so a
// caller that retries a failed call must not retry this one.
export function isReplayCrashError(error: unknown): boolean {
return (
error instanceof CliError &&
error.code === ERROR_CODES.REPLAY_ERROR &&
error.cause instanceof GhosttyWebCrashedError
);
}

function assertAbsolutePath(pathValue: string, label: string): void {
assertNonEmptyString(pathValue, label);
invariant(isAbsolute(pathValue), `${label} must be an absolute path`);
Expand Down
Loading
Loading