Skip to content

feat(mobile): pick a remote instance when creating an agent session#4618

Open
iscekic wants to merge 10 commits into
mainfrom
feature/kilo-remote-process-spawn
Open

feat(mobile): pick a remote instance when creating an agent session#4618
iscekic wants to merge 10 commits into
mainfrom
feature/kilo-remote-process-spawn

Conversation

@iscekic

@iscekic iscekic commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a "Run on" instance picker to the new-agent screen so a user can start a session on a connected kilo remote CLI instance instead of only the managed Cloud Agent.

  • Ingest + tRPC (session-ingest, apps/web): heartbeat schema passthrough for the CLI's new instance field and per-session platform; a live-WebSocket-scan getConnectedInstances() DO RPC (deliberately not backed by stored/cached state, so it survives hibernation); GET /api/instances/active; activeSessions.listInstances tRPC procedure (throws on upstream failure, unlike list, which swallows into an empty array).
  • SDK (apps/web): a CommandDeliveredError seam in the cloud-agent SDK so callers can distinguish "the relay delivered an error response" from "the command never got a response at all" (transport failure); createRemoteSessionOnConnection helper.
  • Mobile picker + submit (apps/mobile): instance-picker.tsx (happy/empty/error/loading states, refetch-on-focus + poll, dedup suffixes for same-name/project instances), a "Run on" selector on the new-agent screen with a reduced composer for remote targets (model/mode/repo/attachments hidden, single "Start session" CTA), a pure outcome classifier mapping the spawn result to ready/retryable/non-retryable UX, and a ?spawned=1 bounded NOT_FOUND retry on the session-detail route to bridge the async ingest-row window. Live sessions are now labeled by their actual platform instead of a hardcoded "CLOUD AGENT".

Non-goals (v1)

  • No prompt-carrying spawn (promptless — the user types after landing in chat, matching the existing /new UX).
  • No model/agent/repo selection for a remote target (CLI defaults apply).
  • Org-scoped flows never show the instance selector (a remote-spawned session is a personal CLI session the picker can't attribute to an org context) — Cloud Agent only there.

Verification

  • apps/mobile: pnpm format:check && pnpm typecheck && pnpm lint && pnpm check:unused && pnpm test all green (155 files / 1070 tests).
  • services/session-ingest: vitest + typecheck + lint green.
  • apps/web: typecheck + lint + touched-scope jest (cloud-agent-sdk, active-sessions-router) green; full jest suite (664 suites) also run clean.
  • Full on-device E2E verification against a local dev stack (paired kilocode CLI build, isolated XDG_DATA_HOME, local session-ingest/nextjs URLs): empty state, happy path (tmux-mode spawn with a real streamed reply), sibling spawns from both /new-in-session and a second picker-initiated spawn, detached (non-tmux) mode, and the retryable-disconnect-then-recover flow were all verified live on an iOS simulator. Two real bugs found during E2E and fixed in this PR:
    • The "instance disconnected" note was rendered only inside the reduced remote composer, which unmounts in the same state update that sets the note — moved the note into the full (Cloud Agent) composer's "Run on" section so it's actually visible after a reset.
    • active-sessions-router.test.ts's beforeAll needed real timeout headroom under full-suite parallel load (unrelated flake, fixed alongside a require() → dynamic-import() lint fix in the same file).
  • Rebased cleanly onto latest main (zero file overlap with the 9 commits it had moved by; no conflicts).

Linked PR

kilocode CLI-side companion PR: Kilo-Org/kilocode#12327

Comment thread apps/mobile/src/components/agents/use-remote-spawn-dispatch.ts
Comment thread apps/mobile/src/app/(app)/agent-chat/new.tsx Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change since the last review fixes both previously-flagged issues (a stale-selection race in the remote-spawn dispatch tail and an unreachable showInstanceDisconnectedNote prop) with no new issues introduced.

Files Reviewed (3 files)
  • apps/mobile/src/app/(app)/agent-chat/new.tsx
  • apps/mobile/src/components/agents/remote-spawn-composer.tsx
  • apps/mobile/src/components/agents/use-remote-spawn-dispatch.ts
Previous Review Summaries (2 snapshots, latest commit c750b86)

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

Previous review (commit c750b86)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change since the last review is a whitespace-only reformat of active-sessions-router.test.ts (chained jest.spyOn(...).mockResolvedValue(...) calls collapsed onto fewer lines); no logic, security, or reliability issues were introduced.

Files Reviewed (1 file)
  • apps/web/src/routers/active-sessions-router.test.ts

Previous review (commit 0d2717a)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

A stale-selection race in the remote-spawn retry path (use-remote-spawn-dispatch.ts) can silently overwrite a user's newer instance pick after a retryable spawn failure.

Overview

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

WARNING

File Line Issue
apps/mobile/src/components/agents/use-remote-spawn-dispatch.ts 145 Stale-selection race can silently discard a newer instance pick during the retryable-failure refetch window

SUGGESTION

File Line Issue
apps/mobile/src/app/(app)/agent-chat/new.tsx 273 showInstanceDisconnectedNote prop passed to RemoteSpawnComposer is unreachable dead code
Files Reviewed (43 files)
  • apps/mobile/src/app/(app)/_layout.tsx
  • apps/mobile/src/app/(app)/agent-chat/[session-id].tsx
  • apps/mobile/src/app/(app)/agent-chat/instance-picker.tsx
  • apps/mobile/src/app/(app)/agent-chat/new.tsx - 1 issue
  • apps/mobile/src/components/agents/instance-selector.tsx
  • apps/mobile/src/components/agents/remote-spawn-composer.tsx
  • apps/mobile/src/components/agents/session-detail-routes.test.ts
  • apps/mobile/src/components/agents/session-detail-routes.ts
  • apps/mobile/src/components/agents/session-list-content.tsx
  • apps/mobile/src/components/agents/session-row.tsx
  • apps/mobile/src/components/agents/use-remote-spawn-dispatch.ts - 1 issue
  • apps/mobile/src/components/agents/user-web-connection-provider.tsx
  • apps/mobile/src/components/home/agent-sessions-section.tsx
  • apps/mobile/src/lib/hooks/remote-instance-spawn-classifier.ts
  • apps/mobile/src/lib/hooks/use-remote-instance-spawn.test.ts
  • apps/mobile/src/lib/hooks/use-remote-instance-spawn.ts
  • apps/mobile/src/lib/instance-picker-rows.test.ts
  • apps/mobile/src/lib/instance-picker-rows.ts
  • apps/mobile/src/lib/new-session-submit.test.ts
  • apps/mobile/src/lib/new-session-submit.ts
  • apps/mobile/src/lib/picker-bridge.ts
  • apps/mobile/src/lib/platform-label.test.ts
  • apps/mobile/src/lib/platform-label.ts
  • apps/mobile/src/lib/remote-submit-outcome.test.ts
  • apps/mobile/src/lib/remote-submit-outcome.ts
  • apps/mobile/src/lib/should-show-run-on-selector.test.ts
  • apps/mobile/src/lib/should-show-run-on-selector.ts
  • apps/mobile/src/lib/spawned-not-found-retry.test.ts
  • apps/mobile/src/lib/spawned-not-found-retry.ts
  • apps/mobile/vitest.config.ts
  • apps/web/src/lib/cloud-agent-sdk/create-session.test.ts
  • apps/web/src/lib/cloud-agent-sdk/create-session.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/lib/cloud-agent-sdk/user-web-connection.test.ts
  • apps/web/src/lib/cloud-agent-sdk/user-web-connection.ts
  • apps/web/src/routers/active-sessions-router.test.ts
  • apps/web/src/routers/active-sessions-router.ts
  • services/session-ingest/src/dos/UserConnectionDO.test.ts
  • services/session-ingest/src/dos/UserConnectionDO.ts
  • services/session-ingest/src/routes/api.test.ts
  • services/session-ingest/src/routes/api.ts
  • services/session-ingest/src/types/user-connection-protocol.test.ts
  • services/session-ingest/src/types/user-connection-protocol.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 34 · Output: 4.4K · Cached: 981K

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.

1 participant