Skip to content

feat(cli): fork a remote session from a message - #15004

Merged
iscekic merged 5 commits into
mainfrom
igor/fork-from-message
Oct 13, 2026
Merged

iscekic merged 5 commits into
mainfrom
igor/fork-from-message

Conversation

@iscekic

@iscekic iscekic commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

bot: Adds a message cut to the remote-session clone, so the mobile app can offer "Fork from here".

Summary

  • create_session accepts cloneUpToMessageId. It is valid only with cloneFromKiloSessionId.
  • fetchCloudSessionForImport sends upToMessageId to the session export. It also filters the export on the client, so an older server that ignores the parameter cannot replay edits made after the cut.
  • The cut is inclusive. With a cut, sessionDiff is dropped, and the files are rebuilt from the per-message summary diffs of the kept messages (the existing fallback).
  • A missing cut message fails with cloud session cut not found.
  • The heartbeat advertises sessionCloneAtMessage: true. Mobile hides the action for CLIs without it.
  • A clone without a cut is unchanged.

Companion PR

  • Kilo-Org/cloud adds the ingest filter, the relay capability, and the mobile action.

Verification

  • bun test for cloud-sessions, session-diff-restore, remote-sender, remote-protocol, remote-ws: all pass.
  • typecheck for packages/opencode and packages/kilo-gateway: clean.
  • script/check-opencode-annotations.ts --worktree: no shared upstream files changed.

@github-actions github-actions Bot added area:cli CLI, TUI and core engine area:gateway Kilo Gateway and auth labels Oct 12, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Follow-up commit a4731fcd fixes imported transcript order. prepareSessionImport now sorts the export's source messages and each message's parts by source ID before issuing fresh IDs, so the ascending local IDs (and the inserted rows) follow transcript order rather than the export's ingest order. byID is a correct comparator over the CLI's fixed-width, timestamp-prefixed IDs, toSorted plus the spread are non-mutating (so the "without mutating the export" test still holds), and the new test covers both message and part reordering. The prior review's 12-file flow (cut-inclusive clone, cloud session cut not found, sessionDiff drop, heartbeat capability) is unchanged. No issues found.

Files Reviewed (2 files)
  • packages/kilo-gateway/src/cloud-sessions.ts
  • packages/kilo-gateway/test/cloud-sessions.test.ts
Previous Review Summary (commit 8f6c4e2)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 8f6c4e2)

Status: No Issues Found | Recommendation: Merge

The clone-at-message flow is coherent and well covered. create_session.cloneUpToMessageId is validated (required alongside cloneFromKiloSessionId via .refine), forwarded through the importFromCloud seam, and mapped to a distinct CloudSessionImportCutNotFound -> cloud session cut not found wire error. The client-side cutSessionExport defensively re-applies the inclusive cut and drops the session-level diff so an older ingest server that ignores upToMessageId cannot replay post-cut edits and files are rebuilt from the kept messages' summary diffs. The lexicographic message-ID comparison is sound because ascending IDs (fixed-width hex timestamp prefix) sort by creation time. Heartbeat sessionCloneAtMessage is advertised at both heartbeat sites, and the changeset is user-facing and clear.

Files Reviewed (12 files)
  • .changeset/remote-fork-from-message.md
  • packages/kilo-gateway/src/cloud-sessions.ts
  • packages/kilo-gateway/test/cloud-sessions.test.ts
  • packages/opencode/src/kilo-sessions/kilo-sessions.ts
  • packages/opencode/src/kilo-sessions/remote-protocol.ts
  • packages/opencode/src/kilo-sessions/remote-sender.ts
  • packages/opencode/src/kilo-sessions/remote-ws.ts
  • packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts
  • packages/opencode/test/kilocode/session-diff-restore.test.ts
  • packages/opencode/test/kilocode/sessions/remote-protocol.test.ts
  • packages/opencode/test/kilocode/sessions/remote-sender.test.ts
  • packages/opencode/test/kilocode/sessions/remote-ws.test.ts

Reviewed by deepseek-v4.1-flash · Input: 52.7K · Output: 12.3K · Cached: 369.2K

Review guidance: REVIEW.md from base branch main

@iscekic

iscekic commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

bot: E2E on a VM with the local stack, a dev iOS build, and two kilo remote CLIs built from this branch. Scenario a (remote CLI source to a second remote directory, fork from the turn 2 reply) passed: the new session holds turns 1-2, the destination has the a.txt and b.txt edits, and c.txt is unchanged. The forked transcript showed each user message after its reply, because the export lists items in ingest order. a4731fc fixes the import order. Screenshots: source, fork sheet, Continue screen, forked session (before the fix).

Source session, 3 turns

Fork from here on the turn 2 reply

Continue screen, destination directory

Forked session holds turns 1-2 (order bug before fix)

@iscekic

iscekic commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Re-run after a4731fc. Scenario a: the forked transcript now shows each user message before its reply, and the destination has only the turn 1-2 edits. Scenario b: a fork from the turn 3 user message cloned turns 1-2, and the turn 3 text waited unsent in the composer. Scenario e: a CLI built from main is listed without the fork capability, the app shows "Update the Kilo CLI to fork from a message.", and Start session stays disabled. The old CLI received no spawn command.

a: forked transcript in order after the fix

b: turn 3 text prefilled, first view

b: reopened, turns 1-2 and the prefill

e: old CLI refused with the update hint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli CLI, TUI and core engine area:gateway Kilo Gateway and auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants