Skip to content

fix(terminal): prove an idle Git Bash prompt through its bin launcher - #22752

Merged
Jinwoo-H merged 8 commits into
mainfrom
gitbash-shell-proof
Sep 25, 2026
Merged

Jinwoo-H merged 8 commits into
mainfrom
gitbash-shell-proof

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​333 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​322
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​93

ELI5

Before Orca cleans up after a full-screen program that crashed, it checks that nothing but the shell is running in the pane. For Git Bash on Windows that check always said "something else is running", so the cleanup never happened. Now the check knows what an idle Git Bash pane looks like.

What Changed

Before: in a Git Bash pane on Windows, if a program turned on mouse reporting and exited without turning it off (for example printf '\033[?1003h\033[?1006h', or a TUI that crashed), mouse reporting stayed on at the next prompt. Moving the mouse printed escape codes into the prompt. PowerShell and cmd panes were already cleaned up.

After: Git Bash panes get the same cleanup as PowerShell and cmd.

Mechanism: On Windows, Orca decides "only the shell is running" by reading the pane's job object (the set of processes Orca started for that pane). The rule was "the job holds exactly one process: the shell". An idle Git Bash pane never has just one process. Orca starts C:\Program Files\Git\bin\bash.exe -c "chcp.com 65001 ...; exec \"$BASH\" ... -i", and two things add processes:

  • bin\bash.exe is a small launcher. It starts ..\usr\bin\bash.exe as a child and waits for it.
  • In MSYS, exec doesn't replace the process. The process that ran exec stays alive as a stub and waits for the new one.

So a real idle pane is three processes in a line: launcher → bash -c "chcp ...; exec" stub → interactive bash. That was measured in a real Orca pane.

The new rule is one check, not a list of allowed sizes. The pane counts as "only the shell" when the job is the shell alone, or when the shell is Git for Windows' bin\bash.exe launcher and every other process in the job forms one straight parent-to-child chain below it, each one a bash.exe. The last bash in the chain is the interactive shell.

  • A command at the prompt (vim, sleep, an agent) adds a process that isn't bash.exe at the end, so the check fails.
  • A background job gives the interactive shell a second child, or leaves a process outside the chain, so the check fails.
  • The check reads the identity process table (windows-process-table). That is the cheaper of the two table reads, though it still opens one limited query handle per process to get start times. It reads it only for the Git Bash launcher, and only when the job has more than one process.
  • Any job process missing from the table fails the check. So does a child whose start time is earlier than its parent's (a sign of a reused process ID; this is only checked when the table reports start times).

The local (non-daemon) provider used to keep only the shell's file name (bash.exe), which can't tell the launcher apart from usr\bin\bash.exe. It now keeps the full spawned path instead and works out the file name from it when needed. The check reads that path as a path, so a shell path with a space in it (/Users/John Doe/bin/zsh) still matches on macOS and Linux. The daemon path already passed the full path.

Known gap, accepted: a foreground bash that runs only builtins also ends the chain with bash.exe, so it counts as a prompt. Examples: a nested interactive bash, a subshell loop, or a fork caught in the instant before it becomes the real command. For a nested bash that answer is correct, since it is a shell at a prompt. In the other cases the worst outcome is resetting leftover mouse and keyboard modes early, and the program that starts next sets its own modes afterwards.

Why

Other options I considered:

  • Launch usr\bin\bash.exe directly, without the launcher. This removes the extra process, but the launcher does more than wait. Measured on Windows: through the launcher, MSYSTEM=MINGW64, PLINK_PROTOCOL=ssh, and /mingw64/bin comes first on PATH. Launched directly, all three are missing. Orca would have to copy the launcher's environment setup and keep it matching future Git for Windows releases, and every Git Bash user's shell environment would change. That is a lot of risk to fix a detection rule.
  • Allow fixed shapes (2 or 3 processes). The first version of this PR allowed exactly [launcher, bash]. That never matched a real Orca pane, which has an extra exec stub. The count depends on how many execs the startup command does, so a fixed count is fragile. The chain rule describes why the processes exist and holds for any number of stubs.
  • Apply the chain rule to any bash.exe, not just the launcher. A usr\bin\bash.exe that the user started directly with a forked subshell has the same shape, and nothing Orca launched explains it. So the rule applies only to the launcher.

Linked Issue

