Skip to content

feat(cli): import cloud transcript on create_session - #13483

Merged
iscekic merged 4 commits into
mainfrom
continue-target-9624
Aug 27, 2026
Merged

feat(cli): import cloud transcript on create_session#13483
iscekic merged 4 commits into
mainfrom
continue-target-9624

Conversation

@iscekic

@iscekic iscekic commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Issue

Fixes #9624

Context

Kilo Code can now continue a session from the cloud. A connected client can ask the CLI to open an
existing cloud session locally, and the CLI downloads that session and opens it instead of starting
a new empty session. When the client does not ask, the CLI starts a new session exactly as before.


Implementation

The create_session command accepts an optional cloneFromKiloSessionId string. When it is set,
the sender imports the cloud session in-process, attaches it, and defers the workspace file restore
and the session-diff storage writes until after the attach succeeds; a failed attach removes the
imported session with no restore or storage side effects. When it is absent, the sender creates a
fresh session exactly as before, import failures map to fixed wire error literals, and a clone
request with no import seam is rejected instead of falling back to a fresh create.

Files
  • packages/opencode/src/kilo-sessions/remote-sender.ts — adds the cloneFromKiloSessionId field, the importFromCloud seam option, the clone branch with import-then-attach-then-finalize ordering, the wire error literal map, and attach-failure rollback.

The cloud-session import logic moves out of the HTTP handler into a shared in-process helper that
fails with four typed errors: unauthorized, upstream (carrying the status and error), bad-request,
and internal. The helper persists the session and its messages and parts, restores workspace files,
and writes the session-diff storage keys. The cloudSessionImport route now delegates to the helper
and keeps its existing HTTP status mapping, so old callers see no change.

Files
  • packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts — new helper with importSession, importSessionWithoutRestore, finalizeSessionImport, and the four tagged errors.
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilo-gateway.tscloudSessionImport lazily imports the helper, provides the request-scoped services, and maps the typed errors to the same HTTP statuses.

The heartbeat capabilities object gains an optional sessionClone flag sent as true. A consumer
can use the flag to tell a capable CLI from an old one, and CLIs that omit it stay wire-compatible.

Files
  • packages/opencode/src/kilo-sessions/remote-protocol.ts — adds sessionClone to the capabilities schema.
  • packages/opencode/src/kilo-sessions/remote-ws.ts — sends capabilities: { attachments: true, sessionClone: true } on fresh and degraded heartbeats.

Production wires the import seam to the in-process helper through a dynamic import and the app
runtime. The dynamic import keeps the HTTP handler graph out of the remote-sender module graph, and
the import runs through the app runtime.

Files
  • packages/opencode/src/kilo-sessions/kilo-sessions.ts — adds the importFromCloud seam that dynamically imports the helper, runs importSessionWithoutRestore, and returns the session plus a finalize closure that runs finalizeSessionImport.

Tests: 2 test files updated — remote-sender.test.ts adds 5 clone-path cases, remote-ws.test.ts updates the capability assertion.
Generated: none.


Screenshots / Video

Visual Changes: N/A

How to Test

Manual/local verification

Verification: no E2E report attached. The mobile/cloud surface carries the runtime verification; this PR is CLI wire only.

Reviewer test steps

  1. Start the CLI with remote enabled.
  2. Send create_session with cloneFromKiloSessionId set to a real cloud session id. Confirm the CLI imports and attaches that session, then restores its workspace files.
  3. Send create_session without the clone field. Confirm the CLI still creates a fresh session.

Blocked checks and substitute verification

None.

Human steps

None.

Notes

None.

Checklist

  • Issue linked above (Fixes #9624)
  • Tests/verification described
  • Screenshots/video N/A (no visual changes)
  • Changeset considered for user-facing changes
  • Diff reviewed and explained

Get in Touch

N/A

Provide the helper's effect services from the group context so the
HTTP import handler keeps the base request graph. Map the tagged
helper errors via Effect.match instead of matchEffect.
@iscekic iscekic self-assigned this Aug 26, 2026
Comment thread packages/opencode/src/kilo-sessions/remote-sender.ts Outdated
Comment thread packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • packages/opencode/src/kilo-sessions/kilo-sessions.ts
  • packages/opencode/src/kilo-sessions/remote-sender.ts
  • packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts
  • packages/opencode/test/kilocode/sessions/remote-sender.test.ts
Previous Review Summaries (2 snapshots, latest commit f068331)

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

Previous review (commit f068331)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilo-sessions/remote-sender.ts 903 Attach-failure rollback does not undo workspace file restores

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts 159 catchCause turns cancel/interrupt into a successful import
Files Reviewed (8 files)
  • packages/opencode/src/kilo-sessions/kilo-sessions.ts - 0 issues
  • packages/opencode/src/kilo-sessions/remote-protocol.ts - 0 issues
  • packages/opencode/src/kilo-sessions/remote-sender.ts - 1 issue
  • packages/opencode/src/kilo-sessions/remote-ws.ts - 0 issues
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilo-gateway.ts - 0 issues
  • packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts - 1 issue
  • packages/opencode/test/kilocode/sessions/remote-sender.test.ts - 0 issues
  • packages/opencode/test/kilocode/sessions/remote-ws.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit 605f41e)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilo-sessions/remote-sender.ts 903 Attach-failure rollback does not undo workspace file restores

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts 165 catchCause turns cancel/interrupt into a successful import
Files Reviewed (8 files)
  • packages/opencode/src/kilo-sessions/kilo-sessions.ts - 0 issues
  • packages/opencode/src/kilo-sessions/remote-protocol.ts - 0 issues
  • packages/opencode/src/kilo-sessions/remote-sender.ts - 1 issue
  • packages/opencode/src/kilo-sessions/remote-ws.ts - 0 issues
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilo-gateway.ts - 0 issues
  • packages/opencode/src/kilocode/server/import-cloud-session-in-process.ts - 1 issue
  • packages/opencode/test/kilocode/sessions/remote-sender.test.ts - 0 issues
  • packages/opencode/test/kilocode/sessions/remote-ws.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 54.7K · Output: 10.4K · Cached: 278.8K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic added the human-ready PR is ready for a human review. label Aug 27, 2026
@iscekic
iscekic merged commit 156fb64 into main Aug 27, 2026
31 checks passed
@iscekic
iscekic deleted the continue-target-9624 branch August 27, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready PR is ready for a human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants