Skip to content

[upstream #24314] fix(pty): signal an agent process group before force-killing a closed terminal - #283

Open
innocarpe wants to merge 8641 commits into
mainfrom
fix-23865-session-end-on-close
Open

innocarpe wants to merge 8641 commits into
mainfrom
fix-23865-session-end-on-close

Conversation

@innocarpe

Copy link
Copy Markdown
Owner

Portfolio mirror of my contribution to upstream stablyai/orca.
Exhibition only — the real review/merge target is upstream.

Upstream

Summary

Description Closing a terminal from Orca sent SIGKILL to the PTY process groups. Claude Code's SessionEnd hooks run on SIGTERM or SIGHUP, so an Orca close skipped them. /exit still ran the hooks. On macOS the PTY root is login, so a signal to that pid does not reach

Note

  • Do not merge this into innocarpe/orca main until the upstream PR is merged.
  • After upstream merges: sync fork from upstream, then close this mirror PR.
  • This open PR exists so visitors see in-flight work on this fork's Pull requests tab.

@innocarpe innocarpe added the bug Something isn't working label Oct 1, 2026
@innocarpe
innocarpe force-pushed the fix-23865-session-end-on-close branch from 790650b to 6f16c92 Compare October 1, 2026 09:14
@innocarpe

ghost commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Sync update (6f16c9268b)

Address review: a root that exits during the SIGTERM grace still gets a process-group SIGKILL, so children that ignored SIGTERM do not survive the close.

@innocarpe

ghost commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Sync update (95efbd0bbb)

The post-exit SIGKILL now signals the process groups captured while the root still owned the PTY. Root exit marks the handle dead before listeners run, so looking that pid up again never reached the OS. A rejected force-kill retry also stays inside the caller's remaining close budget. POSIX tests pin linux, so the SIGTERM sequence does not depend on the host platform.

@innocarpe
innocarpe force-pushed the fix-23865-session-end-on-close branch from 95efbd0 to babdabc Compare October 1, 2026 11:17
@innocarpe

ghost commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Sync update (babdabc202)

The close-time SIGKILL now signals a remembered process group only when a fresh process table still lists that group on this PTY. A group id reused after the root exits is left alone. If the table cannot be read, nothing is signaled.

@innocarpe

ghost commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Sync update (cd34afe858)

When ps rejects -t, the terminal group lookup now reads the full process table and keeps the groups whose tty matches that terminal. A child that ignored SIGTERM is still SIGKILLed after the root exits, instead of the failed lookup skipping every remembered group.

@innocarpe
innocarpe force-pushed the fix-23865-session-end-on-close branch from cd34afe to bd879f6 Compare October 1, 2026 12:22
@innocarpe

ghost commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Sync update (bd879f6f55)

The full-table fallback now matches the tty text those hosts actually print: pts/N from Linux ps, and major,minor from BusyBox. The shared ps reader lives with that fallback.

Neil and others added 19 commits October 20, 2026 15:25
…nd WSL hosts (stablyai#31235)

* fix(orcad): replace a stale terminal daemon once it drains on Linux and WSL hosts

A daemon forked by an older orcad (before stablyai#31135, at umask 077) kept
serving new terminals after an upgrade if it was busy at startup, because
the runtime stale-bundle recycle was macOS-only. orcad now opts in on every
platform; the replacement still waits for exactly zero live sessions and
treats an unverifiable count as keep.

* test(daemon): pin the restart recycle test to linux; tighten wording
…ad of running on a guessed host (stablyai#31234)

* fix(automations): a legacy automation on a twin project refuses instead of running on a guessed host

* fix(automations): capture a legacy run target before the dispatch snapshot, only where it keeps the folder

* fix(automations): re-read a legacy record after capture even when another run captured it first
…tablyai#30937)

* feat(native-chat): Codex chats list and run the skills Codex loaded

A Codex chat's skill list now comes from Codex itself (`skills/list`), live
while the chat runs and refreshed when Codex says its skills changed, and
from a short-lived Codex check while the chat is at rest. Plugin skills keep
Codex's `plugin:skill` names, disabled skills drop out, and each skill file
is its own row. A skill picked from the list reaches Codex as that exact
skill, beside the unchanged `$name` text, on hosts that take it.

* test(native-chat): account for Codex's skill list call; send without a trailing argument

* fix: align skill probes with chat launches and preserve picked mentions

* fix: distinguish skill choices in phone accessibility labels

* fix: clear picked skill files when queued text changes

* fix(native-chat): refresh resting commands when launch settings change

* fix: keep WSL agent refresh on its execution host

* fix: preserve skill selection at read and send boundaries

* fix: narrow agent identity for selected skill notice

* fix: use checked agent predicate for skill notice label

* test: retain locale in composer translation mocks
…afterwards (phase 1a) (stablyai#31251)

* refactor(editor): make the editor buffer record the source of truth for tab buffer state

Writers of the six buffer fields read and write the record, with the OpenFile
fields written as a mirror in the same store update. The store middleware no
longer copies tab values into the record; it only keeps records keyed by open
tabs (seeded from the tab on create, dropped on close) and, in dev and test
builds, asserts every mirror field equals its record. Host-mirrored web tabs
adopt the host's published values explicitly in the session sync patch.

Co-Authored-By: Claude <[email protected]>

* refactor(editor): check the buffer invariant in e2e builds and tidy the record helpers

Co-Authored-By: Claude <[email protected]>

* test(e2e): give session-sync fixtures the now-required editorBuffers

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
…ost that returned the item (stablyai#31252)

* fix(github): a twin project's PR cards, rows and dialogs act on the host that returned the item

* fix(github): key twin rows by host so cache sync keeps each copy; a lone row ignores the stamp
…scan budget (stablyai#31139) (stablyai#31226)

All hosts gave every Orca server a 3 s scan, including the managed servers
Orca reaches through an SSH tunnel, which now serve every SSH host. A healthy
SSH host walking a large home timed out and showed up empty. The saved
environment's connectionDependency now picks the 15 s budget for tunnelled
servers; direct LAN/Tailscale servers keep 3 s.

Reported, with the proposed approach, by @quzard in stablyai#31139.
… test-only editor-state guard (stablyai#31250)

* refactor(editor): drop isWholeEditorState and the diff-signature re-export; bound superseded restore re-reads

- Remove isWholeEditorState; its callers take the real AppState. Tests that
  mocked partial stores now build full states from createTestStore.
- Import getDiskBaselineSignature from shared/disk-baseline-signature
  directly and delete the re-export from diff-content-signature.ts.
- Restored-tab conflict scan: count superseded re-reads toward
  MAX_VERIFY_ATTEMPTS, so a read slower than the re-verify interval gives up
  with the conflict banner instead of looping forever. Adds a regression test.

Co-Authored-By: Claude <[email protected]>

* fix(editor): keep the last read at the superseded re-read cap instead of giving up

A matching read at the cap cleared nothing and showed a false changed-on-disk
banner; it now resolves like any read. Only read failures give up.

Co-Authored-By: Claude <[email protected]>

* fix(editor): back off on superseded restore re-reads instead of capping them

A superseded read may predate the newer check, so it never resolves the
verification, even at the attempt cap. Overlapping checks now delay the next
fresh read (bounded, one timer per tab) and keep verification pending; only
failed reads count toward giving up.

Co-Authored-By: Claude <[email protected]>

* test(editor): address the restored tab by its owned id in the overlapping-check tests

After stablyai#31196 a server's tab is no longer keyed by its path, so these tests
flagged a tab that does not exist and no read was ever issued.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
…ading all of them every 30s (stablyai#31253)

* perf(worktrees): gate the 30s git-common reconciliation sweep on each entry's dir signature

The native-watch reconciliation forced an ungated stat of every leaf of every
worktree admin entry each tick (~7 stats/entry). It now uses the entry-dir
signature gate plus the two leaves git writes in place (gitdir, logs/HEAD),
runs the ungated sweep every 10 ticks (~5 min), and falls back to sweeping
every tick if a sweep ever finds a change the dir signature missed.

Co-Authored-By: Claude <[email protected]>

* fix(worktrees): only distrust the reconciliation dir gate on a confirmed, repeated miss

Detect a missed change on any entry rescan, including ones the in-place leaf
probes trigger, not just full sweeps. Re-stat the admin dir after the leaf
rescan so a rename racing the scan isn't counted, ignore transient missing
leaves, and require misses on two separate ticks before sweeping every tick.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
…eal path in Workspace scope (stablyai#31244)

* fix(ai-vault): keep sessions recorded under a symlinked workspace's real path in Workspace scope (stablyai#31139)

A workspace registered through a symlink (~/work/api -> /data/src/api, or
macOS /var -> /private/var) lost every session whose agent recorded the
resolved cwd: scope matching compared strings, and those rows also counted
against the out-of-scope depth cap.

The host that owns the files (the desktop for local scans, orcad for SSH and
server hosts) now resolves each scope path's real path, scans both spellings,
and gives matching sessions optional matching-only cwdAliases in the
registered spelling. Workspace scope, the depth cap and project attribution
read cwd plus aliases; resume still uses the recorded cwd. Older hosts send
no aliases and older clients strip the field.

Reported, with the proposed approach, by @quzard in stablyai#31139.

* fix(ai-vault): rank aliased attribution by closest root; never resolve recorded cwds

Review feedback: a longer-spelled parent link could take a nested project's
session, and resolving every out-of-scope cwd could stall a listing on a hung
network mount or raise macOS privacy prompts.
…n several hosts (stablyai#31261)

* feat(ai-vault): name the host each search hit came from when hits span several hosts (stablyai#31139)

An All hosts full-text search returned one flat list, and the same title or
path often came up on two machines, so you could resume the wrong copy. When
hits come from two or more hosts, each row now carries the same host chip the
sidebar uses, labelled the way the host menu names that host. Hit order is
unchanged; a single-host result shows no chip.

Reported, with the proposed approach, by @quzard in stablyai#31139.

* fix(ai-vault): let the search-hit host chip shrink in a narrow sidebar
…and the CLI gets --surface chat|terminal (stablyai#31191)

* feat(agent.launch): a launch can name chat or terminal, and the CLI gets --surface chat|terminal

agent.launch gains an optional `surface` field, read by hosts advertising
agent.launch.surface.v1. `terminal` always runs the agent's CLI; `chat` runs a
chat even when the user's default is a terminal, and one the host can prove it
cannot open is refused with a typed no-effects error before anything is
created, so a retry answers with the same refusal. The pick is part of the
replay fingerprint. `orca agent launch` and `orca worktree create --agent`
accept --surface chat|terminal and refuse it on a host that would drop it,
including the legacy worktree.create fallback.

* test(agent.launch): pin the surface pick beside the other pre-start failures

* fix(agent.launch): settle requested surfaces from resolved workspace facts

* fix(agent.launch): describe fallback boundaries and correct test types
…t that returned them (stablyai#31271)

GitLab task items now carry the host of the repo row that fetched them, and the
project-view dialog stamps the row its slug matched. Both resolve through one
provider-neutral helper (getWorkItemRepo, generalized from stablyai#31252's GitHub-only
getGitHubWorkItemRepo), so a repo id published by two hosts never routes an
action to the other host's row.
Kelvin Amoaba and others added 29 commits October 21, 2026 23:48
…ablyai#31686)

* refactor(linear): group issue-context owners and use direct imports

* test(linear): mock concrete current-context owner in WSL move suite
…ablyai#31727)

stablyai#31656 left BrowserAddressBar.tsx one counted line over max-lines, which fails
Lint for every PR. The six copies of clear-a-timeout-ref become one helper.
…over Home (native part ships with the next app build) (stablyai#31305)

* fix(mobile): the home screen's New Workspace opens the create sheet again

The native host-list route dropped the home screen's action=newWorktree when it built
the page's route, so the page opened as a plain list. The route now forwards it, and
the page names it back once applied so a reload does not reopen the sheet.

Reaches phones only with the next native build.

* test(mobile): drop the New Workspace tests that only re-check types and a null guard

* fix(mobile): Home's New Workspace opens the create sheet over Home

Replaces the action=newWorktree route hand-off. The quick action picks a
host (as Tasks does), then mounts the host's create sheet on Home; a
create opens the new workspace's session marked as just created.

The sheet controller becomes a plain visible/onClose component, and the
host screen's route-action state, the action route param and its builder
are deleted.

* fix(mobile): Home's create sheet seeds only proven worktree rows

Home's cold-start seed is a pathless resume row that the name suggester
cannot read, so the sheet now seeds from proven rows and is keyed by host.
The host screen gets one setter for the sheet's visibility and its ref.

* test(mobile): name the Home new-workspace test after the screen it renders

* proto(mobile): Home's New Workspace opens a native drawer hosting the page's create form

Home pushes /new-workspace/<host>, a react-native-screens formSheet over Home whose content is
MobileWebShellScreen for the page route /h/<host>/new-workspace. The page renders the shared
Create Workspace form with its drawers inline, so the form and its pickers fill the native
drawer. The shell's loading, download and failure states render inside the drawer. Prototype only.

* proto(mobile): the New Workspace drawer is the host screen's own sheet over a transparent modal

The native route is a transparentModal hosting the shell over Home; the page route renders the
host screen's NewWorktreeModal on a transparent page, so the drawer is the same component. While
the page loads, the shell shows a placeholder of that sheet (scrim, grabber, spinner or download
bar), and the page's sheet opens in place without its slide. A host that cannot serve the page
(old desktop, blocked, failed) opens the host list instead of a wall in a drawer.

* feat(mobile): Home's New Workspace opens the page's create drawer over a dimmed Home

A transparent native overlay route hosts the host picker and then the page's
/h/[hostId]/new-workspace route, which renders the same NewWorktreeModal as the
host screen's +. The native scrim matches the drawer backdrop and the page's
first drawer opens already dimmed, so Home stays dimmed throughout. Old desktops
without the route fall back to the host list.

* fix(mobile): one loading layer for Home's New Workspace overlay

The overlay route owns a single tappable loading layer (spinner, or the
download on a small card) that stays mounted from the pick until the page
paints, so the fade and spinner no longer restart per shell state. The shell
reports its load and shows the host list for anything it cannot open; the
picker hands the pick over at once and keeps sliding away. The page's first
drawer takes the dimmed backdrop once, and a gate's overlay pending view no
longer stacks a second scrim over a mounted stack. Native /h/[hostId]/new-workspace
redirects to the overlay. Drops the unused session-route params, the
clipboard grant, and pass-through tests.

* feat(mobile): New Workspace loads in a short drawer over an undimmed Home

While the page loads, the overlay shows one short native drawer in the shared
drawer chrome with a spinner or the download, and nothing dims Home: a tap
above it, a drag down or Back cancels. The page's real drawer then slides up
with its own backdrop exactly as on the host screen's +. Drops the native
scrim, the loading card and the already-dimmed backdrop handoff; the overlay's
WebView stays invisible until the page paints, since a fresh one draws opaque.

* feat(mobile): the New Workspace loading drawer dims Home like any drawer

The short loading drawer opens with the shared drawer backdrop and show
duration, and a tap on that backdrop, a drag down or Back cancels. It stays
in the screen's own window (a native Modal over the loading WebView stalls
the page) and goes in the frame the page paints: the shell reports its load
from a layout effect so the WebView shows and the drawer leaves together.

* fix(mobile): the page's first paint waits for a drawer opening with it

A drawer opening as its page screen mounts holds that screen's first-paint
report until its open animation ends, through a hold on the existing report
rather than a new bridge message. The New Workspace overlay's loading drawer
now stays until the create drawer is up, so a cold open no longer shows Home
undimmed between the two.

* refactor(mobile): the New Workspace overlay owns its exits; the loading drawer fades out

The shell no longer imports the feature: an overlay is a shell with
onOverlayLoad, which reports `unavailable` for what it cannot show, and the
overlay route opens the host list for every exit. HostProtocolGate takes one
transparentWhilePending flag. The loading drawer's drag handler follows a
stable cancel, and on paint the drawer fades out eased in, as the shell's page
cover does, because the WebView takes a frame or two to show the page after it
is revealed; removing it outright left Home undimmed for those frames.

* Revert "fix(mobile): the page's first paint waits for a drawer opening with it"

This reverts commit be0913b.

* fix(mobile): Home's host picker leaves when there is no desktop to pick

An unreadable host catalog, or offered desktops that are all gone, left the
picker invisible inside the transparent overlay, holding a screen over Home
with nothing to dismiss it. The catalog read now resolves to no hosts on
failure, and an empty pick list goes back to Home.

* fix(mobile): Home's create drawer names SSH hosts as the host screen does

The page drawer opened from Home passed no host labels, so a project on an SSH
host showed its run target by raw host id. Reading the SSH target summaries
and display overrides moves into one function that both the host screen's
metadata fetch and the page drawer call.
…ablyai#31687)

* fix(security): update Node runtimes for October security releases

* fix(ci): compare normalized web file inventory without ordering artifacts
…lyai#31702)

* fix(mobile): invalidate chat file search on authority migration

Modern search caches and late replies survive authority migration on the same client object. Own cache, capability decision and inventory by logical generation.

* test(mobile): record retired file-search requests after reset

* refactor(browser): simplify address bar callbacks within lint limit

* style(browser): keep client-hosted pane within line limit

* fix(i18n): retire obsolete Portuguese default zoom entries
* fix(mobile): show commit comparison failures with retry

Comparison refusals, transport errors and malformed payloads appear as No file changes. Decode accepted data, preserve loaded files on failed refresh, and offer Retry.

* test(mobile): record commit comparison errors and retry affordance

* refactor(browser): simplify address bar callbacks within lint limit

* style(browser): keep client-hosted pane within line limit

* fix(i18n): retire obsolete Portuguese default zoom entries
* Extract image clipboard copying into shared utility

* Await image reads before reporting clipboard copy success
Pass the selected repository to New Workspace agent detection through the host-authoritative runtime resolver, including WSL paths and Windows project preferences. Preserve old-client request shape, SSH routing, and strict ownership/refusal behavior.

This merge credits @welldoingk’s original WSL agent-detection investigation and community PR stablyai#20101, adapted to the current host-resolved contract.

Co-authored-by: welldoingk <[email protected]>

Fixes stablyai#20060
…yai#31709)

* fix(mobile): own commit generation by workspace and admit once

AI commit generation crosses workspace transitions and admits duplicate calls before a render. Retire the active run on scope changes and use synchronous admission.

* fix(mobile): retire commit generations only after scope commits
… state (stablyai#31711)

Concurrent close replies filter captured terminal arrays and resurrect an already closed terminal. Reconcile the current collection synchronously and respect newer selection and metadata.
…lyai#31620)

* fix(native-chat): open inline images directly in preview dialog

* fix(i18n): add inline image preview translation keys
* fix(terminal): resolve URLs across padded hard-wrapped rows

* Reject oversized wrapped URL prefixes and isolate reconstruction

* Handle preceding links and uppercase schemes in wrapped URLs

* Restore full lint by extracting props and ask dismissal identity

* Keep wrapped URL clicks consistent and require padding evidence

* Preserve soft-wrapped sibling URLs in cold click fallback
)

Switching desktops retains another host history and can scan its filesystem path on the new host. Reset content by host while preserving same-host reconnect identity.
…leases keep working (stablyai#30393)

* fix(native-chat): agents need only a minimum version for chat; newer releases and prereleases run

OpenCode chats accepted only the 1.x and 2.x lines and Pi only 0.x and 1.x,
every prerelease was refused, and a slow or failed --version run counted as
unsupported. A new major would open as a terminal and existing chats said
"Orca can't run this agent in a chat here."

Each agent now lists ascending minimum versions; a version must reach the
latest one on or below its own major line, compared by semver. The check
answers ready, too old, unknown (slow, failed or wordless run) or missing
(did not start). Only too old refuses a launch, as Codex already did, with
"<Agent> X is too old for chats. Update to Y or newer." carried in a new
optional refusal fact agentInstallation; Codex keeps sending
codexInstallation for older clients. Codex's reader and error fold into the
same check.

* refactor(native-chat): a launch check declares its minimum versions; create support and the agent health snapshot run the one shared check

* fix(native-chat): read an agent's version from stderr too, so Pi 0.73 is known too old instead of unreadable
Capture Android terminal keyboard controls in the OTA live input before native web input edits or moves focus. Preserve composition handling, send ordering, and stale-target protection.

Fixes stablyai#25496

Co-authored-by: Sangrak Choi <[email protected]>
Co-authored-by: zenghaolun02 <[email protected]>
)

* fix(browser): bring the client-hosted page pane back under the 400-line limit

Move the client-hosted guest's six event-listener add/remove calls into
bindBrowserClientPageGuestEvents beside the guest load-failure handler,
so ClientHostedBrowserPagePane.tsx drops from 404 to 395 counted lines.
No behavior change.

* test(browser): pin the client page guest event binder's bind and unbind contract

* fix(native-chat): bring the question module back under the 300-line limit

Move answer encoding (pasted answer text and the Claude and Codex selector
keystrokes) into native-chat-ask-answer.ts and re-export it, so importers are
unchanged.
…i#31744)

* fix(sidebar): omit host badges beneath host section headers

* fix(mobile): keep host health without repeating section labels

* test: align host section goldens and preserve chat translation exports

* fix(i18n): retire obsolete Portuguese Codex version key
… terminal

An Orca close sent SIGKILL to the PTY process groups, so Claude SessionEnd
never ran. SIGTERM those groups first and keep the grace inside the existing
physical-exit budget. A process that is still alive is still SIGKILLed.
Plain shells and Windows stay on the direct force-kill.
A shell can die on SIGTERM while a child group ignores it. Treating that root exit as a finished close skipped the group SIGKILL.

Co-authored-by: Cursor <[email protected]>
The root exit marks the handle dead before listeners run, so the
close-time group SIGKILL returned without reaching the OS. Remember
the groups captured with SIGTERM and signal those ids after exit.
A rejected force-kill retry also stays inside the caller's close budget.
A group id captured at SIGTERM can be reused after the root exits.
The close-time SIGKILL now reads the terminal process table and
signals only ids that are still attached. An unreadable table
signals nothing.
Linux ps prints pts/N and BusyBox prints the device major,minor. The full-table fallback compared only the path and its last segment, so those rows never matched and a child that ignored SIGTERM was left running. The shared ps reader now lives with that fallback.
@innocarpe
innocarpe force-pushed the fix-23865-session-end-on-close branch from bd879f6 to e07f4d5 Compare October 22, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants