Skip to content

feat(peers): fork chats on a paired Mac from desktop - #350

Merged
sambitcreate merged 8 commits into
mainfrom
feat/chat-fork-peer
Oct 6, 2026
Merged

sambitcreate merged 8 commits into
mainfrom
feat/chat-fork-peer

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

This lets the desktop fork chats that live on a paired Mac. It follows the chat fork plan (docs/plans/completed/chat-fork-plan.md, Desktop → Paired Macs) and is stacked on #349, which adds the Remote fork routes.

  • Peer operations
    • forkChat: POST /chats/{id}/fork with If-Match and Idempotency-Key, and a strictly checked body.
    • retryForkSummary, skipForkSummary and cancelForkSummary on /chats/{id}/fork-summary/*.
    • Responses are read with the existing Remote protocol parsers.
  • Host adapters: new fork and forkSummary capabilities.
    • A host grants fork when it advertises chat-fork-v1 and the device has chat:write. forkSummary also needs chat-fork-summary-v1.
    • The local adapter grants neither, because the local pane already forks over IPC.
  • Retry safety: if a fork's answer is lost, retrying the identical request reuses its idempotency key, so the host replays the first fork instead of copying twice.
  • Remote chat pane
    • Actions: Fork from here, Edit in fork, and Fork with summary…, using the shared message actions and dialog. They are disabled while a run is active.
    • After a fork: the pane navigates to the fork. Edit in fork puts the prompt text into the fork's composer.
    • In a fork: a "Forked from …" lineage row and the shared ForkSummaryCard, with cancel, retry and skip. A pending or failed summary holds the composer.

Known limits

  • Edit in fork carries text only. The remote composer cannot show attachments the host has already staged, so they are released and the user is asked to reattach them.
  • Fork is offered only for chats that appear in the host's chat feed.
  • The summary card comes from a full-chat read. A chat over the 1 MiB response cap shows the lineage row without the card.

Tests

  • New main/services/peer-remote-chat-fork.test.ts. It runs end to end through the real main IPC, PeerHostManager, the operation builder and parsers, and the host's real AidenRemoteChatService. It covers:
    • a lost answer replays exactly one fork;
    • a stale revision copies nothing;
    • Edit in fork returns the prompt and stages its file;
    • capability gating sends no request when a feature is missing;
    • summary cancel, retry and skip;
    • the host's refusal codes.
  • peer-operation.test.ts: request shape and body validation for the new operations.
  • remote-chat-view.test.tsx: which actions are offered, that they are disabled during a run, the lineage row with the summary card and send hold, and the error wording.
  • Run locally:
    • npx tsc --noEmit -p .
    • npm run test:remote-chat (131 pass)
    • the peer-operation and protocol suites
    • npm run test:ci-policy
    • ESLint on the touched files

Flaky test

🤖 Generated with Claude Code

sambitcreate and others added 2 commits October 5, 2026 14:12
Adds the forkChat and fork-summary peer operations, gates them on the
host's chat-fork-v1 and chat-fork-summary-v1 features, and wires Fork
from here, Edit in fork and Fork with summary into the remote chat pane
with the lineage row, the summary card and the send hold. A fork whose
answer is lost is retried under the same idempotency key, so the host
replays it instead of copying again. Edit in fork seeds only the prompt
text; files the host staged for it are released.

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.

Important

Two recovery paths need fixes before merging: reopening a pane can duplicate an unconfirmed fork, and summary actions on another client can leave this pane's composer blocked.

Reviewed changes: Reviewed the complete desktop paired-Mac fork implementation against the stacked feat/chat-fork-remote base.

  • Peer operations: Added validated fork and summary-control requests, conditional/idempotency headers, and protocol response parsing.
  • Host controls: Added feature/grant-gated adapter capabilities, lineage/prefill mapping, and session-level fork retry handling.
  • Remote UI: Added transcript fork actions, summary confirmation and controls, lineage navigation, text prefill, and summary-based composer holds.
  • Coverage: Reviewed the new IPC-to-host integration tests, operation/parser tests, renderer assertions, and CI test registration.

Verification: all 131 remote-chat tests, all 30 peer-operation/protocol tests, and TypeScript checking passed. Separate production-code reproductions confirmed both findings below; the repository worktree remains unchanged.

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

Comment thread renderer/main/remote-chat-view.tsx Resolved
@very-hermes-bot

very-hermes-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 69ffdfd4af353ce579cc3adbb5a1d63b63cd581a
Generated: 2026-10-06T00:41:15+00:00
Reviews: 1

Summary

Enables the desktop client to fork chats running on a paired Mac, extending remote peer operations with POST /chats/{id}/fork and /chats/{id}/fork-summary/{retry|skip|cancel}. The integration is guarded behind chat-fork-v1 and chat-fork-summary-v1 feature capabilities and chat:write permissions, using ChatIntentLedger to persist request signatures so ambiguous network failures safely replay identical forks under the original idempotency key without duplicate chat creation. In the UI, RemoteChatPane and MessageList surface "Fork from here", "Edit in fork", and "Fork with summary…", handle prefill drafts and attachment release for prompt edits, and enforce composer hold states via useRemoteForkLineage until pending summaries settle. Maintainers should double-check that releasing staged attachments on prompt edits in forkAt remains the intended interim behavior until remote composer attachments are fully supported on desktop.

Confidence Score: 5/5

Fully traced and verified end-to-end across protocol request validation, IPC handlers, host adapters, session controls, idempotency ledger state transitions, and React Query cache invalidation against OpenAPI fixtures.

📁 Important Files Changed
  • main/services/peer-operation.ts & main/services/peer-response.ts: Implements wire-level request serialization (forkBody, headers, empty summary bodies) and response parsing (parseAidenRemoteChatForkResult, parseAidenRemoteChatProjection, forkSummaryCancelled) for the new fork operations; registers summary actions in PEER_CHAT_MUTATIONS.
  • renderer/lib/hosts/remote-host-adapter.ts: Exposes fork, forkSummary, cancelForkSummary, and forkLineage on the remote host adapter; maps wire formats (RFC 3339 timestamps and focus) to local model contracts (at milliseconds and instructions).
  • renderer/lib/hosts/chat-session-control.ts & renderer/lib/hosts/chat-intent-ledger.ts: Coordinates capability guarding, revision checks, and idempotency key persistence across lost network acknowledgments without triggering intrusive unresolved-send notifications.
  • renderer/main/remote-chat-view.tsx & renderer/components/message-list.tsx: Wires transcript actions, dialog confirmations, and prefill draft staging; hides editing before the initial prompt when no older pages exist; manages lineage presentation and composer hold states via useRemoteForkLineage.
  • main/services/peer-remote-chat-fork.test.ts, main/services/peer-operation.test.ts, & renderer/main/remote-chat-view.test.tsx: Comprehensive test coverage covering replay safety, stale revision refusals, capability gating, summary lifecycles, and cache invalidation.
  • package.json & scripts/ci-test-registry.json: Registers the new peer-remote-chat-fork.test.ts suite under test:remote-chat.

Findings

No findings.

Sequence Diagram

sequenceDiagram
    autonumber
    actor User
    participant Pane as RemoteChatPane (Renderer)
    participant Control as ChatSessionControl
    participant Ledger as ChatIntentLedger
    participant Adapter as RemoteHostAdapter
    participant Manager as PeerHostManager (Main)
    participant Host as Paired Mac Host

    User->>Pane: Click "Fork from here" / "Edit in fork"
    Pane->>Control: fork({ messageId, position, summary? }, revision)
    Control->>Ledger: forkKey(ref, signature) / beginFork(ref, intent)
    Control->>Adapter: fork(chatId, { messageId, position, revision, idempotencyKey })
    Adapter->>Manager: transport.call("forkChat", request)
    Manager->>Host: POST /chats/{id}/fork (If-Match, Idempotency-Key)
    alt Successful Fork
        Host-->>Manager: 201 Created { chat, prefill? }
        Manager-->>Adapter: Return parsed fork result
        Adapter-->>Control: HostForkedChat
        Control->>Ledger: settleFork(ref, idempotencyKey)
        Control-->>Pane: HostForkedChat
        opt Edit in fork prefill
            Pane->>Pane: saveComposerDraftText() & releaseAttachments()
        end
        Pane->>Pane: onOpenChat(forked.id)
    else Lost Acknowledgment (outcome_unknown)
        Host--xManager: Network timeout / drop
        Manager-->>Adapter: outcome_unknown error
        Adapter-->>Control: HostChatControlError (outcome_unknown)
        Note over Control,Ledger: Key retained in ledger for identical signature
        Control-->>Pane: Re-throw outcome_unknown
        Pane->>User: Toast prompt to retry safely
    end
Loading
[]

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

sambitcreate and others added 2 commits October 5, 2026 14:35
The Remote contract now calls the summary focus `focus`. The peer bridge
sends and validates `summary.focus`, and maps the host's `focus` back to
the desktop's `instructions` when it reads fork lineage.

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 in this delta. Approval remains withheld while the existing recovery threads are open.

Reviewed changes: Reviewed the changes since 34a31f8e, including the base-branch merge and the fork-summary wire-name correction.

  • Corrected outgoing summary focus: Mapped desktop instructions to wire focus and aligned main-process validation with the host contract.
  • Restored incoming summary focus: Mapped wire focus back to desktop instructions before parsing lineage, preserving the focus across reads and retries.
  • Aligned integration fixtures: Used the host's typed summary-state conflict and safe cancellation message, and updated request-validation cases for the wire field.

Verification: all 99 focused peer-operation, fork-integration, protocol, and host-chat tests passed; all 131 remote-chat tests passed; npx tsc --noEmit -p . passed. The repository worktree is unchanged.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Base automatically changed from feat/chat-fork-remote to main October 5, 2026 21:50
sambitcreate and others added 2 commits October 5, 2026 17:50
…hanged elsewhere

A fork whose answer was lost kept its idempotency key only on the pane's
session control, so reopening the chat and retrying minted a new key and
the host made a second copy. The key now lives in the window's chat
intent ledger, scoped to host and chat, like other unresolved chat
mutations.

The fork lineage read again only while a pending summary's row moved,
and compared the feed's metadata token with the chat's content
revision. A failed summary retried or skipped on another device stayed
failed here and kept the composer held. The lineage now records the
feed revision it was read at and reads again whenever that moves while
the summary is pending or failed.

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.

Important

A delayed summary-action response can overwrite newer lineage and leave the composer blocked after the summary has finished.

Reviewed changes: Reviewed the recovery changes in 56071b93 against the previously reviewed 55cfb3b6 state.

  • Moved fork retry keys into the window-scoped intent ledger so identical retries survive pane/control replacement.
  • Added feed-revision tracking to lineage reads and refreshed both pending and failed summaries when their feed row changes.
  • Extended behavioral coverage for reopening after a lost fork answer and cross-device summary retry/skip transitions.

Verification: all 132 remote-chat tests, all 99 focused peer-operation/fork/protocol/host-chat tests, and TypeScript checking passed. A separate mounted production-hook reproduction confirmed the late-response race described inline; the repository worktree is unchanged.

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

Comment thread renderer/main/remote-chat-view.tsx Resolved
…ummary

A Retry's answer was stamped with the feed revision current when it arrived.
If the summary finished and the pane had already read "ready" meanwhile, the
late "pending" answer replaced it and kept the composer held with no further
read. Summary actions now record the row revision when they start; an answer
whose row moved in the meantime triggers a fresh read instead.

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 56071b93..dd506060, focusing on summary-action response ordering and the previously reported composer-hold race.

  • Captured action-start authority: Recorded the feed revision before awaiting a summary action, rather than assigning the latest revision to its response.
  • Reconciled late responses: Invalidated and re-read lineage when the feed moved during the action, preserving newer cached summary state.
  • Extended mounted behavioral coverage: Checked that a delayed pending response cannot replace a ready summary or restore the send hold, and that an unchanged-row response still applies directly.

Verification: all 133 remote-chat tests, all 99 focused peer-operation/fork/protocol/host-chat tests, and TypeScript checking passed. The repository worktree is unchanged. Hosted CI was still running; macOS Electron E2E was not run in this Linux environment.

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

@sambitcreate
sambitcreate merged commit 6a3d5b1 into main Oct 6, 2026
25 checks passed
@sambitcreate
sambitcreate deleted the feat/chat-fork-peer branch October 6, 2026 01:24
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