Skip to content

feat(cli): add session host registry and kilo cloud adapter - #15351

Merged
kirillk merged 2 commits into
mainfrom
mellow-badger
Oct 21, 2026
Merged

kirillk merged 2 commits into
mainfrom
mellow-badger

Conversation

@kirillk

@kirillk kirillk commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Task Board

This PR is part of the Kilo Task Board and implements task-board issue #5.

What Problem This Solves

Kilo clients can already start and follow cloud agent work through a CLI-specific client, but core has no provider-neutral way to describe a session that may not live in the local runtime. Every consumer currently has to know Cloud-specific identities, transport details, and error shapes, which makes local and hosted sessions hard to combine safely.

Why This Change Was Made

Introduce the internal Session Host seam before any local API or IDE integration is added. The seam keeps hosted identity composite (providerID + native session ID), so equal remote IDs from different providers cannot collide, and keeps provider availability, transport state, and native turn state as separate concepts. Durability and retryability are reported independently, so a temporary runtime or network failure never hides readable history.

Changes:

  • Add a provider-neutral Session Host contract and in-process registry. Hosted identity is always composite; an unknown provider fails explicitly instead of borrowing another provider, and a default is selected only while that specific provider is authenticated and available.
  • Add the built-in kilo-cloud provider with list, get, bounded transcript, start, and an attach descriptor. It reuses Kilo account auth, organization headers, origin validation, Cloud base configuration, and reads the current stored credential per operation.
  • Normalize Cloud responses into the existing native session, message, and part models, verify returned identities match the request, and keep Cloud control IDs, target origins, bearer values, directory selectors, and SSE fences inside the adapter. The attach descriptor carries only identity and a short expiry; attachment routing belongs to the follow-up local attachment work.
  • Map provider failures to stable codes with separate retryable flags, and treat an ambiguous start as retryable only when the caller supplies an idempotency key.
  • Accept workspace_* control identities and the desktop creation origin in the existing Kilo-owned Cloud start contract, matching the Cloud start schema this adapter consumes.

User Impact

No user-visible behavior changes yet. This is the internal boundary that later hosted-session discovery, attach, and IDE work will consume. Local-only behavior is unchanged, and a signed-out account produces an actionable unavailable state instead of a silent fallback to local execution.

Screenshots / Video

N/A - no visual changes.

Evidence

  • bun test ./test/kilocode/session-hosting/ (from packages/opencode/): 16 passed, 0 failed.
  • bun test --timeout 30000 ./test/kilocode/cloud/ (from packages/opencode/): 50 passed, 0 failed.
  • bun run typecheck (from packages/opencode/, also executed by the pre-push hook including the JetBrains plugin): passed.
  • bunx oxlint packages/opencode/src/kilocode/session-hosting packages/opencode/test/kilocode/session-hosting: 0 errors.
  • bun run script/check-opencode-promise-facades.ts: no runtime drift.
  • bun run script/check-opencode-annotations.ts --worktree: no shared upstream source files changed.
  • Tests cover signed-out behavior with zero Cloud requests, two providers with colliding native session IDs, an idle-stopped durable transcript normalized without any SSE target, durable reads surviving a later failure, malformed or mismatched payloads, and an attach descriptor with no URL, token, Cloud control ID, directory selector, or fence.
  • Changeset added for @kilocode/cli.

Dependency

The Cloud-side native session facade and its idempotent start behavior are already merged in Kilo-Org/cloud. This PR adds no runtime flag, migration, or SDK regeneration; the local attachment/HTTP surface and IDE consumption are follow-up work.

@github-actions github-actions Bot added the area:cli CLI, TUI and core engine label Oct 21, 2026
@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The follow-up commit addresses the previously raised findings: idempotent starts now require a stable messageID, the unused list cursor was removed from the contract, Cloud identities are decoded through HostedSessionID before being emitted, and read paths accept an explicit organizationID.

Files Reviewed (4 files)
  • packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts
  • packages/opencode/src/kilocode/session-hosting/types.ts
  • packages/opencode/test/kilocode/session-hosting/kilo-cloud.test.ts
  • packages/opencode/test/kilocode/session-hosting/registry.test.ts
Previous Review Summary (commit 2f452d7)

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

Previous review (commit 2f452d7)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts 279 Start is marked retryable when operationKey is set, but a retry generates a new messageID, so an idempotent replay with the original messageId is rejected as invalid_response and the created session is lost.

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts 223 list() accepts a cursor and the page type exposes cursor, but the adapter never returns one, so callers cannot page past the first page without provider-specific knowledge.
packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts 331 Identities derived from Cloud responses (kiloSessionId, SessionInfo.id) are not validated against HostedSessionID/RemoteSessionID, so the seam can emit ids that its own get/transcript/attach reject.
packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts 200 Reads resolve credentials without an organization input while start() accepts StartInput.organizationID, so sessions started under an explicit org may not be visible to get/list/transcript.
Files Reviewed (9 files)
  • .changeset/session-host-cloud-adapter.md - no issues
  • packages/opencode/src/kilocode/cloud/contracts.ts - no issues
  • packages/opencode/src/kilocode/session-hosting/index.ts - no issues
  • packages/opencode/src/kilocode/session-hosting/kilo-cloud.ts - 4 issues
  • packages/opencode/src/kilocode/session-hosting/registry.ts - no issues
  • packages/opencode/src/kilocode/session-hosting/types.ts - no issues
  • packages/opencode/test/kilocode/session-hosting/kilo-cloud.test.ts - no issues
  • packages/opencode/test/kilocode/session-hosting/registry.test.ts - no issues
  • packages/opencode/test/kilocode/session-hosting/service.test.ts - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 54.9K · Output: 9.4K · Cached: 502.7K

Review guidance: REVIEW.md from base branch main

@kirillk
kirillk merged commit 42530c8 into main Oct 21, 2026
46 of 49 checks passed
@kirillk
kirillk deleted the mellow-badger branch October 21, 2026 17:40
@github-actions

Copy link
Copy Markdown
Contributor

Tracked for the opencode v2 rewrite in #15352 (core-v1-changes-port).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants