Skip to content

CloudAgentNext - Move cli_sessions_v2 creation to session-ingest RPC#242

Open
eshurakov wants to merge 8 commits intomainfrom
eshurakov/cloud-agent-next-cli-session
Open

CloudAgentNext - Move cli_sessions_v2 creation to session-ingest RPC#242
eshurakov wants to merge 8 commits intomainfrom
eshurakov/cloud-agent-next-cli-session

Conversation

@eshurakov
Copy link
Contributor

@eshurakov eshurakov commented Feb 16, 2026

Summary

Update Cloud Agent Next to use the Ingest Service to pre-create CLI sessions and add a link between Cloud Agent Session and CLI session.

  • Separate session-ingest RPC entrypoint from Hono app

@eshurakov eshurakov marked this pull request as ready for review February 16, 2026 20:56
@eshurakov eshurakov requested a review from a team February 16, 2026 20:57
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 16, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

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

WARNING

File Line Issue
cloud-agent-next/src/session-service.ts 1295 Cold-start resume now hard-fails for sessions without kiloSessionId in DO metadata — potential breaking change for pre-existing sessions
Files Reviewed (25 files)
  • cloud-agent-next/src/execution/orchestrator.ts - 0 issues (removed skipLinking)
  • cloud-agent-next/src/persistence/CloudAgentSession.ts - 0 issues (removed linkKiloSessionInBackend)
  • cloud-agent-next/src/persistence/types.ts - 0 issues (SESSION_INGEST type updated)
  • cloud-agent-next/src/router/handlers/session-prepare.ts - 0 issues (session-ingest RPC + rollback logic)
  • cloud-agent-next/src/session-ingest-binding.ts - 0 issues (new RPC binding type)
  • cloud-agent-next/src/session-prepare.test.ts - 0 issues (test updates)
  • cloud-agent-next/src/session-service.test.ts - 0 issues (test updates)
  • cloud-agent-next/src/session-service.ts - 1 issue (cold-start resume guard)
  • cloud-agent-next/src/session/ingest-handlers/kilo-session-capture.ts - 0 issues (removed linkToBackend)
  • cloud-agent-next/src/types.ts - 0 issues (SESSION_INGEST type updated)
  • cloud-agent-next/src/websocket/ingest.ts - 0 issues (removed linkKiloSessionInBackend from context)
  • cloud-agent-next/wrangler.jsonc - 0 issues (added entrypoint: SessionIngestRPC)
  • cloudflare-app-builder/start-dev.sh - 0 issues
  • cloudflare-git-token-service/wrangler.jsonc - 0 issues
  • cloudflare-session-ingest/package.json - 0 issues (vitest v2→v3)
  • cloudflare-session-ingest/src/db/kysely.ts - 0 issues
  • cloudflare-session-ingest/src/index.test.ts - 0 issues
  • cloudflare-session-ingest/src/index.ts - 0 issues (exports SessionIngestRPC)
  • cloudflare-session-ingest/src/routes/api.ts - 0 issues (refactored to use getSessionExport)
  • cloudflare-session-ingest/src/services/session-export.ts - 0 issues (new shared service)
  • cloudflare-session-ingest/src/session-ingest-rpc.ts - 0 issues (new RPC entrypoint)
  • cloudflare-session-ingest/wrangler.jsonc - 0 issues (dev config + comments)
  • pnpm-lock.yaml - skipped (generated)
  • src/routers/cloud-agent-next-router.ts - 0 issues (removed cli_sessions_v2 insert)
  • src/routers/organizations/organization-cloud-agent-next-router.ts - 0 issues (removed cli_sessions_v2 insert)

Replace backend tRPC calls (createV2, linkCloudAgent, delete) with direct
session-ingest WorkerEntrypoint RPC methods (createSessionForCloudAgent,
deleteSessionForCloudAgent). This removes the roundtrip through the Next.js
backend for session record management and moves the DB write closer to the
worker that owns the table.

- Convert session-ingest from plain Hono export to WorkerEntrypoint class
- Add createSessionForCloudAgent / deleteSessionForCloudAgent RPC methods
- Add SessionIngestBinding type declarations for both workers
- Remove linkKiloSessionInBackend from DO, session-service, and ingest handler
- Remove cli_sessions_v2 inserts from Next.js routers
- Add rollback logic in session-prepare when DO prepare() fails
- Upgrade cloudflare-session-ingest vitest to v3.2.4
- Add created_on_platform to session-ingest RPC
@eshurakov eshurakov force-pushed the eshurakov/cloud-agent-next-cli-session branch from 7a5b531 to ff70997 Compare February 17, 2026 10:01
throw new Error('Cannot link session: KILOCODE_BACKEND_BASE_URL not configured');
}

const response = await fetch(`${backendUrl}/api/cloud-sessions/linkSessions`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this endpoint doesn't even exist :-)

Replace session-ingest-binding.d.ts files with regular .ts files that
use explicit exports/imports, consistent with the rest of the codebase.
Extract RPC methods into SessionIngestRPC WorkerEntrypoint class in its
own file, reverting index.ts to export default app. Consumers reference
the named entrypoint via wrangler.jsonc service binding config. Also
adds try/catch + logging around RPC calls in session-service.ts.
@eshurakov eshurakov requested a review from iscekic February 17, 2026 10:59
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could extract some functions for reuse 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely, can do a service layer

throw new Error(
`Session ${sessionId} has no kiloSessionId in metadata. Cannot restore snapshot.`
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[WARNING]: Cold-start resume now hard-fails for sessions without kiloSessionId in DO metadata

Pre-existing sessions that were created before kiloSessionId was persisted in metadata will fail to cold-start resume with this error. Previously, restoreSessionSnapshot used the authToken to call the HTTP export API, so it didn't need kiloSessionId in metadata.

Is there a migration path for these sessions, or is this an acceptable breaking change? If sessions are short-lived enough that no pre-existing ones will attempt cold-start resume, this is fine — but worth confirming.

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