Skip to content

fix(daemon): release the shell-ready barrier through a relayed shell probe - #25899

Closed
ggbdpq wants to merge 3 commits into
stablyai:mainfrom
ggbdpq:fix/shell-ready-barrier-figterm
Closed

ggbdpq wants to merge 3 commits into
stablyai:mainfrom
ggbdpq:fix/shell-ready-barrier-figterm

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

ELI5

If your shell startup files hook into Kiro CLI's terminal relay, every new Orca terminal or agent with a startup command sat frozen for exactly 15 seconds — the command only ran after a safety timeout expired, even though the shell was visibly up and prompting inside the relay. This PR teaches Orca's readiness probe to look one level deeper: when the process in front isn't the shell itself but a relay, Orca checks whether the relay's own shell child is real, legitimate, and prompting — and releases the command as soon as that's true (measured at ~0.3s instead of 15s).

What Changed

  • ShellPromptReadinessProbe gains a relayed-shell branch. The direct path is byte-for-byte the old logic (outer tty is a line editor + foreground exe is the launched shell from a legitimate install). When that direct path does not pass, the probe enumerates the foreground process's direct children (ps -axo pid=,ppid=, bounded) and releases only when a child
    1. runs the expected shell from an install this pane's own PATH resolves (same identity standard as the direct path), and
    2. is foreground on its own tty (stat contains +), and
    3. that inner tty shows line-editor discipline (stty, via the existing parseLineEditorState).
  • SessionShellReadyBarrier and the marker fast path are untouched. The generation/disposed invalidation checks wrap every new await. Normal shells (no relay) never run the extra ps.

Why

The barrier exists so injected commands never land in something that isn't a shell — the sqlite3 guard case (an exec-replaced REPL must not read our command as SQL) is load-bearing and its negative test stays. Kiro's relay breaks the direct check's premise: the foreground exe is the relay binary, and the real shell lives on the relay's inner pty. The three-part child check preserves the barrier's exact paranoia one level down — a child that is merely named zsh, or foreground but not in line-editor mode, still refuses. Setting Q_TERM (the #24933-adjacent idea) was rejected because that issue explicitly wants Orca to not set it; this fix needs no environment changes.

Linked Issue

Fixes #25586

Visual Proof

N/A for attached media in this environment (headless run), but the reproduction is real, not mocked: a new daemon-level integration test builds the reported shape with script(1) — a .zprofile that execs a relayed inner zsh — and asserts the queued command is released and no shell-ready-timeout is logged. Before the fix that case timed out waiting for output (the full 15s); after, it completes in ~0.3s.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Commands actually run locally (macOS): the new integration case red before (PTY output wait timed out) / green after (271ms); the probe suite grew from 16 to 23 tests with zero changes to existing assertions (both relay shapes, inner-non-line-editor refusal, no-shell-child refusal, dispose invalidation, retry-cap); 13 related suites all green (daemon session/shell-ready 116 passed + 3 skipped, PTY startup delivery, agent-startup prompt latency, local PTY shell readiness, shared shell-process-readiness 44, process table, terminal host, relay pty launch 57); pnpm tc exit 0; oxlint/oxfmt --check clean on all four touched files. Real kiro-cli-term was not available — the relay structure was reproduced with script(1) per the issue's own figterm-style framing, and both possible outer-tty states (lnext kept / lnext undefined) are covered by tests.

AI Disclosure

Investigation, coding and verification by GLM-5.3-Flash (ZCode agent); orchestrated, reviewed and committed by a main agent with the same model, human overseeing.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

macOS-verified; the tty-name mapping assumes the standard darwin/Linux layouts (/dev/ttysNNN, /dev/pts/N — darwin tested, Linux is the standard shape). The relay branch adds at most 4 bounded ps sweeps (~0.3s each, async) only when the direct check fails, so normal shells pay nothing. Cross-platform, SSH, and wire surfaces are untouched.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 061cfe11-ed04-4a7f-a6fe-adfcc1acfb59
📥 Commits

Reviewing files that changed from the base of the PR and between fe9d78e01118ea7a3fd03b83f15b32ee19faeb49 and 65a3070aa5b27a71074d4a8b5a7c61aa8bc0eb72.

📒 Files selected for processing (2)
  • src/shared/shell-process-readiness.test.ts
  • src/shared/shell-process-readiness.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The changes add discovery for a shell launched as a relay process’s child. Prompt readiness checks now validate the relayed shell’s PTY when direct-shell readiness is not established. Tests cover relay discovery, direct and relayed readiness checks, disposal, retry limits, and startup command delivery when a zsh relay replaces the shell wrapper.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 65a30