None. Found while investigating the terminal shell-recovery cleanup (the scroll-freeze work). Measured in a real Orca Git Bash pane on Windows: the idle job holds [launcher, bash -c "chcp ...; exec" stub, interactive bash].

Visual Proof

N/A. The change is in a process check with no UI. The Windows test below exercises the real launcher.

Testing

  • Unit tests (agent-foreground-process-git-bash-launcher.test.ts, fake job and process table) cover:

    • These confirm: the real idle chain (launcher → exec stub → bash), the plain hand-off, a nested bash, and a fork caught before its exec.
    • These fail: a command at the prompt (directly, or under a fork stub), a background job (branching, or an orphan outside the chain), a non-bash process in the middle of the chain, a job process missing from the table, a child older than its parent, a process ID reused by an unrelated process, an unreadable table, and a job that doesn't contain the launcher.
    • A directly launched usr\bin\bash.exe and PowerShell never read the table.
  • git-bash.test.ts: the launcher-path check. local-pty-child-process-verdict.test.ts: the local provider passes the full spawned path.

  • Windows-only test agent-foreground-process-git-bash.win32.test.ts, on the Windows CI list. It builds the pane with Orca's own daemon launch code (createDaemonPtyEnvironment, createPtyShellLaunchPlan with shellOverride: 'git-bash', spawnNativeDaemonPty) and checks it through the daemon's confirmPtyShellForeground. It runs twice: once with the plain --login startup, and once with Orca's --rcfile wrapper (Codex preflight set). At the idle prompt the job has 3 processes and the check passes. sleep 60 fails it, Ctrl-C passes it again, and sleep 60 & fails it. Passed on a real Windows 11 machine with Git for Windows, along with windows-msys-job.win32.test.ts.

  • pnpm tc:node passes, oxlint is clean, and check:code-quality:changed passes.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

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

  • Windows only. The macOS and Linux paths are unchanged, apart from the local provider now passing the full shell path. That check already accepted full paths such as /bin/zsh.
  • SSH: unchanged. Remote panes are checked on the remote host.
  • Not in scope: the cached-agent job check (judgeCachedAgentJobEvidence, "the shell is alone, so retire the cached agent") has the same one-process assumption. For Git Bash it falls through to the regular process scan, so it's slower but still correct.

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)

Git for Windows' bin\bash.exe is a launcher that runs usr\bin\bash.exe as a
child and waits, so an idle Git Bash pane's job always holds two pids and the
Windows shell proof never confirmed it. Accept exactly the launcher plus its
direct bash.exe child, checked against the identity process table.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Launcher predicate — isGitForWindowsBashLauncherPath (git-bash.ts) matches Git for Windows' bin\bash.exe and excludes usr\bin\bash.exe, with unit coverage for both the launcher and the MSYS binary.
  • Shell-alone proof — isWindowsShellAloneInJob (agent-foreground-process.ts) keeps the one-process path unchanged and adds exactly one accepted shape: the spawned path is the launcher, the job holds two processes, and the second is a direct bash.exe child of the launcher. Any other shape, an unreadable table, or a missing row fails closed. The table is only consulted in that one shape.
  • Local provider wiring — ptyShellPath records the post-fallback spawned path in activateLocalPtySession and the confirm path now uses it instead of the basename, so the launcher is distinguishable; it is cleared alongside ptyShellName in clearPtyState. The daemon path already passed the full path.
  • Tests — new unit suite for the accepted/refuted job shapes and the "never reads the table for other shells" contract, a predicate test in git-bash.test.ts, a local-provider contract test pinning the full path, and a Windows-only integration test against the real launcher added to the Windows CI list.

I verified pnpm tc:node is clean and the four touched non-Windows suites pass locally (85 tests); the Windows integration suite is skipped here but is wired into the Windows job. The existing powershell.exe, null-job, and rejecting-reader tests still pass because size 2 + a non-launcher path falls through to false.

ℹ️ The process-table caller inventory omits the new reader

The "Which callers need which" table in docs/reference/windows-process-enumeration.md is the doc's inventory of who reads the process table and on which flag set, but it does not list the identity read this PR adds in agent-foreground-process.ts. Non-blocking, but the table is otherwise exhaustive and future maintainers use it to reason about the identity/detailed split.

Technical details
# Add agent-foreground-process.ts to the caller table

## Affected sites
- `docs/reference/windows-process-enumeration.md:167-185` — "Which callers need which" table
  does not include the new `readWindowsProcessIdentityTableFresh` caller.

