Skip to content

Show phone-started turns live on the Mac and clear the stale background marker - #448

Merged
sambitcreate merged 9 commits into
mainfrom
stream/desktop-d5-live-remote-turns
Oct 13, 2026
Merged

sambitcreate merged 9 commits into
mainfrom
stream/desktop-d5-live-remote-turns

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of docs/plans/live-cross-device-streaming-plan.md (slice D5). A turn started from a phone now streams live in the Mac chat pane instead of appearing only after it finishes, and the stale "Response continues in the background…" marker is cleared correctly.

  • Main: new runs:observeLocal / runs:unobserveLocal IPC mirrors runs this Mac hosts (from HostRunRegistry) to the window that asked. Frames are batched (~16ms, 256 events/flush), sent only to the subscribing document, resumable by cursor, and released on unsubscribe, document destroy/navigate, or run end. Zero cost while nobody watches; no new network calls.
  • Renderer: LocalHostAdapter.observe folds frames through the existing remote-stream-translator into the detached projection store, so the pane shows live text, reasoning, timeline and Stop with no new UI. The pane observes only when the visible chat is active and not owned by this window; the window's own detached run always wins.
  • Handoff: the live projection stays until a completed chat read contains the run's saved reply (bounded retries), so the reply never flashes away when the run ends or activity goes idle first.
  • Stop: for a mirrored run, Stop escalates to runs:stopLocal → llmClient.cancel(runId, "user_stop"), the same host authority a paired phone with runs:control uses. Steer stays hidden for mirrored runs.
  • Stale marker fix: chats:settled fires per run, but the marker waited for the whole chat to go idle; a phone turn starting right after kept it stuck. The window now asks runs:settledLocal which of its runs are truly finished and releases only those.

Wire events and the Remote protocol are unchanged, so iOS and Android are unaffected.

Tests

  • main/handlers/local-runs.test.ts: register-and-invoke over the real registry (batching, cross-chat isolation, cursor resume, next-run adoption, release on destroy, input validation, settled query) plus an in-process end-to-end chain (registry → handlers → adapter → observer → store) showing live text before settle, host Stop, and release.
  • renderer/lib/hosts/observed-local-run.test.ts, local-host-adapter.test.ts, chat-terminal-sync.test.ts: idle-before-done ordering keeps the reply on screen, cancelled/stale reads don't hand off, failed start reads retry, stuck-marker reproduction.
  • npm run test:remote-chat, npm run test:aiden-remote, npm run test:ci-policy, npx tsc --noEmit -p ., npm run lint all pass locally.
  • Playwright not added: the e2e harness has no fake paired phone or pausable provider; covered by the in-process end-to-end test instead.

Review follow-ups

  • Fixed: the settled-stream release re-reads the chat before it drops the marker. If the observer's own refetch cancels that read, the release now retries it up to three times instead of leaving the marker up until the chat goes idle. Covered in chat-terminal-sync.test.ts, which includes a chat whose read keeps failing.

  • Deferred (P3): the observer's release grace timer closes the mirror even when its final read failed. The chat-level idle re-read still restores the transcript.

  • Deferred (P3): a journal gap of more than 4,096 events hides live text for the rest of that run. The persisted reply still lands.

  • Deferred (P3 hardening): runs:stopLocal doesn't check that the calling document observes the run. The renderer is first-party, and other stop paths share this trust model.

  • Deferred (P3): when a phone sends its next turn immediately after a reply finishes, the mirrored reply can disappear for one local chat read before the saved message replaces it.

  • Deferred (P3): if the observe call itself fails, it isn't retried while the chat stays busy. The persisted transcript still lands when the chat settles.

  • Merge hotspot with Show the composer's readiness message once (D1) #453: both PRs touch renderer/main/chat-transition.test.tsx (~353) and renderer/components/environment-subagents-contract.test.ts (~592). Whichever merges second needs a recheck.

Flaky tests

🤖 Generated with Claude Code

sambitcreate and others added 2 commits October 13, 2026 00:25
…nd marker

Main serves a per-document observation of the runs it hosts (runs:observeLocal,
runs:unobserveLocal) over the host run journal, batched at about 16ms and sent
only to the subscribing document. Observations are released on unsubscribe, on
destroy and when they end, and cost nothing while nobody watches. Stop for a run
this window did not start uses host authority (runs:stopLocal).

The renderer replays early frames in LocalHostAdapter.observe, folds them
through the remote stream translator into the detached projection store, and
the chat pane observes only an active chat it is not running itself.

"Response continues in the background" no longer sticks when a newer turn keeps
the chat busy: settled detached streams are confirmed with runs:settledLocal,
the chat is re-read, and only those streams are released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chat goes idle before the run's end frame and before the reply is read,
so tying the observation to activity closed it early and the reply flashed
away. The pane now starts observing when the chat becomes busy, stops at once
only on a chat change, a draft, unmount or its own turn, and on idle releases
the run after hand-off (bounded by a grace period and a final read).

Hand-off now needs a completed read that holds the run's reply; failed or
cancelled reads and reads that predate the reply retry with backoff. A failed
read for a new turn is retried, and owed reads retry on the next frame, so the
phone's message cannot stay missing for the whole turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@very-hermes-bot very-hermes-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

Comment thread renderer/main/chat-pane.tsx Outdated
Comment on lines +281 to +286
const visibleDetachedProjection =
cachedMessages?.[cachedMessages.length - 1]?.role === "assistant" ? null : detachedProjection;
// Run input is admitted only for the document that owns the run, so a
// mirrored run (a phone's turn) offers Stop and queueing but not Steer.
const observedRunVisible = visibleDetachedProjection?.observed === true;
const steerableDetachedProjection = observedRunVisible ? null : visibleDetachedProjection;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1 · logic] Observed phone-started turns are suppressed in existing chats ending in an assistant message
Confidence: 0.95

When an observed run starts in a chat whose prior turn ended in an assistant message, visibleDetachedProjection is suppressed to null until an async refetch completes, displaying the stale background marker and hiding the live stream.

Repair: Only suppress an observed detached projection if the last cached assistant message matches the observed run's generation ID in its timeline.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed: Added a check to only suppress the observed projection if the last cached assistant message matches the observed run's generation ID. This allows new observed turns to display even in existing chats that end with a previous assistant message.

The logic now correctly identifies when a cached message belongs to the current observed run versus a prior one, preserving visibility of incoming mirrored turns.

@very-hermes-bot

very-hermes-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 292e125e7b466025b8cf7ac95e3d724cc39a69e8
Generated: 2026-10-13T09:22:02+00:00
Reviews: 1

Summary

Desktop clients on macOS now mirror turns started on paired devices (such as phones) live in the chat pane and properly clear background drain markers when turns finish. In the main process, LocalRunObservers and the new runs:observeLocal IPC channel mirror batched host-run frames (~16ms intervals) exclusively to active subscribing renderer documents, scoped to the current run with cursor-based resumption. In the renderer, useObservedLocalRun and LocalHostAdapter.observe fold frames through the remote stream translator into chat-terminal-sync's detached projection store, projecting live text, reasoning, and Stop capabilities while withholding Steer. For handoff and cleanup, releaseSettledDetachedLifecycleStreams verifies with main (runs:settledLocal) which captured streams have completed and re-reads the transcript with bounded retries before releasing drain markers, preventing the "Response continues in the background…" state from remaining stuck. Maintainers should double-check that the bounded query limit (MAX_SETTLED_QUERY = 64) and settled refresh retry delay (FALLBACK_RETRY_DELAY_MS = 100ms) align with expected maximum concurrent runs and IPC backpressure under heavy traffic.

Confidence Score: 5/5

Fully traced and verified across main process IPC handlers, run observers, lifecycle transitions, renderer projection sync, and test suites.

📁 Important Files Changed
  • main/services/local-run-observers.ts: Core observation engine batching host-run journal events into ~16ms frames per document, handling cursor resumes, run adoptions, and lifecycle detachments.
  • main/handlers/local-runs.ts & main/handlers/local-runs-main.ts: IPC registration for runs:observeLocal, runs:unobserveLocal, runs:stopLocal, and runs:settledLocal, binding observation targets to validated renderer documents.
  • main/services/aiden-remote-host-runs.ts: Extracted wire framing utilities (hostRunWireEvent, hostRunGapSnapshotEvent, hostRunEndedEvent) for shared use between Remote SSE and the local observer.
  • renderer/lib/hosts/observed-local-run.ts & renderer/lib/hosts/use-observed-local-run.ts: Client-side run observation lifecycle managing connection state, pacing, transcript refetches, and handoff to the cached reply.
  • renderer/lib/hosts/local-host-adapter.ts: Implements observation buffering and Stop escalation to host authority (stopHostRun) for watched remote turns.
  • renderer/lib/chat-terminal-sync.ts: Manages detached lifecycle projections for mirrored runs, projection visibility filtering (visibleDetachedLifecycleProjection), and per-stream settlement release (releaseSettledDetachedLifecycleStreams).
  • renderer/main/chat-pane.tsx & renderer/main/root-view.tsx: Integrates observed run projection and pacing into the chat interface, disables Steer on mirrored turns, and wires stream settlement cleanup in the root shell.
  • main/handlers/local-runs.test.ts, renderer/lib/hosts/observed-local-run.test.ts, renderer/lib/chat-terminal-sync.test.ts, renderer/lib/hosts/local-host-adapter.test.ts: Comprehensive integration, contract, and behavioral unit test suites covering batching, race conditions, handoffs, and cancellation.

Findings

No findings.

📊 Sequence Diagram
sequenceDiagram
  autonumber
  actor Phone as Paired Device (Phone)
  participant Main as Electron Main (LocalRunObservers)
  participant Renderer as Mac Renderer (ChatPane)
  participant Store as Chat Store / Cache

  Phone->>Main: Starts turn on Chat A
  Main-->>Renderer: chats:activity-changed (Chat A active)
  Renderer->>Main: runs:observeLocal(chatId)
  Main-->>Renderer: PeerRunSubscription (buffered events)
  loop Every ~16ms frame while streaming
    Main-->>Renderer: runs:local-frame (batched events)
    Renderer->>Renderer: Paced live projection in ChatPane
  end
  Main->>Store: Saves completed assistant reply
  Main-->>Renderer: runs:local-frame (run.ended, state:ended)
  Renderer->>Store: refetch() (reads persisted reply)
  Store-->>Renderer: Transcript containing saved reply
  Renderer->>Renderer: handOff() (clears projection, shows message)
  Renderer->>Main: runs:unobserveLocal(subscriptionId)
Loading

Machine-Readable Findings

[]

Last reviewed commit: 292e125e7b46
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

@pullfrog pullfrog 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.

Important

Two reproduced handoff bugs need fixing: a late idle-release read can remove a newer live turn, and ordinary text-only replies keep the stale background marker after their saved reply has been read.

Reviewed changes Reviewed the document-scoped host-run mirror, renderer projection lifecycle, Stop authority, and per-run detached-marker settlement across both commits.

  • Local observation transport: Adds batched, cursor-aware IPC observations with document cleanup, reusing the existing Remote SSE event projections.
  • Live desktop transcript: Mirrors phone-started turns into the detached projection store, retains replies during transcript handoff, and offers host-authority Stop without Steer.
  • Exact-run settlement: Queries finished generation IDs and refreshes the transcript before clearing their detached markers, independently of newer chat activity.

Validation: focused observation/settlement suites, test:remote-chat, protocol/host-feed/IPC tests, test:ci-policy, and TypeScript checking passed. Two deterministic probes reproduced the inline findings. Both native decoders were inspected; iOS release-policy checks passed, but native XCTest was not run on Linux. The focused Android test attempt returned Tool 'shell' timed out after 120000ms.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

sambitcreate and others added 3 commits October 13, 2026 01:18
…e condition, and text-only reply recognition

This commit addresses three findings from code review:

