Skip to content

feat(cloud): fork a cloud session directly into a new cloud session - #5909

Merged
eshurakov merged 14 commits into
Kilo-Org:mainfrom
maphew:kilo/solid-logic-1ny
Sep 17, 2026
Merged

eshurakov merged 14 commits into
Kilo-Org:mainfrom
maphew:kilo/solid-logic-1ny

Conversation

@maphew

@maphew maphew commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #5999.

Cloud sessions can currently be forked to VS Code Kilo or the Kilo Code CLI, but not directly into another cloud session. This PR adds a cloud-to-cloud fork from the web session surfaces so users no longer need to round-trip through CLI/VS Code.

The fork reuses the existing clone path that mobile's "Continue in new session" already uses (prepareSession clone variant): the source transcript is cloned into a new Cloud Agent session that inherits the source session's repository, model, mode, and custom agents, then the user lands in the new session.

What changed

  • New pure derivation module (cloud-session-fork.ts) with tests: turns a source session's runtime config into a clone prepareSession request, maps GitHub/GitLab repositories (with git-URL fallbacks and platform inference), forwards custom agent lists for profile-defined modes, and returns typed rejection reasons (non-cloud sessions, missing config, Bitbucket/unknown platforms, org mismatches) with user-facing messages.
  • New useCloudSessionFork hook: loads runtime state, runs the clone with an idempotency key that survives ambiguous failures, invalidates session queries, navigates to the new session, and toasts failures.
  • UI: "Fork to a new Cloud Agent session" action in the sessions listing dialog, the session actions (Share/Fork) dialog, and the read-only session continuation panel (replacing the "Continue in Cloud Agent coming soon" placeholder). The action is only offered for sessions that carry a cloud_agent_session_id (true Cloud Agent sessions).

Validation

  • 44 new unit tests across derivation, orchestration, error mapping, and runtime-agent sanitization.
  • tsgo --noEmit, oxfmt, and oxlint clean for all changed files.
  • Related existing suites still green (ChatHeader, terminal-tabs).
  • An adversarial review was run against the PR and its findings were addressed in follow-up commits: custom-agent mode forwarding, malformed variant/repository validation, idempotent operationKey reuse across ambiguous failures, permissive canForkToCloud default, runtime-agent schema pruning, and raw server-error leakage.

Follow-ups (not in scope)

  • Forking Bitbucket cloud sessions is rejected with a clear message until repository identity (workspace/repository UUIDs) is available from session runtime state.
  • Session continuation from non-cloud (CLI-only) sessions is not offered (and rejected with a clear message if attempted).

…ud session

Extract the pure decision logic that turns a source session's runtime
configuration into a clone-style prepareSession request: repository and
model/mode inheritance, per-platform mapping, and rejection reasons with
user-facing messages. The orchestrator guards organization boundaries and
drives invalidation, navigation, and error reporting.
Adds the web UI for the cloud-to-cloud fork that previously only worked via
CLI/VS Code round-trips. The sessions listing, session actions dialog, and
read-only session continuation panel now offer 'Fork to a new Cloud Agent
session', which clones the source session and navigates to the new session.
Non-cloud (CLI, Agent Manager, Gastown) rows cannot be cloned into a new
cloud session: they have no cloud runtime configuration to inherit. Hide the
new fork action unless the source row has a cloud_agent_session_id, keeping
editor/CLI fork options intact.
- Forward runtime agents alongside a custom agent mode so profile-defined
  custom modes stay forkable (prepare requires the destination to carry the
  matching runtimeAgents).
- Drop malformed runtime variants and validate repository fields instead of
  letting the fork fail at the zod boundary; fall back to the runtime git URL
  when githubRepo is absent, and infer the platform when runtime metadata
  omits it.
- Reuse one operationKey per (context, session) after an ambiguous failure so
  a retry replays the settled create instead of minting a duplicate session;
  rotate the key once the fork settles.
- Default SessionContinuationPanel.canForkToCloud to false so future callers
  must opt in, and only surface the new-session fork for rows that carry a
  cloud_agent_session_id.
- Toast a generic message for unexpected failures instead of leaking internal
  zod/worker error text.
Custom agent lists read from runtime state are unconstrained while the
prepare schema bounds each agent (slug/name/model/variant length and charset,
20 agents max). Prune invalid agents, cap the list at 20, and only forward
variants alongside their model so a pathological session cannot reject the
whole fork at the zod boundary.
@maphew
maphew marked this pull request as ready for review September 6, 2026 06:16
@kilo-code-bot

