Skip to content

feat(cloud-agent): add workspace read model and synchronized tabs - #11225

Open
eshurakov wants to merge 9 commits into
mainfrom
kilo/long-crest-fno
Open

eshurakov wants to merge 9 commits into
mainfrom
kilo/long-crest-fno

Conversation

@eshurakov

@eshurakov eshurakov commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Current review preparation (2026-11-17)

  • Current head: da42cfe59f43067acd5c24fea29f2555e2fe1168.
  • Addressed and resolved seven review threads: bounded stack lookup, adopted standalone rows, deployment backfill locks, stalled live refresh, the ungrouped-limit notice, unused tab cleanup, and ineffective truncation coverage.
  • One human design thread remains open: complete tab-summary payloads grow with chats in a workspace. The current design requires every open tab. No silent chat cap was added.
  • Confirmed conflicts required a squash and rebase. Saved a local backup, regenerated migration metadata, and used an explicit inspected-head push lease. Later human-review fixes use a normal follow-up commit.
  • Focused local tests, schema consistency, migration bootstrap, web and Session Ingest typechecks, and changed-file type-aware lint passed. Browser and real Worker-event checks confirmed adoption and the 50-of-63 truncation notice.
  • Timeout recovery has focused test coverage. Full agent execution and real-model behavior were not rerun.
  • All 11 required checks passed for the current head da42cfe59f43067acd5c24fea29f2555e2fe1168. All check runs completed; none currently fail.
  • The non-required extension browser job passed on its single retry. Its first run failed an unchanged connection-grace timing assertion (4,401 ms versus 4,500 ms). No assertions or checks were weakened.
  • Automated review completed. It confirms the seven fixes and retains one unbounded-summary-payload warning in the open design thread.
  • New local evidence and exact verification results are attached in the review-preparation comment.

Summary

  • Add PostgreSQL-backed workspace summaries, stable chat pagination, and explicit standalone-session reads.
  • Centralize workspace activity, stack destinations, visibility limits, and navigation IDs on the server.
  • Synchronize closed tabs and tab order with atomic workspace mutations and a one-time browser-state import.
  • Replace sidebar-wide detail reads with hydrated summaries, batched workspace events, and state-based polling.
  • Fix a defect found during manual testing: metadata changes must not renew an old busy/retry status.

Local manual verification

Tests used the real local web app, PostgreSQL, Session Ingest Worker, and WebSocket connections. Metadata fixtures were synthetic.

Area Observed result
API contracts and access 24 assertions passed, including personal/organization boundaries, foreign IDs, input limits, and standalone compatibility.
Heavy sidebar 2,000 workspaces and 10,000 root chats. Returned 500 manual-folder groups and 50 ungrouped groups, with stack layers and total counts. No worktreeDetails requests.
Search and filters Found a hidden workspace and chat 123. Repository normalization and Cloud/CLI filters passed.
Chat pagination Read all 123 chats across pages without gaps or duplicates, including microsecond timestamps.
Tabs Close/reopen synchronized across two browsers. Relative reorder synchronized through the real mutation. Concurrent closes/reopens retained both writes. Reload retained order.
Legacy import Imported closed tabs for an untouched workspace and removed the browser key.
Navigation and stacks Selected the latest remaining open chat. Navigated stack layers without detail-request fanout. Child attention moved the stack to Needs you.
Folders Created, renamed, moved, and deleted folders. Move/delete results reached the other browser.
Activity Verified attention/review/done destinations, running-over-failure priority, and stale busy handling after the fix. Status transitions used synthetic metadata.
Live events Three workspace events coalesced into one affected-summary request. A real 200-ID batch, rename/delete events, tab cleanup, and final-root rollback passed.
Reconnect The offline browser retained the old name, then loaded the missed rename after reconnecting.
Polling Idle: zero sidebar requests for 65 seconds. Running: an affected-summary poll after 30 seconds.

The local stack and test browsers were stopped after verification.

Automated verification

  • 549 PostgreSQL/router tests passed.
  • 306 sidebar/activity tests passed.
  • The stale busy/retry regression failed before the fix and passed afterward.
  • Formatting, changed-file type-aware lint, and the web typecheck passed.
  • Earlier implementation verification is recorded in docs/plans/cloud-agent-workspace-read-model.md.

