Elyra
Elyra The coding agent eTerm The terminal that knows where each command ends Huskarl AI colleagues on your own Mac Starf An activity monitor for Apple silicon that never invents a number etrans An SSH and SFTP client for macOS Elyra VM Virtual machines for macOS, Linux and Windows on your Mac Litr A small, native web browser for macOS Notr A notebook for macOS e The native code editor Elyra Grove Native local development environment Askr The real server for Laravel & PHP Elyra Framework Rust + Svelte 5 framework for desktop apps Elyra Conductor Local project conductor Refr Local-first PDF workspace for macOS Elyra Workspace A desktop workspace for coding agents eDock A container runtime for the Mac Elyra SQL Server MySQL-compatible SQL server in Rust Elyra Félagi Agents as teammates on one board Elyra SQL Client Native desktop SQL workbench Elyra SQL Anywhere Replication-ready SQL engine Elyra Sjá SEO & GEO workspace for macOS Elyra DataGrid Server-driven data grid for Laravel
Reference
Ratatosk CLI
Roadmap
RFC 0001: make:resource
RFC 0002: live queries
RFC 0003: MCP server
RFC 0004: MCP resource templates
RFC 0005: a Laravel backend
RFC 0006: Laravel broadcasting
RFC 0007: offline and sync
RFC 0008: Laravel notifications
RFC 0009: Files
RFC 0010: Laravel abilities
RFC 0011: an assistant in the app
RFC 0012: @elyra/ui
RFC 0013: the assistant sees the window
RFC 0014: Elyra Inspector
RFC 0015: presence
RFC 0016: capabilities per window
RFC 0017: record invalidation
RFC 0018: the assistant's answer, streamed
RFC 0019: a window from the tray
RFC 0020: an app that stays in the tray
RFC 0021: a server chosen at sign-in
RFC 0022: signed in to more than one server
RFC 0023: private channels a window listens to
RFC 0024: updates from the backend
RFC 0025: commands and configuration
RFC 0026: the running app, for coding agents
RFC 0027: the assistant's code mode
RFC 0028: the tray's icon, and the app's
RFC 0029: installers
RFC 0030: the app's identity on Windows
RFC 0031: a token per workspace
RFC 0032: the microphone
RFC 0033: diagnostics the user can send
RFC 0034: one screen in several states at once
RFC 0035: point at it, and hand it to the agent
RFC 0036: rata check, the app checked as a whole
RFC 0037: Theme Studio
RFC 0038: edit it in its own app
RFC 0039: a write shown at once in every window
RFC 0040: the two halves agree
RFC 0041: Quick Look
RFC 0042: follow a colleague
RFC 0043: every write seen
RFC 0044: composite keys
RFC 0045: bigint all the way
RFC 0046: pivot columns
RFC 0047: relations on any key
RFC 0048: more providers
RFC 0049: OpenAI web search
RFC 0050: integer-keyed arguments
RFC 0051: citations
RFC 0052: open documents
RFC 0053: exit hooks
RFC 0054: the gui feature
Release notes
Changelog
Elyra
RFC 0053 — Exit hooks: work done however the app ends

RFC 0053 — Exit hooks: work done however the app ends

Status: implemented (2026-11-24) · Target: 0.54.0 · builds on windows & lifecycle, sidecar, updater · see Decisions

Summary

An app that starts something outside itself has to end it when it quits: an ssh -N tunnel, a database server it launched, a lock file, a half-written temp file. Elyra gives it no place to do that. The event loop (tao) ends the process without running destructors, and the updater's relaunch calls process::exit(0) directly. So whatever the app started lives on after it, as ElyraSQL's tunnels do on macOS and Windows.

This RFC adds exit hooks. They run once, whichever way the process ends: the last window closed, Quit, a relaunch into an update, the end of an --mcp run, or a signal from the OS or a terminal.

App::new()
    .on_exit(|ctx| ctx.get::<Tunnels>().close_all())
    .run()?;
// A command-line tool built on the same crates, with no window (RFC 0054).
fn main() -> anyhow::Result<()> {
    let _exit = elyra::exit::guard();          // hooks on drop, and on Ctrl-C/SIGTERM
    elyra::exit::on_exit(tunnel::kill_all);
    run_cli()
}
  • One list, run once: App::on_exit and the free elyra::exit::on_exit add to the same process-wide list. The first way out runs it, and every later way finds it empty.
  • Every way out the framework controls: the event loop's end, the updater's relaunch, --mcp's end, and SIGINT/SIGTERM/SIGHUP (Unix) and Ctrl-C, Ctrl-Break and closing the console (Windows), each followed by the exit it would have made.
  • The framework's own children too: sidecars the app spawned with Sidecar are ended by a hook of the framework's, so sidecar stops leaving processes behind.

Motivation

  • ElyraSQL, moving from its fork onto the framework, keeps its SSH tunnels in ssh -N children. Its fork has a global on_exit(fn()) run on LoopDestroyed, and its updater calls the hooks before it relaunches. Without that here, moving to the framework would leave tunnels running after every quit.
  • Sidecar has the same bug today: its children are tokio Children without kill_on_drop, and nothing drops them anyway, so a sidecar outlives the app that started it.
  • Drop is the usual answer and doesn't work here. tao's run never returns, and process::exit skips destructors, so an app can't rely on one.

Current state (0.53)

  • shell/webview.rs: ControlFlow::Exit when the last window closes (lifetime::ends) and on Quit. tao then sends Event::LoopDestroyed and exits the process. Nothing handles LoopDestroyed.
  • The updater: updater.rs (apply_and_relaunch), updater/runtime.rs and shell/update.rs end with std::process::exit(0) after arranging the relaunch.
  • App::run_mcp (--mcp) returns when stdin closes. Its caller's destructors run, but there's no hook for state that lives elsewhere.
  • No signal handling: Ctrl-C in a terminal, or kill, ends the process at once.
  • Sidecar spawns with tokio::process::Command, without kill_on_drop(true), and kills a child only on sidecar.kill(id).

Design

The list

pub mod exit {
    /// Run `hook` once when the process ends, whichever way. Hooks run in
    /// the reverse order they were added (the last thing set up is the
    /// first torn down), on the thread that's ending the process.
    pub fn on_exit(hook: impl FnOnce() + Send + 'static);

    /// Run the hooks now, once: what every way out calls. A second call
    /// finds the list empty.
    pub fn run();

    /// For a `main` without `App::run`: runs the hooks when dropped, and
    /// installs the signal handlers below. Hold it for the life of `main`.
    pub fn guard() -> ExitGuard;
}

impl App {
    /// `on_exit` with the app's `Ctx`, added when the app starts.
    pub fn on_exit(self, hook: impl FnOnce(&Ctx) + Send + 'static) -> Self;
}

A hook that panics is caught. The error is logged and the rest still run.

Where it's called

How the process ends Where exit::run() is called
Last window closed, Quit, the tray's Quit, macOS ⌘Q Event::LoopDestroyed in the event loop
A relaunch into an update before each process::exit(0) in the updater
--mcp ends (stdin closed) when run_mcp returns
SIGINT, SIGTERM, SIGHUP (Unix) a signal thread: run the hooks, then exit with 128 + the signal
Ctrl-C, Ctrl-Break, console closed (Windows) SetConsoleCtrlHandler: run the hooks, then exit
A CLI's main returns or unwinds ExitGuard's Drop

The signal handlers are installed by App::run and by exit::guard(), and not by a library that only links Elyra. An app that installs its own handlers can turn them off (App::exit_on_signals(false), open question 3).

What it can't catch

SIGKILL, a force-quit from Activity Monitor or Task Manager, a crash, and a power loss end the process with no chance to run anything. On Linux a child can still be ended with the parent through PR_SET_PDEATHSIG. The docs say this, and point a process that must never be left behind at its own watchdog: the child exits when its stdin closes, as ssh -N can be set up to.

Windows log-off and shutdown reach a GUI app (with no console) as WM_QUERYENDSESSION/WM_ENDSESSION to its windows. tao doesn't pass them on today, so they're open question 2.

Sidecars

Sidecar spawns with kill_on_drop(true) and registers one framework hook that kills the children still running. So a sidecar ends with the app, as the docs always implied.

Testing

  • Unit: order (reverse), once only (run twice, a hook added during run), a panicking hook not stopping the others, App::on_exit getting the app's Ctx.
  • Integration (Unix): a test binary that registers a hook writing a file, then is sent SIGTERM. The file is there, and the exit code is 143. The same with ExitGuard on a normal return.
  • Windows: a console child sent CTRL_BREAK_EVENT (GenerateConsoleCtrlEvent), checked the same way.
  • The running app in CI: the example app adds a hook that writes a marker file. The macOS, Linux and Windows walk-throughs quit it as they do now and check the file.
  • Sidecar: a spawned sleep 60 is gone after the hooks run.

Implementation plan

  1. framework/src/exit.rs: the list, run, guard, the Unix signal thread (signal-hook, or tokio's signal feature), and the Windows console handler.
  2. The calls: LoopDestroyed, the updater's three exits, run_mcp. App::on_exit, and exit_on_signals if decided.
  3. Sidecar: kill_on_drop and the framework's hook.
  4. Tests, the example's marker and CI checks, docs (windows.md#lifecycle, sidecar.md, a short exit.md), CHANGELOG.

Open questions

Answered in Decisions.

  1. Hook signature: FnOnce with or without Ctx? Recommendation: both, as above. elyra::exit::on_exit takes a plain FnOnce() so a CLI and a library can use it without an App. App::on_exit hands over the app's Ctx, which is where an app keeps what it has to close.
  2. Windows log-off and shutdown for a GUI app: handle WM_ENDSESSION through a hidden message window of our own, or wait for tao? Recommendation: our own message-only window, created on the event loop's thread, that runs the hooks on WM_ENDSESSION (wParam true). Without it, a tunnel survives every log-off, which is one of the cases ElyraSQL names. If it turns out to be more than a small, contained module, it moves to its own change and the docs say so.
  3. Signal handlers by default? Recommendation: yes in App::run and exit::guard(), with App::exit_on_signals(false) for an app that installs its own. Ctrl-C in rata dev then ends the app the way Quit does, which is what a developer expects.
  4. A time limit for the hooks? A hook that hangs keeps the process alive. Recommendation: no limit in the framework. Hooks run in order on the exiting thread, and the docs ask them to be quick and to signal children rather than wait for them. A limit would mean killing a thread half-way through closing something, which is worse than a slow quit.
  5. Async hooks? Recommendation: no. At exit the runtime may already be shutting down. A hook that needs async work does rt.block_on on a handle it kept, or sends a signal and returns.

Not in this RFC

  • Asking before quitting ("unsaved changes"): that's beforeclose on the page, and a window's close request.
  • Restoring state at the next launch.
  • The gui feature a CLI needs to build without tao and wry: RFC 0054.

Alternatives considered

  • Drop on a value in the container: never dropped, because the process exits without unwinding.
  • Only LoopDestroyed, as the fork does: it misses the updater's relaunch (the fork calls the hooks there by hand), signals, and a CLI.
  • PR_SET_PDEATHSIG everywhere: Linux only, and only for children.

As built

As designed, with these specifics:

  • framework/src/exit.rs: a process-wide list of FnOnce() + Send. run() takes it and runs it last first, again while hooks added during the run leave it non-empty; a panicking hook is caught and logged. App::on_exit hooks are added in prepare, each with a clone of the app's Ctx.
  • Unix signals: a thread waits on SIGINT, SIGTERM and SIGHUP (signal-hook), runs the hooks, and exits with 128 + the signal.
  • Windows: SetConsoleCtrlHandler for Ctrl-C and Ctrl-Break (exit STATUS_CONTROL_C_EXIT) and for close, log-off and shutdown (exit 0). The session's end comes from a hidden top-level window, not a message-only one as the design said: Windows broadcasts WM_QUERYENDSESSION/WM_ENDSESSION to top-level windows only. The window is never shown, and lives on a thread of its own with its own message loop.
  • Where run() is called: Event::LoopDestroyed, before each of the updater's three process::exit(0) calls, and after run_mcp returns. App::run installs the signal handlers unless exit_on_signals(false); exit::guard() always does.
  • Sidecar: children spawn with kill_on_drop(true), and their pids are kept while they run. A framework hook kills them synchronously by pid (kill(SIGKILL) on Unix, TerminateProcess on Windows), since their tasks wouldn't run again before the process ends.
  • Tests: the hooks' order, once-only semantics, a hook added during a run, a panic, and a guard (exit.rs); a sidecar child ended by pid (sidecar.rs); framework/tests/exit_hooks.rs starts its own binary as a child with a hook, sends SIGTERM (Unix) or CTRL_BREAK_EVENT (Windows), and checks the marker and the exit code; a guard in main. The example app writes ELYRA_EXIT_MARKER in its hook, and CI checks it after ending the app with SIGTERM (Linux, macOS) and after closing its window (Windows). Windows log-off isn't driven in CI.

Decisions

  1. Both signatures: elyra::exit::on_exit(FnOnce()) for a CLI or a library, App::on_exit(FnOnce(&Ctx)) for an app.
  2. Windows log-off and shutdown through a message-only window of our own that runs the hooks on WM_ENDSESSION; if it isn't a small, contained module, it moves to its own change and the docs say so.
  3. Signal handlers by default in App::run and exit::guard(), with App::exit_on_signals(false) to leave them to the app.
  4. No time limit: hooks run in order on the exiting thread, and the docs ask them to be quick.
  5. No async hooks.