kilo-code-bot Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The continuation-panel cloud fork flagged previously was removed because it was unreachable, and no new issues were found in the incremental changes.

Files Reviewed (2 files)
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/web/src/components/cloud-agent-next/SessionContinuationPanel.tsx
Previous Review Summaries (2 snapshots, latest commit db3dda6)

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

Previous review (commit db3dda6)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

CRITICAL

File Line Issue
apps/web/src/components/cloud-agent-next/CloudChatPage.tsx 1385 Continuation-panel fork gating (activeSessionType === 'cloud-agent') can never be true inside the isReadOnly branch, so the new button remains unreachable
Files Reviewed (6 files)
  • apps/web/src/components/cloud-agent-next/ChatHeader.tsx
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx - 1 issue
  • apps/web/src/components/cloud-agent-next/SessionActionsDialog.tsx
  • apps/web/src/components/cloud-agent-next/cloud-session-fork.test.ts
  • apps/web/src/components/cloud-agent-next/cloud-session-fork.ts
  • apps/web/src/components/cloud-agent-next/use-cloud-session-fork.ts

Fix these issues in Kilo Cloud

Previous review (commit 844cf4a)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (8 files)
  • apps/web/src/app/(app)/cloud/sessions/SessionsPageContent.tsx
  • apps/web/src/components/cloud-agent-next/ChatHeader.tsx
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/web/src/components/cloud-agent-next/SessionActionsDialog.tsx
  • apps/web/src/components/cloud-agent-next/SessionContinuationPanel.tsx
  • apps/web/src/components/cloud-agent-next/cloud-session-fork.test.ts
  • apps/web/src/components/cloud-agent-next/cloud-session-fork.ts
  • apps/web/src/components/cloud-agent-next/use-cloud-session-fork.ts

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

maphew and others added 4 commits September 9, 2026 08:09
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

@kilo-code-bot kilo-code-bot 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.

Reviewed against the codebase. The split into a pure derivation module + tested orchestration + thin hook is good, and the derivation details line up with the prepareSession clone schema (mode slug, variant charset/max length, runtime-agent slug/name/model limits and the 20-agent cap, exactly-one-repository rule). Org-context matching, Bitbucket/unknown-platform rejection, and the GitHub/GitLab URL fallbacks all look correct.

Requesting changes for two reachability problems that make the new UI either unreachable or misleading, plus warnings noted inline.

Critical

  1. SessionContinuationPanel's canForkToCloud is effectively always false: read-only resolution implies there is no cloud_agent_session_id, so the new button in that panel never renders.
  2. SessionActionsDialog offers the cloud fork for CLI-only sessions, which contradicts the PR description; it always fails with This session has no saved Cloud Agent configuration to copy.

Warnings

  1. The fork does not inherit the source session's profile, env vars/secrets, skills, or branch - it silently drops them.
  2. The operationKey comment doesn't match the code (rotates only on success), and the key only lives in memory, so it doesn't survive a reload after an ambiguous failure.
  3. MODE_SLUG_PATTERN omits the prepare schema's max(50).
  4. Every thrown error becomes a retry-inviting generic toast, including non-retryable NOT_FOUND/FORBIDDEN.

Details are in the inline comments. Happy to re-review once these are addressed.

Comment thread apps/web/src/components/cloud-agent-next/CloudChatPage.tsx Outdated
Comment thread apps/web/src/components/cloud-agent-next/SessionActionsDialog.tsx Outdated
Comment thread apps/web/src/components/cloud-agent-next/cloud-session-fork.ts
Comment thread apps/web/src/components/cloud-agent-next/use-cloud-session-fork.ts Outdated
Comment thread apps/web/src/components/cloud-agent-next/cloud-session-fork.ts
Comment thread apps/web/src/components/cloud-agent-next/use-cloud-session-fork.ts Outdated

@maphew maphew left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed all 6 review threads in db3dda6: eligibility gating for both fork surfaces, profile/branch scope documented, operation-key comment corrected, mode 50-char cap enforced with test, NOT_FOUND/FORBIDDEN mapped to terminal messages. Thread replies posted inline.

Comment thread apps/web/src/components/cloud-agent-next/CloudChatPage.tsx Outdated
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.

[FEATURE]: Fork a cloud session directly into a new cloud session

2 participants