Verification limits

  • The current conflict-driven rebase is complete. Upstream behavior and the generated MCP catalog changes remain intact. Regenerated migration 0363_workspace_read_model preserves the eight generated DDL statements and concurrent-index retry safety. The unnecessary deployment backfill is removed; reads handle null or stale activity.
  • Full agent-runtime tests could not start. Local immutable-artifact publication failed twice with a closed Miniflare R2 connection. The runtime health endpoint never became available. Cold/warm turns, streaming, queue, and Stop remain unverified in this pass.
  • Tab reorder was verified through the real mutation and browser rendering, not a pointer-drag gesture.
  • This is focused verification, not a full repository pnpm validate run.

Earlier review preparation

  • Resolved confirmed merge conflicts, with a local backup and an explicit inspected-head push lease. Preserved the later CI-generated MCP catalog commit.
  • Updated the repository-filter test fixture for workspace summary lookup. Aligned folder and PR-refresh mocks with summary queries and the 500-workspace limit. Split session/workspace write mocks without removing the original session assertions; added workspace-write assertions.
  • Fixed five Markdown table separators after CI reported padding errors. The exact check passes across all 206 tracked Markdown files.
  • Passed 2,650 local tests: 419 workspace/router/activity tests, 141 sidebar tests, 222 SDK tests, 64 database/schema checks, all 1,781 Session Ingest tests, and 23 folder/PR-status tests. Three existing Session Ingest tests remain skipped.
  • Passed web, database, SDK, and Session Ingest typechecks; conflict-file type-aware lint; formatting; whitespace checks; and empty-database migration bootstrap. Broad PR-file lint timed out locally.
  • Passed 24 authenticated local HTTP assertions. Browser checks confirmed workspace navigation, no worktreeDetails requests, persisted tab close, and event-driven reopen. Local services and the test browser were stopped afterward.
  • CI exposed the stale folder, PR-refresh, and Session Ingest fixtures. Each failure reproduced locally before its fix and passed afterward. Published the fixes as a normal follow-up commit.
  • No review comments or threads existed during preparation.

Earlier CI status

  • Final source head: c301aea39c319f11b9c53b70d3594ced86e9e110.
  • All 11 required checks passed for that head. The PR has no merge conflicts and still requires human approval.
  • The non-required cloud-agent-next (other) job passed on its single retry. Its first run failed an unchanged daemonized-process cleanup test; no test was disabled or changed.
  • Automated Kilo Code Review remains pending. No review comments or threads exist.

Evidence

Screenshots show only synthetic fixture data and the tested sidebar/tab regions.

Synthetic stack attention and sidebar destinations

Synchronized remaining chat tabs after a cross-browser close

@eshurakov
eshurakov marked this pull request as ready for review November 16, 2026 20:31
@kilo-code-bot

kilo-code-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental pass over commit 5d666a0, which removes the unused IDX_cloud_agent_worktrees_owner_activity index and updates the plan doc to the shipped 0369 migration; the diff is consistent across schema, migration, snapshot, and docs, with no new defects.

Assumptions: [INFERENCE] No migrations, tests, or typechecks were executed in this read-only session. Both prior findings are verified resolved at current HEAD: no remaining reference to owner_activity anywhere in the repo, the migration still contains exactly four CREATE INDEX CONCURRENTLY statements (matching the doc's "four concurrent indexes"), and every concurrent build keeps its retry-safe DROP INDEX CONCURRENTLY IF EXISTS + COMMIT/BEGIN + timeout-reset sandwich per packages/db/AGENTS.md. The _journal.json when bump and snapshot id change are generated metadata for an unrecorded migration, so they are safe.

Files Reviewed (5 files)
  • packages/db/src/migrations/0369_workspace_read_model.sql - 0 issues
  • packages/db/src/schema.ts - 0 issues
  • packages/db/src/migrations/meta/0369_snapshot.json (generated) - 0 issues
  • packages/db/src/migrations/meta/_journal.json (generated) - 0 issues
  • docs/plans/cloud-agent-workspace-read-model.md - 0 issues
Previous Review Summaries (10 snapshots, latest commit b5b4ed4)

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

Previous review (commit b5b4ed4)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

Incremental pass over the rebase that renamed the read-model migration to 0369; no new defects, and the two earlier suggestions still apply to current HEAD.

Assumptions: [INFERENCE] No tests, migrations, or browser checks were executed in this read-only session. Since the previous review, the only PR-side change is the migration renumbering (0368_workspace_read_model.sql renamed to 0369_workspace_read_model.sql with identical content) plus regenerated journal/snapshot; the remainder of fb53aed..b5b4ed is incoming main work that is out of scope here.

Overview

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

SUGGESTION

File Line Issue
packages/db/src/migrations/0369_workspace_read_model.sql 38 IDX_cloud_agent_worktrees_owner_activity (kilo_user_id, organization_id, last_activity_at DESC) has no reader: both workspace reads drive from workspace_directory/scoped_workspaces and ORDER BY w.worktree_id, and every other cloud_agent_worktrees access filters on worktree_id. The index therefore costs a concurrent build and write overhead only; either add the owner-sorted read that needs it or drop it from the schema and regenerate.
docs/plans/cloud-agent-workspace-read-model.md 211 Plan still names 0363_workspace_read_model; after this rebase the shipped migration is 0369_workspace_read_model (journal idx 369).
Files Reviewed (3 files)
  • packages/db/src/migrations/0369_workspace_read_model.sql (renamed from 0368, content unchanged) - 1 issue
  • packages/db/src/migrations/meta/_journal.json (generated, idx 369 consistent) - 0 issues
  • docs/plans/cloud-agent-workspace-read-model.md - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit fb53aed)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

Both new findings are migration/documentation hygiene: the accepted plan still names the pre-renumbering migration, and one added concurrent index has no query that consumes its third column.

Assumptions: [INFERENCE] Tests, the migration run, and browser behaviour were not executed in this read-only session; every claim below comes from reading the current sources and the PR's own reported verification. The pre-existing human thread about unbounded workspace-summary payloads remains open and is not re-raised here.

Overview

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

SUGGESTION

File Line Issue
packages/db/src/migrations/0368_workspace_read_model.sql 38 IDX_cloud_agent_worktrees_owner_activity has no reader: both workspace reads order by w.worktree_id and activity caps run in JS, so the index adds a concurrent build and write cost only
docs/plans/cloud-agent-workspace-read-model.md 211 Plan names 0363_workspace_read_model; this PR ships 0368_workspace_read_model
Files Reviewed (14 files)
  • packages/db/src/migrations/0368_workspace_read_model.sql - 1 issue
  • docs/plans/cloud-agent-workspace-read-model.md - 1 issue
  • packages/db/src/schema.ts - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • apps/web/src/lib/cloud-agent/workspace-read-model.ts - 0 issues
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - 0 issues
  • apps/web/src/lib/cloud-agent/workspace-tab-state.ts - 0 issues
  • apps/web/src/lib/cloud-agent/workspace-activity.ts - 0 issues
  • apps/web/src/lib/cloud-agent/session-events.ts - 0 issues
  • apps/web/src/routers/cli-sessions-v2-router.ts - 0 issues
  • apps/web/src/routers/cloud-agent-sidebar-scope.ts - 0 issues
  • services/session-ingest/src/routes/api.ts - 0 issues
  • services/session-ingest/src/session-events.ts - 0 issues
  • apps/web/src/components/cloud-agent-next/hooks/useSidebarLiveUpdates.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit d66c3f9)

The review did not run because the selected model is no longer available.

Choose another model in Kilo Code review settings: https://app.kilo.ai/code-reviews

Previous review (commit d66c3f9)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental range since the previously reviewed head contains only a test-fixture UUID update in the AI-gateway usage client tests, so the sole remaining item is the unchanged unbounded root-chat payload in workspace summaries, retained by design in the open human design thread.

Assumptions: [INFERENCE] Static review only; no test execution in this pass. git diff cb9f4623b..HEAD touches only packages/web-shared/src/lib/ai-gateway/usage-record-client.test.ts (6 insertions, 2 deletions), replacing usage-1 with a valid UUIDv7 usage id in the recorded/duplicate response fixtures to match the shared usage-id schema; no production code changed. The carried warning was re-verified against current HEAD at the same line and already has an active reviewer comment (iscekic), so it was not re-posted.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 381 Carried, unchanged at head, open human design thread: jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a long-lived workspace is re-sent in full on each coalesced live event, each running poll, and each tab mutation refresh. The author's reply retains this by design pending an API/UI contract change; no silent cap should be added without that decision.
Files Reviewed (2 files this pass)
  • packages/web-shared/src/lib/ai-gateway/usage-record-client.test.ts - fixture-only change; no issues
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - unchanged from the previously reviewed head; targeted re-check of workspaceChatHydrationQuery confirms the carried finding at line 381

Fix these issues in Kilo Cloud

Previous review (commit cb9f462)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental range since the previously reviewed head contains no new PR-side code: the only content difference in PR files is the migration renumber to packages/db/src/migrations/0367_workspace_read_model.sql (upstream added 0366_latest_alias_targets), so the remaining item is the unchanged unbounded root-chat payload in workspace summaries, retained by design in an open human thread.

Assumptions: [INFERENCE] Static review only; no PostgreSQL execution in this pass. git diff b1ed85a..HEAD limited to PR paths shows only the 0366 → 0367 migration rename plus regenerated journal/snapshot; the migrated file differs from the previously reviewed 0366 file only in statement-breakpoint line breaks, and _journal.json now lists 0367_workspace_read_model at idx 367 after the upstream 0366_latest_alias_targets entry.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 381 Carried, unchanged at head, open human design thread: jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a long-lived workspace is re-sent in full on each coalesced live event and each running poll. The author's reply retains this by design pending a contract change; no silent cap should be added without that decision.
Files Reviewed (2 files this pass)
  • packages/db/src/migrations/0367_workspace_read_model.sql - renumbered copy of the previously reviewed 0366 migration; eight DDL statements, CONCURRENTLY index builds, DO $$ ... $$; guard and commit/begin split unchanged; no issues
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - unchanged from the previously reviewed head; targeted re-check of workspaceChatHydrationQuery confirms the carried finding at line 381

Fix these issues in Kilo Cloud

Previous review (commit b1ed85a)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental range contains no PR-side code changes: apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts and the list-workspaces test are identical to the previously reviewed head, so the stack-admission narrowing (indexed repository/branch shortlist plus repository-and-branch latest-chat match) holds; the only remaining item is the unchanged unbounded root-chat payload in workspace summaries, retained by design in an open human thread.

Assumptions: [INFERENCE] Static review only; no PostgreSQL execution in this pass, so plan choice and cost are reasoned from the SQL and the declared indexes (cli_sessions_v2_git_url_branch_idx, IDX_cloud_agent_worktrees_git_url_branch). The OR git_branch IN (...) arm of workspace_directory is still not counted as a finding: rows admitted by it are dropped by the repository-and-branch predicate in workspaceStackDirectoryQuery, and git_url/git_branch are written together by their only writers, so it costs a bounded lateral rather than a wrong result or a full-scope scan.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 381 Carried, unchanged at head, open human design thread: jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a long-lived workspace is re-sent in full on each coalesced live event and each running poll. The author's reply retains this by design pending a contract change; no silent cap should be added without that decision.
Files Reviewed (2 files this pass)
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - unchanged from the previously reviewed head; admission narrowing and repository-plus-branch match re-verified; 1 carried finding at line 381
  • apps/web/src/routers/cli-sessions-v2-list-workspaces.test.ts - unchanged from the previously reviewed head; cross-repository and stale-branch exclusion fixtures present; no issues

Previous review (commit d91886d)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental fix narrows the stack lookup to root chats that resolve to a seed-repository PR base branch and now compares repository and branch together, resolving both prior findings; the only remaining issue is the unchanged unbounded root-chat payload in workspace summaries, retained by design in an open human thread.

Assumptions: [INFERENCE] Static review only: no PostgreSQL execution or test run in this pass, so query costs and results are reasoned from the SQL. git_url and git_branch on cloud_agent_worktrees are written together by their only writers (recordWorkspaceCheckout, registerCloudAgentWorktree), so the residual branch-only admission arm is effectively unreachable for current data and is not counted as a finding. The unbounded-summary-payload finding is carried from the open human thread on line 381; no inline comment is re-posted for it.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 381 Carried, unchanged at head, open human design thread: jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a long-lived workspace is re-sent in full on each coalesced live event and each running poll. The author's reply retains this by design pending a contract change.
Files Reviewed (2 files this pass)
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - prior broad-admission and branch-only-match findings verified fixed; 1 carried finding re-verified at line 381
  • apps/web/src/routers/cli-sessions-v2-list-workspaces.test.ts - added fixtures cover the cross-repository and stale-branch exclusions; no issues

Fix these issues in Kilo Cloud

Previous review (commit 1a68ca4)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The attempted fix for null checkout URLs filters rows after admission rather than admitting fewer rows: because workspace_pr_base_refs is not stack-scoped, every repository-less workspace in the scope still enters the CTE and pays the per-row root-chat lateral, and the branch-only final match also accepts other repositories' workspaces.

Assumptions: [INFERENCE] Static review only: no PostgreSQL execution, EXPLAIN, or test run in this pass, so the scan cost and row counts below are reasoned from the SQL. The supplied incremental SHA da42cfe is not an ancestor of head 1a68ca4 (the branch content was squashed onto a newer main), so I compared the trees restricted to this PR's paths: the only PR file whose content changed since the previous review is workspace-read-model-queries.ts (24 lines), and the earlier adoption, migration-backfill and refresh-timeout findings are unchanged at head and already resolved. The unbounded-summary-payload finding is carried from the open human thread on line 368; no inline comment is re-posted for it.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 147 New in this head: OR (git_url IS NULL AND EXISTS (SELECT 1 FROM workspace_pr_base_refs)) gates admission on an uncorrelated EXISTS over every PR of the seed repositories, so it is true for any active repository and the CTE still returns every repository-less workspace in the user/organization scope. The outer WHERE drops those rows only after workspaceStackDirectoryQuery has run the visible root-chat lateral for each of them.
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 368 Carried, unchanged at head, open human design thread: jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a long-lived workspace is re-sent in full on each coalesced live event and each running poll. The author's reply retains this by design pending a contract change, so this pass adds no duplicate inline comment.

SUGGESTION

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 322 coalesce(w.git_branch, visible.git_branch) IN (SELECT branch FROM workspace_pr_base_refs) compares the branch without the repository, so a repository-less workspace from another repository whose branch equals a seed-repo base branch (typically main) is returned; it is dropped later by the component filter, so this is wasted work and a wider payload rather than a wrong summary. Compare (visible.git_url, branch) instead.
Files Reviewed (1 changed file this pass)
  • apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts - 2 new issues, 1 carried finding verified at line 368

The remaining 99 PR files are byte-identical to the previously reviewed head da42cfe in this repository's tree comparison, so they were not re-analyzed beyond the targeted check for the carried payload finding.

Fix these issues in Kilo Cloud

Previous review (commit da42cfe)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The highest-risk remaining issue is that every workspace summary still carries every root chat of that workspace with no bound, so the payload the sidebar re-fetches on each live event and 30s poll grows without limit for a long-lived workspace; the second is a residual scope-wide null-repository fallback in the stack CTE that expands a one-stack lookup to the user's whole scope.

Assumptions: [INFERENCE] Static review only: no test run, typecheck, or live PostgreSQL instance, so the payload sizes and query plans below are reasoned from the SQL and from the existing review thread rather than re-measured. The supplied incremental SHA 504e11a is not an ancestor of head da42cfe, so the fallback from the incremental instructions applied and I reviewed the full gh pr diff 11225 at da42cfe. The payload finding is already tracked in the open thread on the same line, so this pass posts no duplicate inline comment for it and treats the author's retained-design rationale as the open product decision. The earlier standalone-adoption, migration-backfill and refresh-timeout findings are fixed at head and are not repeated.

Overview

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

WARNING

File Line Issue
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 356 jsonb_agg in workspaceChatHydrationQuery returns every visible root chat per workspace with no LIMIT, and hydrateWorkspaces puts that array on every sidebar row, so a single long-lived workspace is re-sent in full on each coalesced live event, each running poll, and each tab mutation refresh. Carried from the open review thread; bounding history to the paged workspaceChats procedure needs the agreed contract change.
apps/web/src/lib/cloud-agent/workspace-read-model-queries.ts 144 OR git_url IS NULL in workspace_directory matches every repository-less workspace in the user/organization scope, not just the requested stack; requested rows are already covered by workspace_family and workspace_seeds, so the extra rows only add the pr lateral and visible-chat lateral before readWorkspaceSummaries discards them.
Files Reviewed (100 files)
  • Workspace read model: apps/web/src/lib/cloud-agent/workspace-read-model.ts, workspace-read-model-queries.ts, workspace-activity.ts, workspace-tab-state.ts, workspace-folders.ts, session-events.ts - 2 issues
  • Sidebar hooks: useSidebarLiveUpdates.ts, useWorkspaceSummaries.ts, useWorkspaceChats.ts, useWorkspaceFolders.ts, useStandaloneSessions.ts, useSidebarSessions.ts, useClosedWorktreeChatTabs.ts, useActiveSessions.ts, sidebar-queries.ts, sidebar-query-scope.ts, sidebar-session-model.ts, sidebar-workspace-model.ts, workspace-refresh.ts, workspace-refresh-membership.ts, workspace-session-cache.ts, useChatStackInfo.ts (+ tests) - no new issues
  • Sidebar components: ChatSidebar.tsx, CloudSidebarLayout.tsx, CloudAgentProvider.tsx, PrHoverCardContent.tsx, WorkspaceFolderSection.tsx, server/PrefetchedCloudSidebar.tsx, session-deletion.ts, sidebar-ordering.ts, worktree-chat-tabs.ts (+ tests) - no new issues
  • Routers: cli-sessions-v2-router.ts, cloud-agent-sidebar-scope.ts, workspace-folders-router.ts (+ tests) - no new issues
  • Database and SDK: packages/db/src/schema.ts, 0363_workspace_read_model.sql, migration metadata, packages/cloud-agent-sdk/src/schemas.ts (+ tests) - no new issues
  • Session Ingest: routes/api.ts, services/hosted-workspace-session.ts, services/workspace-activity.ts, services/worktree-deletion.ts, session-events.ts, session-ingest-rpc.ts, dos/UserConnectionDO.ts, dos/SessionIngestDO.ts, types/user-connection-protocol.ts (+ unit and postgres tests) - no new issues
  • Docs and MCP catalog: .specs/cloud-agent-session.md, docs/plans/cloud-agent-workspace-read-model.md, services/kilo-mcp/catalog.json - no new issues

Fix these issues in Kilo Cloud

Previous review (commit 504e11a)

Status: 4 Issues Found | Recommendation: Address before merge

Executive Summary

This incremental pass (11 files, +275/−32 since c301aea) fixes stack-layer pickup, legacy-activity ordering, tab-import gating, and review-decision polling; the four previously reported issues in the workspace read model, sidebar live updates, migration backfill, and refresh coordinator remain unresolved, and no new defect was found in the changed lines.

Assumptions: [INFERENCE] I reviewed statically without running tests, typecheck, or a live PostgreSQL instance. hydrateWorkspaces now calls after() from next/server, which is reachable from the Server Component prefetch in PrefetchedCloudSidebar; I could not confirm here that Next 16 accepts after() in a Server Component render, and its

[Snapshot truncated.]

Additional previous summary content was truncated to keep this comment within platform limits.


Reviewed by deepseek-flash-latest · Input: 34.3K · Output: 4.7K · Cached: 402.1K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bot: Automated full review with end-to-end evidence for this pull request, requested by @eshurakov.

This PR moves the Cloud Agent sidebar onto a PostgreSQL read model. It adds listWorkspaceSummaries/readWorkspaceSummaries/readWorkspaceChatPage (workspace-read-model.ts, workspace-read-model-queries.ts) with server-side activity aggregation, stack destinations and visibility limits; moves closed-tab and tab-order state onto cloud_agent_worktrees (closed_session_ids, tab_order, plus five new tRPC tab mutations in workspace-tab-state.ts); adds a workspace.updated event end to end (session-ingest protocol, DO broadcast, SDK schema, useSidebarLiveUpdates); and replaces sidebar-wide worktreeDetails reads with hydrated summaries. Migration 0361_workspace_read_model adds the columns, five indexes with the repository's retry-safe concurrent-index pattern, and a last_activity_at backfill.

What I verified on this VM, from the checkout, against a real local Postgres migrated by this PR and the real web app driven through Chromium:

  • Typecheck clean for the web app and the three touched packages; db jest 75, cloud-agent-next jest 2888, router/sidebar jest 537, workspace lib jest 34, session-ingest vitest 1781 (+85 postgres), SDK jest 2447 all passing.
  • Migration bootstrap on an empty database, and its SQL replayed twice without error.
  • Tab close, reopen, reorder and reload all persisted through the new mutations, and a second browser with cleared local storage showed the state that came from the server; foreign worktree and foreign chat ids returned 404.
  • Chat pagination read 123 chats across three cursor pages with no gaps or duplicates; workspace lastActivityAt used the newer of workspace and session activity; an idle sidebar made no worktreeDetails calls and no summary polling.

The thing to fix first is the shape of the summary payload: every visible workspace ships every root chat with no bound. One workspace with 2001 chats cost 522 KB, and the 50-workspace sidebar page cost 609 KB, on the request that live events and polling re-fetch. After that, the ungrouped cap of 50 silently hides workspaces because nextCursor is only produced for searches, so the new “Load more workspaces” button cannot appear for the default list and the removed “limited to…” note leaves the user with no signal. Smaller items: workspaceTabDeletionUpdate and the workspaceRowsTruncated prop are now dead, and the truncation it.each case tests a value the component ignores.

No blocker found: no data loss or authz hole observed, and every build, typecheck and suite I could run passed. iOS was not exercised (no simulator or signing identity on this VM); the change adds no iOS code.

E2E: run.

Ran the real Next.js app (next dev on the checkout) against a local PostgreSQL 18 migrated by this PR's own migrations, with a fake-login user, and drove it with Playwright Chromium. iOS is out of scope on this VM, and the change touches no iOS surface; Android and the CLI were not needed because the changed behavior is the web sidebar, the tRPC read model and the session-ingest worker.

Setup and checks that ran green:

  • packages/db migration bootstrap to an empty database: 0361_workspace_read_model applied, adding closed_session_ids, tab_order, last_activity_at and the four concurrent indexes; re-running its SQL a second time succeeded (drop-if-exists plus the DO guard), so it is retry-safe. Covered by the schema check npx jest in packages/db: 75 passed.
  • Web typecheck (tsgo --noEmit), plus tsgo for packages/db, packages/cloud-agent-sdk and services/session-ingest: clean.
  • apps/web jest: cloud-agent-next suite 2888 passed (164 suites), routers/cli-sessions-v2 + workspace-folders + server 537 passed, workspace-tab-state/session-events/workspace-activity 34 passed.
  • services/session-ingest vitest: 1781 passed, 3 skipped; postgres config: 85 passed. packages/cloud-agent-sdk jest: 2447 passed.

Happy path, observed in the running app (tab-sync-transcript.log, screenshots 01-06):

  • Sidebar rendered the seeded workspaces from cliSessionsV2.listWorkspaces (01-sidebar-workspaces.png).
  • Opening a worktree showed both root chats as tabs (A tabs open: ["Alpha root chat","Alpha chat two"], 02-browser-a-two-tabs.png).
  • Closing one tab removed it and persisted to the row (closed_session_ids = {ses_alpha_root_0002}, tab_order = {ses_alpha_root_0001}); after a reload the tab stayed closed (03-browser-a-after-close.png).
  • A second browser context with localStorage.clear() showed the same single open tab, so the state came from the server, not the browser (B tabs (empty localStorage): ["Alpha root chat"], 04-browser-b-server-state.png).
  • Opening the closed chat's address reopened its tab (B tabs after reopening: ["Alpha root chat","Alpha chat two"], 05-browser-b-reopened.png) and the first browser showed the same after reload (06-browser-a-sees-reopen.png).
  • Reorder through the real mutation moved tab_order to {ses_alpha_root_0002,ses_alpha_root_0001} and the tabs rendered in that order after reload (reorder.log).
  • Foreign input is refused: closing an unknown chat id and closing a chat under a workspace the user does not own both returned 404 Workspace chat not found (reorder.log).

Pagination, activity and cost measurements (pagination.log, list-payload.log, summary-payload.log, truncation.log, search-paging.log, requests-idle.log): 123 chats read across three pages (50/50/23) with keyset cursors, 123 unique, no gaps or duplicates; the workspace lastActivityAt equalled the greater of workspace and session activity; one workspace with 2001 chats produced a 522 KB summary and the 50-workspace sidebar page produced 609 KB; an idle sidebar issued no worktreeDetails calls and no workspace polling over 30 s.

The ungrouped cap was observed as a problem and is reported as a remark, not a blocker: with 63 ungrouped workspaces only 50 rendered and no cap or paging message appeared.

Every remark is attached to the changed line where GitHub accepts one.

This service never pushes, rebases, forces, closes, labels, or merges, and it posts nothing else on this pull request.

LEFT JOIN workspace_open_runs open_runs ON open_runs.worktree_id = w.worktree_id
LEFT JOIN LATERAL (${workspacePrQuery(sql`${workspacePrFields}, pr_observations`)}) pr ON true
INNER JOIN LATERAL (
SELECT jsonb_agg(${chatJson} ORDER BY s.created_at, s.session_id) AS chats

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every workspace summary carries every root chat of that workspace, with no LIMIT. hydrateWorkspaceChats aggregates all visible chats per worktree here, and hydrateWorkspaces puts that array on each row the sidebar renders.

Measured on the local stack against this checkout, with one workspace holding 2001 root chats:

  • cliSessionsV2.workspaceSummaries for that single workspace returned 522 KB (openChats: 2001), against 13 KB for one 50-chat page of cliSessionsV2.workspaceChats.
  • cliSessionsV2.listWorkspaces (limit 200, 50 visible workspaces) returned 609 KB with 2173 chats carried.

This is the payload that useSidebarLiveUpdates re-fetches through workspaceSummaries on each coalesced live event and each 30s running poll, and that useClosedWorktreeChatTabs.refresh re-fetches after every tab mutation. A long-lived worktree grows this without bound, so the request that the PR intended to make heavy lists cheap is the one that keeps every chat of every visible workspace in memory and on the wire. The sidebar itself only needs the ordered open tabs, the closed-tab ids and the representative session.

Smallest fix: bound the aggregate in this lateral join (for example recent chats plus the closed ids the row already names), and let the new paged workspaceChats procedure serve history. If a cap is chosen, make openChats/chatCount reflect it so the UI can show that history is truncated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The payload growth is real. The current design explicitly retains every open and closed tab summary (docs/plans/cloud-agent-workspace-read-model.md, sections 2, 6, and 9). Chat membership defines open tabs unless the user closes them. Capping openChats here would silently hide open tabs and change tab navigation, synchronization, and counts. I have not added that contract change during review preparation. Separating compact sidebar summaries from paginated selected-workspace tabs needs an agreed API/UI change and dedicated verification. This thread remains open for that decision; the current PR does not solve payload growth within one long-lived workspace.

@eshurakov

Copy link
Copy Markdown
Contributor Author

Review preparation verification

  • Fixed seven review concerns across bfd1cd9ae8 and da42cfe59f. The payload-scaling design thread remains open.
  • Confirmed merge conflicts required the first rewrite. Created a local backup, regenerated migration 0363, and pushed with the inspected-head lease. Published later feedback fixes with a normal push.
  • Local checks passed: 107 sidebar/layout/tab tests, eight production Worker deletion tests, 22 live-update/coordinator tests, 63 schema tests, web and Session Ingest typechecks, changed-file type-aware lint, and empty-database migration bootstrap. Earlier focused runs also passed 275 integration tests and 592 Session Ingest tests; two existing tests were skipped.
  • The stack-lookup and adoption regressions failed before their fixes. Timeout tests cover aborts and recovery after a later event.
  • The real local web app, PostgreSQL, and Session Ingest confirmed adoption removes the standalone row without a list refetch. Authenticated API checks confirmed connected-stack reads and null-activity fallback.
  • A 63-workspace local fixture rendered 50 rows and the correct truncation notice. Its regression failed before the fix.
  • Browser fixtures contain synthetic metadata. This pass does not verify agent execution or real-model behavior. Local services and the browser are stopped.

Evidence

The adopted chat no longer appears as a standalone sidebar row:

Synthetic sidebar after chat adoption

The ungrouped list reports its limit and total:

Synthetic sidebar with the 50-of-63 workspace notice

Use PostgreSQL workspace summaries, paginate chat history, and synchronize tab state across clients. Limit incomplete-checkout stack candidates without dropping explicit links or inferred ancestors.
Use PostgreSQL workspace summaries, paginate chat history, and synchronize tab state across clients. Limit incomplete-checkout stack candidates without dropping explicit links or inferred ancestors.

This branch has not been deployed

No deployments
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