Skip to content

Studio: Finish site creation when the CLI reports done, not when telemetry lets the process exit - #5522

Merged
chubes4 merged 2 commits into
trunkfrom
cli/report-command-done
Oct 28, 2026
Merged

chubes4 merged 2 commits into
trunkfrom
cli/report-command-done

Conversation

@chubes4

@chubes4 chubes4 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude (via the Pi coding agent in a Roadie session) traced where the app waits on the CLI, wrote the change and the tests, and measured the timings below. I reviewed the diff and the measurements.

Proposed Changes

The app treats a CLI command as finished when its process exits. After site create finishes, it sends a Tracks event, and Node keeps the process alive until that request completes. So the create flow waits on a telemetry request after the site is ready.

  • The CLI sends a done message once a command has finished successfully, from one place after the command handler returns (apps/cli/index.ts).
  • runCliCommand resolves on that message, and still on exit for anything that doesn't send it. Failures still wait for the exit and reject with the command's error.
  • Site start, stop and delete keep finishing on exit for now. Their tail is smaller and they need a separate look.
  • The process keeps running in the background until the request completes, so no events or stats are lost.
  • site create reports its result before an import finishes, so runCliCommand keeps resolving with that result but only once done arrives.
  • The preview manager ignores the new message instead of logging it as an invalid event.

Measured with a production CLI build forked over IPC like the app does, with telemetry on, time from done to the process exiting:

command runs time after done
site create 5 338–421 ms
site start / stop, telemetry opted out 3 each 7–9 ms

That is the time the app no longer waits. It depends on the user's latency to WordPress.com; these numbers are from a fast connection. CI's performance metrics won't show it, because Tracks requests are skipped in E2E runs.

Testing Instructions

  • npm test -- packages/common/lib/tests/cli-process.test.ts
  • The new test resolves a create from a command that reports done and never exits. It times out without this change.
  • Manually, in a packaged build with analytics on: create a site, and the app shows it as created as soon as the CLI reports it.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@wpmobilebot

wpmobilebot commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing e5466d2 vs trunk

app-size

Metric trunk e5466d2 Diff Change
App Size (Mac) 954.75 MB 954.53 MB 0.22 MB ⚪ 0.0%

site-editor

Metric trunk e5466d2 Diff Change
load 1210 ms 1227 ms +17 ms ⚪ 0.0%

site-startup

Metric trunk e5466d2 Diff Change
siteCreation 4980 ms 4482 ms 498 ms 🟢 -10.0%
siteStartup 1551 ms 1581 ms +30 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@chubes4 chubes4 changed the title Studio: Finish CLI commands when they report done, not when telemetry lets the process exit Studio: Finish site creation when the CLI reports done, not when telemetry lets the process exit Oct 28, 2026
@chubes4
chubes4 merged commit 4840fc6 into trunk Oct 28, 2026
13 checks passed
@chubes4
chubes4 deleted the cli/report-command-done branch October 28, 2026 15:33
chubes4 added a commit that referenced this pull request Oct 28, 2026
… its process to exit (#5524)

## Related issues

- Follows #5522.

## How AI was used in this PR

Claude (via the Pi coding agent in a Roadie session) traced the
start/stop timing, wrote the change and the test, and measured the CLI
message ordering below. I reviewed the diff and the measurements.

## Proposed Changes

Starting or stopping a site from the app resolves when the `site
start`/`site stop` process exits. After finishing, both commands send a
Tracks event, so the status button keeps its spinner while the request
completes.

Since #5522, the start/stop could resolve on the CLI's `done` message
instead, but that loses a race. The site stays "transitioning" until the
event releasing its start/stop operation arrives, and that event reaches
the app in the same millisecond as `done` (8 of 8 runs). When `done`
wins, the app sees the operation still held and refetches the whole site
list. In a CI run with only that change, `siteStartup` went from 1,594
to 1,868 ms (build 24349).

This PR removes the race instead of waiting it out:

- `site start` and `site stop` report the site after the operation is
released, with its running state.
- `startSite`/`stopSite` resolve with that site when the command reports
`done`, and the app writes it into the cached list the same way it
applies a site event.
- With nothing to show, such as a site serving its PHP error page or a
stop that failed, the app reads the list as before.
- This replaces the check for whether the list already showed the site,
so start/stop no longer depend on the order of events and command
results.

Measured with a production CLI build forked over IPC:

| | |
|---|---|
| reported site after start / already running | `running: true`, no
operation |
| reported site after stop / already stopped | `running: false`, no
operation |
| failed stop | no result, rejects as before |
| time from `done` to exit, telemetry on (from #5522) | start 161–174
ms, stop 165–326 ms |

That tail is the time the app no longer waits after a start or stop. It
depends on the user's connection. CI skips Tracks, so CI's performance
metrics should stay flat for `siteStartup`.

## Testing Instructions

- `npm test -- apps/ui/src/data/queries/use-sites.test.tsx`
- The updated test starts and stops a site whose release event hasn't
arrived yet. It shows the reported site without refetching the list, and
fails without this change.
- Manually, in a packaged build with analytics on: start and stop a
site, and the status button settles as soon as the site is running or
stopped.

## Pre-merge Checklist

- [x] Have you checked for TypeScript, React or other console errors?
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