The relayed-shell readiness change has no identified issue that needs fixing before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the daemon change: releasing the shell-ready barrier through a relayed-shell probe.
Description check ✅ Passed The description covers the problem, implementation, linked issue, testing, and checklist. The visual-proof section says media is unavailable in this environment, but the template asks for proof for be…
Linked Issues check ✅ Passed Issue #25586 requires prompt startup-command delivery when a relay replaces the shell while preserving the guard against non-shell processes. The reviewed implementation checks a relay child’s shell i…
Out of Scope Changes check ✅ Passed The update changes relay-child error handling in src/shared/shell-process-readiness.ts and adds a focused regression test. Both changes support reliable relay readiness for issue #25586. No unrelate…
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8af0600a-e2f2-4b8a-b3a2-74417d213454
📥 Commits

Reviewing files that changed from the base of the PR and between 5cf3585 and fe9d78e01118ea7a3fd03b83f15b32ee19faeb49.

📒 Files selected for processing (4)
  • src/main/daemon/repro-13767-shell-ready-marker-lost-to-exec.test.ts
  • src/main/shell-prompt-readiness-probe.test.ts
  • src/main/shell-prompt-readiness-probe.ts
  • src/shared/shell-process-readiness.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/shared/shell-process-readiness.ts Resolved
…probe

When a startup profile `exec`s into a terminal relay (kiro-cli-term,
figterm-style shell integration), the foreground process is no longer
the launched shell and the wrapper's orca-shell-ready marker never
arrives — so SessionShellReadyBarrier held every startup command for
the full 15-second timeout even though the real shell was up and
prompting inside the relay's own pty.

The shell-prompt readiness probe now detects that shape: when the
direct identity check does not pass, it enumerates the foreground
process's direct children and releases when one runs the expected
shell from a legitimate install AND is foreground on its own tty AND
that tty shows line-editor discipline. The sqlite3-style guard is
preserved — no shell child, no release, same 15s timeout as today —
and the marker fast path is untouched.

Fixes stablyai#25586

Generated-by: GLM-5.3-Flash (ZCode)
A relay child listed by the first ps scan can exit before its own
probes run; the resulting ps/readlink/realpath rejection aborted the
whole child loop, so a valid relayed shell later in the list was never
checked and the probe attempt was silently lost. Each child's probe
sequence now skips on error, matching the existing missing-tty
continue semantics.

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq
ggbdpq force-pushed the fix/shell-ready-barrier-figterm branch from 65a3070 to 5d6879c Compare October 13, 2026 04:27
@ggbdpq

ggbdpq commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main to clear the conflict from #27729 (lsof non-blocking args).

One rebase fallout needed a fix (5d6879c312): that change added a real-process lsof smoke test to shell-process-readiness.test.ts, and this PR's execFile mock reset to a bare vi.fn() in beforeEach, so the smoke test never resolved (30s timeout). The mock now falls back to the real child process when a test stages nothing, wrapping the real callback's string stdout to the { stdout } shape the promisified call convention uses. The suite is 9/9 with the new upstream test included.

Verified: shell-process-readiness.test.ts 9/9 (including upstream's new real-lsof smoke test), shell-prompt-readiness-probe.test.ts 23/23, typecheck:node clean, oxlint/oxfmt clean. Note: the repro-13767-shell-ready-marker-lost-to-exec suite (real zsh/bash PTY integration) currently times out on every real-shell case on this machine — plain main shows the same failures (13 on both), so I could not re-confirm those cases green locally this round; no code path they cover was touched by the rebase.

… execFile mock

Rebase fallout from stablyai#27729: upstream added a smoke test that drives the real
lsof, and the execFile mock in this file previously reset to a bare vi.fn(),
so that test never resolved. The fallback wraps the real child process to the
mock's callback convention ({ stdout }) because the source promisifies
execFile and staged tests model the promisified result.

Found by the rebase onto main; 9/9 in the suite.
nwparker added a commit that referenced this pull request Oct 25, 2026
…term relay (#33495)

Release queued startup input when a figterm-style relay (Kiro CLI's kiro-cli-term) exec-replaces the shell: if the pane's foreground process isn't a shell, accept a direct child that is the expected shell, foreground on its own tty, at an editable prompt. Startup with Kiro shell integration drops from a 15s timeout to <1s.

Fixes #25586
Supersedes #25899

Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @ggbdpq! Your commits were carried into #33495 (merged, with your co-author credit), rebased and slimmed down (shared shell-identity check, child tty read from the existing ps call). Closing this one in favor of it.

@nwparker nwparker closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 15s freeze on terminal startup commands when Kiro CLI / figterm is installed (shell-ready-timeout)

2 participants