Repository navigation
fix(terminal): reset modifyOtherKeys and focus after each session - #718
Conversation
…sion 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~, readline typed ";5;99~" into the line, and the next Enter ran it. The restore dl writes after every session now also writes ESC[>4;0m and ESC[?1004l. Both are sets, so they change nothing on a terminal that is already in the default state. Release 0.64.2.
CSI > 4 m resets the resource to its initial value, so a user's modifyOtherKeys: 1 survives a session.
Reviewer's GuideThe PR fixes terminal state leakage after sessions that exit without cleanup by adding non-destructive modifyOtherKeys and focus-report resets to the unconditional restore sequence, adds unit and pty regression coverage, and releases the changes as version 0.64.2. Sequence diagram for terminal restoration after an unclean sessionsequenceDiagram
participant Shell
participant dl
participant Session
participant Terminal
dl->>Session: start session
Session->>Terminal: enable modifyOtherKeys and focus reports
Session--xdl: exit without cleanup
dl->>Terminal: RESTORE
Note over Terminal: ESC[>4m resets modifyOtherKeys
Note over Terminal: ESC[?1004l disables focus reports
Terminal-->>Shell: Ctrl-C remains an interrupt key
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
blooop
left a comment
There was a problem hiding this comment.
This was generated by AI during review.
Reviewed head de56c9ee against merge base e3be4469 (git diff e3be4469...HEAD). The Standards axis ran in a fresh context that did not see the code written. Its findings at 1b48e541 are below, with what de56c9ee did about each one.
Standards
- The release is in the same commit as the fix (
25ad70f8), and the fixup commitsc92616a3and1b48e541stay in the merge history. Earlier releases are a separaterelease: X.Y.Zcommit (931b730f, #716). Non-blocking. Not changed: the split needs a force-push for a cosmetic gain. - The CHANGELOG entry has no PR link, and 0.64.1's entry has one. Non-blocking. Fixed in
de56c9ee. docs/cli.mddescribes only the kitty case: the9;133usymptom andprintf '\033[<u'. The;5;99~symptom and its manual fix are missing. The module doc interminal.rslists the same four modes. Non-blocking. Fixed inde56c9ee: both now namemodifyOtherKeysand focus reports, and the doc names the symptom andprintf '\033[>4m\033[?1004l'.- The claim "every sequence is a no-op when it is not needed" overstates
ESC[>4m. It resets the mode to the configured value, so it also undoes a value that the user's own shell set. Non-blocking. Fixed inde56c9ee: the module doc anddocs/cli.mdsay it is a reset, not an off. - Fowler smells: the two sequences appear in
RESTORE, in the unit test and in the pty test constants.RESTOREispub(crate), so the integration test cannot reuse it. Nit, acceptable. No other smells. - PR body: a reviewer gets the why and the change from the body alone, and it matches the head (files, test name, byte order). The reported line was quoted in two forms. Nit. Fixed in
de56c9ee.
Spec
No spec available. The PR closes no issue, and no commit names one.
Verdict
Approve. No blocking findings.
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="rust/devlaunch-runner/src/terminal.rs" line_range="93-94" />
<code_context>
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
"\x1b[?2004l", // bracketed paste off
"\x1b[?1000l", // mouse: normal tracking off
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 2
<location path="rust/devlaunch-runner/src/terminal.rs" line_range="93-94" />
<code_context>
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
"\x1b[?2004l", // bracketed paste off
"\x1b[?1000l", // mouse: normal tracking off
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 3
<location path="CHANGELOG.md" line_range="14" />
<code_context>
+
+### Fixed
+
+- **Ctrl-C works at the shell again after a session that ends without cleaning up.**
+ 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:
</code_context>
<issue_to_address>
**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.
</issue_to_address>| "\x1b[>4m", // xterm modifyOtherKeys reset | ||
| "\x1b[?1004l", // focus reports off |
There was a problem hiding this comment.
🟡 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.| "\x1b[>4m", // xterm modifyOtherKeys reset | ||
| "\x1b[?1004l", // focus reports off |
There was a problem hiding this comment.
🟡 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.|
|
||
| ### Fixed | ||
|
|
||
| - **Ctrl-C works at the shell again after a session that ends without cleaning up.** |
There was a problem hiding this comment.
🟡 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.
After a session that ends without its own cleanup, Ctrl-C at your shell cancels the line again. Before this change, Ctrl-C typed
;5;99~into the line, and the next Enter ran that line. This PR also releases 0.64.2.In short
Claude Code switches on two terminal modes in the container:
modifyOtherKeys. While it is on, Ctrl-C sends the textESC[27;5;99~, not the byte that sends SIGINT.ESC[IandESC[Owhen the pane gets or loses focus.When the session ends through
ssh -tand the agent's own reset does not reach the terminal, both modes stay on. Bash then gets text where it expects keys. Readline takesESC[27and types;5;99~into the line. On 2026-10-31 the line becamedla <url>;5;99~;5;99~;5;99~;5;99~exit. Bash randla, then tried to run5and99~.dlalready writes a restore (a fixed list of escape sequences that turn off modes a session can leave on) after every session. That list turned off the kitty keyboard protocol, but it did not turn offmodifyOtherKeysor focus reports. Now the list also writesESC[>4mandESC[?1004l.ESC[>4mresetsmodifyOtherKeysto the terminal's own configured value, so a user who setsXTerm*modifyOtherKeys: 1keeps that value. Neither sequence is a push, so both change nothing on a terminal that is already at its defaults.Evidence
The pty test in
rust/dl/tests/terminal.rsruns the builtdlon a pty. A fake devpod session switches on the kitty keyboard protocol,modifyOtherKeysand focus reports, then exits with status 255. These are the bytes that reached the terminal after the session output, onmainand on this branch:On
main, nothing turns offmodifyOtherKeysor focus reports, so the terminal keeps both modes. On this branch, the restore turns off both. Source: the test with a temporaryeprintln!of the bytes it read, run in a worktree ofmainand on this branch.full bytes
I did not test this in a real terminal emulator. The machine I used has no display.
What this changes
rust/devlaunch-runner/src/terminal.rs:RESTOREalso writesESC[>4m(modifyOtherKeysreset) andESC[?1004l(focus reports off). The doc comment says why. A new unit test pins both sequences.rust/dl/tests/terminal.rs: the fake session also switches onmodifyOtherKeysand focus reports. The test fails ifdldoes not turn off both after the session.docs/cli.md: the page on a dead session now namesmodifyOtherKeys, focus reports, the;5;99~symptom andprintf '\033[>4m\033[?1004l'as the manual fix.rust/Cargo.toml,rust/Cargo.lockandREADME.md, and aCHANGELOG.mdentry.Where this fits
session ends (cleanly or not) terminal::restore() ESC[?1047l alternate screen off ESC[<u kitty keyboard protocol: pop one entry + ESC[>4m modifyOtherKeys reset + ESC[?1004l focus reports off ESC[?2004l bracketed paste off … mouse modes off, cursor on, autowrap on, attributes resetHow I checked it
The pty test failed before the fix and passes after it:
With the
terminal.rsfix removed,a_session_that_dies_holding_the_terminal_gives_it_backfails. With the fix, it passes.A self-review changed
ESC[>4;0mtoESC[>4min c92616a3. The first form forced the mode to 0 and lost a user's own setting. After that change, I ran the pty test again and read the bytes above.commands I ran
I did not run
pixi run test-e2e.Merge danger
Door: one-way. The code change is a plain revert. But the merge publishes 0.64.2 to the conda channel and PyPI, and a published version stays published.
Blast radius: small. If a terminal does not ignore
ESC[>4morESC[?1004l, it prints those bytes once after each session. Every xterm-compatible terminal ignores a sequence it does not know.Not covered
A host
claudesession thatdldid not start can also leave these modes on.dlcannot fix that case, becausedldoes not run the session. APROMPT_COMMANDin the shell is the fix for that case.🤖 Generated with Claude Code
Summary by Sourcery
Restore terminal input and focus behavior after sessions end unexpectedly, and release version 0.64.2.
Bug Fixes:
Tests:
Chores: