Skip to content

fix(cloud-agent): hide no-op preparation rows so 'Environment prepared' shows only on cold starts#4631

Merged
eshurakov merged 1 commit into
mainfrom
session/agent_06de1ad3-b1e8-459d-a68a-b420bae0f441
Jul 20, 2026
Merged

fix(cloud-agent): hide no-op preparation rows so 'Environment prepared' shows only on cold starts#4631
eshurakov merged 1 commit into
mainfrom
session/agent_06de1ad3-b1e8-459d-a68a-b420bae0f441

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Problem

"Environment prepared" appeared beneath every message in both the web and mobile cloud-agent chat UIs, not just on cold starts.

Root cause

ensureWrapper runs on every message delivery and unconditionally emits the preparation progress markers sandbox_provision (cloudflare-agent-sandbox.ts:529) and sandbox_boot (:639), even when reusing a warm sandbox/wrapper. The first onProgress call creates an attempt_started snapshot (preparation-progress.ts:77), and executeDirectly always finalizes the recorder as completed on success (CloudAgentSession.ts:3229). So every message produced a completed attempt, which the UI rendered as "Environment prepared" (PreparationRow.tsx / PreparationDrawer.tsx on web; PreparationGroup on mobile).

Fix

Surface the indicator only for genuine cold starts by hiding no-op completed attempts at the UI layer (the option chosen for this change):

  • A completed attempt whose steps are only the always-on synthetic markers (sandbox_provision, sandbox_boot) is treated as a warm-reuse no-op and hidden.
  • A real cold start always records at least one substantive step (cloning, workspace_setup, kilo_session, kilo_server, …), so it stays visible.
  • Running and failed attempts are never hidden, so live cold-start progress and failures remain visible.

Shared SDK

  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.ts — new isNoOpCompletedPreparationAttempt() + SYNTHETIC_PREPARATION_STEPS (single source of truth for both apps).
  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.test.ts — canonical tests.
  • apps/web/src/lib/cloud-agent-sdk/index.ts — exports the predicate.
  • apps/web/src/components/cloud-agent-next/preparation-summary.ts — replaced the local copy with a re-export so existing web import sites are unchanged.

Web

  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsxpreparationByMessageId skips no-op completed attempts, so neither StaticMessages nor DynamicMessages render the row.

Mobile

  • apps/mobile/src/components/agents/session-transcript.tsmergeSessionTranscript filters no-op completed attempts before grouping; this is the single chokepoint for both inline and orphaned attempts.
  • apps/mobile/vitest.config.ts — added the cloud-agent-sdk/preparation-attempts alias, matching the existing context-usage/cli-model/message-id/remote-model-order pattern (vitest does not honor the cloud-agent-sdk/* tsconfig path; Metro does, so runtime is unaffected).
  • apps/mobile/src/components/agents/session-transcript.test.ts — existing fixtures upgraded to realistic cold-start shapes (a cloning step so they remain visible); added a warm-reuse no-op test and a running-attempt-stays-visible test.

Verification

  • Mobile: pnpm test — 137 files / 927 tests pass. pnpm lint and pnpm typecheck clean for changed files (pre-existing unrelated errors elsewhere).
  • Web: pnpm run lint clean (0 errors). Web Jest (pnpm test) could not run in this environment — its global setup requires PostgreSQL. tsgo --noEmit exceeded the sandbox time budget (large app, no errors emitted before timeout). The web change is a behavior-preserving refactor (predicate moved to the SDK and re-exported), so please run pnpm test/pnpm typecheck locally to confirm.
  • pnpm format:changed and git diff --check clean.

Known limitation

A warm-reuse attempt briefly shows "Preparing environment" while running before it completes and gets hidden. If that flicker is noticeable, the durable fix is to gate onProgress to genuine cold work in ensureWrapper (backend option).

@kilo-code-bot

kilo-code-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Re-reviewed the shared isNoOpCompletedPreparationAttempt predicate and its wiring into the web and mobile chat UIs at the current HEAD (0adffc4); the logic remains correct, well-tested, and consistently applied across both platforms with no evidence of runtime errors, logic bugs, or breaking API changes.

Files Reviewed (8 files)
  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.ts
  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.test.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/components/cloud-agent-next/preparation-summary.ts
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/mobile/src/components/agents/session-transcript.ts
  • apps/mobile/src/components/agents/session-transcript.test.ts
  • apps/mobile/vitest.config.ts
Previous Review Summary (commit ce75931)

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

Previous review (commit ce75931)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the shared isNoOpCompletedPreparationAttempt predicate and its wiring into the web and mobile chat UIs; the logic is correct, well-tested, and consistently applied across both platforms with no evidence of runtime errors, logic bugs, or breaking API changes in the actual PR diff (verified against the true merge-base to exclude unrelated base-branch drift).

Files Reviewed (8 files)
  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.ts
  • apps/web/src/lib/cloud-agent-sdk/preparation-attempts.test.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/components/cloud-agent-next/preparation-summary.ts
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/mobile/src/components/agents/session-transcript.ts
  • apps/mobile/src/components/agents/session-transcript.test.ts
  • apps/mobile/vitest.config.ts

Reviewed by claude-sonnet-5 · Input: 30 · Output: 4.2K · Cached: 615.3K

Review guidance: REVIEW.md from base branch main

…d' shows only on cold starts

"Environment prepared" appeared beneath every message in both the web and
mobile cloud-agent chat UIs, not just on cold starts.

Root cause: `ensureWrapper` runs on every message delivery and unconditionally
emits the preparation markers `sandbox_provision` and `sandbox_boot`, even when
reusing a warm sandbox/wrapper. The first `onProgress` call creates an
`attempt_started` snapshot, and `executeDirectly` always finalizes the recorder
as `completed` on success. So every message produced a completed attempt, which
the UI rendered as "Environment prepared".

Fix: hide no-op completed attempts at the UI layer. A completed attempt whose
steps are only the always-on synthetic markers is treated as warm-reuse and
hidden. Real cold starts always record at least one substantive step, so they
stay visible. Running and failed attempts are never hidden.

- Add shared `isNoOpCompletedPreparationAttempt` to `cloud-agent-sdk`
- Web: skip no-op attempts in `preparationByMessageId`
- Mobile: filter no-op attempts in `mergeSessionTranscript`
- Add a `cloud-agent-sdk/preparation-attempts` vitest alias (mobile)

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@eshurakov
eshurakov force-pushed the session/agent_06de1ad3-b1e8-459d-a68a-b420bae0f441 branch from ce75931 to 0adffc4 Compare July 20, 2026 09:23
@eshurakov
eshurakov merged commit 678b0cc into main Jul 20, 2026
19 checks passed
@eshurakov
eshurakov deleted the session/agent_06de1ad3-b1e8-459d-a68a-b420bae0f441 branch July 20, 2026 13:50
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