Skip to content

Cloud Agent - Add kilo cloud command for running asynchronous cloud agent tasks - #11849

Merged
eshurakov merged 3 commits into
mainfrom
lucky-look
Jul 22, 2026
Merged

Cloud Agent - Add kilo cloud command for running asynchronous cloud agent tasks#11849
eshurakov merged 3 commits into
mainfrom
lucky-look

Conversation

@eshurakov

@eshurakov eshurakov commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Add the kilo cloud command for running asynchronous Cloud Agent tasks with repository, model, mode, and organization defaults. Includes kilo cloud start --stream to print admission output and stream WebSocket events as JSONL until the server closes the connection. Registers the command in the CLI setup, adds supporting cloud modules, tests, docs, and a changeset.

Manual testing

Verified end-to-end against the production Cloud Agent backend using a locally built binary from this branch (bun run script/build.ts --single --skip-install, version 0.0.0-lucky-look-202607211425):

  • kilo cloud start — repository auto-inferred as Kilo-Org/kilocode from the origin remote, --branch lucky-look passed explicitly, --model kilo/moonshotai/kimi-k3 accepted after validation against the org model catalog; session admitted and queued
  • kilo cloud status — observed the full queuedrunningcompleted lifecycle (~2.4 min, completionSource: idle_reconciliation)
  • kilo cloud result — assistant responded exactly as prompted
  • kilo cloud send — follow-up prompt on the same session admitted and completed successfully

Test session: agent_4b8ad310-b9e6-490d-840d-e945449273da

Comment thread packages/opencode/src/kilocode/cloud/repository.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/websocket-stream.ts
Comment thread packages/opencode/src/kilocode/cloud/websocket-stream.ts
Comment thread packages/opencode/src/kilocode/cloud/stream-ticket.ts
Comment thread packages/opencode/src/kilocode/cloud/contracts.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/commands.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/message-id.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/auth.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/defaults.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/trpc.ts
@kilo-code-bot

kilo-code-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental update

Since the last review (fc31b4e0ea64d6dc988bf017f5d2c8cd7888c03d -> 8997ef912331f44cce7e1a9adee8f3e16733d884), websocket-stream.ts was reworked to fix transport-failure handling: fail() now closes the socket and waits (bounded by min(timeoutMs, 1000ms)) for in-flight writeLine calls in the pending chain to drain before rejecting, so already-received events are flushed in order instead of being dropped on connection loss. A new abort() helper rejects immediately (without draining) for backpressure (MAX_QUEUED_BYTES exceeded) and write-failure cases, where waiting would not help. New tests cover both the successful-drain and bounded-timeout-during-stall paths. Reviewed this change for races between the drain timer and the pending.then() resolution path (double-settle is safely a no-op), and for interaction with the existing aborted flag guarding late writes after failure — no new issues found.

Files Reviewed (2 files)
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts
Previous Review Summaries (7 snapshots, latest commit fc31b4e)

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

Previous review (commit fc31b4e)

Status: No Issues Found | Recommendation: Merge

Incremental update

The only change since the last review (f142611398428b116b872d624f0b1fc5d4a160c9 -> fc31b4e0ea64d6dc988bf017f5d2c8cd7888c03d) is a documentation-only comment in websocket-stream.ts clarifying that MAX_QUEUED_BYTES is measured via text.length (UTF-16 units) and that in-memory usage can reach roughly twice the bound for non-Latin-1 payloads. This directly addresses the previously flagged suggestion about byte-count accuracy by making the trade-off explicit and intentional. No new issues were introduced.

Files Reviewed (1 file)
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts

Previous review (commit f142611)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/cloud/websocket-stream.ts 101 MAX_QUEUED_BYTES cap is measured via text.length (UTF-16 units), not actual bytes, so non-ASCII payloads can exceed the intended 8 MB bound
Resolved since last review
  • packages/opencode/src/kilocode/cloud/commands.ts / packages/opencode/src/kilocode/cloud/websocket-stream.ts - the previously flagged unbounded-memory backpressure issue is fixed: writeLine is now serialized and awaited end-to-end, and stream writes are capped at 8 MB with a loud failure (WebSocket stream output consumer is too slow) instead of unbounded growth. New tests cover slow-write ordering, write-failure propagation, and the memory bound.
Files changed since last review (4 files)
  • packages/opencode/src/kilocode/cloud/commands.ts - 0 new issues (writeLine made async, mirrors existing print() write pattern)
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts - 1 new issue (byte-count accuracy, see above)
  • packages/opencode/test/kilocode/cloud/command.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts - no issues

Fix these issues in Kilo Cloud

Previous review (commit 6cd4f14)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/kilocode/cloud/commands.ts 117 Stream output ignores stdout backpressure and can grow memory without bound (existing finding, still applicable, not re-posted)
Files Reviewed (30 files)
  • .changeset/run-cloud-agent.md - resolved (release note wording updated)
  • packages/kilo-docs/lychee.toml - no issues
  • packages/kilo-docs/markdoc/partials/cli-commands-table.md - no issues
  • packages/kilo-docs/pages/code-with-ai/platforms/cli-reference.md - no issues
  • packages/kilo-docs/source-links.md - no issues
  • packages/opencode/src/kilocode/cli/cmd/cloud.ts - no issues
  • packages/opencode/src/kilocode/cli/setup.ts - no issues
  • packages/opencode/src/kilocode/cloud/auth.ts - resolved (redacted-token finding no longer reproduces)
  • packages/opencode/src/kilocode/cloud/catalog.ts - no issues
  • packages/opencode/src/kilocode/cloud/commands.ts - 1 issue (backpressure, unresolved)
  • packages/opencode/src/kilocode/cloud/contracts.ts - no issues
  • packages/opencode/src/kilocode/cloud/defaults.ts - no issues
  • packages/opencode/src/kilocode/cloud/errors.ts - no issues
  • packages/opencode/src/kilocode/cloud/http.ts - no issues
  • packages/opencode/src/kilocode/cloud/message-id.ts - no issues
  • packages/opencode/src/kilocode/cloud/origin.ts - no issues
  • packages/opencode/src/kilocode/cloud/repository.ts - no issues
  • packages/opencode/src/kilocode/cloud/response-json.ts - resolved (oversized Content-Length responses now cancel the body)
  • packages/opencode/src/kilocode/cloud/stream-ticket.ts - resolved (request timeout added; redirects disabled via redirect: "error")
  • packages/opencode/src/kilocode/cloud/trpc.ts - resolved (error-path response body now drained via discard)
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts - resolved (idle timer added; stream origin now pinned to expected origin)
  • packages/opencode/src/kilocode/commands.ts - no issues
  • packages/opencode/test/kilocode/cli-shutdown.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/command.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/defaults.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/repository.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/stream-ticket.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/transport.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts - no issues
  • packages/opencode/test/kilocode/help.test.ts - no issues

Fix these issues in Kilo Cloud

Previous review (commit 3434edd)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

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

SUGGESTION

File Line Issue
packages/opencode/test/kilocode/cloud/cli.test.ts N/A Removing the only process-level CLI test leaves public flag parsing and request forwarding unverified
packages/opencode/test/kilocode/cloud/response-json.test.ts N/A Removing the cancellation regression test leaves the oversized-response resource-release fix unverified
Files Reviewed (7 files)
  • packages/opencode/src/kilocode/cloud/contracts.ts - no issues
  • packages/opencode/src/kilocode/cloud/repository.ts - no issues
  • packages/opencode/src/kilocode/cloud/stream-ticket.ts - no issues
  • packages/opencode/test/kilocode/cloud/cli.test.ts - 1 issue
  • packages/opencode/test/kilocode/cloud/lifecycle.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/repository.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/response-json.test.ts - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit e029db3)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (9 files)
  • .changeset/run-cloud-agent.md
  • packages/opencode/src/kilocode/cloud/commands.ts
  • packages/opencode/src/kilocode/cloud/response-json.ts
  • packages/opencode/src/kilocode/cloud/stream-ticket.ts
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts
  • packages/opencode/test/kilocode/cloud/command.test.ts
  • packages/opencode/test/kilocode/cloud/response-json.test.ts
  • packages/opencode/test/kilocode/cloud/stream-ticket.test.ts
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts

Previous review (commit 76a72f2)

Status: 10 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/kilocode/cloud/repository.ts 194 Hostname-only checks allow DNS names that resolve to private addresses to bypass the repository SSRF boundary
packages/opencode/src/kilocode/cloud/stream-ticket.ts 60 Stream-ticket POST follows redirects outside the validated Web App origin
packages/opencode/src/kilocode/cloud/stream-ticket.ts 68 Malformed 403/404 response bodies abort before the intended retry logic
packages/opencode/src/kilocode/cloud/websocket-stream.ts 101 Abnormal WebSocket close codes are treated as successful stream completion
packages/opencode/src/kilocode/cloud/commands.ts 117 Stream output ignores stdout backpressure and can grow the process write queue without bound
packages/opencode/src/kilocode/cloud/commands.ts 189 Admission JSON can expose the WebSocket ticket in logs and terminal history
packages/opencode/src/kilocode/cloud/commands.ts 191 Stream-ticket acquisition failure after successful admission still returns a command failure that may trigger an unsafe retry
packages/opencode/src/kilocode/cloud/commands.ts 201 All WebSocket failures are silently suppressed, so truncated streams exit successfully without a diagnostic

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/cloud/response-json.ts 12 Oversized Content-Length responses are rejected without cancelling their bodies
.changeset/run-cloud-agent.md 5 Release note says streaming lasts until server close despite client-side completion and idle deadlines
Files Reviewed (32 files)
  • .changeset/run-cloud-agent.md - 1 issue
  • packages/kilo-docs/lychee.toml - no issues
  • packages/kilo-docs/markdoc/partials/cli-commands-table.md - no issues
  • packages/kilo-docs/pages/code-with-ai/platforms/cli-reference.md - no issues
  • packages/kilo-docs/source-links.md - no issues
  • packages/opencode/src/kilocode/cli/cmd/cloud.ts - no issues
  • packages/opencode/src/kilocode/cli/setup.ts - no issues
  • packages/opencode/src/kilocode/cloud/auth.ts - no issues
  • packages/opencode/src/kilocode/cloud/catalog.ts - no issues
  • packages/opencode/src/kilocode/cloud/commands.ts - 4 issues
  • packages/opencode/src/kilocode/cloud/contracts.ts - no issues
  • packages/opencode/src/kilocode/cloud/defaults.ts - no issues
  • packages/opencode/src/kilocode/cloud/errors.ts - no issues
  • packages/opencode/src/kilocode/cloud/http.ts - no issues
  • packages/opencode/src/kilocode/cloud/message-id.ts - no issues
  • packages/opencode/src/kilocode/cloud/origin.ts - no issues
  • packages/opencode/src/kilocode/cloud/repository.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/response-json.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/stream-ticket.ts - 2 issues
  • packages/opencode/src/kilocode/cloud/trpc.ts - no issues
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts - 1 issue
  • packages/opencode/src/kilocode/commands.ts - no issues
  • packages/opencode/test/kilocode/cli-shutdown.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/cli.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/command.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/defaults.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/lifecycle.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/repository.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/stream-ticket.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/transport.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts - no issues
  • packages/opencode/test/kilocode/help.test.ts - no issues

Fix these issues in Kilo Cloud

Previous review (commit e67d67d)