1. [chat-pane #1] Observed phone-started turns are no longer suppressed when the chat's cached messages end in an assistant message from a different run. The suppression now checks if the last cached assistant message matches the observed run's generation ID, allowing new observed turns to display even in existing chats.

2. [observed-local-run #2] Fixed a race condition where an obsolete idle-release grace-period read could close a retained observer. After the async read completes, we now recheck the release authority flag before closing, so a retained observation survives if it was claimed by a newer turn.

3. [observed-local-run #3] Text-only replies without timeline fields are now recognized as the current run's saved reply by matching the doneMessageId from the persisted message. The hasReplyFrom predicate now checks both timeline.generationId (for multi-step replies) and doneMessageId (for text-only replies).

All observer lifecycle and chat visibility tests pass, including two new tests covering the release race condition and text-only reply handoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the original handoff rule for this window's own detached runs, so a
text-only reply without a timeline never renders twice, and revoke a grace
release by generation so a later release cannot be closed by an older read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Extract the rule into visibleDetachedLifecycleProjection and cover it with
unit cases instead of the source grep that pinned the old chat-pane line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes Reviewed the two follow-up commits since the previous Pullfrog review, through 2ee74e7.

  • Recognized text-only replies: Matched saved assistant messages by doneMessageId when a timeline is absent, allowing immediate projection handoff.
  • Revoked obsolete releases: Rechecked release authority after asynchronous reads and used a generation token to prevent an older read from closing a newer observation.
  • Scoped projection suppression: Kept phone-started turns visible over previous cached replies while preserving the handoff rule for this window’s owned runs.

Validation: 178 focused tests, a held-read race probe, and TypeScript checking passed.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes Reviewed b12643c, the follow-up commit since the previous Pullfrog review at 2ee74e7.

  • Extracted projection visibility: Moved the existing rule into visibleDetachedLifecycleProjection without changing owned-run handoff or mirrored-run identity checks.
  • Replaced source-shape coverage: Removed the outdated source-text assertion and added behavioral cases for absent cache data, previous replies, current-run replies, and owned versus mirrored projections.

Validation: all 79 focused projection, observer, adapter, IPC, and existing component-contract tests passed; npx tsc --noEmit -p . also passed. Electron UI tests were not run on this Linux runner.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

The inline visibility rule pattern that was checked by assert.match on
line 353 was extracted into visibleDetachedLifecycleProjection() in
chat-terminal-sync.ts. That function's behavior is now properly tested
behaviorally in chat-terminal-sync.test.ts ("a saved reply hides an own
run, but a mirrored run only by its own reply"), so the source-grep
assertion is no longer needed.

According to AGENTS.md testing guidelines, source-grep contract tests
should not be grown when the logic they test has been extracted and
tested behaviorally elsewhere.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes Reviewed 7f7d469, the test-only follow-up since the prior Pullfrog review at b12643c.

  • Removed obsolete source-shape coverage: Deleted the assertion for the former inline projection-visibility expression in chat-transition.test.tsx; the extracted rule remains covered behaviorally in chat-terminal-sync.test.ts, with no application behavior changes.

Validation: all 48 tests in the transition and terminal-sync suites passed. Both suites remain registered for CI. Electron and native-client tests were not rerun for this test-only delta.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

sambitcreate and others added 2 commits October 13, 2026 03:08
A phone's run mirrored on this Mac was hidden only by a cached reply
stamped with its timeline. A text-only reply is saved without one, so
when the chat's settle notice cached it before the observer let go, the
reply showed twice. Carry the message id the run reported on done with
the projection and hide it when the cache ends with that message, the
same rule the observer uses to recognise the saved reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every shown detached projection was passed to the transcript as complete,
which suited a route-detached run but also marked a phone's live turn
complete from its first frame, skipping the paced reveal and streaming
treatment. The observer now reports when the mirrored run has finished,
and only then is its text presented as final; a route-detached run is
shown complete as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes Reviewed ac451c3 and b37c819, the two follow-up commits since the prior Pullfrog review at 7f7d469.

  • Propagated saved-reply identity: Added doneMessageId to mirrored projections so a text-only reply cached by another read hides its live duplicate immediately, without mistaking a previous reply for the current turn.
  • Preserved live presentation: Added terminal-state tracking and kept mirrored replies incomplete while running, enabling paced text reveal and live reasoning while preserving the existing presentation of owned route-detached runs.
  • Extended behavioral coverage: Exercised competing-read handoff, live-to-terminal completion, and unchanged owned-run presentation through the real observer and projection store.

Validation: all 108 focused observation, settlement, translation, reveal, IPC, and transition tests passed; npm run test:remote-chat passed all 149 tests; TypeScript checking passed. Electron UI tests were not run on this Linux runner. Native suites were not rerun because this delta changes only desktop renderer behavior, not shared wire contracts. Full CI was still pending when inspected.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

The observer's refetch and the settled-stream release both cancel and
re-read the same chat query, so the release could lose its read and leave
"Response continues in the background…" up until the chat went idle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes Reviewed 292e125, the settled-stream refresh follow-up since the prior Pullfrog review at b37c819.

  • Retried cancelled refreshes: Added up to three transcript-refresh attempts before releasing the exact settled streams, preserving newer runs and retaining markers when reads keep failing.
  • Extended behavioral coverage: Exercised recovery after a competing read cancels the refresh and continued draining when every refresh fails.

Validation: all 79 focused settlement, observation, adapter, IPC, and transition tests passed; npm run test:remote-chat passed all 149 tests; TypeScript checking passed. An additional probe using the real TanStack QueryClient confirmed cancellation recovery, preservation of a newer retained stream, and rejection of a late cancelled result. Electron and native suites were not rerun for this desktop-only delta; hosted CI for this head was still pending when inspected.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@sambitcreate
sambitcreate merged commit 6ff81e6 into main Oct 13, 2026
27 checks passed
@sambitcreate
sambitcreate deleted the stream/desktop-d5-live-remote-turns branch October 13, 2026 16:56
sambitcreate added a commit that referenced this pull request Oct 13, 2026
…diness-line

Resolve the two source-grep conflicts with #448: D1 moved the readiness
copy into chatReadinessMessage() and main moved the detached-projection
visibility rule into visibleDetachedLifecycleProjection(), so both stale
assertions are dropped in favour of their behavioral tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants