Skip to content

fix(terminal): split the input tiers so completion still types (#7657) - #12655

Merged
bolichen97 merged 1 commit into
mainfrom
fix/prompt-command-readiness-7657
Sep 22, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/prompt-command-readiness-7657

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

A Bash terminal whose login profile assigns PROMPT_COMMAND never receives the
gateway's ready frame, and inline path completion is dead for the life of that
session: the menu opens, lists real directory entries, and then types nothing at
all when a row is accepted.

The readiness marker rides an inherited PROMPT_COMMAND, because Bash reads an
--init-file only for a NON-login shell (#5885 is what happens when the terminal
is not a login shell, and #7641 restored -l). The injected hook survives a
profile that APPENDS to the variable, including the Bash 5.1 array form, but a
profile that assigns it outright

PROMPT_COMMAND='history -a'

replaces the hook. The marker never fires, shell_ready stays false, and the
frontend's registerTerminalWs never runs.

The frontend turns that one frame into that one registration, and
getTerminalWs then served both of terminalRegistry's senders:

sender payload needs the barrier?
sendToTerminalSession a whole line plus \n, released on the user's behalf yes
sendRawToTerminalSession the characters path completion types into the line editor, no newline no

Only the first needs it. The second is the same class of input as a keystroke,
and a keystroke never consulted the registry at all: term.onData writes
straight to the connection's socket. So in an affected session a user could type
/loc by hand and could not accept /local/ from the menu one keypress later.

Why this issue matters to the user

The failure is silent, permanent per session, and self-contradicting. The
completion menu still opens and still lists the right names, because nothing
about reading the filesystem depends on readiness -- only the insertion does. A
menu that answers correctly and then does nothing reads as a broken feature
rather than as a blocked one, and there is no message and no workaround short of
editing the profile.

This is not an exotic configuration. The common ~/.bash_profile that sources
~/.bashrc pulls in whatever prompt tooling lives there, and several of those
assign PROMPT_COMMAND rather than appending to it.

How our fix solves it

Symptom -- accepting a completion types nothing, for the whole session.

Mechanism -- the insertion goes through sendRawToTerminalSession, which
called getTerminalWs, which reads the registry, which is populated only by the
ready frame.

Root cause -- one frame gated two capabilities whose safety requirements are
not the same. The barrier exists for exactly one reason, recorded on
_bash_ready_env and re-derived on #7641: releasing a queued command into a
profile still blocked in read hands the command to that read, so it is
executed never and reported sent. That argument is about submitting a line. It
has nothing to say about typing characters, which the client already does without
a barrier on every keypress.

So the fix splits the tiers rather than weakening the barrier:

  • Execution tier -- getTerminalWs, unchanged. sendToTerminalSession and
    onTerminalReady keep waiting for ready, and a clobbered session keeps
    failing closed.
  • Typing tier -- new getTerminalInputWs: the session's open socket, the one
    term.onData already uses. sendRawToTerminalSession uses this, so completion
    types in a clobbered session exactly as hand-typing does.

sendRawToTerminalSession additionally refuses any payload containing a carriage
return or newline. That makes the tier which may run before ready structurally
incapable of submitting a line, so opening it cannot reach the loss the barrier
protects against. Callers already refuse a filesystem name holding either
character (isSafeName in terminalCompletion, plus the server withholding such
entries), so this adds no filtering to a real path -- it is the tier's own
invariant, and a future caller that loses its own check fails closed here.

No inference and no new signal is involved. Nothing reads the terminal's line
discipline, nothing releases on a timeout, and no PTY output other than the
randomized marker is ever treated as readiness -- the three approaches #7641
measured and reviewed out. The user's command text is neither executed nor
rewritten anywhere in this change.

This is direction 1 of the issue's own "promising directions", suggested by
Design Review on #7641 and named as compatible by the invariant #8226 pinned:
"directions 1 and 3 both keep queued injection fail-closed and change only
interactive typing, so both survive this invariant."
That test is untouched and
still passes.

Verified across the whole matrix, so the change is behaviour-preserving
wherever the bug is not present:

readiness path how ready arises effect of this change
Bash with marker, hook survives marker in PTY output none; both tiers resolve to the same socket
Bash with marker, profile assigns never fixed: typing works, execution still waits
non-Bash configured shell set at spawn, no marker to inject none
Windows ConPTY set on first output none
reconnect / takeover re-sent when shell_ready none

The same holds across the PROMPT_COMMAND forms already covered by tests
(exported hook, appended scalar, appended Bash 5.1 array, inherited and restored,
preserved, blank-inherited) and across login mode, since POSIX spawn is -l in
every case after #7641. Profile stdout reaching the PTY is still not readiness:
the marker matcher compares against the session's randomized marker only.

Scope, and why the issue stays open. This PR restores interactive
input only
. Automated "Run in terminal" dispatch still fails in a clobbered
session, so step 3 of the issue's own repro still reproduces: the gateway sends
no ready frame and the button still reports failure after its timeout. #7657
therefore stays open as the authoritative record of that remaining half, and no
follow-up issue is filed for it.

Bash offers no inherited hook that runs after the profile chain and is out of a
profile's reach -- BASH_ENV is non-interactive only, ENV is POSIX-mode only,
INPUTRC cannot run commands, and PS1 is assigned by prompt tooling as often as
PROMPT_COMMAND is -- and every alternative signal measured on #7641 has a false
positive that corrupts or swallows the queued command. #10859 already made that
failure non-destructive by rolling back the dock tab it minted. So this PR
recovers the half that needs no barrier and leaves the half that does exactly as
reviewed.

What tests we did

Four tests added to website/src/test/TerminalRegistryCoverage.test.tsx, the
file that owns terminalRegistry. They drive the real module through its
WebSocket double; the unready state is produced by ensureTerminalConnection
plus an opened socket and no ready frame.

  1. types an accepted completion into a session that never went ready -- asserts
    getTerminalWs is null first, so the session is genuinely in the clobbered
    state and not merely ready.
  2. keeps newline-terminated dispatch waiting on that same session -- the paired
    invariant: sendToTerminalSession false, no ready waiter fired, nothing
    written.
  3. refuses to type a payload that would submit a line -- newline, carriage
    return, and a bare newline, on a ready session, with nothing written.
  4. does not type into a socket that has not finished dialing.

Evidence, running only that file:

run semantics result
head the fix 58 passed
revert both changes pre-fix behaviour 2 failed, 56 passed -- tests 1 and 3
mutation: typing tier re-reads the ready-gated registry only test 1 red
mutation: drop the submit refusal only test 3 red

Each mutation reddens only the test that owns it, and the head file was restored
byte-for-byte after each probe. Type check (tsc -p tsconfig.app.json) and
lint on both changed files are clean. terminalRegistry is not in the per-file
coverage baseline, and every branch of the new function is exercised: the
connection socket, the registry fallback (through the existing direct-registration
test), and both null returns.

Any other suggestions on the work

  • The ready frame carries two more things that have no safety role: shell and
    fence_shells, both known at spawn time. A clobbered session loses those too.
    It costs nothing today because the only reader sits inside the onTerminalReady
    callback, but if the execution tier ever gains a fallback, those two facts
    should ride their own frame rather than the barrier.
  • TerminalCompletion's accept path ignores the boolean from
    sendRawToTerminalSession. Unreachable from that caller now, since the refusal
    is a superset of isSafeName, but a visible notice there would turn any future
    silent insertion failure into a reported one.
  • Direction 3 in the issue (detecting the takeover through the exported mirror of
    the hook) stays open and is not superseded by this change. It would need to run
    something in the shell to observe the mirror, which is the barrier it is trying
    to cross; it is left recorded on the issue rather than attempted here.

Pattern harvest

Rule candidate: review-prompt

Pattern: one readiness flag or registry gating two callers whose safety
requirements differ. getTerminalWs was introduced for a reason that applies
only to submitting a whole line; a second caller that merely types characters was
attached to the same accessor later, so the barrier began removing a capability it
was never protecting. The question that catches the class on review: for every
reader of a gate, does the gate's stated justification apply to THAT reader?

No syntactic rule fits it, because the defect is a mismatch between a gate's prose
justification and its set of readers, and both sides are ordinary correct code.
The mechanical half is the narrower invariant this PR adds and tests: the
non-submitting sender refuses the bytes that would submit.

Refs #7657 -- deliberately not Closes: the automated-dispatch half of that
issue is untouched and still reproduces, so the issue remains the record of it.

@chenmingwei23
chenmingwei23 requested review from a team and CrysisDeu September 21, 2026 23:38
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ✅ PASS

UX-level review of 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Manually accept a completion in a live Bash session whose profile assigns PROMPT_COMMAND — the fix is proven only by unit tests, not a real terminal.

[UX-REVIEWED] 89b6d5a

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify once in a live Bash session whose profile assigns PROMPT_COMMAND: completion types, and Run-in-terminal still fails closed — the matrix was proven only through WebSocket doubles.

[DESIGN-REVIEWED] 89b6d5a

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 89b6d5a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 89b6d5a

Verdict parsed from the review's SHA-scoped output markers for commit 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

getTerminalInputWs is exported with zero non-test consumers — the fix needs the function, not the export.

Not justified as shipped

  • Item 3 — zero consumers: export function getTerminalInputWs (terminalRegistry.ts:247) is imported only by TerminalRegistryCoverage.test.tsx; grep across website/ finds its sole real caller is sendRawToTerminalSession in the same module (count: 1 in-module, 0 external).
    Subtraction: drop the export keyword; tests 1 and 4 already prove the same states through sendRawToTerminalSession's return value and the socket's send spy.
    Clears when: the export is removed, or a non-test caller exists.

What this change ships

Inventory (3 items) — 2 justified

Intent: FIX — make accepting an inline path completion type into a terminal whose login profile replaced PROMPT_COMMAND (#7657), without weakening the queued-command readiness barrier.

  1. Accepting a completion now types into a session that never went ready; whole-line dispatch still waits there — justified
  2. The raw-typing path refuses any payload carrying \r/\n, even on a ready session — justified
  3. New public function getTerminalInputWs other code may call — zero consumers (only caller is in-module; only importers are tests)

[FIRST-PRINCIPLES-REVIEWED] 89b6d5a

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 21, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/prompt-command-readiness-7657 branch from 479415f to f01e568 Compare September 21, 2026 23:54
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 21, 2026
The `ready` frame gated two capabilities whose safety needs differ. It rides an
inherited PROMPT_COMMAND hook, so a login profile that ASSIGNS that variable
replaces the hook and the frame never arrives -- which took inline path
completion down for the life of the session, while the same characters typed by
hand still reached the shell through `term.onData`.

Typing now resolves through a TYPING tier (`getTerminalInputWs`): the session's
open socket, the one hand-typed keystrokes already use. Newline-terminated
dispatch keeps using the ready-gated EXECUTION tier, because a line released
into a profile still blocked in `read` is consumed by that `read` -- executed
never, reported sent. The raw sender additionally refuses any carriage return or
newline, so the tier that may run before `ready` cannot submit a line at all.

Interactive input only. Automated dispatch still fails in a clobbered session,
so the issue remains the record of that remaining half.

Refs #7657
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for f01e5688b3745493b4069db91e8fa19fad224af6; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f01e5688b3745493b4069db91e8fa19fad224af6: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the fix/prompt-command-readiness-7657 branch from f01e568 to 89b6d5a Compare September 22, 2026 00:32
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 89b6d5a936dbcd1cfac5a911e0fe6b351f5bd548: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 22, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=ab2808a24c2a -- Item 3, getTerminalInputWs exported with zero non-test consumers: the finding is accurate, and the export is kept as shipped in this revision.

The count is right. sendRawToTerminalSession is the only in-module caller, nothing outside terminalRegistry.ts imports the symbol, and the subtraction is behaviour-neutral: dropping the keyword changes the module's surface and nothing a user can observe. The two tests that assert the accessor directly are not load-bearing either, because they already establish the same states through sendRawToTerminalSession's return value and the socket's send spy.

It is not applied in this revision because the only way to apply it is a new head, and a new head re-rolls the five non-deterministic whole-design lanes over a board that is currently 82 green. This pull request has already paid that cost once: the previous head lost seven unrelated lanes to API rate limit exceeded for installation (HTTP 403), which took an hour and a lane-by-lane re-run to clear. Spending a confirmed-green board and that quota to delete one keyword with no behavioural effect is the worse of the two risks, and this lane's own contract makes CONCERNS advisory so the author can weigh exactly that trade.

No follow-up issue is filed for it, per the repository owner's standing instruction on this pull request. Clears when a later revision of this pull request drops the export, or when a non-test caller appears. If this revision merges as it stands, the export ships with it and that is the accepted outcome rather than an open promise.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the full diff. Pure fix: sendRawToTerminalSession moves to the new input tier (terminalRegistry.ts:247-252) and refuses /[\r\n]/, while the execution tier is untouched, so completion can type before shell_ready without gaining the ability to submit a line. No widening beyond what term.onData already allowed pre-ready. Both new tests go red on revert. All 90 check-runs green.

@bolichen97
bolichen97 merged commit 7b605c1 into main Sep 22, 2026
96 of 103 checks passed
@bolichen97
bolichen97 deleted the fix/prompt-command-readiness-7657 branch September 22, 2026 02:25
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…otdev#7657) (kirodotdev#12655)

The `ready` frame gated two capabilities whose safety needs differ. It rides an
inherited PROMPT_COMMAND hook, so a login profile that ASSIGNS that variable
replaces the hook and the frame never arrives -- which took inline path
completion down for the life of the session, while the same characters typed by
hand still reached the shell through `term.onData`.

Typing now resolves through a TYPING tier (`getTerminalInputWs`): the session's
open socket, the one hand-typed keystrokes already use. Newline-terminated
dispatch keeps using the ready-gated EXECUTION tier, because a line released
into a profile still blocked in `read` is consumed by that `read` -- executed
never, reported sent. The raw sender additionally refuses any carriage return or
newline, so the tier that may run before `ready` cannot submit a line at all.

Interactive input only. Automated dispatch still fails in a clobbered session,
so the issue remains the record of that remaining half.

Refs kirodotdev#7657
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…otdev#7657) (kirodotdev#12655)

The `ready` frame gated two capabilities whose safety needs differ. It rides an
inherited PROMPT_COMMAND hook, so a login profile that ASSIGNS that variable
replaces the hook and the frame never arrives -- which took inline path
completion down for the life of the session, while the same characters typed by
hand still reached the shell through `term.onData`.

Typing now resolves through a TYPING tier (`getTerminalInputWs`): the session's
open socket, the one hand-typed keystrokes already use. Newline-terminated
dispatch keeps using the ready-gated EXECUTION tier, because a line released
into a profile still blocked in `read` is consumed by that `read` -- executed
never, reported sent. The raw sender additionally refuses any carriage return or
newline, so the tier that may run before `ready` cannot submit a line at all.

Interactive input only. Automated dispatch still fails in a clobbered session,
so the issue remains the record of that remaining half.

Refs kirodotdev#7657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants