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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Deferred submit follows the current keyboard protocol

## Status

Implemented locally; pending maintainer review.

## Context

The non-Codex runtime input path waits for text echo before submitting Enter.
It previously encoded Enter while queuing the text. A cold CLI can negotiate
the CSI u keyboard protocol or return to legacy VT before the echo barrier opens, leaving that stored
sequence in the previous protocol. In a real WSL launch the initial Claude text
remained in its editor; a later deliberate Enter submitted it.

Re-encoding Enter alone passed the mode regressions but still left that text in
the editor on a real cold launch. Retaining the echo barrier and placing one
non-text Right boundary immediately before Enter allowed the cold task to run.

## Evidence

The view regressions queue a Claude prompt, change its keyboard protocol while
echoing the text, then flush the existing barrier. They cover both legacy-to-CSI-u
and CSI-u-to-legacy, plus a second wakeup that must not submit again.

## Decision

The shared barrier owns only its baseline screen. GPUI and legacy adapters keep
their existing echo condition and encode Enter with the shared input encoder at
flush time. Immediate empty submissions and Codex's ordered submission sequence
retain their existing behavior. Initial validation remains before text is written.
Only identified Claude deferred submissions add Right before their single Enter,
through the shared input encoder. Ordinary shells and other providers keep Enter
alone. Text and this commit sequence stay in separate writes across the barrier.

## Rejected alternatives

- Sleep and send another Enter: timing does not establish which protocol is active
and automatic retries can submit a task twice.
- Re-encode Enter alone: passes protocol tests but failed real cold acceptance.
- Always send CR: ignores negotiated CSI u and Windows input protocols.
- Store both old and new encodings: the terminal state is the current authority.

## Consequences

No new timer, prompt retry, readiness heuristic or persistent state. The input
encoder owns both the program boundary and protocol encoding. Live cold-launch
acceptance must separately verify that the CLI actually started its task.

## Validation

Run the view's runtime-submission and hidden-wakeup regressions, the GPUI product
build, and the legacy adapter compile check. Record live cold-launch results with
the repair deliverable instead of treating byte-level tests as model completion.

## Supersedes

None. Extends the non-Codex barrier described alongside
2026-09-21-runtime-codex-submission-boundary.md.

## Revisit when

The provider offers a stable input acknowledgement or changes keyboard negotiation.
1 change: 0 additions & 1 deletion pebrel_app/src/display/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub struct NebulaInlineImage {
#[derive(Debug, Clone)]
pub(crate) struct RuntimeSubmitBarrier {
pub(crate) baseline_screen: String,
pub(crate) submit_bytes: Vec<u8>,
}

#[derive(Debug, Default, Clone)]
Expand Down
47 changes: 47 additions & 0 deletions pebrel_app/src/gpui_shell/terminal/view/output_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,53 @@ use gpui::TestAppContext;
use std::cell::{Cell, RefCell};
use std::rc::Rc;

#[gpui::test]
fn runtime_submission_reencodes_enter_after_keyboard_mode_changes(cx: &mut TestAppContext) {
let (view, window, receiver) = open(cx);
view.update(window, |view, cx| {
view.session.as_ref().unwrap().term.lock().set_options(pebrel_terminal::term::Config {
kitty_keyboard: true,
..Default::default()
});
view.running_program = Some("claude".into());
view.runtime_prompt("cold start".into(), true, cx).unwrap();
assert!(matches!(receiver.try_recv().unwrap(), Msg::Input(bytes)
if bytes.as_ref() == b"cold start"));
// A cold CLI can negotiate the CSI u protocol after accepting its initial text.
feed(view, b"\x1b[>1u\r\n> cold start");
assert!(view.term_mode().contains(TermMode::DISAMBIGUATE_ESC_CODES));
view.flush_pending_runtime_submit(cx);
assert!(matches!(receiver.try_recv().unwrap(), Msg::Input(bytes)
if bytes.as_ref() == b"\x1b[C\x1b[13u"));
view.process_event(TermEvent::Wakeup, cx);
assert!(receiver.try_recv().is_err(), "submit Enter exactly once");
});
}

#[gpui::test]
fn runtime_submission_reencodes_enter_when_keyboard_mode_returns_to_legacy(
cx: &mut TestAppContext,
) {
let (view, window, receiver) = open(cx);
view.update(window, |view, cx| {
view.session.as_ref().unwrap().term.lock().set_options(pebrel_terminal::term::Config {
kitty_keyboard: true,
..Default::default()
});
view.running_program = Some("claude".into());
feed(view, b"\x1b[>1u");
assert!(view.term_mode().contains(TermMode::DISAMBIGUATE_ESC_CODES));
view.runtime_prompt("legacy echo".into(), true, cx).unwrap();
assert!(matches!(receiver.try_recv().unwrap(), Msg::Input(bytes)
if bytes.as_ref() == b"legacy echo"));
feed(view, b"\x1b[<u\r\n> legacy echo");
view.flush_pending_runtime_submit(cx);
assert!(matches!(receiver.try_recv().unwrap(), Msg::Input(bytes)
if bytes.as_ref() == b"\x1b[C\r"));
assert!(view.pending_runtime_submit.is_none());
});
}

#[gpui::test]
fn runtime_submission_codex_prompt_does_not_depend_on_a_repaint(cx: &mut TestAppContext) {
let (view, window, receiver) = open(cx);
Expand Down
17 changes: 10 additions & 7 deletions pebrel_app/src/gpui_shell/terminal/view/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,13 @@ impl TerminalView {
}
let bytes =
crate::input::terminal_input::build_runtime_text_sequence(&command, self.term_mode());
let submit_bytes = self.runtime_key_sequence(
self.runtime_key_sequence(
crate::runtime_api::RuntimeKey::Enter,
crate::runtime_api::RuntimeKeyModifiers::default(),
1,
)?;
self.pending_runtime_submit = Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: self.runtime_screen_snapshot().unwrap_or_default(),
submit_bytes,
});
self.capture_runtime_prompt();
let run = crate::runtime_api::begin_runtime_run();
Expand Down Expand Up @@ -719,7 +718,6 @@ impl TerminalView {
} else {
self.pending_runtime_submit = Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: self.runtime_screen_snapshot().unwrap_or_default(),
submit_bytes,
});
}
}
Expand Down Expand Up @@ -853,14 +851,13 @@ impl TerminalView {
let codex_submit =
submit && self.runtime_agent().is_some_and(|agent| agent.kind == "codex");
if submit && !codex_submit {
let submit_bytes = self.runtime_key_sequence(
self.runtime_key_sequence(
crate::runtime_api::RuntimeKey::Enter,
crate::runtime_api::RuntimeKeyModifiers::default(),
1,
)?;
self.pending_runtime_submit = Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: self.runtime_screen_snapshot().unwrap_or_default(),
submit_bytes,
});
}
if codex_submit {
Expand Down Expand Up @@ -1356,8 +1353,14 @@ impl TerminalView {
if screen == pending.baseline_screen {
return;
}
let pending = self.pending_runtime_submit.take().expect("checked above");
self.write_input(pending.submit_bytes, cx);
// A cold CLI can negotiate a different keyboard protocol while its
// text is being echoed. Encode Enter at delivery, never at queuing.
let submit_bytes = crate::input::terminal_input::build_runtime_deferred_submission(
self.running_program.as_deref(),
self.term_mode(),
);
self.pending_runtime_submit = None;
self.write_input(submit_bytes, cx);
}
}

Expand Down
43 changes: 43 additions & 0 deletions pebrel_app/src/input/terminal_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@ pub(crate) fn build_runtime_codex_submission(text: &str, mode: TermMode) -> Vec<
bytes
}

/// Commit echoed runtime text. Claude also buffers a fresh paste; a non-text
/// boundary must precede Enter so that Enter cannot become pasted content.
pub(crate) fn build_runtime_deferred_submission(program: Option<&str>, mode: TermMode) -> Vec<u8> {
let mut bytes = Vec::new();
if program == Some("claude") {
bytes.extend(build_runtime_sequence(RuntimeKey::Right, Default::default(), 1, mode));
}
bytes.extend(build_runtime_sequence(RuntimeKey::Enter, Default::default(), 1, mode));
bytes
}

