Skip to content

Resolve the real site running state when resuming code sessions headlessly#4096

Open
shaunandrews wants to merge 1 commit into
trunkfrom
stu-2001-fix-agent-stopped-site-status
Open

Resolve the real site running state when resuming code sessions headlessly#4096
shaunandrews wants to merge 1 commit into
trunkfrom
stu-2001-fix-agent-stopped-site-status

Conversation

@shaunandrews

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Code investigated the root cause, wrote the fix and tests, and drafted this PR. I reviewed and directed the work.

Proposed Changes

In desktop Studio Code sessions, the agent's per-turn context banner always described the active local site as (stopped), no matter its actual state. The agent would then defensively call site_start before WP-CLI or other site operations — wasting a tool call every turn and confusing users whose site was clearly already running.

The cause: every desktop turn runs studio code sessions resume --json, which hydrates the active site from the session's event log. That log carries no running state, and the missing flag defaulted to "stopped". Now the headless resume path asks the daemon whether the site is actually up before dispatching the turn, so the agent sees the truth: no more redundant site_start calls, and the agent can correctly warn when the site really is stopped.

Sites missing from the CLI config are still treated as stopped, and remote (WordPress.com) sites skip the check since running state doesn't apply to them.

Testing Instructions

  1. Start a local site in Studio and open a Studio Code session on it.
  2. Ask the agent something that makes it run WP-CLI (e.g. "list my plugins with wp-cli").
  3. Before this fix, the agent's context showed (stopped) and it would often call site_start first; now the context shows (running) and it goes straight to the WP-CLI call.
  4. Stop the site and send another message — the context should now report (stopped).
  5. Unit tests: npm test -- apps/cli/commands/ai/sessions/tests/resume.test.ts

Pre-merge Checklist

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

🤖 Generated with Claude Code

…essly

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 9c203e1 vs trunk

app-size

Metric trunk 9c203e1 Diff Change
App Size (Mac) 1411.75 MB 1411.75 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 9c203e1 Diff Change
load 1076 ms 773 ms 303 ms 🟢 -28.2%

site-startup

Metric trunk 9c203e1 Diff Change
siteCreation 6521 ms 6534 ms +13 ms ⚪ 0.0%
siteStartup 2397 ms 2384 ms 13 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

@shaunandrews shaunandrews requested a review from bcotrim July 6, 2026 23:18
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