## Required outcome
- The table lists `agent-foreground-process.ts` as an identity-flag reader
  (`pid` / `ppid` / `name`, fresh), with a one-line note that it is only reached for an
  accepted Git Bash launcher shape.

## Open questions for the human
- Optional; the table is an inventory rather than a contract, so this can be deferred.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 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: d1810efe-8682-422f-801f-35e8284559c3

📥 Commits

Reviewing files that changed from the base of the PR and between 93652fa and 2cd1fde.

📒 Files selected for processing (10)
  • src/main/git-bash.ts
  • src/main/providers/agent-foreground-process-shell-path.test.ts
  • src/main/providers/agent-foreground-process.ts
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-foreground-inspection-cheap-tier.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider-state.ts
  • src/main/providers/local-pty-session-activation.ts
  • src/main/providers/local-pty-session-operations.ts
  • src/main/providers/windows-shell-alone-in-job.ts
💤 Files with no reviewable changes (1)
  • src/main/providers/local-pty-session-activation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/providers/local-pty-provider-state.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change records each local PTY’s spawned shell path and passes it to foreground confirmation. Windows job validation now accepts a shell-only job or a Git for Windows Bash launcher with its verified bash.exe child. Unit and Windows integration tests cover these process shapes and shell states. The Windows package test run now includes the Git Bash foreground-process integration test.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 2cd1f

The Git Bash idle-prompt change is mergeable on the supplied evidence; its Windows test has the required launcher on the configured runner.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 2cd1f

The new Git Bash check enables cleanup at an idle prompt, but it can also mistake a running nested Bash process for an idle shell. The identified effect is limited to terminal state in the affected pane; no privilege or cross-user exposure is established.

Retained concerns

  • Low · reliability · inferred: A linear Bash process chain can be confirmed as an idle prompt while a nested Bash is still running. If an unclean terminal-recovery episode occurs then, the recovery barrier may reset terminal modes and mark shell ownership prematurely.
Security review details

Security Blast Radius

  • inferred — The identified false-positive path affects terminal recovery for a Windows Git Bash PTY. The inspected flow does not establish a cross-user, cross-tenant, or privilege-changing outcome.

Security Findings and Attack Paths

  • inferred — A process able to run inside its Git Bash pane may be treated as part of the shell chain if it presents the expected process name and linear parentage. A deliberately renamed application's behavior and a security impact from that misclassification have not been verified.

Trust Boundaries and Controls

  • observed — The check requires the launched shell PID in the job, rejects missing identity rows, branches, non-Bash children, and children known to predate their parent; inspection errors return false. These controls do not distinguish an active nested Bash from the interactive prompt.

Resilience and Maintainability Implications

  • observed — Windows integration coverage checks an idle Git Bash prompt, a running foreground command, a background command, and confirmation after interruption. It does not resolve the separately acknowledged nested-Bash ambiguity.

Hardening Proposals

  • proposed — Before treating a Bash-only chain as an idle prompt, seek independent evidence of the foreground shell's state, or retain the fail-closed result when that state cannot be distinguished from a running nested Bash. Include a renamed active executable in validation of the process-name assumption.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 14 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, platform impact, and checklist. However, the required Linked Issue is explicitly marked as "None," and the required issue referen… Add the issue number or link that this pull request addresses. If CI will run the unchecked lint, typecheck, test, and build commands, state that explicitly; otherwise provide their results.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: validating idle Git Bash prompts through the Windows launcher.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, platform impact, and checklist. However, the required Linked Issue is explicitly marked as "None," and the required issue reference is missing.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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: 8986afb7-5659-45bc-8534-c5316f7b2e25

📥 Commits

Reviewing files that changed from the base of the PR and between 9678dfb and ff1da52.

📒 Files selected for processing (10)
  • .github/workflows/pr.yml
  • src/main/git-bash.test.ts
  • src/main/git-bash.ts
  • src/main/providers/agent-foreground-process-git-bash-launcher.test.ts
  • src/main/providers/agent-foreground-process-git-bash.win32.test.ts
  • src/main/providers/agent-foreground-process.ts
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider-state.ts
  • src/main/providers/local-pty-session-activation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Orca launches Git Bash as bin\bash.exe -c "chcp.com ...; exec \"$BASH\" ... -i",
