Skip to content

fix(remote): stop an empty host inventory settling the mirror - #16414

Merged
brennanb2025 merged 3 commits into
mainfrom
brennan/sta-5377-empty-host-inventory-settle
Aug 25, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennan/sta-5377-empty-host-inventory-settle

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​303 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​297
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141

ELI5 — what a user actually sees

Who this affects: anyone running an agent on a remote machine — an SSH host or a paired runtime. Purely local and WSL sessions are unaffected.

The setup. You have Codex or Claude running in a terminal on a remote host. You close the lid, lose wifi for a moment, or the app reconnects for any reason.

Before this fix. On reconnect, Orca asks the host "which terminal sessions do you have?" The host is alive and your agent is still running — but it hasn't finished publishing its session list yet, so it truthfully answers "none so far."

Orca reads that empty answer as "the agent is gone" and helpfully starts a fresh one. Now there are two agents running against the same workspace: the original, still alive on the host and still writing files, plus a brand-new duplicate. What you see:

  • an agent session that appears to restart itself after a reconnect
  • two agents editing the same repo, interleaving each other's work
  • Codex refusing the new session with an "already has an active writer" style error
  • in the worst case, the duplicate resuming from an older checkpoint and undoing work the original just did

After this fix. Before concluding the agent is gone, Orca asks a second, different question: "do you actually have any live terminals right now?" That question reads the host's live PTY table rather than its session list, so it sees the truth even before publishing finishes.

  • host says "yes, I have live terminals" → Orca waits instead of forking. Your agent reconnects to the session it already had.
  • host says "genuinely none" → Orca proceeds exactly as before. Nothing hangs.
  • the question fails or is unanswerable → Orca waits rather than guessing. A missing answer is not proof of death.

Why the "genuinely none" case matters. The naive fix — "never settle on an empty list" — would swap this bug for a worse one: a host that legitimately has zero terminals would leave your panes waiting forever. The tests pin both directions, so neither failure can come back.

Net effect for users: reconnecting to a remote agent no longer risks spawning a duplicate of it, and a remote host with no terminals still opens instantly.

What breaks

web-session-tabs-sync.ts upgrades a fully-applied host inventory into an
environment-wide "the host has spoken" verdict:

const settles = frames.filter(({ decision }) => decision.settlesHostMirror)
if (fullInventory && settles.length === fullInventory.publishedSnapshotCount) {
  markHostSessionMirrorHydrated(fullInventory.environmentId)

With zero published snapshots both sides are 0, so 0 === 0 fires that
verdict with no host evidence behind it. There is no floor requiring that even
one frame carried any.

A live host legitimately answers []: session.tabs.listAll returns
[...this.mobileSessionTabsByWorktree.values()] from a map constructed empty,
and the full hydrate early-returns without writing when an authoritative window
already exists. So an unpublished-but-live host is indistinguishable from a host
that owns nothing — as far as the session-tab mirror is concerned.

Consequence

markHostSessionMirrorHydrated stamps the generation and drains parked waiters
→ host-mirrored-pane-liveness.ts returns null because the mirror now reads as
hydrated even though ptyIdsByTabId[tabId] is still empty →
resume-sleeping-agent-session.ts stops parking → it forks codex resume /
claude --resume against a PTY the host is still running. Duplicate agent
sessions (codex -32600 already has an active writer). Relay / SSH-paired only.

host-session-mirror-hydration.ts exists precisely to prevent this — its header
says it tells "the host reported no PTY" apart from "the host has not
answered yet"
. An empty inventory from an unpublished host is a third case
the code did not distinguish. Per the SSH execution boundary it is
unverifiable, not exited.

The tension this fix has to respect

A healthy host with genuinely zero terminals must still settle, or its panes
park forever — the opposite failure, frozen instead of duplicated. Naively
requiring settles.length > 0 trades one bug for the other. The distinguisher
has to be host readiness, not list emptiness.

Why terminal.list is the right signal

terminal.list reads the host's PTY controller — ptysById plus the
cross-generation daemon inventory via
refreshPtyWorktreeRecordsWithControllerInventory → allLivePtyIds — not
the session-tab mirror. So it sees live PTYs even when
mobileSessionTabsByWorktree is empty. That is exactly the third state the
mirror cannot see, and it needs no wire change: the client already calls
terminal.list on this same path, on the same paired connection, from
web-session-terminal-orphan-recovery.ts — routing, auth and error guards all
exist.

When publishedSnapshotCount === 0, the environment-wide settle is now gated
behind one probe for that environment:

  • empty answer → settle (genuinely zero-terminal host, no hang)
  • non-empty, or error → leave waiters parked; later updated frames and
    tombstones settle per-worktree as before

requireFreshPtyLiveness: true means an unavailable daemon inventory raises
terminal_liveness_unavailable rather than answering a false empty, and that
lands as unverifiable → parked. Park-on-error matches the module's own rule
that a failed inventory is never proof a host-owned PTY exited.

Per-worktree settles (markHostSessionMirrorWorktreeHydrated) are untouched,
and an inventory that did publish snapshots still settles synchronously in
the same tick, with no probe round trip (pinned by a test). The deferred arm
re-checks the connection generation before stamping, because a reconnect during
the round trip would make the answer speak for a connection whose PTYs nobody
listed.

Old hosts need no fallback

The client pulls, so every deployed host already answers terminal.list. On
hosts predating requireFreshPtyLiveness (#5473) zod strips the unknown param
and the host returns a best-effort list: a non-empty answer still parks (safe),
and a false empty reproduces today's behaviour exactly. Strictly monotone
improvement, no regression, no capability negotiation needed.

Test coverage

publishedSnapshotCount previously appeared only in the production file —
zero tests. That is why this shipped. The new suite pins all three states,
because two of them are opposite failure modes:

  1. live-but-unpublished host (snapshots: [] + a live PTY) ⇒ must not
    settle, waiters stay parked — this is the regression
  2. genuinely zero-terminal host (both empty) ⇒ settle does fire — guards the
    hang
  3. probe error ⇒ stays parked
  4. plus: a published inventory still settles in-tick with no probe

host-session-mirror-settle-census.test.ts is updated deliberately (the
env-wide mark now has two audited arms inside the same receipt), as that census
instructs.

Red / green

src/renderer/src/runtime/web-session-tabs-sync.ts reverted to origin/main
(5ebc4bb2bc), everything else unchanged:

### RED — src/renderer/src/runtime/web-session-tabs-sync.ts reverted to origin/main (5ebc4bb2bc)

 FAIL  host-session-mirror-empty-inventory-settle.test.ts > empty host inventory settling the session mirror > leaves waiters parked when the host is live but has not published
AssertionError: expected 1 to be +0 // Object.is equality

- Expected
+ Received

- 0
+ 1

 ❯ src/renderer/src/runtime/host-session-mirror-empty-inventory-settle.test.ts:98:26
     96|     await flushProbe()
     97|
     98|     expect(resumeSweeps).toBe(0)
       |                          ^

 FAIL  host-session-mirror-empty-inventory-settle.test.ts > empty host inventory settling the session mirror > leaves waiters parked when the readiness probe fails
AssertionError: expected 1 to be +0 // Object.is equality

- Expected
+ Received

- 0
+ 1

 ❯ src/renderer/src/runtime/host-session-mirror-empty-inventory-settle.test.ts:131:26

 Test Files  1 failed (1)
      Tests  2 failed | 2 passed (4)

Note which two pass on unfixed main: the zero-terminal settle and the
published-inventory settle. The regression is the parking pair.

Fix restored:

### GREEN — fix restored

 RUN  v4.1.5

 Test Files  1 passed (1)
      Tests  4 passed (4)

Full renderer runtime suite on the rebased base:

 Test Files  119 passed (119)
      Tests  881 passed (881)

src/renderer/src/lib/ (the resume/liveness consumers): 453 passed,
4322 passed | 1 skipped. typecheck:web, oxfmt, oxlint (base +
code-quality native + type-aware), check:max-lines-ratchet and
check:reliability-gates all clean.

Fixes STA-5377

An inventory with zero published snapshots satisfied
`settles.length === fullInventory.publishedSnapshotCount` as `0 === 0` and
fired the environment-wide host-mirror verdict with no host evidence behind
it. A live relay/SSH-paired host answers exactly that until its renderer's
first publish, so the drained resume sweep forked a second agent onto a PTY
the host was still running.

Gate that one case behind a `terminal.list` readiness probe: it reads the PTY
controller, not the session-tab mirror, so it sees live PTYs the mirror has
not published. Only "no terminals" settles; live or unverifiable leaves
waiters parked for the next inventory or per-worktree frame — a host with
genuinely zero terminals still settles, so panes do not park forever.

Fixes STA-5377
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41fa4210-2f0e-42e3-bd84-89066bf5bdca

📥 Commits

Reviewing files that changed from the base of the PR and between c11a771 and 0ee54d0.

📒 Files selected for processing (2)
  • src/renderer/src/runtime/host-live-terminal-probe.ts
  • src/renderer/src/runtime/host-session-mirror-empty-inventory-settle.test.ts

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


📝 Walkthrough

Walkthrough

Adds complete host terminal liveness validation through terminal.list, including totalCount and execution-host coverage. Probes return live, none, or unverifiable and coalesce by environment and connection generation. Empty host inventories settle only when no live terminals exist and the connection generation remains unchanged. Tests cover omitted hosts, generation isolation, hydration behavior, census counts, and runtime call methods.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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. Analyzed 10 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the primary fix: preventing an empty host inventory from incorrectly settling the session mirror.
Description check ✅ Passed The description is detailed and relevant. It explains the user impact, root cause, implemented probe behavior, compatibility considerations, linked issue, and extensive test results. Some template hea…
Full details: Description check

Explanation

The description is detailed and relevant. It explains the user impact, root cause, implemented probe behavior, compatibility considerations, linked issue, and extensive test results. Some template headings and checklist items are omitted, including explicit visual-proof or N/A confirmation, but the core required information is present.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bcad4ea3-1e32-4786-9a10-0fc26953fb53

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebc4bb and 3284f24.

📒 Files selected for processing (5)
  • src/renderer/src/runtime/host-live-terminal-probe.ts
  • src/renderer/src/runtime/host-session-mirror-empty-inventory-settle.test.ts
  • src/renderer/src/runtime/host-session-mirror-settle-census.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync-window-visibility.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Real-surface SSH/relay validation (STA-5377)

Throwaway Linux Docker SSH target ([email protected]:2222, linux-arm64 relay), isolated Electron profile, identity Orca: brennan/sta-5377-empty-host-inventory-settle / worktree review-16414. pnpm build:relay first. Remote repo is demo-project at /work/demo-project (local git bundle after GitHub HTTPS clone was blocked).

What the real SSH path proved

  • Connected host with no project yet (zero terminals).
  • Opened /work/demo-project over SSH; Explorer listed the remote tree; one remote PTY (ssh:…@@pty-1).
  • A command written in that PTY created /work/demo-project/.sta5377-live on the host.
  • Disconnect parked the pane: “This terminal is waiting for qa-linux-ssh” — tab kept, PTY handle cleared, no second session.
  • Reconnect reused the same tab id and same @@pty-1 (tabCount=1, ptyCount=1). Relay log: socket client closed with ptys=1, then handshake + client accepted. Renderer reattach { replay: true }.
  • After closing the tab: connected host, 0 terminal sessions.
  • Pausing the container: status reconnecting, error Relay channel lost. Reconnecting.... Pane shows “This terminal will resume after the host is available.” Not treated as exited.

Connected, no project yet:

03-ssh-connected-zero-project.png

Live SSH PTY + remote explorer:

05-ssh-project-live-terminal.png

Disconnect parks (does not kill) the session:

08-ssh-disconnected-terminal-waiting.png

Reconnect: one Terminal 1, same PTY, sentinel file still on the host:

09-ssh-reconnected-single-pty.png

Genuinely zero terminals, host still connected:

10-ssh-connected-zero-terminals.png

Loss of contact stays reconnecting / resume-later, not “the host has none”:

11-ssh-relay-channel-lost-reconnecting.png

Remaining gap (this is the STA-5377 race)

This topology is SSH as an execution host. runtimeEnvironments.list() stayed []. Session-tab sync only mirrors kind: 'runtime' hosts, so terminal.list / session.tabs.listAll were never issued on this path (probeLog empty). Hydration for the SSH id stayed false.

Not exercised live:

  1. Paired-runtime empty inventory (the actual 0===0 settle): a live host that answers session.tabs.listAll = [] while terminal.list is non-empty, so waiters stay parked.
  2. Duplicate agent resume on that unpublished window (needs a sleeping agent on a mirrored web-terminal-* pane).
  3. Probe error terminal_liveness_unavailable as the empty-inventory distinguisher (seen only on local orchestration recovery at startup, not on this SSH settle path).

Logs inspected: renderer console (reattach replay; no settle-probe calls), Electron [ssh-relay] Platform: linux-arm64 → Relay started successfully / reconnect via existing socket, remote relay.log (client closed with ptys=1 then re-accepted). No product files were modified.

Verdict: SSH/relay/PTY connect, live PTY, zero-terminal host, disconnect-park, and loss-of-contact reconnect are real and healthy. Do not treat this run as live proof of the empty-inventory settle itself — that still needs a paired runtime host over relay.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: land after fixes

Senior review found and fixed two release-relevant races, both pushed to this PR:

  • c11a771fe9 scopes in-flight terminal.list readiness probes by connection generation, so a reconnect cannot reuse the prior connection's none evidence.
  • 0ee54d0b21 treats a present omitted host scope as unverifiable while preserving the best-effort response from compatible older hosts that do not publish hostScope; this keeps the genuine-zero anti-hang behavior.

Final mechanism coverage pins all required outcomes: live-but-unpublished and probe-error stay parked; genuinely-zero settles; published inventory settles in-tick; probes do not cross reconnect generations; partial current-host censuses stay unverifiable; and valid legacy live/zero results retain compatibility. Final readiness found zero remaining candidates. Focused tests, typecheck:web, oxfmt, oxlint, diff checks, package/Windows/wire CI, and the complete PR check run are green. One unrelated Node 24 shard initially timed out in the existing 130,000-leaf persistence stress test; the exact file passed locally (7/7, 13.2s) and the failed CI job passed on rerun.

Real-surface evidence: an isolated Electron instance was identity-checked against this worktree, the relay was built and deployed to a throwaway Linux SSH container with a real demo-project, a remote PTY changed backing filesystem state, disconnect parked the pane, reconnect reused the same tab/PTY with replay, and a paused transport remained reconnecting rather than reading as exited. Screenshots and the run note are attached in the earlier evidence comment: #16414 (comment)

Remaining caveat: that live topology was a direct SSH execution host, not a paired kind: runtime host, so it did not exercise the exact empty session-tab inventory branch. The release-blocker behavior therefore has deterministic mechanism proof plus adjacent real SSH/relay proof, but not a live paired-runtime reproduction. No merge was performed.

@brennanb2025
brennanb2025 merged commit bc98655 into main Aug 25, 2026
99 of 101 checks passed
brennanb2025 added a commit that referenced this pull request Aug 25, 2026
* fix(remote): stop an empty host inventory settling the mirror

An inventory with zero published snapshots satisfied
`settles.length === fullInventory.publishedSnapshotCount` as `0 === 0` and
fired the environment-wide host-mirror verdict with no host evidence behind
it. A live relay/SSH-paired host answers exactly that until its renderer's
first publish, so the drained resume sweep forked a second agent onto a PTY
the host was still running.

Gate that one case behind a `terminal.list` readiness probe: it reads the PTY
controller, not the session-tab mirror, so it sees live PTYs the mirror has
not published. Only "no terminals" settles; live or unverifiable leaves
waiters parked for the next inventory or per-worktree frame — a host with
genuinely zero terminals still settles, so panes do not park forever.

Fixes STA-5377

* fix(remote): fence host readiness probes by generation

* fix(remote): preserve legacy terminal probe fallback
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…ai#16414)

* fix(remote): stop an empty host inventory settling the mirror

An inventory with zero published snapshots satisfied
`settles.length === fullInventory.publishedSnapshotCount` as `0 === 0` and
fired the environment-wide host-mirror verdict with no host evidence behind
it. A live relay/SSH-paired host answers exactly that until its renderer's
first publish, so the drained resume sweep forked a second agent onto a PTY
the host was still running.

Gate that one case behind a `terminal.list` readiness probe: it reads the PTY
controller, not the session-tab mirror, so it sees live PTYs the mirror has
not published. Only "no terminals" settles; live or unverifiable leaves
waiters parked for the next inventory or per-worktree frame — a host with
genuinely zero terminals still settles, so panes do not park forever.

Fixes STA-5377

* fix(remote): fence host readiness probes by generation

* fix(remote): preserve legacy terminal probe fallback
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…ai#16414)

* fix(remote): stop an empty host inventory settling the mirror

An inventory with zero published snapshots satisfied
`settles.length === fullInventory.publishedSnapshotCount` as `0 === 0` and
fired the environment-wide host-mirror verdict with no host evidence behind
it. A live relay/SSH-paired host answers exactly that until its renderer's
first publish, so the drained resume sweep forked a second agent onto a PTY
the host was still running.

Gate that one case behind a `terminal.list` readiness probe: it reads the PTY
controller, not the session-tab mirror, so it sees live PTYs the mirror has
not published. Only "no terminals" settles; live or unverifiable leaves
waiters parked for the next inventory or per-worktree frame — a host with
genuinely zero terminals still settles, so panes do not park forever.

Fixes STA-5377

* fix(remote): fence host readiness probes by generation

* fix(remote): preserve legacy terminal probe fallback

(cherry picked from commit bc98655)
nwparker added a commit that referenced this pull request Sep 2, 2026
…g destruction (#17981)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (#16414, #16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from #13621 that blocked this were all written before the
`authoritative` label existed (#13621 landed 2026-08-11; the capability landed
2026-08-26 in #16546). #13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs #11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs #15317
nwparker added a commit that referenced this pull request Sep 2, 2026
…rifiable, not idle (#18012)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (#16414, #16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from #13621 that blocked this were all written before the
`authoritative` label existed (#13621 landed 2026-08-11; the capability landed
2026-08-26 in #16546). #13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs #11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs #15317

* fix(sidebar): stop a stale agent row claiming the pane is empty

A stale non-`done` entry decayed to `idle` whether or not Orca still held the
pane's PTY, so "we lost the reporting stream" and "nothing is running here" were
the same display class. Split the destination on evidence already computed: with
a live PTY the row is `unverifiable` and reports the observer's own fact — how
long the silence has run — so the user can apply context Orca has no way to know.
With no PTY it stays `idle`.

Smart sort gains class 4 for it, between working (3) and idle (now 5): still
plausibly the most important pane, never outranking one that is reporting, and
never a claim that the agent finished. `unverifiable` stays renderer-local; the
dashboard card projection publishes today's `idle` because that vocabulary is
validated against a fixed allowlist in main and read by older pop-outs.

AGENT_STATUS_STALE_AFTER_MS is unchanged.

* fix(agent-status): decay a mirrored remote row on the replica's own clock

A paired client mirrored a remote host's status rows verbatim, host wall clock
included, and the staleness gate then computed `rendererNow - hostStamp`. The
effective window was 30 minutes plus or minus the two machines' skew: a host
running fast held every remote row permanently fresh, a host running slow decayed
them on arrival. The constant was never the lever there — the subtraction
straddled two clocks.

The replica now stamps `mirroredEvidenceReceivedAt` from its own clock when the
authority's observation advances, carries it forward across an exact repaint (a
restated observation is not a new one), and decays against it. Both sides of the
subtraction come from one machine; locally observed rows carry no stamp and are
unchanged.

The alternative the type comment named — carrying the authority's freshness
verdict — was rejected: a verdict is computed at publish time and cannot age
between snapshots, so once the host goes quiet the replica would hold `fresh`
forever. That is precisely the loss-of-contact case the window exists for.
AGENT_STATUS_STALE_AFTER_MS is unchanged; the clock rules move to
agent-status-freshness.ts to keep agent-status-types.ts under its line budget.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
…g destruction (stablyai#17981)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

stablyai#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (stablyai#16414, stablyai#16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from stablyai#13621 that blocked this were all written before the
`authoritative` label existed (stablyai#13621 landed 2026-08-11; the capability landed
2026-08-26 in stablyai#16546). stablyai#13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs stablyai#11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

stablyai#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs stablyai#15317

Mirror-Of: 4e35e05
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
…rifiable, not idle (stablyai#18012)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

stablyai#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (stablyai#16414, stablyai#16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from stablyai#13621 that blocked this were all written before the
`authoritative` label existed (stablyai#13621 landed 2026-08-11; the capability landed
2026-08-26 in stablyai#16546). stablyai#13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs stablyai#11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

stablyai#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs stablyai#15317

* fix(sidebar): stop a stale agent row claiming the pane is empty

A stale non-`done` entry decayed to `idle` whether or not Orca still held the
pane's PTY, so "we lost the reporting stream" and "nothing is running here" were
the same display class. Split the destination on evidence already computed: with
a live PTY the row is `unverifiable` and reports the observer's own fact — how
long the silence has run — so the user can apply context Orca has no way to know.
With no PTY it stays `idle`.

Smart sort gains class 4 for it, between working (3) and idle (now 5): still
plausibly the most important pane, never outranking one that is reporting, and
never a claim that the agent finished. `unverifiable` stays renderer-local; the
dashboard card projection publishes today's `idle` because that vocabulary is
validated against a fixed allowlist in main and read by older pop-outs.

AGENT_STATUS_STALE_AFTER_MS is unchanged.

* fix(agent-status): decay a mirrored remote row on the replica's own clock

A paired client mirrored a remote host's status rows verbatim, host wall clock
included, and the staleness gate then computed `rendererNow - hostStamp`. The
effective window was 30 minutes plus or minus the two machines' skew: a host
running fast held every remote row permanently fresh, a host running slow decayed
them on arrival. The constant was never the lever there — the subtraction
straddled two clocks.

The replica now stamps `mirroredEvidenceReceivedAt` from its own clock when the
authority's observation advances, carries it forward across an exact repaint (a
restated observation is not a new one), and decays against it. Both sides of the
subtraction come from one machine; locally observed rows carry no stamp and are
unchanged.

The alternative the type comment named — carrying the authority's freshness
verdict — was rejected: a verdict is computed at publish time and cannot age
between snapshots, so once the host goes quiet the replica would hold `fresh`
forever. That is precisely the loss-of-contact case the window exists for.
AGENT_STATUS_STALE_AFTER_MS is unchanged; the clock rules move to
agent-status-freshness.ts to keep agent-status-types.ts under its line budget.

Mirror-Of: 266b2ea
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ai#16414)

* fix(remote): stop an empty host inventory settling the mirror

An inventory with zero published snapshots satisfied
`settles.length === fullInventory.publishedSnapshotCount` as `0 === 0` and
fired the environment-wide host-mirror verdict with no host evidence behind
it. A live relay/SSH-paired host answers exactly that until its renderer's
first publish, so the drained resume sweep forked a second agent onto a PTY
the host was still running.

Gate that one case behind a `terminal.list` readiness probe: it reads the PTY
controller, not the session-tab mirror, so it sees live PTYs the mirror has
not published. Only "no terminals" settles; live or unverifiable leaves
waiters parked for the next inventory or per-worktree frame — a host with
genuinely zero terminals still settles, so panes do not park forever.

Fixes STA-5377

* fix(remote): fence host readiness probes by generation

* fix(remote): preserve legacy terminal probe fallback
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…g destruction (stablyai#17981)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

stablyai#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (stablyai#16414, stablyai#16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from stablyai#13621 that blocked this were all written before the
`authoritative` label existed (stablyai#13621 landed 2026-08-11; the capability landed
2026-08-26 in stablyai#16546). stablyai#13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs stablyai#11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

stablyai#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs stablyai#15317
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…rifiable, not idle (stablyai#18012)

* fix(remote): stop one unlabelled inventory tombstoning a live worktree mirror

stablyai#11495 Step C. `buildMissingWebSessionTabsRemovals` synthesised a `removed: true`
tombstone -- emptying a worktree's entire mirror -- for any tracked worktree
absent from a single inventory frame, without ever consulting the host's own
authority label. `mirror-settle` already refuses to settle an *empty* inventory
that is not `authoritative` (stablyai#16414, stablyai#16546); the strictly more destructive
action was ungated.

An inventory the host labels `authoritative` carries a complete PTY census, so
one omission is host attestation and removal stays immediate. An unlabelled
inventory is a degraded or version-skewed census: `unverifiable`, not `exited`.
It must now repeat before it can destroy anything, reusing the two-observation
shape of `confirmSurfaceInventoryAbsence`. A legacy host that never negotiates
the capability still converges after two rounds, so ghost rows cannot outlive
the fence.

The 14 tests from stablyai#13621 that blocked this were all written before the
`authoritative` label existed (stablyai#13621 landed 2026-08-11; the capability landed
2026-08-26 in stablyai#16546). stablyai#13621's own summary says "Reconcile each resumed host
from an authoritative inventory, including removals", so their fixtures are
retargeted to say so explicitly rather than weakened.

Refs stablyai#11495

* fix(agent-status): stop a reconnect replay restamping the staleness clock

stablyai#15317 correctness half. `receivedAt` was doing two jobs: delivery order and
evidence age. A relay reconnect replays every cached row, and `receivedAt` must
restamp to clear the connection watermark that `clearStatusEntriesForConnection`
raises -- so a pane stuck at `working` had its 30-minute deadline pushed out by
another 30 minutes on every reconnect. The TTL was never reached, which is why
this read as a tuning question.

Two clocks, not one rewritten clock:

- `receivedAt` is untouched. The transient-clear watermark and the four `<`
  ordering drops (`agent-status-event-applicator`, `agent-status-live-entry-builder`,
  `agent-status-cleanup-actions`) keep working unchanged. Restamping a replay with
  its original time would have made it `<= watermark` and dropped it outright,
  leaving the pane with no row at all.
- `evidenceObservedAt` is new, optional, and read only by the staleness
  comparison (`isFreshNonDoneAgentStatus`, `isExplicitAgentStatusFresh`, the
  freshness scheduler). Main holds it per pane across the transport clear -- the
  clear deletes the row on purpose, but the *age* of evidence a later replay
  restates is not a claim about the pane. Absent means "no separate observation",
  and every consumer falls back to `receivedAt`/`updatedAt`, so old hosts and old
  rows behave exactly as today.

Behaviour: a genuinely active pane keeps stamping the observation clock from its
real events, so it stays `working` across a reconnect. A pane whose relay
restarted replays nothing and still falls through to title evidence. A torn-down
pane drops its remembered clock in `clearPaneState`, so a reused pane key cannot
inherit one.

`AGENT_STATUS_STALE_AFTER_MS` is deliberately unchanged -- the window length
remains a product decision.

Refs stablyai#15317

* fix(sidebar): stop a stale agent row claiming the pane is empty

A stale non-`done` entry decayed to `idle` whether or not Orca still held the
pane's PTY, so "we lost the reporting stream" and "nothing is running here" were
the same display class. Split the destination on evidence already computed: with
a live PTY the row is `unverifiable` and reports the observer's own fact — how
long the silence has run — so the user can apply context Orca has no way to know.
With no PTY it stays `idle`.

Smart sort gains class 4 for it, between working (3) and idle (now 5): still
plausibly the most important pane, never outranking one that is reporting, and
never a claim that the agent finished. `unverifiable` stays renderer-local; the
dashboard card projection publishes today's `idle` because that vocabulary is
validated against a fixed allowlist in main and read by older pop-outs.

AGENT_STATUS_STALE_AFTER_MS is unchanged.

* fix(agent-status): decay a mirrored remote row on the replica's own clock

A paired client mirrored a remote host's status rows verbatim, host wall clock
included, and the staleness gate then computed `rendererNow - hostStamp`. The
effective window was 30 minutes plus or minus the two machines' skew: a host
running fast held every remote row permanently fresh, a host running slow decayed
them on arrival. The constant was never the lever there — the subtraction
straddled two clocks.

The replica now stamps `mirroredEvidenceReceivedAt` from its own clock when the
authority's observation advances, carries it forward across an exact repaint (a
restated observation is not a new one), and decays against it. Both sides of the
subtraction come from one machine; locally observed rows carry no stamp and are
unchanged.

The alternative the type comment named — carrying the authority's freshness
verdict — was rejected: a verdict is computed at publish time and cannot age
between snapshots, so once the host goes quiet the replica would hold `fresh`
forever. That is precisely the loss-of-contact case the window exists for.
AGENT_STATUS_STALE_AFTER_MS is unchanged; the clock rules move to
agent-status-freshness.ts to keep agent-status-types.ts under its line budget.
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