fix(cloud-agent): hide no-op preparation rows so 'Environment prepared' shows only on cold starts#4631
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryRe-reviewed the shared Files Reviewed (8 files)
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 SummaryReviewed the shared Files Reviewed (8 files)
Reviewed by claude-sonnet-5 · Input: 30 · Output: 4.2K · Cached: 615.3K Review guidance: REVIEW.md from base branch |
…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>
ce75931 to
0adffc4
Compare
Problem
"Environment prepared" appeared beneath every message in both the web and mobile cloud-agent chat UIs, not just on cold starts.
Root cause
ensureWrapperruns on every message delivery and unconditionally emits the preparation progress markerssandbox_provision(cloudflare-agent-sandbox.ts:529) andsandbox_boot(:639), even when reusing a warm sandbox/wrapper. The firstonProgresscall creates anattempt_startedsnapshot (preparation-progress.ts:77), andexecuteDirectlyalways finalizes the recorder ascompletedon success (CloudAgentSession.ts:3229). So every message produced a completed attempt, which the UI rendered as "Environment prepared" (PreparationRow.tsx/PreparationDrawer.tsxon web;PreparationGroupon 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):
sandbox_provision,sandbox_boot) is treated as a warm-reuse no-op and hidden.cloning,workspace_setup,kilo_session,kilo_server, …), so it stays visible.Shared SDK
apps/web/src/lib/cloud-agent-sdk/preparation-attempts.ts— newisNoOpCompletedPreparationAttempt()+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.tsx—preparationByMessageIdskips no-op completed attempts, so neitherStaticMessagesnorDynamicMessagesrender the row.Mobile
apps/mobile/src/components/agents/session-transcript.ts—mergeSessionTranscriptfilters no-op completed attempts before grouping; this is the single chokepoint for both inline and orphaned attempts.apps/mobile/vitest.config.ts— added thecloud-agent-sdk/preparation-attemptsalias, matching the existingcontext-usage/cli-model/message-id/remote-model-orderpattern (vitest does not honor thecloud-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 (acloningstep so they remain visible); added a warm-reuse no-op test and a running-attempt-stays-visible test.Verification
pnpm test— 137 files / 927 tests pass.pnpm lintandpnpm typecheckclean for changed files (pre-existing unrelated errors elsewhere).pnpm run lintclean (0 errors). Web Jest (pnpm test) could not run in this environment — its global setup requires PostgreSQL.tsgo --noEmitexceeded 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 runpnpm test/pnpm typechecklocally to confirm.pnpm format:changedandgit diff --checkclean.Known limitation
A warm-reuse attempt briefly shows "Preparing environment" while
runningbefore it completes and gets hidden. If that flicker is noticeable, the durable fix is to gateonProgressto genuine cold work inensureWrapper(backend option).