Skip to content

feat(foreground): structured foreground result + neutral unknown-alive tab presence - #9435

Closed
bbingz wants to merge 15 commits into
stablyai:mainfrom
bbingz:bbingz/unknown-alive-presence
Closed

bbingz wants to merge 15 commits into
stablyai:mainfrom
bbingz:bbingz/unknown-alive-presence

Conversation

@bbingz

@bbingz bbingz commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Structured foreground result + neutral unknown-alive presence

Part of #9414. Stacked on the structured-foreground-resolution branch — review
the commits after its tip (base: orca/structured-foreground-resolution).

Problem

When a pane's foreground process is a live coding agent that Orca does not
recognize — a renamed or forked binary (a personal claude fork, a wrapper
named my-agent, etc.) — the tab-icon resolver collapsed it to a bare shell.
The scan result reaching the renderer was "recognized TuiAgent or null", so
an unrecognized-but-alive foreground was indistinguishable from an empty prompt.
The pane looked idle even while the fork agent was actively working.

The parent branch (server-side recognition of renamed binaries) deliberately
deferred two pieces that only make sense together — the type ships with its
consumer, so neither is speculative plumbing:

  1. a structured foreground result that carries the raw process name, not just
    the recognized-or-null engine, and
  2. a renderer layer that turns that raw name into a neutral live identity.

Design (the two parts, shipped together)

1. Structured foreground result. New concretely-named shared module
src/shared/foreground-process-resolution.ts exports
ForegroundProcessResolution { engine: TuiAgent | null; rawProcessName: string | null; isShell: boolean } and resolveForegroundProcess(name). The deployed-relay
wire contract stays string | null (parent-branch decision); every consumer that
only has the legacy string rebuilds the structure locally via
resolveForegroundProcess — i.e. { engine: recognize(...), rawProcessName, isShell: isShellProcess(...) }. The path is threaded only where the consumer
needs it:

  • pane-foreground-agent-tracker.ts publishes rawProcessName on the one entry
    the consumer reads — the command-path publish for a live, non-shell,
    unrecognized foreground. Recognized agents still publish their engine; shells
    carry no raw name (the consumer rejects them). No daemon cache rework.
  • The pane-foreground-agent store slice: entries gain an optional
    rawProcessName, and a new resolveFreshPaneForegroundRawProcess reuses
    fix(agents): keep-awake + sidebar attribution from foreground process evidence #9415's exact TTL + PTY-binding freshness gate (extracted into one shared
    helper, so the existing resolveFreshPaneForegroundAgent behavior is byte-for-
    byte unchanged).

2. Neutral unknown-alive presence. use-tab-agent.ts gains an additive
return type TabAgentIdentity = TuiAgent | { kind: 'unknown-live'; label: string } | null. After every existing recognized layer resolves null, the precedence
chain falls through to an unknown-live identity only when the pane's fresh
(TTL/PTY-gated, local-only) foreground reports a non-shell rawProcessName
and the title shows agent activity (spinner/working/needs-input via the
existing detectAgentStatusFromTitle classification). The label is the raw
process name — never a fake TuiAgent, never a vendor name.

The vim/htop boundary. The title-activity requirement is exactly what
separates a fork agent from a full-screen text editor: vim and htop set static
titles that classify to no activity, so they never gain agent presence. This
is stated in a why-comment and tested at both the resolver and hook levels.

3. UI. TerminalTabLeadingIcon and the SortableTab drag overlay
(TabDragPreview) render the unknown-live identity with an existing neutral
glyph — the lucide Terminal icon (the same generic terminal/process glyph the
drag ghost already uses for plain terminals), with the raw process name as its
tooltip. Recognized agents render exactly as before.

Non-goals (unchanged from #9415/parent)

  • No sidebar agent row and no worktree ring change — those read the
    recognized-agent field (resolveFreshPaneForegroundAgent), which stays null
    for unknown-live evidence.
  • No busy / keep-awake change — keep-awake holds on recognized engines only;
    an unknown-live entry has agent: null, so it never holds the machine awake.
  • No persistence — unknown-live identity is runtime-derived evidence and is
    never written into workspace session persistence.

Cross-platform / SSH / WSL

Unknown-live is strictly local: remote/SSH/WSL panes produce no foreground
process evidence (the tracker excludes non-trackable PTYs), and the hook
short-circuits isRemoteLike, so remote tabs degrade to their existing
title/hook identity with no behavior change.

Tests

  • foreground-process-resolution.test.ts — old-relay string degradation
    (recognized / unrecognized non-shell / shell / null).
  • pane-foreground-agent.test.ts — entries carry rawProcessName;
    resolveFreshPaneForegroundRawProcess fresh/stale/PTY-mismatch/shell/engine
    gates; existing resolveFreshPaneForegroundAgent tests stay green untouched.
  • pane-foreground-agent-tracker.test.ts — the persistent-unknown-process publish
    now carries the raw name (unknown-live source).
  • use-tab-agent-process-signals.test.ts — resolver: working title → unknown-live,
    no activity → null (vim), engine wins; hook: non-shell raw name + working title
    → unknown-live, vim static title → null, shell raw name → null, stale evidence
    → null.
  • TerminalTabLeadingIcon.test.tsx — unknown-live renders the neutral glyph +
    raw-name tooltip; recognized provider still wins.

Targeted vitest + typecheck (node/cli/web) + oxlint on touched files all green.

ELI5

When a terminal is running an agent binary Orca does not recognize by name, the tab no longer pretends it is a bare shell. Unknown-but-alive agents get a neutral presence so status and icons stay honest.

@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebase status: HARD (draft, not pushed) — conflicts with latest origin/main; lower-priority draft stack left for a follow-up session.

@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebase status (2026-07-22)

Attempted restack onto current main; this draft stack still has large multi-file conflicts (sidebar/worktree-status / lifecycle / hook-service) against recent main landings.

Leaving draft until base PRs (#8872 close-intent, #9415 unknown-busy) land, then restack. Not closing — work is still intended, just blocked on a clean base.

@bbingz
bbingz force-pushed the bbingz/unknown-alive-presence branch from 5efce1e to 049d174 Compare July 22, 2026 03:18
@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Restack onto rebased #9434 tip

Cherry-picked the two unique commits onto the rebased bbingz/structured-foreground-resolution tip (which already sits on current main):

  1. feat(foreground): carry structured resolution to the renderer tracker
  2. feat(tab-icon): neutral unknown-live presence for unrecognized fork agents

New head: $(git rev-parse HEAD)
Base retargeted to bbingz/structured-foreground-resolution so the PR diff is unique-only (stack remains draft).

Conflicts in use-tab-agent.ts / SortableTab.tsx resolved by keeping the unknown-live identity path.

@bbingz
bbingz force-pushed the bbingz/unknown-alive-presence branch from 049d174 to 6a5eaef Compare July 23, 2026 02:37
@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Restack note

Rebased onto rebased #9434 tip (force-with-lease). Stack base commits match #9434.

  • feat(foreground): carry structured resolution to the renderer tracker
  • feat(tab-icon): neutral unknown-live presence for unrecognized fork agents

Tests: foreground-process-resolution + TerminalTabLeadingIcon — 12 passed.

Depends on #9434 landing first (or merge as stacked head including #9434 commits).

@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Restack + review guide (community, awaiting maintainer)

Draft. Restacked onto rebased #9434 tip (force-with-lease). Stack base matches #9434. +2 unique commits (11 total including #9415+#9434).

Unique vs main

  • Structured foreground resolution carried to renderer tracker (foreground-process-resolution)
  • Neutral unknown-live tab leading icon for unrecognized fork agents (title activity + non-shell FG)

Stack / depends

#9415 → #9434 → #9435 (this)

Tests (local)

  • foreground-process-resolution + TerminalTabLeadingIcon — 12 passed

Community author cannot merge. Leave draft until base of stack is reviewed.

@bbingz
bbingz force-pushed the bbingz/unknown-alive-presence branch 2 times, most recently from 55ab9a6 to c683e3b Compare July 26, 2026 14:06
@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
@bbingz
bbingz force-pushed the bbingz/unknown-alive-presence branch 2 times, most recently from 2b1e29a to ff906f8 Compare July 31, 2026 09:54
bbingz and others added 14 commits August 6, 2026 07:39
…-status gate

A confirmed foreground that is neither a shell nor a recognized agent
(wrapper/fork agent binaries) previously counted as "shell only", which
suppressed fresh hook state and reported the pane idle. Only a confirmed
real shell (or an unavailable confirmation, matching the fail-closed catch
path) may now suppress explicit hook status.
…L + revalidation

Hook 'working' statuses were the only wake evidence, so wrapper-launched or
manually-run recognized agents (resolved by the existing foreground scans)
let the machine sleep mid-run. The runtime now reports each completed scan's
recognized-agent-or-null result; AgentAwakeService holds wake eligibility per
PTY while that evidence is fresh (5 min TTL), renews it at expiry via a
cache-only revalidation callback (never a new scan, 2h hard cap), and drops
it on a null report or PTY stop. Arbitrary non-shell processes never grant
wake. No new scans or cadences are added.
…rocess identity

Wrapper-launched claude (a shell function exec'ing the real binary) emits
Claude activity titles without the literal 'claude' token, so the row builder
and worktree ring rejected the pane as unattributable — invisible while
working. The paneForegroundAgent slice already resolves the recognized
foreground process; surface it as identity attribution:

- Slice entries now carry observedAt (stamped centrally) and the publishing
  PTY; resolveFreshPaneForegroundAgent gates consumers on a 30s TTL plus
  pane/tab PTY liveness so stale evidence after agent exit cannot fake a
  working state. The completion coordinator's existing inspections re-arm
  the observation (no new scans, no new cadence).
- resolveTitleDerivedAgentType/resolveAgentTypeFromTerminalTitle accept the
  process agent so a token-less Claude title yields a Claude row and an
  attributable working ring. State still comes from title activity or hooks;
  process identity alone never invents 'working'. Hook rows keep precedence.
- worktree-agent-activity-summary narrows the slice per worktree with stable
  references; card status, agent rows, and section activity consume it.
…to PTY, expire attribution on wall clock

Review fixes for the busy/visibility PR:

- agent-awake-foreground-evidence: enforce the 2h reportedAt cap
  unconditionally in pruneAndCount and align boundary comparisons with
  nextExpiry, so a stale timer firing at the cap (or exactly at the TTL)
  can no longer keep the power-save blocker held forever with no timer
  rescheduled. New test drives revalidation-renewed evidence to the cap
  and asserts the blocker stops with no timer left.
- onForegroundAgentInspected now carries the PTY the inspection ran
  against; pty-connection only accepts it while the pane still owns that
  PTY, and refreshPaneForegroundAgentObservation stamps it on created
  entries and rebinds (identity-only) evidence held for a previous PTY
  instead of keeping it fresh across a respawn.
- new usePaneForegroundAgentEvidenceExpiryTick schedules a one-shot
  re-render at the earliest evidence expiry for the worktree ring and
  agent rows, so a past-TTL working ring/row drops without unrelated
  store churn.
- restore the Claude-glyph regression fixture alongside the braille
  variant (it.each) in worktree-title-derived-agent-rows.test.
- update terminal-pane-detach-agent-identity.test for the central
  observedAt stamping introduced by this branch (was failing).
Known launch agents skip runtime foreground probes, so feed existing renderer inspections into runtime identity and wake evidence. Keep the review-driven rationale comments concise.
UNION rebase kept PR's ptyId stamping on setPaneForegroundAgent
publishes; two main-era expectations lagged. Align them with the
PR field and nearby tests. Cosmetic indent fix on the revoke path.
…ble image

Foreground-process recognition collapsed unrecognized live processes to
the shell fallback, so an argv0-renamed real binary or a native fork at a
non-standard path (e.g. ~/.local/bin/grok) was never identified.

Add a lazy executable-image evidence pass that runs ONLY for still-
unrecognized non-shell foreground ('+') candidates: resolve the real
executable (Linux /proc/PID/exe, macOS lsof -d txt, Windows the already-
captured CIM ExecutablePath) and re-run agent recognition on its basename.
Per-PID cached behind a short TTL; no extra ps scan, so both ps-scan-volume
guards stay green. Interpreter forks resolve to node/python and stay
unrecognized (script CLIs remain covered by argv/entrypoint recognition).
On SSH, orca-runtime had no way to confirm a foreground read, so it
trusted a possibly-stale relay getForegroundProcess result (an idle-looking
shell that still fronts a live agent).

Add pty.confirmForegroundProcess: the relay handler forces a fresh
post-boundary process-table scan (new fresh option threaded through
getForegroundProcessName), and SshPtyProvider.confirmForegroundProcess
requests it. Old-relay tolerant: a missing method (JSON-RPC -32601) is
feature-detected and latched, degrading to today's trusting
getForegroundProcess read instead of erroring.
…cognition

Executable-image evidence recognized a renamed binary by its basename alone
(recognizeAgentProcess on the resolved path), bypassing the command-line
recognizer's guards: the headless one-shot filter and the generic `orca` vs
`orca claude-teams` subcommand rule. A renamed `claude --print` or a bare
`orca` was therefore mislabeled as an interactive agent.

Recognize the resolved image WITH the process's original arguments: substitute
the real executable as argv0 and re-run recognizeAgentProcessFromCommandLine so
those guards still apply. Applies to the POSIX (local + relay) and Windows
ExecutablePath paths. Also corrects the per-PID cache comment: a recycled/exec'd
PID can be briefly mislabeled (stale path is re-recognized), not merely missed.

Adds headless, generic-orca, and genuine-claude-teams recognition tests plus a
Windows generic-orca ExecutablePath negative test.
Adversarial review found two defects in executable-image recognition:

- recognizeAgentFromExecutableImage stripped the original argv0 by the
  first whitespace, which breaks a quoted path with an internal space
  (Windows "C:\Program Files\...\x.exe"): the dangling quote swallowed
  following tokens, burying --print (headless one-shot mislabeled as an
  interactive agent) or claude-teams (genuine orca launch failed
  recognition). Strip argv0 quote-aware instead.
- The per-PID executable-path cache was never evicted; every distinct
  non-shell foreground command accumulated an entry forever in a
  long-lived daemon. Sweep expired entries once the map crosses a soft
  cap so it stays bounded to the active TTL window.

Tests: quoted spaced-path headless/interactive/orca-claude-teams cases,
bounded-cache eviction, and the default Linux readlink('/proc/PID/exe')
reader (success + null-on-failure).
Introduce ForegroundProcessResolution { engine, rawProcessName, isShell }
so an unrecognized live foreground is no longer collapsed to a bare shell.
The deployed-relay wire contract stays string|null; consumers rebuild the
structure locally via resolveForegroundProcess (degrade old-relay strings).

Thread it only along the renderer path: the pane-foreground-agent tracker
publishes rawProcessName on the command-path entry for a live, non-shell,
unrecognized foreground (recognized agents publish their engine; shells need
no raw name). The store slice gains an optional rawProcessName and a new
resolveFreshPaneForegroundRawProcess that reuses stablyai#9415's TTL/PTY freshness
gate (extracted into one shared helper — existing resolveFreshPaneForegroundAgent
behavior unchanged).
…gents

useTabAgent now returns TabAgentIdentity (TuiAgent | { kind: 'unknown-live';
label } | null). After every recognized layer resolves null, the precedence
chain falls through to a neutral live identity when the pane's fresh
(TTL/PTY-gated, local-only) foreground reports a non-shell rawProcessName AND
the title shows agent activity (spinner/working via detectAgentStatusFromTitle).
The title-activity gate is what separates a fork agent from a full-screen text
editor: vim/htop set static titles that classify to no activity, so they never
gain agent presence.

TerminalTabLeadingIcon and the SortableTab drag overlay render it with the
neutral lucide Terminal glyph and the raw process name as tooltip — never a
vendor logo. No sidebar row, no worktree ring, no busy/keep-awake change (those
read the recognized-agent field, null here), no persistence.
@bbingz

bbingz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of fork PR backlog cleanup.

This draft is long-conflicted (DIRTY) against current main and is not being actively rebased. Feel free to reopen or open a fresh PR if the work is still wanted.

@bbingz bbingz closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants