Skip to content

fix(runtime): typed close intent + host-side adjudication for session tab closes - #8872

Closed
bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:bbingz/fix-remote-mirror-pty-exit
Closed

bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:bbingz/fix-remote-mirror-pty-exit

Conversation

@bbingz

@bbingz bbingz commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

fix(runtime): typed close intent + host-side adjudication for session tab closes

Part of #9414. Reworked from this PR's original client-side approach — see the
rework comment below. The intent field is consumed by the lifecycle-state
follow-up and by #8888 attribution logging.

Problem

session.tabs.close carried only {worktree, tabId}. The host could not tell
a user-initiated close from a transport-artifact echo: when a paired client
loses a mirrored PTY stream it fires closeTerminalTab(reason: 'pty-exit'),
the reason was dropped before the RPC, and closeMobileSessionTab killed live
PTYs unconditionally. A transient transport blip could therefore terminate a
working agent on the host.

Fix

Thread a typed close reason end-to-end and make the host the sole decision
point:

  • Wire schema — session.tabs.close params gain an optional
    reason: 'user' | 'pty-exit' | 'cleanup' (CloseTab in
    session-tabs-schemas.ts). Reasonless payloads still validate.
  • Client threading — closeTerminalTab already had options.reason
    locally but dropped it; it now flows through closeWebRuntimeSessionTab and
    web-runtime-session.ts onto the RPC. Direct user actions (tab close, bulk
    close, tab-group close, mirrored editor close, mobile tab close, CLI
    handle-addressed close) send reason: 'user'. Callers whose origin is not
    clearly a user action stay reasonless — the client never invents an
    explicit-close claim.
  • Host adjudication — in closeMobileSessionTab, a close whose reason is
    present and not 'user' is treated as an echo, not an authorization. If any
    leaf under the addressed terminal parent still resolves a connected PTY
    record (findPtyForMobileTerminalTab(...)?.connected === true after
    refreshMobileSessionPtyRecords — record presence alone is not liveness:
    exited PTYs stay addressable as disconnected records in ptysById), the
    host refuses every destructive branch — direct ptyController.kill, the
    whole-parent renderer close relay, and the headless teardown/kill loop — and
    returns { closed: true, refused: true }. Unless the echo addressed a dead
    leaf under a live sibling (below), it also republishes the session snapshot
    with a bumped snapshotVersion so the echoing client re-syncs and
    re-attaches, and marks the response with additive
    { snapshotRepublished: true }.
    When the PTY is genuinely dead/absent (including a retained
    disconnected record), the close proceeds normally so the tab record retires —
    this is what keeps headless hosts retiring dead tabs.
  • Dead leaf under a live sibling — an echoed close of a dead split leaf
    whose sibling PTY is live is refused (the only reachable close path for a
    single leaf is the whole-parent close, which would kill the live sibling)
    but not republished: re-adding the dead leaf on the echoing client would
    feed an endless refuse→republish→re-echo cycle. Retiring just the dead leaf
    record host-side is left to the follow-up that consumes the intent field.
  • Refusal recovery marker — all refusals return
    { closed: true, refused: true }; only paths that actually republish also
    return snapshotRepublished: true. The renderer then clears only the target
    tab's alias intents and permits one replay of the exact current
    epoch/version. Dead-leaf refusals retain suppression, while older concurrent
    frames remain behind the monotonic gate and cannot clear unrelated intents.
    Both response fields are additive and skew-safe for older clients.
  • Parked-tab lifecycle closes — closeTerminalTab gains a
    hostCloseReason option that tags the wire reason without triggering the
    local reason === 'pty-exit' pinned-guard bypass. The parked-tab watcher's
    autonomous pty-exit close now sends hostCloseReason: 'pty-exit', so
    backgrounded tabs get the same host adjudication as mounted ones while
    keeping the parked pinned-tab confirmation flow.
  • Daemon last-ditch guard — the daemon kill request gains an optional
    intent field. intent: 'auto' is refused (typed KillResponse
    { refused: true }) while the session's foreground is a live non-shell
    process; missing intent keeps the legacy unconditional kill. Old daemons
    ignore the extra field, so no protocol-version bump is required today
    because no caller sends intent: 'auto' yet. Precondition for the
    lifecycle-state follow-up: before any caller starts sending
    intent: 'auto', bump PROTOCOL_VERSION (or add a handshake capability) —
    daemons survive app updates, and without it a caller cannot distinguish
    "refused" from "old daemon silently killed". (KillRequest moved to
    daemon-kill-request.ts because types.ts sits at its max-lines cap.)

Why the echo is preserved

The client-side echo is deliberately not suppressed. Per the comment in
terminal-tab-actions.ts: "a remote-owned worktree's tabs are
host-authoritative, so the close MUST reach the host or its next snapshot
re-adds the tab (the 'close then snaps back' bug)"
. Additionally, the host's
own pty-exit handling never retires tab records, so headless hosts rely on the
client echo to retire genuinely dead tabs. Safety comes from the host-side
gate, not from suppression.

Version-skew behavior

Client \ Host Old host New host
Old client (no reason) Unchanged legacy close Missing reason → legacy destructive close (unchanged)
New client, user close reason stripped by the host's non-strict zod object → legacy close reason: 'user' → destructive close (explicit intent)
New client, echo (pty-exit/cleanup) reason stripped → legacy close (no worse than today) Live PTY → refused + republished marker; dead PTY → tab retires; dead leaf with live sibling → refused without replay

Same shape for the daemon intent field: old daemons ignore it; new daemons
only change behavior when intent: 'auto' is explicitly sent.

Behavior note: after a live-PTY refusal, the republished marker restores the
mirror immediately even if the same snapshot version arrived before the RPC
response. A dead-leaf refusal intentionally keeps its close intent and does not
open the replay gate, preventing the dead mirror from being re-added.

Tests

  • session-tabs-schemas.test.ts — close params round-trip with each reason;
    reasonless payload validates (skew safety); unknown reason rejected.
  • terminal-tab-actions.test.ts — pty-exit close still reaches the host and
    now carries the reason; reasonless close stays reasonless on the wire; local
    prune behavior unchanged; bulk closes send reason: 'user';
    hostCloseReason reaches the wire without tagging the local reason and
    without bypassing the pinned confirmation guard.
  • terminal-parked-tab-watchers.test.ts — the parked autonomous exit close
    carries hostCloseReason: 'pty-exit'.
  • web-runtime-session.test.ts — wire-level params carry the reason and omit
    it when absent; only a refusal carrying snapshotRepublished clears the
    target close intent and opens replay recovery.
  • orca-runtime.test.ts (close intent adjudication) —
    (a) pty-exit/cleanup + live PTY → no kill, no renderer relay,
    refused: true, snapshotRepublished: true, and a
    bumped version; (b) pty-exit +
    dead headless tab → retires normally, including when the exited PTY still
    has a retained disconnected record
    (the production state after
    onPtyExit); (c) user + live PTY → destructive (whole-parent relay and
    direct split-leaf kill branches); (d) missing reason + live PTY → legacy
    destructive; (e) runtime-owned headless branch refused while live; (f) dead
    split leaf under a live sibling → refused without a republish (no churn
    loop).
  • daemon-server-kill-request.test.ts — intent: 'auto' + live non-shell
    foreground → refused, no subprocess kill; shell foreground → proceeds;
    missing intent → legacy unconditional kill.
  • web-session-tabs-sync.test.ts — same-version replay remains available, older
    same-epoch frames stay rejected, and a second pending close intent survives
    refusal recovery.

Verification after rebasing onto current main: focused Vitest runs of 12
files / 976 tests and the daemon + remote transport set of 3 files / 93 tests
passed; node/CLI/web and mobile TypeScript checks passed; changed-file oxlint,
type-aware lint, formatting, max-lines ratchet, and git diff --check passed.
Independent post-fix gate: Spec compliance PASS / Code quality APPROVED.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review 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
📝 Walkthrough

Walkthrough

Updated terminal and session-tab close flows to carry explicit reasons and user-origin metadata. PTY-exit and cleanup echoes can be refused when live runtime PTYs remain, while dead headless tabs are retired and user or legacy closes remain destructive. Added close-reason RPC schemas, runtime adjudication tests, and daemon kill intent handling that refuses automatic kills for live non-shell foreground processes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed, but it does not follow the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections, including a Summary, Screenshots or 'No visual change', the testing checklist, AI Review Report, Security Audit, and Notes.
✅ 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 is concise and accurately summarizes the main change around typed close intent and host-side adjudication.

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.

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 15, 2026 16:47
@bbingz
bbingz force-pushed the bbingz/fix-remote-mirror-pty-exit branch from e57bfc0 to ac9fa1b Compare July 16, 2026 14:34
@bbingz bbingz changed the title fix(terminal): keep remote mirror exits local fix(runtime): require explicit remote close intent Jul 16, 2026
@bbingz
bbingz force-pushed the bbingz/fix-remote-mirror-pty-exit branch from 8fbb81a to 32abe4a Compare July 19, 2026 03:38
@bbingz bbingz changed the title fix(runtime): require explicit remote close intent fix(runtime): typed close intent + host-side adjudication for session tab closes Jul 19, 2026
@bbingz

bbingz commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Rework note — the branch was force-pushed with a full reimplementation (old approach: client-side close-intent recording; it left the host unable to adjudicate and, as later analysis showed, could not distinguish a transport-artifact echo from a genuine exit host-side).

Key changes vs. the original:

  • The close echo is preserved for every reason — suppressing it breaks tab retirement on headless hosts and triggers the documented "close then snaps back" behavior. Safety now comes from a host-side gate in closeMobileSessionTab covering every destructive branch.
  • Liveness is judged on connected PTY records (?.connected === true) — exited PTYs keep retained disconnected records, so record presence alone would refuse forever and dead tabs would never retire.
  • Refused closes return a skew-safe { closed: true, refused: true } marker; a dead split leaf under a live sibling is refused without a snapshot republish to avoid an echo churn loop.
  • Parked (backgrounded) tabs now tag the wire via a new hostCloseReason option, so they get the same host adjudication without bypassing the local pinned-tab confirmation.
  • Optional daemon-level intent guard as a last-ditch defense (no protocol bump needed until a caller sends intent: 'auto' — precondition documented in the body).

Part of #9414; complements #8888 (attribution) and the lifecycle-state follow-up.

@bbingz
bbingz force-pushed the bbingz/fix-remote-mirror-pty-exit branch from 32abe4a to 857c082 Compare July 19, 2026 13:36
@bbingz

bbingz commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (clean, 6 commits). Resolved daemon-server.ts kill-path conflict by keeping both:

  • main's cancelPendingPtySpawnPreparations + SessionNotFoundError handling
  • this PR's auto-intent refuse when a non-shell foreground is live

@Jinwoo-H

Copy link
Copy Markdown
Contributor

PR #8872 Windows/WSL red-green audit: refused-close reconciliation candidate

Audit date: 2026-07-19 (America/Vancouver)
PR: #8872
Reviewed PR head: 857c08269e061584587817a6ac7bd5c3bcb12297
Candidate commit: 5533a29d7e3a8e4d00e6a51693d7b5602c540670

Outcome

PASS. The candidate fixes the acceptance failure observed at 857c08269: when the
host refuses a lifecycle close for a still-live PTY, the client now clears only that
tab's optimistic close marker, reopens the freshness gate for the authoritative
environment/worktree snapshot, and immediately refreshes it. The same WSL terminal
reappeared after runtime switch-back and was then closed normally through the real
Windows UI exactly once.

No stale, disconnected, expired, ambiguous, or ownership-mismatched action killed a
host PTY. The remote PR branch was still exactly 857c08269 after verification and
before push preparation.

Preserved RED baseline

The two prior reports remain unchanged:

  • REPORT.md / 8fbb81a26 RED baseline: client-side route invalidation stopped the
    destructive stale route, but switching back left a live host PTY invisible.
  • REPORT-current-857c08269.md: host adjudication correctly refused pty-exit, but
    snapshot 6 was accepted while the optimistic close marker still hid the tab. Once the
    marker expired, the unchanged snapshot was rejected as a duplicate forever.

Preservation hashes:

  • REPORT.md: 3F850AEEDC3F85423E933F43380F86C03578BEB4C4708D2CB02032DB335C64CB
  • live-switch-back-failure.png:
    4D751898D15D37CF5D122A7A419D27F8236524E52033A44064BB4924B42299B7

Candidate implementation

Files changed from 857c08269:

  • web-session-close-intent.ts: clear one (worktree, host tab) close intent.
  • web-runtime-session.ts: when session.tabs.close returns { refused: true }, clear
    the immediate and resolved IDs, reset freshness only for that environment/worktree,
    then perform the existing eager authoritative refresh.
  • Three focused test files prove exact intent scoping, same-version snapshot replay, and
    response ordering before snapshot application.

Explicit successful closes retain the existing optimistic suppression path. No global
freshness ordering rule, host close policy, SSH path, or platform-specific path changed.

Environment and exact builds

  • Windows 11 Home 10.0.26200, x64.
  • WSL package 2.3.26.0; Ubuntu 24.04.1 LTS; running WSL2 kernel
    5.15.153.1-microsoft-standard-WSL2 (same machine/topology as the RED runs).
  • Windows: Node v25.9.0, pnpm 10.24.0.
  • WSL build/runtime: Node v24.15.0, pnpm 10.24.0.
  • Windows identity: 8871-review @ codex/pr8872-refused-close-reconcile, exact Git SHA
    5533a29d7e3a8e4d00e6a51693d7b5602c540670.
  • WSL source: git archive 5533a29d7e3a8e4d00e6a51693d7b5602c540670;
    archive SHA-256
    818A1287322359368FF8C302BA022EED76EA8634073F397E474D642D638C4C7E.

Build commands on both Windows and WSL:

pnpm install --frozen-lockfile   # WSL fresh archive; Windows lockfile already installed
pnpm run typecheck
pnpm run build:cli
pnpm run build:electron-vite

Live topology:

  • Visible Windows Electron desktop, isolated profile, CDP 127.0.0.1:9350.
  • Paired WSL2 orca serve --json --port 6794 --pairing-address 127.0.0.1, isolated
    profile and daemon protocol v23.
  • Windows environment ID acc79c93-f8f8-4a09-9e15-f6524c7785b9.
  • WSL runtime ID 5c4fff07-4ecb-4d0b-9b29-9a1793fb33f7.
  • Runtime PID 11833; daemon PID 11884.
  • Worktree
    51c2e49a-44e9-488a-8df5-a2a17eaacf76::/home/jinwoo/orca-pr8872-5533a29d-audit-20260719.

Primary acceptance flow

Authoritative identifiers:

  • Host tab 4ac6de78-6ffe-48a6-be3e-480dcec0fa67.
  • Leaf 579812c3-2d3f-476f-a56b-10cfd395a4d4.
  • Handle term_31832d8e-d241-4ddb-a63f-7d08b59790f9.
  • PTY serve-8efe7533-d744-4142-9cb3-fd43b834ed99 on /dev/pts/5.
  • Mirror web-terminal-4ac6de78-6ffe-48a6-be3e-480dcec0fa67.
  • Shell PID 13006; sleep 600 child PID 13470.

Exact steps and evidence:

  1. Created the terminal through the real paired session API, mounted its Windows mirror,
    and sent sleep 600 & wait. Both PIDs were alive.
  2. Called the real mirror lifecycle action with reason: pty-exit. The local state
    synchronously became tabs: [], ptys: null.
  3. Awaited switchRuntimeEnvironment(null) and immediately attempted an explicit
    user close against the stale mirror ID.
  4. At 2026-07-19T22:44:47.257Z, the same host tab/leaf/handle/PTY remained in the
    authoritative snapshot; PIDs 13006 and 13470 remained alive. Destructive daemon
    close count: 0.
  5. Switched back, refetched the real repo/worktree catalog, selected the same worktree,
    and waited five seconds.
  6. At 2026-07-19T22:45:21.972Z, the same mirror, remote handle, PTY mapping, and unified
    tab were present. The host snapshot still contained the same identifiers and both
    PIDs were alive.
  7. Clicked the actual Close tab Terminal UI button. The daemon logged exactly one
    session-killed at 22:46:17.520Z and one session-exited at 22:46:17.525Z for
    that exact PTY. Shell 13006 and child 13470 were absent afterward.
  8. Repeated the explicit action against the old mirror ID. The kill/exit counts stayed
    at one.

Result: PASS. The lifecycle/stale action was non-destructive, the authoritative
mirror returned, and the later deliberate UI close retired the exact process tree once.

Remaining live matrix

Scenario Result Exact live evidence
Mirror pty-exit PASS Primary and parked flows pruned locally; live host PTYs survived and identical mirrors returned
Disconnected mirror PASS Server PID 11833 was SIGSTOPed; tab 079d5a2e…, PTY serve-720a86a6…, shell 14314, child 14501 survived; after SIGCONT, identical handle term_d78214ce… reconciled; later user close produced one kill
Explicit UI tab close PASS Primary UI click killed only serve-8efe7533…, exactly once
Duplicate explicit close PASS Repeating primary old mirror close left daemon kill/exit counts at 1/1
Parked/background pty-exit PASS Inactive tab 1800269c… pruned while active sibling bcb9094c… remained; both mirrors returned; shells/children 14785/14972 and 14973/15161 stayed alive
Dead split leaf/live sibling PASS Right shell 16143 exited; left PTY serve-23e94956…, shell 15956, child 16142 remained alive; renderer layout retained only the live leaf; later deliberate parent close killed it once
Genuinely dead headless terminal PASS exit retired tab 39db81aa…, PTY serve-274df05d…, shell 15767; after six seconds host and renderer both had no tab, with no snap-back
Host-tab replacement safety PASS Old e354a2a2…/serve-9c50c633… was deliberately closed; new b55fa43d…/serve-42268adf…, shell 16566, child 16752 survived the old mirror action; replacement kill count stayed zero
Runtime away/back restores all mirrors PASS Two authoritative tabs 1800269c… and bcb9094c… returned with their original handles; all four PIDs remained alive
Failed runtime switch PASS Switching to missing-environment-audit returned false; active runtime stayed acc79c93…; the original terminal remained operable and was later closed through CLI
Stale/expired control (>10 s) PASS Old mirror e354a2a2… was retried after 11 seconds; it emitted no destructive target and could not affect replacement PTY serve-42268adf…; shell/child stayed alive
User close PASS Real UI user close carried explicit user intent and killed exact primary PTY once
CLI close PASS Exact candidate CLI listed handle term_2c8b1150…; terminal close --tab retired PTY serve-c9247755…, shell 15530, child 15700 once
Automation explicit close PASS Real session.tabs.close with reason: user retired only serve-f4bcc5f2… once
Legacy reasonless close PASS Real reasonless session.tabs.close retired only serve-74e9dce9… once
Daemon auto-intent guard PASS Live foreground node PID 16977 under shell 16791; real daemon kill { intent: auto } returned { refused: true }, logged one refusal at 23:02:02.077Z, and both PIDs remained alive; later user close killed the PTY once

Final cleanup at 2026-07-19T23:03:37.325Z: host snapshot tabs: [], renderer
localTabs: [], renderer remote PTY mappings empty, and daemon had no child sessions.

Close counts and source interpretation

  • Non-destructive lifecycle flows invoked the real closeTerminalTab(..., { reason: 'pty-exit' }) source once per scenario. Host survival plus unchanged-tab
    republish/reconciliation proves refusal. These lifecycle responses could not be
    transparently wrapped because the production preload bridge is frozen; their exact
    plaintext count/source is therefore supported by the single invocation, source path,
    snapshot behavior, zero daemon kills, and focused wire tests rather than a mutable RPC
    recorder.
  • Explicit destructive controls have direct daemon evidence: each target has one
    session-killed and one session-exited; duplicate/stale targets have no additional
    event.
  • Automation reason: user, legacy reason omission, and daemon intent: auto request
    and response bodies were directly captured from real, non-mocked control paths.

Automated verification

  • Renderer/schema/session focused Vitest: 98 passed.
  • Host close-adjudication Vitest: 10 passed.
  • Daemon intent Vitest: 2 passed.
  • Full Node/CLI/web typecheck: passed.
  • Targeted oxlint, React Doctor pre-commit lint, oxfmt --check, and git diff --check: passed.
  • Windows CLI and Electron/Vite builds: passed.
  • WSL CLI and Electron/Vite builds: passed from the exact candidate archive.

Artifacts

  • candidate-5533a29d-primary-before.png — live terminal before lifecycle prune,
    SHA-256 A9677B418B641D722AB3365F61B636049A77B823F197BDE67DF8EB4A340DB4DE.
  • candidate-5533a29d-primary-restored.png — same visible mirror after switch-back,
    SHA-256 6C0DC3B1DD9D54EE3B810C58AC272A884EDFC2B6E8DF74357C8744FB5B73ADEF.
  • candidate-5533a29d-primary-after-close.png — renderer after normal UI close,
    SHA-256 E850CCDCBF5B66F6012D62ACDB5E33A69B529C72E42F2204B8598C95B08C0B25.
  • candidate-5533a29d-daemon-events.ndjson — filtered exact session event lines.
  • daemon-auto-kill-probe.mjs — token-safe local daemon protocol probe; it reads the
    token path at runtime and never prints or stores the credential.

Evidence classification and gaps

  • Recovered: the 0f41e7349 destructive stale-route failure and preserved
    8fbb81a26/857c08269 RED reports and screenshots.
  • New direct: exact candidate provenance/builds, real paired process trees, host
    snapshots, renderer state, UI screenshots, explicit close/daemon event counts, CLI
    output, and auto-intent response.
  • Inferred only: plaintext lifecycle close response/count due the frozen preload
    API; the inference is corroborated as described above.
  • Remaining gaps: native-Windows orca serve was not repeated; the required WSL2
    primary topology and full requested matrix were clean. No tokens, pairing URLs/codes,
    device credentials, daemon tokens, authorization headers, private keys, or user data
    are included.

@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:37
@bbingz
bbingz force-pushed the bbingz/fix-remote-mirror-pty-exit branch from 5533a29 to bb69fac Compare July 21, 2026 09:22
@bbingz

bbingz commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@OrcaWin The PR is now rebased onto current main at bb69fac775. The prior Windows/WSL PASS belonged to the old head and is no longer valid; could you please rerun the native Windows and WSL checks on this updated head? Local focused tests, root/mobile typechecks, lint/format, max-lines, and the independent spec gate are green.

@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H @OrcaWin Following up on the Windows/WSL red-green PASS for the refused-close reconciliation path (#8871).

Branch is MERGEABLE on current main after the earlier restack. Companion host-side guard is #8888 (currently needs rebase — working that next). Ready to land #8872 whenever you are.

@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

Related to #9952 (sessions vanishing over remote Orca link).

bbingz added 3 commits July 23, 2026 09:37
… live

The daemon kill request gains an optional intent field ('auto' | 'user').
When intent is 'auto' and the session's foreground process is a live
non-shell process (an agent at work), the daemon refuses the kill and
answers { refused: true } instead. Missing intent keeps the legacy
unconditional kill, and old daemons ignore the extra field, so no
protocol version bump is needed.

KillRequest moves to daemon-kill-request.ts because types.ts sits at its
max-lines cap.
Give the ad-hoc { refused: true } kill reply a KillResponse type so the
lifecycle-state follow-up consumes a declared shape. Sending intent:'auto'
still requires a PROTOCOL_VERSION or handshake-capability bump first —
surviving old daemons silently ignore the guard otherwise.
@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current origin/main (41751dd90d).

Scope after restack: main already absorbed the session-tab close-intent / closeLifecycle / refused-mirror recovery path that this PR originally carried. Those commits were dropped as superseded during the rebase (would only regress the newer host/client contract).

Still unique and kept (3 commits):

  1. daemon refuses intent: 'auto' kills while a live non-shell foreground runs
  2. typed KillResponse next to KillRequest
  3. focused kill-request routing tests

ahead=3 behind=0. Kill-request tests green.

@bbingz
bbingz force-pushed the bbingz/fix-remote-mirror-pty-exit branch from bb69fac to c85c636 Compare July 23, 2026 01:39
@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing original close-intent / host-adjudication scope as superseded

The original problem — host cannot distinguish user vs lifecycle closes, and must refuse destructive closes against still-live PTYs — is landed on main via:

Main also early-returns remote pty-exit closes in the renderer (terminal-tab-actions) rather than echoing them for host adjudication — a different (and shipped) strategy than this PR’s original client-echo design.

Residual unique work (not closed as “done forever”)

The current tip of this branch is already narrow (~daemon only):

  • KillRequest.intent?: 'auto' | 'user'
  • refuse auto kills while a non-shell foreground is live

That residual is not on main. If we still want it before any intent:'auto' caller lands, re-open as a narrow daemon follow-up (new PR title/body scoped only to auto-intent kill refusal). Do not re-land the superseded session-tab close-intent stack.

Closing as PARTIALLY SUPERSEDED (tab-close adjudication done; daemon residual optional follow-up).

@bbingz bbingz closed this Jul 23, 2026
@bbingz
bbingz deleted the bbingz/fix-remote-mirror-pty-exit branch August 1, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants