Skip to content

fix(terminal): detect foreground from the physical PTY owner - #36342

Merged
brennanb2025 merged 10 commits into
mainfrom
brennanb2025/lu-foreground-detect
Nov 1, 2026
Merged

brennanb2025 merged 10 commits into
mainfrom
brennanb2025/lu-foreground-detect

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1085 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1083
Prod 44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1010 $\color{#cf222e}{\Huge{\mathbf{−}}}$​185 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​825

ELI5

A running terminal agent can currently refuse its first task because another retained terminal daemon cannot be inspected, or because Orca remembers an outdated terminal for a reused process ID. This change reads the foreground process group from the terminal itself, at the process that owns it. A healthy target no longer depends on unrelated terminal inventory or a stale PID-to-terminal cache.

What Changed

  • POSIX foreground detection reads the live PTY master's foreground group and resolves its runnable members using a strict, terminal-scoped process capture. A dead group leader or missing root row does not hide a running member. Incomplete, truncated, malformed, or incoherent captures remain unknown.
  • Daemon and in-process terminals share the detector. Display and name refreshes resolve the master group against the existing shared process snapshot (no per-terminal process scan); only an admission decision takes a fresh terminal-scoped capture. Resize uses the same master-group source while retaining its own-terminal and lifetime protections.
  • Admission inspection routes to the established target owner, including in degraded mode (in-process terminals beside an unreachable daemon). Ordinary inspection, stop verification and liveness checks keep their existing routing and errors. Filtered inventory never replaces the complete inventory or retires omitted sessions. Results and reused input proof are discarded when the target session or incarnation changes.
  • Additive protocol 55 inspection fields carry the foreground observation independently of child-census and destructive-action evidence. Older owners use target-scoped metadata and fresh root/TTY proof, without a minimum version or forced restart.

The existing shell/unknown admission rules and refusal text remain. Local non-shell admission still accepts user wrappers without requiring provider recognition. User-entered commands, aliases, shell functions, and launch commands are unchanged. No settings or saved fields are added.

Why

The common pattern starts with the physical terminal owner's master descriptor. Reconstructing that authority from a global application inventory lets one unrelated failed owner block a healthy terminal; caching terminal names by numeric PID also confuses PID reuse. The owner-held descriptor removes those dependencies. Strict capture validation prevents partial output from becoming positive evidence.

This repairs the confirmed failure class. The historical macOS coordinator-rebind and Linux daemon-update reports do not contain the PID/TTY traces needed to isolate their exact trigger, so this PR does not claim those incidents were faithfully reproduced. Foreground detection and a subsequent terminal write remain non-atomic: an agent can exit between them. The existing shell-return watcher and guarded input policy remain; this does not claim recipient-bound delivery.

Differences from the common pattern:

  • Same as the common pattern: the terminal's owner reads the foreground process group from its own live terminal descriptor, resolves the group's live members, and treats an unreadable or non-positive group as unknown. Managed SSH and WSL hosts run this in their own runtime; desktop process IDs are never used as remote process authority.
  • Intended (owner ruling; returned-shell protection from feat(agent-launch): keep long prompts off the launch line and paste them after readiness (step 1 of 7) #24257): automated task delivery (worker start, dispatch preamble, launch prompt, connector prompts) writes only after the terminal's current foreground is shown to be a non-shell program. A proved shell, and on local macOS/Linux an unknown result, refuse before any task bytes. On local hosts any non-shell member counts, so user wrappers, aliases and shell functions keep working. The common pattern writes typed and automated input without a foreground check; ordinary keystrokes in Orca stay direct.
  • Intended (a decision admits an automated write): a decision sample reads the group before and after its process capture and rejects incomplete, malformed or incoherent captures, with at most one reread inside the existing three-second deadline. The common pattern takes one sample because it only uses the result for display or to offer UI.
  • Intended (terminal daemons outlive app updates, so several owners can exist): the query is routed to the owner that established the terminal. A terminal whose owner cannot be established, or whose owner or incarnation changes during the read, is unknown and refused like any other unknown. In the common pattern the process holding the terminal is always the one asked.
  • Intended (mixed versions): older POSIX daemons and native modules use a fresh, target-scoped root/TTY read with no process-ID cache. Missing ownership, PID, TTY or process visibility stays unknown. No minimum version or restart is required.
  • Intended (mixed versions): an already-installed older client keeps its own caller-side inventory check until it updates; the new daemon stays compatible with it.
  • Intended (existing gap; the common pattern has no Windows equivalent): Windows/ConPTY keeps its current console/job/process-tree evidence and admission policy. A local Windows pane running wsl.exe still cannot prove the guest's foreground.
  • Intended (mixed versions; existing gap): retained relay-era SSH panes have no foreground channel and keep their existing bridge and policies; extending that protocol is outside this change.
  • Same as the common pattern: display names keep their existing cached polling and retention (the group's members are read from the shared, cached process snapshot); only decisions take a fresh terminal-scoped sample.

Linked Issue

Tracked in STA-9961.

Visual Proof

N/A — no visual layout or copy changes. This is the detector underneath existing terminal actions. Real terminal/agent and cross-platform QA remains for the review loop; no app run is claimed here.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

CI is green on the head, including the patched native module built for Linux glibc/musl (x64 and arm64), macOS and Windows. The native accessor test runs on the rebuilt Linux module. Contracts cover:

  • physical group and member resolution, and parity with the previous admission check across real process shapes;
  • both failing-on-main regressions: same-action recovery after PID reuse, and truncated-capture rejection;
  • malformed, timed-out and empty capture rejection;
  • a known target succeeding while an unrelated inventory is unavailable, in normal and degraded mode;
  • an unresolved owner staying unknown;
  • scoped reads never retiring omitted sessions, with stop and liveness checks keeping their existing behavior;
  • older daemons (protocols 39, 43, 54) never receiving the new request;
  • session and route replacement, shell return before Enter, and clock-step age clamping;
  • a display-refresh scaling contract: one shared snapshot per refresh round and no per-terminal scans, at N and 10N terminals.

Real-app QA used real Claude and Codex:

  • macOS: upgrade from the previous build with live hand-typed agents. The old background service was kept, its sessions re-attached and follow-ups replied. Fresh worker start for Claude and Codex then delivered and got replies with the old service still present. A launch that ends at a shell never received the task. claude, a cx() { command codex; } function and an alias were each recognized and delivered to. Redraw after a split was clean.
  • Linux (WSL-host runtime): the guest's background service loads the patched native module, and the accessor returned the right group. Claude and Codex worker start delivered before and after a graceful restart, with the same guest service and every terminal surviving. A shell launch never received the task, and the cx function was delivered to.

Review

Full path:

  1. Size: more than 150 changed production lines and more than five production files; one physical-PTY detection mechanism.
  2. Risk: native PTY lifetime, orchestration input admission, optional IPC/RPC fields, and mixed client/daemon versions.
  3. Repeat: returned-shell protection (feat(agent-launch): keep long prompts off the launch line and paste them after readiness (step 1 of 7) #24257) and recent process-reader fixes affect this mechanism.
  4. Effect: crosses the runtime, daemon, native addon, and host boundary; not a local rendering/pure-function change.

Agent skill upstream boundary

  • Not applicable; no skill-installer source or fixtures copied or translated.

Notes

Review/QA must exercise macOS and Linux fresh/rebound terminals with Claude and Codex, manual commands and an argument-dropping shell function, shell return before dispatch, follow-up/status consumers, retained owners and mixed versions, and the affected Windows/managed WSL/SSH routes. Existing folder and git workspaces and new workspaces share the detector. There is no mobile layout change; mobile reads the existing host projection.

Checklist

  • One focused mechanism; producer, routing, compatibility fallback, and consumer plumbing land together
  • Explained the before/after, mechanism, and alternative
  • Visual proof marked N/A with reason
  • Self-reviewed for correctness, security, and bounded process work
  • Cross-platform, SSH/remote, folder-workspace, and compatibility impact considered
  • CI lint/typecheck/build and required real-run QA complete

@brennanb2025
brennanb2025 marked this pull request as ready for review October 30, 2026 11:38
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f321299-33dc-4533-a89c-f9734dc4521a
Commits

Reviewing files that changed from the base of the PR and between 9201993 and 403abde.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 4
  • config/patches/[email protected]
  • src/main/daemon/daemon-pty-adapter-session-adoption.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/ipc/pty/runtime/operations.ts

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

Walkthrough

The changes add PTY foreground-process-group capture and process-table resolution, then expose validated foreground observations through local and daemon inspection paths. Inspection requests can be scoped to a PTY owner and checked against changes in session, ownership, or terminal incarnation. Runtime agent checks consume these observations and invalidate foreground proof when terminal identity changes. The daemon protocol version increases to 55.

Merge Risk: Moderate · previous review 403ab

Agent input can be accepted or refused based on a stale foreground process. Resolve the race before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description is detailed and covers the required sections, including scope, rationale, testing, compatibility, visual proof, and checklist items. However, the Linked Issue section provides only “ST… Add a valid linked issue reference, such as “Fixes #” or the repository’s supported issue link format. Reconcile the Testing section with the actual validation status, and clearly identify any checks that remain pending or are…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: detecting terminal foreground processes from the physical PTY owner.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 25 functions across 49 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description is detailed and covers the required sections, including scope, rationale, testing, compatibility, visual proof, and checklist items. However, the Linked Issue section provides only “STA-9961” and does not include an actual issue link or “Fixes #” reference. The testing claims also conflict with the PR objectives, which state that lint, typecheck, build, native compilation, and real-provider runs had not run.

Resolution

Add a valid linked issue reference, such as “Fixes #<issue-number>” or the repository’s supported issue link format. Reconcile the Testing section with the actual validation status, and clearly identify any checks that remain pending or are covered only by CI.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58fa6438-25dd-4ed9-9648-113546cbf9d0
Commits

Reviewing files that changed from the base of the PR and between ab50d78 and d067f3b.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 63
  • config/patches/[email protected]
  • src/main/daemon/daemon-foreground-process-protocol.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/daemon-pty-adapter-session-adoption.test.ts
  • src/main/daemon/daemon-pty-adapter-steady-state-compat.test.ts
  • src/main/daemon/daemon-pty-process-inspection.ts
  • src/main/daemon/daemon-pty-router-inventory.test.ts
  • src/main/daemon/daemon-pty-router-test-fixture.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-pty-session-inventory.ts
  • src/main/daemon/daemon-pty-target-inspection.ts
  • src/main/daemon/daemon-request-router.ts
  • src/main/daemon/daemon-session-owner-resolution.ts
  • src/main/daemon/pty-subprocess-foreground-identity.test.ts
  • src/main/daemon/pty-subprocess/spawn-file-foreground-process.ts
  • src/main/daemon/pty-subprocess/subprocess-handle.ts
  • src/main/daemon/session-process-inspection.ts
  • src/main/daemon/session-subprocess-handle.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-process-inspection.test.ts
  • src/main/daemon/terminal-host-process-inspection.ts
  • src/main/daemon/terminal-host-session-inspection-operations.ts
  • src/main/daemon/terminal-host.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/ipc/pty/runtime/controller.ts
  • src/main/ipc/pty/runtime/inventory-operations.ts
  • src/main/ipc/pty/runtime/operations.ts
  • src/main/providers/local-pty-provider-foreground-process.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/local-pty-session-operations.ts
  • src/main/providers/pty-foreground-confirmation.ts
  • src/main/providers/pty-process-inspection.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/pty/posix-pty-foreground-group.test.ts
  • src/main/pty/posix-pty-foreground-group.ts
  • src/main/pty/pty-master-foreground-native.test.ts
  • src/main/pty/pty-master-foreground-observation.test.ts
  • src/main/pty/pty-master-foreground-observation.ts
  • src/main/pty/terminal-process-rows.ts
  • src/main/runtime/launched-agent-foreground.test.ts
  • src/main/runtime/launched-agent-foreground.ts
  • src/main/runtime/launched-agent-write-guard.test.ts
  • src/main/runtime/launched-agent-write-guard.ts
  • src/main/runtime/rpc/methods/terminal/terminal-inspect-process-params.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-query-methods.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/session-tabs/runtime-terminal-process-inspection.test.ts
  • src/main/runtime/session-tabs/runtime-terminal-process-inspection.ts
  • src/main/runtime/session-tabs/structured-session-tab-restoration.ts
  • src/main/runtime/terminal-foreground-capture.test.ts
  • src/main/runtime/terminal-foreground-group.ts
  • src/main/runtime/workspaces/workspace-activation.ts
  • src/main/runtime/workspaces/workspace-foreground-inspection.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/shared/libproc-argv-completion.ts
  • src/shared/libproc-process-table.test.ts
  • src/shared/libproc-process-table.ts
  • src/shared/process-table-snapshot.ts
  • src/shared/rpc-contract/terminal-unary-params.ts
  • src/shared/terminal-foreground-observation.ts
  • src/shared/terminal-process-inspection.ts

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

…ics around master-group foreground

Review round 1 fixes for the physical-owner foreground observation:

- Stop and liveness verification keep complete-inventory proof: the router's
  scoped listProcesses({ptyIds}) is owner resolution again (absent = []).
  Only the launch guard's old-owner fallback asks for an established
  target's owner via an internal targetOwnerOnly option.
- Degraded daemon mode routes foreground observations and target reads to
  the established owner, so an unreachable unrelated daemon cannot refuse a
  known terminal there either.
- Display and name refreshes read the master's foreground group but take
  member rows from the shared single-flight process-table snapshot; no
  per-terminal ps per refresh. Recognized agent names skip the confirm scan
  again, and builds without the native accessor keep the existing reader.
- Ordinary inspections keep their first-match routing; strict owner and
  incarnation checks apply only to foreground decisions. The unused
  foregroundOnly preload/IPC/RPC surface is removed.
- Local inventory forwards only the target scope, never caller deadlines.
- An interpreter running an agent script counts as that agent, as before;
  a blank argv row no longer voids a terminal capture outside the
  foreground group.
- Bump the packaged compatibility contract to daemon protocol 55 and move
  the node-pty accessor above the process getter's doc comment.

@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: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e16843f2-3187-470c-af08-fe0991779cb4
Commits

Reviewing files that changed from the base of the PR and between d067f3b and 9474341.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 24
  • config/patches/[email protected]
  • src/main/daemon/daemon-pty-adapter-session-adoption.test.ts
  • src/main/daemon/daemon-pty-router-inventory.test.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-pty-session-inventory.ts
  • src/main/daemon/daemon-pty-target-inspection.ts
  • src/main/daemon/degraded-daemon-owner-recovery.ts
  • src/main/daemon/degraded-daemon-pty-provider.test.ts
  • src/main/daemon/degraded-daemon-pty-provider.ts
  • src/main/daemon/pty-foreground-display-scan-scaling.test.ts
  • src/main/daemon/pty-subprocess/spawn-file-foreground-process.ts
  • src/main/daemon/terminal-host-process-inspection.test.ts
  • src/main/ipc/pty/runtime/inventory-operations.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/pty/pty-master-foreground-observation.test.ts
  • src/main/pty/pty-master-foreground-observation.ts
  • src/main/runtime/launched-agent-foreground.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/terminal-foreground-capture.test.ts
  • src/main/runtime/terminal-foreground-group.ts
  • src/main/runtime/workspaces/workspace-foreground-inspection.ts
  • src/shared/local-build-compatibility-contract.json
  • src/shared/local-build-compatibility-contract.ts
  • src/shared/process-table-snapshot.ts
Files skipped from review as they are similar to previous changes: 1
  • src/main/daemon/terminal-host-process-inspection.test.ts

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

Comment thread config/patches/[email protected] Resolved
…ndant foreground tests

Remove two stray context lines from the src/unixTerminal.ts hunk so its body
matches its header (strict patch parsers reject the mismatch), and update the
lockfile patch hash. Prune foreground tests whose rows repeat branches the
parity table already covers.
…tion age nonnegative

Display refreshes filtered the whole shared process table per pane, so
work grew with panes times processes. Group each snapshot by normalized
TTY once, memoized by array identity, and look each pane up directly;
the scaling contract now counts row TTY reads at N and 10N panes.

Both foreground observation producers clamp capturedAgeMs at zero, so a
wall-clock step back during the read no longer yields an envelope the
validator rejects and the launch guard refuses.
…atibility suite

Main removed daemon-pty-adapter-steady-state-compat.test.ts; the merge restored it with only this branch's block. Reuse the suite's existing inspection adapter helper so no new type assertion is added.
@brennanb2025

brennanb2025 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Review loop status — ready

The problem. Starting a worker on an agent could fail with agent_not_in_foreground even though the agent was running and idle. Before Orca types a task into a freshly launched agent, it checks that an agent, not a bare shell, owns the terminal's foreground. On main, that check rebuilt the answer from every terminal background service's inventory, then mapped a root process ID to a terminal through a cache keyed only by process ID. One unreadable, unrelated service (for example the previous version's service kept alive across an app update), a reused process ID, or a truncated ps capture made the answer "unknown". On macOS and Linux, unknown refuses the task.

The change users get. The process that owns the terminal now asks the terminal itself which process group is in the foreground (a new native accessor on the PTY), then resolves that group's live members. A healthy terminal no longer depends on unrelated services or a stale cache. A real shell in the foreground is still refused, and user-typed agents, aliases and shell functions are still accepted. No settings, saved data or copy changed.

What review fixed (4 review rounds, 1 decider ruling; ledger has the full list):

  • Stop and liveness checks (close tab, sleep or delete a worktree) briefly read a stopped terminal as "gone" when an old service was present. They now keep main's behavior.
  • The packaged app's compatibility contract was still at the old protocol number, so the packaged background service rejected the app. It is now in line.
  • Degraded mode (terminals running in-process beside an unreachable service) now uses the same owner-routed check.
  • Display and name refreshes no longer run a ps per terminal or scan the whole process table per terminal. Each refresh reads one shared snapshot, indexed by terminal. Perf contract tests cover both.
  • Local inventory no longer inherits callers' short deadlines. Ordinary inspection keeps main's routing.
  • An interpreter running an agent script still counts as an agent. A negative age after a clock step can no longer refuse a launch. Malformed patch hunk and redundant tests were fixed.

Deferred (P3, none user-visible): a re-export shim; Windows reporting a capability it never delivers (no caller relies on it); two test-assertion nits; and a bot review note about a fresh display read whose group can move while its snapshot is captured. That one was checked: decision reads use the existing resolver (pty-foreground-confirmation.ts:46-48) and admission takes its own coherent capture, so at most one display refresh lags.

Verified

  • CI green on the head 57bbc0b05c7, including the patched native module built for Linux glibc/musl (x64, arm64), macOS and Windows, and the native accessor test on Linux. Unrelated flakes were rerun once each and passed: a chat-worker fake-timer test, a Windows SSH e2e temp-folder cleanup (EPERM), the Windows compiler probe (runner timeout at 15 minutes), and two almalinux8 SSH matrix cells (15-minute timeouts); on 57bbc0b05c7, the same chat-worker fake-timer test again and a macOS persistence job whose artifact download timed out before any test ran.
  • Real-app QA on macOS with real Claude and Codex, against 92019936aff. Since then the branch has only merged main (403abde3c6c, a25fea0db8d with conflict resolutions checked by a separate reviewer, 93172142d13) and moved a test (d5fdf7ac4ff). The latest merge, 57bbc0b05c7 (318 main commits), had three conflicts, all in imports or tests main had pruned; a separate reviewer checked each resolution and main's new code and found main adds no caller or implementer of what this PR changes, so the QA below still holds:
    • Upgrade with live agents (the reported scenario's shape): from main (protocol 54) with hand-typed Claude and Codex running. The old service was kept beside the new one, every session re-attached with the same processes, and follow-ups got replies.
    • Fresh worker start for Claude and Codex then delivered the task and got a reply, with the old service still present. No agent_not_in_foreground.
    • Native accessor: present in the PR build and loaded by the new service. It returned the agent's group, and nothing once the terminal closed.
    • A launch that ends at a shell never receives the task. The existing readiness wait stops it first; that code is unchanged.
    • Typed agents: claude, cx() { command codex; } and alias cc=claude were each recognized and received tasks.
    • Redraw after a split was clean. Real agent configs were unchanged.
  • Real-app QA on Linux, against 93172142d13 (the head before the latest main merge), using a WSL-host runtime with real Claude and Codex:
    • The guest's background service (protocol 55) loads the patched native module, and the accessor returned the right group.
    • Claude and Codex worker start delivered the task and got replies, both before and after a graceful restart. The same guest service survived, as did every terminal.
    • A shell launch never received the task.
    • The cx() Codex was recognized and delivered to.
    • One observation, not caused by this PR (traced): after Codex exits in a remote-host pane, the tab keeps Codex's icon for up to 30 minutes, because nothing on the host retires Codex's hook row. That's existing behavior in code this PR doesn't touch.

Not verified: the historical reports' exact trigger. They carry no process or terminal traces, so this fixes the confirmed failure class without claiming those incidents were reproduced. The check-then-write race (an agent exiting between the check and the write) is unchanged and stated in the PR body.

For Brennan's review

Fresh worker: Claude Fresh worker: Codex Upgrade: old sessions re-attached
f1-claude.png f1-codex.png f2-adopted.png
Follow-up into re-attached Codex Launch ending at a shell gets no task cx() { command codex; } Redraw after split
f2-followup-codex.png f3-shell-refused.png f4-cx.png f6-after.png
Linux: fresh worker, Codex Linux: after restart, sessions back Linux: fresh worker after restart, Claude Linux: cx() Codex
f5-f1-codex.png f5-post-adopted.png f5-post-f1-claude.png f5-f4b-cx.png

Spots where human judgment matters:

  1. pty-master-foreground-observation.ts:45 — how the foreground group's members decide shell vs agent (local admission keeps "any non-shell member is an agent").
  2. daemon-pty-router.ts:276 — the old-service fallback: only an established owner is asked; no route falls back to main's owner resolution.
  3. pty-master-foreground-observation.ts:163 — the coherence check (group before and after the capture, one reread) that guards an automated write.

…2025/lu-foreground-detect

# Conflicts:
#	src/main/daemon/degraded-daemon-pty-provider.test.ts
#	src/main/daemon/terminal-host-process-inspection.test.ts
#	src/main/runtime/workspaces/workspace-activation.ts
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