Skip to content

feat(remote): fork chats from paired devices and aiden serve - #349

Merged
sambitcreate merged 5 commits into
mainfrom
feat/chat-fork-remote
Oct 5, 2026
Merged

sambitcreate merged 5 commits into
mainfrom
feat/chat-fork-remote

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Summary

Part 4 of the chat fork plan (docs/plans/chat-fork-plan.md). It lets paired devices and aiden serve fork chats. It is stacked on #345.

  • Contract revision 21.
    • New routes: POST /chats/{chatId}/fork (forkChat) and POST /chats/{chatId}/fork-summary/{retry|skip|cancel}.
    • Lineage: forkedFrom on chats, chat rows (with no summary) and message windows.
    • Features: chat-fork-v1 and chat-fork-summary-v1.
    • Updated together: the API doc, OpenAPI, the fixture, the TS parsers, and the iOS and Android revision assertions.
  • One fork service. chat-fork-service.ts now serves the desktop window and Remote alike. The desktop chats:fork handler uses it.
  • Prefill. A fork before a prompt returns that prompt as prefill. Its attachments are restaged for the calling device only.
  • Errors.
    • Busy or unavailable: 409 operation_in_progress, which can be retried.
    • Unknown message: 404.
    • Ineligible cut: 400.
    • Too large: 413.
    • Revision mismatch: 409 revision_conflict.
    • Replays are idempotent.
  • aiden serve. It forks without summaries, so it never advertises chat-fork-summary-v1.
    • A daemon turn reads its history from the chat's pi journal, so the fork gets a journal seeded from the copied visible messages.
    • The service now passes those messages to the journal. A journal adapter must not read the store inside beforeInstall, because the store holds the source's lock there.
  • CLI README. Documents pi's own /fork and /tree for the TUI.

Paired-Mac fork actions on desktop come in a follow-up PR, because they go through the peer-operation layer. The iOS and Android menus follow after that.

Tests

  • aiden-remote-chats.test.ts: forks after a reply and before a prompt, attachment restaging, error mapping, a host without summaries, and the summary actions.
  • aiden-remote-router.test.ts: feature gating, If-Match and Idempotency-Key, scopes, and the summary routes.
  • aiden-remote-protocol.test.ts: fixture lineage, prefill, and the row rules; OpenAPI route freezing.
  • packages/cli/tests/parity.test.mjs: forks over HTTPS from aiden serve and checks that the fork's next turn sends the copied history to the model.
  • Run locally:
    • the Remote, fork and chat suites (250 pass);
    • CLI npm test;
    • tsc for the root and the CLI;
    • npm run test:ci-policy;
    • Android AidenBotContractTest.
  • iOS: the local simulator listing hung, so CI covers the one-line revision assertion.

🤖 Generated with Claude Code

Contract revision 21 adds POST /chats/{chatId}/fork and
POST /chats/{chatId}/fork-summary/{retry|skip|cancel}, the forkedFrom
lineage on chats, rows and message windows, and the chat-fork-v1 and
chat-fork-summary-v1 features.

Desktop and Remote share one fork service. A fork before a prompt
returns the prompt as prefill, with its attachments restaged for the
calling device. Busy sources, unknown messages, ineligible cuts and
oversized forks map to stable Remote errors, and replays are idempotent.

aiden serve forks without summaries. A daemon turn reads its history
from the chat's pi journal, so the fork gets a journal seeded from the
copied visible messages.

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.

Caution

Fork summaries expose host-private data and make focused-summary chats unreadable by the existing native clients. Two additional failure paths can report an unsuccessful fork after committing it, or report success without preserving its model context.

Reviewed changes Reviewed the complete stacked PR against feat/chat-fork-summary, including shared copy orchestration, Remote contracts, daemon history, and native compatibility.

  • Shared fork service: Desktop IPC and Remote now share source locking, workspace admission, dependent-record preparation, summary startup, and publication.
  • Remote API: Revision 21 adds fork and summary-control routes, feature negotiation, lineage projections, idempotent creation, and device-bound attachment prefill.
  • Daemon context: aiden serve seeds fork journals from copied visible messages and advertises plain forks only.
  • Verification: All 166 focused tests, the rebuilt CLI HTTPS parity test, and root/CLI TypeScript checks passed. Local reproductions confirmed the projection, oversized-outcome, and journal-failure findings; Android verification timed out (Tool 'shell' timed out after 120000ms), and iOS execution was unavailable because this Linux runner has no xcodebuild.

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

Comment thread main/services/aiden-remote-chats.ts Resolved
Comment thread main/services/aiden-remote-chats.ts Resolved
Comment thread main/services/aiden-remote-chats.ts Resolved
Comment thread main/services/chat-fork-service.ts Resolved
Base automatically changed from feat/chat-fork-summary to main October 5, 2026 17:46
sambitcreate and others added 2 commits October 5, 2026 13:46
The fork move left four source-grep assertions pointing at handler code
that now lives in the fork service. Drop the stale lines, retarget the
Bot platform guard to the copyBotChat caller, and cover the unrecovered
artifact block with a behavioral fork-service test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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: 56a27c97682ba8eccedb4e0eb3ab263455dff9e2
Generated: 2026-10-05T19:09:34+00:00
Reviews: 1

Summary

Part 4 of the chat fork plan extends Aiden's chat-forking capability to paired Remote devices and the headless aiden serve daemon under Remote contract revision 21. Desktop and remote forking are now unified behind a shared chatForkService, introducing authenticated routes for creating forks (POST /chats/{chatId}/fork) and managing their summary lifecycle (POST /chats/{chatId}/fork-summary/{retry|skip|cancel}). On forks before a prompt (position: "before"), the prompt text is returned as prefill and its attachments are securely restaged as pending uploads scoped to the calling device and new chat; for aiden serve, visible history is seeded directly into a newly initialized pi session journal without carrying previous tool outputs. Maintainers should double-check that mobile clients accommodate the 5-minute temporary attachment TTL when presenting prefilled attachments in the composer, ensuring that delayed user edits do not result in expired attachment references on turn submission.

Confidence Score: 5/5

Fully traced and verified the end-to-end flow across router authentication, mutation locks, idempotency ledger replay, workspace admission, store-level copy locks, journal seeding in the CLI daemon, attachment restaging, and the cross-platform contract fixtures and mobile test assertions.

📁 Important Files Changed
  • main/services/chat-fork-service.ts: Centralizes regular and bot chat copy coordination, workspace admission, html artifact copying, and model journal synchronization across desktop and Remote callers.
  • main/services/chat-fork-service-main.ts: Binds the Electron main-process runtime dependencies (chat store, LLM client, generative UI store, compaction journal, and IPC notifications) to the fork service.
  • main/services/aiden-remote-chats.ts: Implements Remote fork and fork-summary actions with idempotency ledgers, precondition validation, response size bounds checks, and attachment restaging.
  • main/services/aiden-remote-router.ts: Exposes and routes POST /chats/{chatId}/fork and POST /chats/{chatId}/fork-summary/{action}, advertising chat-fork-v1 and chat-fork-summary-v1 features.
  • main/services/aiden-remote-protocol.ts: Bumps contract revision to 21, adds DTO parsers for fork results, lineage, and summary projections, and enforces strict key separation (e.g. summary excluded from chat row projections).
  • main/services/aiden-remote-attachments.ts: Implements stage() to re-register existing chat attachments as temporary pending attachments for the requesting device and destination chat.
  • packages/cli/src/daemon-forks.ts: Adapts chatForkService for aiden serve by seeding pi session journals directly from visible messages without requiring summary services.
  • protocol/aiden-remote/v1/openapi.json & protocol/aiden-remote/v1/fixtures/contract.json: Updates the wire contract specification and test fixture to revision 21 with fork exchanges.
  • android/app/src/test/java/sbtbiswas/AidenOnTheGo/AidenBotContractTest.kt & ios/AidenOnTheGoTests/AidenRemotePhase0Tests.swift: Advances the contract revision expectation to 21 for native mobile test harnesses.

Findings

No findings.

Sequence Diagram

sequenceDiagram
    autonumber
    actor Client as Paired Device (Remote)
    participant Router as Remote Router
    participant RemoteChats as RemoteChatService
    participant ForkService as ChatForkService
    participant Store as ChatStore
    participant AttStore as RemoteAttachmentStore

    Client->>Router: POST /chats/{chatId}/fork (If-Match, Idempotency-Key)
    Router->>RemoteChats: fork(deviceId, chatId, revision, key, body)
    RemoteChats->>ForkService: fork(request, caller)
    ForkService->>Store: copyVisibleHistory(sourceId, targetId, forkAt, ...)
    Store->>ForkService: beforeInstall(targetChat, sourceMessageIds)
    ForkService->>RemoteChats: assertInstallable(targetChat)
    Store-->>ForkService: forkedChat
    ForkService-->>RemoteChats: forkedChat
    opt Position is "before" and prompt has attachments
        RemoteChats->>AttStore: stage(deviceId, forkedChat.id, attachments)
        AttStore-->>RemoteChats: stagedAttachments
    end
    RemoteChats-->>Router: { chat: project(forkedChat), prefill? }
    Router-->>Client: 201 Created
Loading
[]

Last reviewed commit: 56a27c97682b
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.

ℹ️ No new issues found in this delta. Approval remains withheld because the existing review findings are unresolved.

Reviewed changes Reviewed the test updates and merge of main since the previous review at d1b04f6.

  • Retargeted guard assertions: Updated the Bot platform check to follow copyBotChat and removed stale source assertions for logic moved out of the handler.
  • Added artifact-block coverage: Exercised the real fork service and chat store to verify that an unrecovered artifact prevents copying and that clearing the block allows a copy.
  • Merged current main: Checked the resulting full PR diff for context and confirmed the test inventory remains registered correctly.
  • Verified affected suites: Passed all 49 tests across the five changed test files and all 10 CI-registry checks.

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

A restaged prefill attachment is redeemed by its upload ID on the fork's
next turn, so the fixture now uses an att_ ID and the parser rejects any
other shape.

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 because the existing review findings are unresolved.

Reviewed changes Reviewed the attachment-ID validation change since the previous review at c4b9fb7, with the full PR diff as context.

  • Tightened prefill validation: Required restaged attachment IDs to match the upload and turn-redemption format, preventing acceptance of unusable history-style IDs.
  • Corrected the shared fixture: Replaced the edit-fork attachment ID with a valid upload-shaped ID and added a behavioral parser rejection test.
  • Verified affected behavior: Passed all 114 tests across the Remote protocol, chat service, and operation-contract suites, including fixture parsing and device/chat-bound attachment redemption.

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

…devices

- Project fork summaries for Remote with `focus` in place of the private
  `instructions` name, without the host file list, and with only Aiden's
  own failure text. Provider errors stay on the Mac.
- Map only real summary state conflicts to 409; other failures are not
  echoed to the device.
- Check that the fork response can be sent and replayed before the copy is
  installed, so a 413 leaves no new chat behind.
- `aiden serve` refuses a fork whose journal it cannot seed, because its
  turns read earlier messages only from the journal.
- Record ready and failed summary vectors in the contract fixture.

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 652a1f1..56a27c9, with the complete PR diff as context.

  • Sanitized Remote summaries: Omitted host file lists, translated internal instructions to public focus, and restricted failure text to Aiden-owned messages.
  • Separated summary conflicts: Mapped only ForkSummaryStateError to a public conflict, leaving unexpected exceptions to the generic HTTP error sanitizer.
  • Preflighted fork outcomes: Checked the complete response, including conservative attachment-prefill metadata and durable-result limits, before installing the new chat.
  • Required daemon history: Refused daemon forks when journal preparation throws or returns false, while preserving the desktop fallback and cleaning up partially prepared journals.
  • Verified affected behavior: Passed all 202 focused behavioral tests, the rebuilt CLI HTTPS parity test, both TypeScript checks, and all 10 CI registry checks. Native validator inspection supported compatibility; Android verification returned Tool 'shell' timed out after 120000ms, and iOS execution was unavailable because this Linux runner has no xcodebuild.

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

@sambitcreate
sambitcreate merged commit 21e3dc3 into main Oct 5, 2026
45 of 47 checks passed
@sambitcreate
sambitcreate deleted the feat/chat-fork-remote branch October 5, 2026 21:50
sambitcreate added a commit that referenced this pull request Oct 6, 2026
…ct revision 23

#349 (chat fork, revision 21) and #352 (provider creation, revision 22)
merged first, so chat-messages-window-metadata-v1 moves to revision 23
across the server, iOS, Android, fixtures, OpenAPI and docs. Window pages
also carry main's forkedFrom lineage so a windowed refresh keeps the fork
row on both clients.

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