Never drop the first prompt when the Smart Routing model switch fails - #863
Merged
lilly-luo merged 2 commits intoOct 1, 2026
Merged
Conversation
The first-prompt replay lost the user's prompt on every non-happy path: switch timeout left it pasted but unsubmitted, persist timeout SIGTERMed Claude, an output stream that never went quiet stalled forever, and the success path bundled Enter with the bracketed-paste close, which a freshly booted TUI can absorb. Unattended launches (isaac/OpenUI) have nobody to press Enter, so the agent sat idle. Paste and Enter are now separate writes; submission is confirmed by the UserPromptSubmit hook re-firing, with bounded Enter retries; and every switch failure falls back to submitting on the default model. Co-authored-by: Isaac <no-reply@databricks.com>
Collaborator
Author
|
🤖 @andy-xu-db @lilly-luo could you review? This hardens the first-prompt replay in |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Smart Routing's first-prompt replay can no longer drop the user's prompt. If the
/modelswitch can't be confirmed, ucode now submits the prompt on the default model. Before this change it left the prompt typed but unsubmitted, or SIGTERMed Claude.Why
The
UserPromptSubmithook blocks the first prompt, andrun_claude_ptyswitches the model and replays it. Every non-happy path lost the prompt:submit=False("restored but not submitted").os.kill(pid, SIGTERM).waiting_to_switch: no bound. If output never goes quiet for 0.75 s, the prompt is never replayed.inject_promptwroteESC[200~…ESC[201~\rin one write. A freshly booted TUI intermittently absorbs a\rbundled with the paste close.In unattended launches (isaac/OpenUI threads started with a positional prompt) nobody presses Enter, so the agent sits idle. Full write-up with diagrams: OpenUI first-prompt drop: ucode Smart Routing replay race
How
submit=False, then send Enter afterPASTE_SUBMIT_DELAY_S(0.3 s).serve_first_prompt_socket(on_submitted_prompt=…)). If it hasn't fired withinSUBMIT_VERIFY_S(4 s, which covers the hook CLI's cold start of about 1.4 s), re-send Enter, up toMAX_SUBMIT_ATTEMPTS(3). Extra Enters into an empty box are no-ops.ESC_GAP_Sso the paste isn't parsed as an Alt sequence, then submit./model, then submit. Claude is no longer killed.READY_TIMEOUT_S(10 s): skip the switch and submit.Tests
tests/test_claude_pty_replay.pycovers the paste/Enter gap, Enter retry and stop-on-signal, all three fail-open paths, and the socket callback.just lintpasses. Full suite (hermeticHOME, excludingtest_codex_smart_routing_v2.py, whosetest_owns_app_server_interposer_and_tui_lifecyclekills the pytest process onmaintoo): 2744 passed, 41 failed. The same 41 fail onmain; they are environment-dependent and unrelated.This pull request and its description were written by Isaac.