Repository navigation
fix(remote): stop an empty host inventory settling the mirror - #16414
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughAdds complete host terminal liveness validation through 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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 💡
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
src/renderer/src/runtime/host-live-terminal-probe.tssrc/renderer/src/runtime/host-session-mirror-empty-inventory-settle.test.tssrc/renderer/src/runtime/host-session-mirror-settle-census.test.tssrc/renderer/src/runtime/web-session-tabs-sync-window-visibility.test.tsxsrc/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.
Real-surface SSH/relay validation (STA-5377)Throwaway Linux Docker SSH target ( What the real SSH path proved
Connected, no project yet: Live SSH PTY + remote explorer: Disconnect parks (does not kill) the session: Reconnect: one Terminal 1, same PTY, sentinel file still on the host: Genuinely zero terminals, host still connected: Loss of contact stays Remaining gap (this is the STA-5377 race)This topology is SSH as an execution host. Not exercised live:
Logs inspected: renderer console (reattach replay; no settle-probe calls), Electron 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. |
Review status: land after fixesSenior review found and fixed two release-relevant races, both pushed to this PR:
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, 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 Remaining caveat: that live topology was a direct SSH execution host, not a paired |
* 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
…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
…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)
…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
…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.
…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
…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
…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
…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
…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.






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:
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.
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.tsupgrades a fully-applied host inventory into anenvironment-wide "the host has spoken" verdict:
With zero published snapshots both sides are
0, so0 === 0fires thatverdict with no host evidence behind it. There is no floor requiring that even
one frame carried any.
A live host legitimately answers
[]:session.tabs.listAllreturns[...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
markHostSessionMirrorHydratedstamps the generation and drains parked waiters→
host-mirrored-pane-liveness.tsreturns null because the mirror now reads ashydrated even though
ptyIdsByTabId[tabId]is still empty →resume-sleeping-agent-session.tsstops parking → it forkscodex resume/claude --resumeagainst a PTY the host is still running. Duplicate agentsessions (
codex -32600 already has an active writer). Relay / SSH-paired only.host-session-mirror-hydration.tsexists precisely to prevent this — its headersays 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, notexited.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 > 0trades one bug for the other. The distinguisherhas to be host readiness, not list emptiness.
Why
terminal.listis the right signalterminal.listreads the host's PTY controller —ptysByIdplus thecross-generation daemon inventory via
refreshPtyWorktreeRecordsWithControllerInventory→allLivePtyIds— notthe session-tab mirror. So it sees live PTYs even when
mobileSessionTabsByWorktreeis empty. That is exactly the third state themirror cannot see, and it needs no wire change: the client already calls
terminal.liston this same path, on the same paired connection, fromweb-session-terminal-orphan-recovery.ts— routing, auth and error guards allexist.
When
publishedSnapshotCount === 0, the environment-wide settle is now gatedbehind one probe for that environment:
updatedframes andtombstones settle per-worktree as before
requireFreshPtyLiveness: truemeans an unavailable daemon inventory raisesterminal_liveness_unavailablerather than answering a false empty, and thatlands as
unverifiable→ parked. Park-on-error matches the module's own rulethat 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. Onhosts predating
requireFreshPtyLiveness(#5473) zod strips the unknown paramand 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
publishedSnapshotCountpreviously 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:
snapshots: []+ a live PTY) ⇒ must notsettle, waiters stay parked — this is the regression
hang
host-session-mirror-settle-census.test.tsis updated deliberately (theenv-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.tsreverted toorigin/main(
5ebc4bb2bc), everything else unchanged:Note which two pass on unfixed main: the zero-terminal settle and the
published-inventory settle. The regression is the parking pair.
Fix restored:
Full renderer runtime suite on the rebased base:
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-ratchetandcheck:reliability-gatesall clean.Fixes STA-5377