Skip to content

Crash handler — restore terminal, flush session, offer resume #30

Description

@aakashrajput

Why

A fatal error mid-session currently loses the terminal state and can lose the last bits of session progress. Sessions are precious — crashes should degrade gracefully.

What

Process-level crash handler:

  • process.on("uncaughtException") + unhandledRejection: restore the terminal (leave alt-screen, show cursor, disable mouse), flush the current session JSONL to disk, print a short message with the session id and a klaatai chat --resume <id> hint, exit non-zero
  • Detect startup crash loops: if the last run crashed during boot (marker file), start with a safe-mode hint (skip plugins/MCP) instead of crashing identically again

Where to start

  • src/engine/app.ts / src/engine/terminal.ts — terminal teardown helpers already exist
  • Session persistence: session-save path in src/screens/repl.ts
  • Marker file under ~/.klaatai/

Acceptance criteria

  • Simulated throw inside a running REPL restores the terminal and prints the resume hint
  • Session file is intact and resumable afterwards
  • typecheck + tests green

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions