Skip to content
Merged
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.64.2] - 2026-10-31

### Fixed

- **Ctrl-C works at the shell again after a session that ends without cleaning up.**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Configured keyboard mode still breaks Ctrl-C

When the terminal's initial modifyOtherKeys value is 1, the release note promises Ctrl-C works again, but the restore leaves modifyOtherKeys enabled, so bash still receives ESC[27;5;99~ instead of SIGINT.

Qualify the release note to state that Ctrl-C is restored when the terminal's configured initial mode is off.

Prompt for AI agents
In `CHANGELOG.md` at line 14:

**Configured keyboard mode still breaks Ctrl-C**

When the terminal's initial `modifyOtherKeys` value is 1, the release note promises Ctrl-C works again, but the restore leaves `modifyOtherKeys` enabled, so bash still receives `ESC[27;5;99~` instead of SIGINT.

Qualify the release note to state that Ctrl-C is restored when the terminal's configured initial mode is off.

Claude Code switches on xterm `modifyOtherKeys` and focus reports in the container.
When the session ended without its own reset reaching the terminal, both stayed on:
Ctrl-C reached bash as `ESC[27;5;99~`, so it typed `;5;99~` into the line instead of
cancelling it, and focus changes printed `^[[I` and `^[[O`. The restore `dl` writes
after every session now also turns off both modes
([#718](https://github.com/blooop/devlaunch/pull/718)).

## [0.64.1] - 2026-10-30

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ one argument instead of a clone, a config file and a build command.
[![GitHub pull-requests merged](https://badgen.net/github/merged-prs/blooop/devlaunch)](https://github.com/blooop/devlaunch/pulls?q=is%3Amerged)
[![GitHub release](https://img.shields.io/github/release/blooop/devlaunch.svg)](https://GitHub.com/blooop/devlaunch/releases/)
[![PyPI](https://img.shields.io/pypi/v/devlaunch)](https://pypi.org/project/devlaunch/)
[![Conda](https://img.shields.io/badge/conda-v0.64.1-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch)
[![Conda](https://img.shields.io/badge/conda-v0.64.2-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch)
[![License](https://img.shields.io/github/license/blooop/devlaunch)](https://opensource.org/license/mit/)
[![Platform](https://img.shields.io/badge/platform-linux--64-blue)](https://github.com/blooop/devlaunch/releases)
[![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
Expand Down Expand Up @@ -350,7 +350,7 @@ clone, and [docs/cleanup.md](docs/cleanup.md) says what it carries one past and

```bash
$ dl --version
dl 0.64.1
dl 0.64.2
```

`--devcontainer <variant|path>` picks a non-default `devcontainer.json`. A bare name means
Expand Down
18 changes: 12 additions & 6 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ one of devpod's ssh-config context options names a different one. Set
### Getting the terminal back when a session dies badly

A terminal is not only a stream. A full screen program switches modes on in the
emulator for its own use, the kitty keyboard protocol, bracketed paste, mouse
reporting, the alternate screen, and is expected to switch them off again on the
emulator for its own use, the kitty keyboard protocol, xterm `modifyOtherKeys`,
focus reports, bracketed paste, mouse reporting, the alternate screen, and is expected to switch them off again on the
way out. One that is killed never gets the chance, and those modes live in your
terminal rather than in the connection, so nothing between the program and the
glass undoes them.
Expand All @@ -285,22 +285,28 @@ broken: ssh restores the tty settings on its way out, so the shell still echoes
and still edits lines, and yet Ctrl-C does nothing and ordinary keys print things
like `9;133u` at the prompt. Those are kitty keyboard protocol key reports, still
switched on. Ctrl-C is one of them, arriving as an escape sequence instead of as
the byte that raises SIGINT.
the byte that raises SIGINT. Claude Code also switches on xterm `modifyOtherKeys`
and focus reports. With those left on, Ctrl-C at the prompt types `;5;99~` into
the line instead of cancelling it, so the next Enter runs that line, and each
focus change prints `^[[I` or `^[[O`.

`dl` is the last process holding that terminal, so `dl` repairs it. Every session
ends with a short restore written to the terminal, over either transport, and the
interrupt handler writes the same thing before it exits. It goes out after a
clean session too, because ssh's exit status does not say whether the far end
cleaned up after itself. That costs nothing: every sequence in it is chosen for
doing nothing when the mode it names is already off. The one obvious candidate
doing nothing when the mode it names is already off. `ESC [ > 4 m` is a reset,
not an off: it puts `modifyOtherKeys` back to your terminal's configured value.
The one obvious candidate
that is not, `ESC [ ? 1049 l`, is left out on purpose, because it restores the
cursor as well as the screen and would scramble the display on every ordinary
exit.

Nothing is written when `dl`'s own output is not a terminal, so `dl <ws> -- ls >
files.txt` keeps its output free of escape sequences. If you are ever left with a
wrecked terminal some other way, `printf '\033[<u'` undoes this particular one
and `reset` undoes everything.
wrecked terminal some other way, `printf '\033[<u'` undoes the kitty keyboard
protocol, `printf '\033[>4m\033[?1004l'` undoes `modifyOtherKeys` and focus
reports, and `reset` undoes everything.

### `--rm`: the throwaway workspace

Expand Down
10 changes: 5 additions & 5 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
# The single source of the version (docs/rust-rewrite-plan.md: cutover ships
# 0.1.0, version read from Cargo.toml).
[workspace.package]
version = "0.64.1"
version = "0.64.2"
edition = "2024"
license = "MIT"
repository = "https://github.com/blooop/devlaunch"
Expand Down
34 changes: 31 additions & 3 deletions rust/devlaunch-runner/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! A child that inherits this process's stdout inherits the *terminal*, and a
//! terminal is not only a stream: it holds modes an application switches on for
//! its own use and is expected to switch off again on the way out. The kitty
//! keyboard protocol, bracketed paste, mouse reporting and the alternate screen
//! all live in the emulator, not in the connection and not in the tty driver, so
//! keyboard protocol, xterm `modifyOtherKeys`, focus reports, bracketed paste,
//! mouse reporting and the alternate screen all live in the emulator, not in the connection and not in the tty driver, so
//! nothing between the application and the glass undoes them.
//!
//! An application that exits normally undoes its own. One that is *killed* never
Expand All @@ -28,7 +28,12 @@
//! badly, because "did the remote die without cleaning up" is not a question
//! ssh's exit status answers. That is only safe if a restore costs nothing when
//! there was nothing to restore, so each sequence below was chosen for being
//! idempotent, and the one obvious candidate that is *not* was left out:
//! idempotent, and the one obvious candidate that is *not* was left out. One
//! sequence is a reset rather than an off: `ESC [ > 4 m` puts `modifyOtherKeys`
//! back to the terminal's configured value, so it also undoes a value the user's
//! own shell set before `dl` ran.
//!
//! The candidate left out:
//!
//! `ESC [ ? 1049 l` is the usual way to leave the alternate screen, and it is
//! also a DECRC — xterm's ctlseqs defines it as "Use Normal Screen Buffer and
Expand Down Expand Up @@ -71,6 +76,15 @@
/// child of `dl`'s is reaped is that child's, and nobody else's to lose. A
/// caller that violates the contract is damaged by the first pop and no further
/// by the rest, which is why counting them buys nothing.
/// - `ESC [ > 4 m` — xterm `modifyOtherKeys` back to its initial value, which is
/// off unless the user's resources say otherwise. Claude Code switches it on,
/// and while it is on Ctrl-C arrives as `ESC [ 27;5;99 ~`, not as the byte that
/// raises SIGINT. Readline takes the `ESC [ 27` and types `;5;99~` into the
/// line, so Ctrl-C at the prompt no longer cancels it, and the next Enter runs
/// it: reported on 2026-10-31 as `dla <url>;5;99~;5;99~;5;99~;5;99~exit`. `ESC [ > 4 ; 0 m`
/// would force it to 0 and lose a user's `modifyOtherKeys: 1`.
/// - `ESC [ ? 1004 l` — focus reports off, or each focus change prints `^[[I` or
/// `^[[O` at the prompt. Claude Code switches this on as well.
/// - `ESC [ ? 2004 l` — bracketed paste off, or a paste arrives wrapped in
/// `ESC [ 200 ~` markers that the shell prints instead of obeying.
/// - `ESC [ ? 1000 l` … `ESC [ ? 1015 l` — the mouse tracking modes and the three
Expand All @@ -81,6 +95,8 @@
pub(crate) const RESTORE: &str = concat!(
"\x1b[?1047l", // alternate screen off
"\x1b[<u", // kitty keyboard protocol: pop one stack entry
"\x1b[>4m", // xterm modifyOtherKeys reset
"\x1b[?1004l", // focus reports off
Comment on lines +93 to +94

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Terminal modes remain enabled

When signal-driven shutdown restores the terminal before the foreground child stops, and the child writes mode-setting sequences afterward, interrupt::drain does not restore the terminal again after the child exits, and cleanup_and_exit uses _exit, leaving those modes enabled when dl exits.

Restore the terminal again after the foreground child has stopped and before exiting.

Prompt for AI agents
In `rust/devlaunch-runner/src/terminal.rs` at lines 93-94:

**Terminal modes remain enabled**

When signal-driven shutdown restores the terminal before the foreground child stops, and the child writes mode-setting sequences afterward, `interrupt::drain` does not restore the terminal again after the child exits, and `cleanup_and_exit` uses `_exit`, leaving those modes enabled when `dl` exits.

Restore the terminal again after the foreground child has stopped and before exiting.

Comment on lines +93 to +94

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Parent terminal modes disappear

When dl runs inside a terminal application that enabled focus reports or a non-resource modifyOtherKeys mode, terminal::restore unconditionally writes the focus-off and modifyOtherKeys reset sequences instead of preserving the modes active before dl, so the enclosing application loses its expected focus or modified-key events.

Preserve and restore the caller's prior focus-report and modifyOtherKeys settings instead of unconditionally resetting them.

Prompt for AI agents
In `rust/devlaunch-runner/src/terminal.rs` at lines 93-94:

**Parent terminal modes disappear**

When `dl` runs inside a terminal application that enabled focus reports or a non-resource `modifyOtherKeys` mode, `terminal::restore` unconditionally writes the focus-off and `modifyOtherKeys` reset sequences instead of preserving the modes active before `dl`, so the enclosing application loses its expected focus or modified-key events.

Preserve and restore the caller's prior focus-report and `modifyOtherKeys` settings instead of unconditionally resetting them.

"\x1b[?2004l", // bracketed paste off
"\x1b[?1000l", // mouse: normal tracking off
"\x1b[?1002l", // mouse: button-event tracking off
Expand Down Expand Up @@ -182,6 +198,18 @@ mod tests {
);
}

/// The 2026-10-31 report: Claude Code died holding `modifyOtherKeys` and focus
/// reports, and Ctrl-C at the shell typed `;5;99~` into the line instead of
/// cancelling it.
#[test]
fn the_restore_turns_off_the_modes_claude_code_switches_on() {
assert!(RESTORE.contains("\x1b[>4m"), "modifyOtherKeys: {RESTORE:?}");
assert!(
RESTORE.contains("\x1b[?1004l"),
"focus reports: {RESTORE:?}"
);
}

/// Every sequence is a complete CSI: introducer, parameters, final byte. A
/// truncated one would be printed as text by the terminal, which is the
/// failure this module exists to prevent.
Expand Down
20 changes: 19 additions & 1 deletion rust/dl/tests/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ const MAIN: &str = "devlaunch-main-3j1t";
const KEYBOARD_PUSH: &str = "\x1b[>1u";
const KEYBOARD_POP: &str = "\x1b[<u";

/// The two modes Claude Code switches on in the container, and what undoes them.
/// The 2026-10-31 report: with `modifyOtherKeys` stranded, Ctrl-C reached bash
/// as `ESC [ 27;5;99 ~` and typed `;5;99~` into the line.
const OTHER_KEYS_ON: &str = "\x1b[>4;2m";
const OTHER_KEYS_OFF: &str = "\x1b[>4m";
const FOCUS_ON: &str = "\x1b[?1004h";
const FOCUS_OFF: &str = "\x1b[?1004l";

/// What the session says before it dies, so "the repair came after the session"
/// can be told from "the repair came instead of one".
const SESSION_SAID: &str = "REMOTE-PUSHED";
Expand All @@ -55,7 +63,7 @@ fn a_session_that_dies_holding_the_terminal_gives_it_back() {
// session that cleaned up after itself, which is the whole reason the repair
// is unconditional.
world.devpod_answers_ssh_with(
&format!("{KEYBOARD_PUSH}{SESSION_SAID}\n"),
&format!("{KEYBOARD_PUSH}{OTHER_KEYS_ON}{FOCUS_ON}{SESSION_SAID}\n"),
// 255 is what OpenSSH exits with when the connection breaks under it, and
// what devpod's own `exit status 137` tunnel failure surfaces as.
255,
Expand All @@ -80,6 +88,16 @@ fn a_session_that_dies_holding_the_terminal_gives_it_back() {
{pushed}, session output at {said}, repair at {popped}.\nThe terminal \
saw:\n{seen:?}"
);
for (off, mode) in [
(OTHER_KEYS_OFF, "modifyOtherKeys"),
(FOCUS_OFF, "focus reports"),
] {
assert!(
seen[said..].contains(off),
"dl exited leaving {mode} on: nothing wrote {off:?} after the session.\n\
The terminal saw:\n{seen:?}"
);
}
}

// ===========================================================================
Expand Down
Loading