and each MSYS exec leaves its pre-exec process alive as a stub, so an idle
pane's job is launcher -> stub -> interactive bash. Accept any job that is one
parent-to-child chain rooted at the launcher whose every later member is
bash.exe, instead of a fixed two-process shape.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (ff1da52), the author found the real idle shape is three processes, not two, and reworked the proof:

  • Chain-based shell proof — isWindowsShellAloneInJob moved into a dedicated windows-shell-alone-in-job.ts and now accepts one unbranched parent-to-child chain rooted at the launcher, every later member named bash.exe, instead of a fixed two-process shape. It adds a startedBefore pid-reuse guard; branches, non-bash links, missing rows, and non-launcher shells still fail closed. The identity table is read only for a launcher pane whose job holds more than one process.
  • Unit suite rewrite — covers launcher → exec stub → bash, the bare hand-off, nested/forked bash leaves, branches and orphans, missing/older/reused rows, and the "table never read for other shells" contract.
  • Windows integration test rewrite — now drives Orca's real launch plan (createPtyShellLaunchPlan + spawnNativeDaemonPty) for both the login shell and the Codex --rcfile wrapper, asserting the idle three-process job and then refuting sleep 60 and sleep 60 &.

I verified pnpm run typecheck:node is clean and the touched non-Windows suites pass (41 tests across the launcher unit, git-bash, and local verdict suites; 66 across the surrounding shell-proof suites). The Windows suite is skipped here but is wired into the Windows job.

The accepted residual — a foreground bash running only builtins reads as an idle prompt — is documented in the function's doc-comment and blessed in the test, so it is a stated trade-off rather than a defect.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (32eaa9e), the only new commit registers the Git Bash shell-proof test in the second of the two Windows lane lists:

  • Windows scope registration — added src/main/providers/agent-foreground-process-git-bash.win32.test.ts to WINDOWS_PACKAGE_TESTS in config/scripts/pr-code-change-scope.mjs:270, mirroring its existing entry in the .github/workflows/pr.yml Windows lane (pr.yml:988). This closes the classifier half of the dual-registration contract enforced by config/scripts/win32-test-lane-registration.test.mjs — WINDOWS_PACKAGE_TESTS decides whether the package_windows job runs for a diff, and the file was previously in the lane argv only. Ordering is immaterial (Array.includes), and both lists keep the entry after windows-msys-job.win32.test.ts.

The substantive chain proof (windows-shell-alone-in-job.ts) and its unit/integration coverage were reviewed and cleared in the prior run; no production code paths changed here.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

A spawned shell path with a space (/Users/John Doe/bin/zsh) was split as a
command line, so the POSIX proof compared against "john" and never
confirmed. Local panes now keep only the spawned shell path and derive the
name from it; the Git Bash chain walk drops guards the member check already
covers.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (69d807bd0), the head 2cd1fdec4c fixes a real space-in-path bug and consolidates the shell state:

  • Spawned shell read as a path — the POSIX branch of confirmShellForegroundProcess now basenames spawnedShellProcess with split(/[\\/]/).pop() instead of executableBasename, which parsed it as a command line and truncated /Users/John Doe/bin/zsh to john. This is the fix for CodeRabbit's login-wrapper concern and covers both the local (ptyShellPath) and daemon (args.shellPath) callers, both of which pass an unquoted path. executableBasename remains in use for the process-table row.command values, so it is not dead.
  • One shell map — the independent ptyShellName map is removed; ptyShellPath (plan.shellPath) is now the single source of truth and getPtyShellName(id) derives the basename via getSpawnedShellName. All readers (local-pty-foreground-inspection.ts, local-pty-session-operations.ts) and the clear path are updated; no stale ptyShellName reference remains.
  • Launcher predicate rewritten — isGitForWindowsBashLauncherPath is now a direct regex equivalent to the old isGitForWindowsBashPath && !endsWith('\usr\bin\bash.exe'), decoupling it from the broader predicate.
  • startedBefore refactor — takes numeric start times from a startMsByPid map built from the member rows; behavior is unchanged because every parent pid is a member.
  • Regression test — agent-foreground-process-shell-path.test.ts drives the real POSIX confirmation with a space-bearing path; it fails before the fix.

Verified pnpm tc:node clean, oxlint clean on the changed source files, and 96 tests across the seven touched suites pass. The Windows integration suite is skipped on this host but is wired into both Windows lane lists.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit a05649d into main Sep 25, 2026
30 checks passed
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.

1 participant