fn runtime_modifiers(modifiers: RuntimeKeyModifiers) -> ModifiersState {
let mut state = ModifiersState::empty();
state.set(ModifiersState::SHIFT, modifiers.shift);
Expand Down Expand Up @@ -1281,6 +1292,38 @@ mod vt_tests {
);
}

#[test]
fn runtime_submission_claude_deferred_boundary_preserves_other_programs() {
assert_eq!(
build_runtime_deferred_submission(Some("claude"), TermMode::empty()),
b"\x1b[C\r"
);
assert_eq!(
build_runtime_deferred_submission(Some("claude"), TermMode::APP_CURSOR),
b"\x1bOC\r"
);
assert_eq!(
build_runtime_deferred_submission(Some("claude"), TermMode::DISAMBIGUATE_ESC_CODES),
b"\x1b[C\x1b[13u"
);
for program in [None, Some("bash"), Some("opencode")] {
assert_eq!(build_runtime_deferred_submission(program, TermMode::empty()), b"\r");
}
}

#[cfg(target_os = "windows")]
#[test]
fn runtime_submission_claude_native_boundary_has_one_enter_press() {
let bytes = build_runtime_deferred_submission(Some("claude"), TermMode::WIN32_INPUT_MODE);
let sequence = String::from_utf8(bytes).unwrap();
let records: Vec<_> = sequence.split_inclusive('_').collect();
assert_eq!(records.len(), 4, "Right press/release then Enter press/release");
assert!(records[0].starts_with("\x1b[39;"));
assert!(records[1].starts_with("\x1b[39;"));
assert!(records[2].starts_with("\x1b[13;"));
assert!(records[3].starts_with("\x1b[13;"));
}

#[test]
fn runtime_submission_codex_large_paste_has_one_boundary_and_one_submit() {
let text = "中文\n".repeat(4096);
Expand Down
17 changes: 8 additions & 9 deletions pebrel_app/src/window_context/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ impl WindowContext {
pane.nebula_state.runtime_submit_barrier =
Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: runtime_screen_snapshot(pane).unwrap_or_default(),
submit_bytes,
});
}
}
Expand Down Expand Up @@ -487,12 +486,10 @@ impl WindowContext {
if codex_submit {
bytes = crate::input::terminal_input::build_runtime_codex_submission(&text, mode);
} else if submit {
let submit_bytes =
runtime_key_sequence(pane, RuntimeKey::Enter, RuntimeKeyModifiers::default(), 1)?;
runtime_key_sequence(pane, RuntimeKey::Enter, RuntimeKeyModifiers::default(), 1)?;
pane.nebula_state.runtime_submit_barrier =
Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: runtime_screen_snapshot(pane).unwrap_or_default(),
submit_bytes,
});
}
pane.notifier.notify(bytes);
Expand Down Expand Up @@ -648,12 +645,10 @@ impl WindowContext {
}
let mode = *pane.terminal.lock().mode();
let bytes = crate::input::terminal_input::build_runtime_text_sequence(&command, mode);
let submit_bytes =
runtime_key_sequence(pane, RuntimeKey::Enter, RuntimeKeyModifiers::default(), 1)?;
runtime_key_sequence(pane, RuntimeKey::Enter, RuntimeKeyModifiers::default(), 1)?;
pane.nebula_state.runtime_submit_barrier =
Some(crate::display::state::RuntimeSubmitBarrier {
baseline_screen: runtime_screen_snapshot(pane).unwrap_or_default(),
submit_bytes,
});
let run = crate::runtime_api::begin_runtime_run();
let run_id = run.run_id;
Expand Down Expand Up @@ -714,8 +709,12 @@ impl WindowContext {
return;
}
let pane = &mut self.panes[index];
let pending = pane.nebula_state.runtime_submit_barrier.take().expect("checked above");
pane.notifier.notify(pending.submit_bytes);
let submit_bytes = crate::input::terminal_input::build_runtime_deferred_submission(
pane.nebula_state.running_program.as_deref(),
*pane.terminal.lock().mode(),
);
pane.nebula_state.runtime_submit_barrier = None;
pane.notifier.notify(submit_bytes);
}
}

Expand Down
Loading