Skip to content

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

Open
maphew wants to merge 5 commits into
Kilo-Org:mainfrom
maphew:kilo/solid-logic-1ny
Open

feat(cloud): fork a cloud session directly into a new cloud session#5909
maphew wants to merge 5 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 Kilo-Org/kilocode#13825.

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

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 grok-4.6 · Input: 173.6K · Output: 23.5K · Cached: 1.9M

Review guidance: REVIEW.md from base branch main

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

1 participant