Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(team): wait for the cleared input box before retyping the prompt

Jack Rudenko62c58b596273
diff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.md
index 4d5ed761..0041dafb 100644
--- a/ai-docs/architecture/pane-session.md
+++ b/ai-docs/architecture/pane-session.md
@@ -329,9 +329,14 @@ only an empty box is typed again — a blind retry put the line in the box twice
match. With no witness 10 s after delivery, a line still in the box is cleared with ctrl-u, retyped
once and submitted (`resent_enter`, then `retyped_prompt`): a line typed into the startup stdin
reset (Boot, above) may show in the box without the child holding it as input, so a bare
-second Enter cannot be relied on to submit it. If ctrl-u left the line in
-place the remedy is one more Enter, and a box left holding anything else is `clear_failed` — a
-second copy is never typed. The retyped line is the same line, so the witness and read coverage
+second Enter cannot be relied on to submit it. The first frame after ctrl-u is not evidence: under
+load it can be a stale redraw still holding the line (report-F, three parallel slots: ctrl-u at
++1020 ms, the empty box first drawn at +1830 ms; a single 500 ms frame wait read the stale box,
+pressed a bare Enter on a box ctrl-u had already emptied, and the prompt was lost). So frames are
+read until the box stops showing the line, for up to `NUDGE_CLEAR_DEADLINE_MS` (3 s, ~3.7x the
+measured 810 ms): an empty box is retyped, a box holding anything else is `clear_failed` and
+nothing is typed, and only a line STILL in the box at the deadline gets the old remedy, one more
+Enter. A second copy is never typed while the first could still be in the box. The retyped line is the same line, so the witness and read coverage
are unchanged. A panel command (`/cost`, `/usage`, `/config`: a full-screen panel, no record,
input swallowed until Esc) gets an Esc 500 ms after delivery (`panel_dismissed`), and once the empty
box is back its admission ends without a turn (`panel_command`); it used to wait the 30 s bound and
diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.ts
index 3738f628..f75ef820 100644
--- a/packages/cli/src/pane/pane-session.ts
+++ b/packages/cli/src/pane/pane-session.ts
@@ -128,6 +128,15 @@ const PANEL_SETTLE_MS = 500;
* slots failed `prompt_not_accepted`. 3 s waits the reset out.
*/
export const REPL_STABLE_MS = 3_000;
+/**
+ * After the nudge's ctrl-u, how long to keep reading frames for the box to stop showing the
+ * line before concluding ctrl-u did not take. The first frame after the key is not evidence:
+ * under load it can be a stale redraw still holding the line. Measured 2026-10-16 (report-F,
+ * three parallel slots): 810 ms from ctrl-u to the first frame with the empty box, and a
+ * single 500 ms frame wait read the stale box, sent a bare Enter on an emptied box and lost
+ * the prompt. 3 s is ~3.7x that latency and still ends well inside `ADMIT_TIMEOUT_MS`.
+ */
+export const NUDGE_CLEAR_DEADLINE_MS = 3_000;
/** A dialog or choice screen static this long blocks boot. */
const BOOT_STATIC_MS = 5_000;
const TICK_MS = 250;
@@ -192,6 +201,7 @@ export interface PaneSessionOptions {
corroborationMs?: number;
bootStaticMs?: number;
replStableMs?: number;
+ nudgeClearDeadlineMs?: number;
};
}
@@ -1099,6 +1109,29 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
* on to submit it. Ctrl-U clears the box (phase2-captures keylog). The same line is
* retyped, so the turn's witness and read coverage are unchanged.
*/
+ /**
+ * Read frames after the nudge's ctrl-u until the box no longer shows the line, or
+ * `NUDGE_CLEAR_DEADLINE_MS` passes. `empty`: ctrl-u took. `other`: the box holds
+ * something else (or is gone from the screen at the deadline). `line`: the line is still
+ * there at the deadline. `gone`: the admission ended meanwhile.
+ */
+ private async awaitClearedBox(
+ adm: Admission,
+ head: string
+ ): Promise<"empty" | "line" | "other" | "gone"> {
+ const end = Date.now() + this.t("nudgeClearDeadlineMs", NUDGE_CLEAR_DEADLINE_MS);
+ for (;;) {
+ if (this.admission !== adm || this.phase !== "ADMITTING") return "gone";
+ const box = inputBox(this.screen);
+ if (box && box.text === "") return "empty";
+ if (box && !box.text.startsWith(head)) return "other";
+ const left = end - Date.now();
+ if (left <= 0) return box ? "line" : "other";
+ // Resolves on the next frame (screen seq change) or at the deadline.
+ await this.nextFrame(left);
+ }
+ }
+
private nudge(adm: Admission): void {
const box = inputBox(this.screen);
const line = adm.plan.mode === "control" || adm.plan.mode === "refused" ? "" : adm.plan.line;
@@ -1109,13 +1142,14 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
void (async () => {
if (box.menuOpen) await this.key("escape");
await this.key("ctrl-u");
- await this.nextFrame(500);
- const after = inputBox(this.screen);
- if (after && after.text === "") {
+ const after = await this.awaitClearedBox(adm, head);
+ if (after === "gone") return; // accepted or ended meanwhile: nothing to resend
+ if (after === "empty") {
this.anomaly("retyped_prompt");
await this.typeAndSubmit(adm.plan);
- } else if (after?.text.startsWith(head)) {
- // Ctrl-U did not take: the old remedy, one more Enter. Never type a second copy.
+ } else if (after === "line") {
+ // Ctrl-U did not take within the deadline: the old remedy, one more Enter.
+ // Never type a second copy while the first could still be in the box.
await this.key("enter");
} else {
this.anomaly("clear_failed");