Repository navigation
feat(cloud-agent-next): expose worktree ownership on getSession - #6210
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe prior Files Reviewed (2 files)
Resolved in a04fb3e
Previous Review Summary (commit 942ecdd)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 942ecdd)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (4 files)
Fix these issues in Kilo Cloud No memory-leak or security exposure found: the added read is a single PK-indexed lookup gated to worktree sessions, the pool is per-request as elsewhere in the handler, and only non-secret identifiers are returned. Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
Summary
getSessionnow exposes the session's worktree ownership so clients can read it through the public API instead of querying PostgreSQL directly.GetSessionOutputgains three optional, nullable fields:worktreeIdmetadata.workspace.worktreeId(MetadataWorkspaceSchema)parentSessionIdcli_sessions_v2.parent_session_idcloudAgentSessionScopeIdcli_sessions_v2.cloud_agent_session_scope_idThe PostgreSQL row is read with the same columns and query shape as
findOwnershipRowinsession-worktree.ts, viagetPgDb(ctx.env), keyed bykilo_user_id,session_id, andcloud_agent_session_id.Why PostgreSQL is only read for worktree sessions
parentSessionIdandcloudAgentSessionScopeIdare not stored in the session Durable Object metadata — they only exist on thecli_sessions_v2ownership row. Ordinary sessions have no worktree and therefore no grouped ownership to return, so the handler gates the ownership read onmetadata.workspace.worktreeId. This keepsgetSessionfor ordinary sessions free of this additional database round-trip. When a worktree session has no ownership row,parentSessionIdandcloudAgentSessionScopeIdare returned asnull; for non-worktree sessions the three fields are omitted.No tokens, callback targets, or callback headers are exposed.
Changes
services/cloud-agent-next/src/router/schemas.ts— extendGetSessionOutputwithworktreeId,parentSessionId,cloudAgentSessionScopeIdservices/cloud-agent-next/src/router/handlers/session-management.ts— read worktree ownership for worktree sessionsapps/web/src/lib/cloud-agent-next/cloud-agent-client.ts— mirror the output typeservices/cloud-agent-next/src/router.test.ts— focused coverage for present, no-row, and non-worktree casesVerification
./node_modules/.bin/vitest run src/router.test.ts→ 150 passed./node_modules/.bin/vitest run src/router.test.ts -t "worktree ownership"→ 3 passed./node_modules/.bin/tsgo --noEmit(services/cloud-agent-next) → passed./node_modules/.bin/oxlint --config .oxlintrc.json <changed files>→ 0 warnings, 0 errorstsgoonapps/web/src/lib/cloud-agent-next/cloud-agent-client.ts→ passedNot completed: the full
apps/webjest/typecheck. The web jest global setup requires a reachable shared PostgreSQL (pnpm test:db) and Docker is unavailable in this environment, and the fullapps/webtsgorun exceeded the 2-minute command budget.