Status: 11 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/kilocode/cloud/repository.ts 151 github()'s dot-segment guard checks pre-strip path parts, not the final owner/repo value — a ...git segment resolves to .. and bypasses the traversal check
packages/opencode/src/kilocode/cloud/websocket-stream.ts 70 Absolute streamUrl from the server response is not pinned to the expected origin, unlike http.ts's SSRF guard
packages/opencode/src/kilocode/cloud/websocket-stream.ts 17 No connect/idle timeout for the WebSocket stream; a stalled connection hangs the CLI forever
packages/opencode/src/kilocode/cloud/stream-ticket.ts 52 Stream-ticket HTTP request has no timeout, unlike http.ts's bearer client
packages/opencode/src/kilocode/cloud/contracts.ts 92 AgentSendResponseSchema.cloudAgentSessionId uses a bare z.string() instead of the strict CloudAgentSessionIdSchema used by sibling schemas
packages/opencode/src/kilocode/cloud/commands.ts 200 A stream failure after a successful start admission is reported as a command failure (non-zero exit), which could cause automation to retry an already-admitted session

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/cloud/contracts.ts 94 AgentSendResponseSchema.streamUrl is missing .min(1) unlike its sibling schema
packages/opencode/src/kilocode/cloud/message-id.ts 5 Left-shift by 12 bits with nothing filled into the low bits — the prefix's last 3 hex chars are always 000
packages/opencode/src/kilocode/cloud/auth.ts 39 Raw, unredacted Auth.Info is threaded through alongside the Redacted token
packages/opencode/src/kilocode/cloud/defaults.ts 69 Final mode fallback doesn't re-check hidden/subagent like the preceding branches
packages/opencode/src/kilocode/cloud/trpc.ts 127 Response body isn't drained on the !response.ok error path, a minor resource-leak risk
Files Reviewed (30 files)
  • .changeset/run-cloud-agent.md - no issues
  • packages/kilo-docs/lychee.toml - no issues
  • packages/kilo-docs/markdoc/partials/cli-commands-table.md - no issues
  • packages/kilo-docs/pages/code-with-ai/platforms/cli-reference.md - no issues
  • packages/kilo-docs/source-links.md - no issues
  • packages/opencode/src/kilocode/cli/cmd/cloud.ts - no issues
  • packages/opencode/src/kilocode/cli/setup.ts - no issues
  • packages/opencode/src/kilocode/cloud/auth.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/catalog.ts - no issues
  • packages/opencode/src/kilocode/cloud/commands.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/contracts.ts - 2 issues
  • packages/opencode/src/kilocode/cloud/defaults.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/errors.ts - no issues
  • packages/opencode/src/kilocode/cloud/http.ts - no issues (contrast reference for other findings)
  • packages/opencode/src/kilocode/cloud/message-id.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/origin.ts - no issues
  • packages/opencode/src/kilocode/cloud/repository.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/response-json.ts - no issues
  • packages/opencode/src/kilocode/cloud/stream-ticket.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/trpc.ts - 1 issue
  • packages/opencode/src/kilocode/cloud/websocket-stream.ts - 2 issues
  • packages/opencode/src/kilocode/commands.ts - no issues
  • packages/opencode/test/kilocode/cli-shutdown.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/cli.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/command.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/defaults.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/lifecycle.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/repository.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/stream-ticket.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/transport.test.ts - no issues
  • packages/opencode/test/kilocode/cloud/websocket-stream.test.ts - no issues
  • packages/opencode/test/kilocode/help.test.ts - no issues

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 32 · Output: 12K · Cached: 934.5K

Review guidance: REVIEW.md from base branch main

NJ-2020 pushed a commit to NJ-2020/kilocode that referenced this pull request Jul 4, 2026
@eshurakov
eshurakov force-pushed the lucky-look branch 3 times, most recently from 828cdab to 76a72f2 Compare July 13, 2026 09:30
Comment thread packages/opencode/src/kilocode/cloud/repository.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/stream-ticket.ts
Comment thread packages/opencode/src/kilocode/cloud/stream-ticket.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/websocket-stream.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/commands.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/commands.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/commands.ts Outdated
Comment thread packages/opencode/src/kilocode/cloud/response-json.ts
Comment thread .changeset/run-cloud-agent.md Outdated
…t tasks

- Reject stream-ticket redirects and preserve retries for malformed 403/404 bodies
- Reject abnormal WebSocket closes instead of treating them as completion
- Redact ticket-bearing streamUrl from admission and send output
- Report post-admission stream failures as a JSONL error event while
  preserving the successful admission exit status
- Cancel oversized response bodies before throwing
- Relax cloud agent response schemas to accept arbitrary bounded strings
  instead of strict enums, remove SSRF host restrictions from repository
  URL validation, and drop low-value tests whose coverage is already
  provided by command, transport, and stream-ticket tests
Comment thread packages/opencode/src/kilocode/cloud/websocket-stream.ts
Serialize stream writes through a flush-aware chain and cap queued
output at 8 MB, failing the stream loudly when the stdout consumer
cannot keep up instead of growing process memory without bound. Drain
pending writes before resolving so received lines are never truncated
or a late write failure silently swallowed.
@johnnyeric

Copy link
Copy Markdown
Contributor

@eshurakov Found one thing worth double checking, could you take a look?

fail() rejects without draining pending, so error output can reorder or truncate received events

websocket-stream.ts:68 — fail() rejects immediately while queued writes are still in flight. finish() awaits pending before settling, but fail() doesn't, so the failure path doesn't honor the guarantee in this commit's own message ("drain pending writes before resolving so received lines are never truncated").

Otherwise, all looks good.

@eshurakov
eshurakov merged commit fe01f53 into main Jul 22, 2026
43 of 46 checks passed
@eshurakov
eshurakov deleted the lucky-look branch July 22, 2026 13:48
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
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.

2 participants