Skip to content

Studio Code: Close daemon socket after per-turn site status check so headless runs can exit - #4175

Merged
bcotrim merged 1 commit into
trunkfrom
fix-code-headless-daemon-socket-leak
Jul 11, 2026
Merged

Studio Code: Close daemon socket after per-turn site status check so headless runs can exit#4175
bcotrim merged 1 commit into
trunkfrom
fix-code-headless-daemon-socket-leak

Conversation

@shaunandrews

@shaunandrews shaunandrews commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Code applied the fix, verified it end-to-end in both directions (fixed build exits, unfixed build hangs), and drafted this PR. I reviewed and directed the work.

Proposed Changes

Since #4096, every headless studio code … --json turn on a local site leaves the CLI process alive after it reports turn.completed. The per-turn site running-state check opens a connection to the process-manager daemon and never closes it, and that open socket keeps the process from exiting.

The desktop app feels this the most: each turn forks a headless code sessions resume child and treats the child's exit as the end of the turn. Because the child never exits, the session appears stuck in the working state forever — the stop button and the sidebar agent-activity indicator never clear — and an orphaned node process piles up for every turn taken on a running-or-stopped local site.

The fix closes the daemon connection as soon as the running-state check completes, the same way every other daemon consumer in the CLI already does. The connection is a singleton, so anything later in the turn that needs the daemon (like the WP-CLI tool) reconnects transparently.

Testing Instructions

  1. npm run cli:build
  2. Run a headless turn against a local site: node apps/cli/dist/cli/main.mjs code --json --path ~/Studio/<site> "Reply with only the word OK."
  3. The process should exit on its own a moment after the turn.completed event (on trunk it hangs indefinitely and must be killed).
  4. In the desktop app, take a turn in a Studio Code session on a local site and confirm the working indicator clears when the turn finishes.
  5. Tests: npm test -- apps/cli/commands/ai/sessions/tests/resume.test.ts apps/cli/commands/ai/tests/index.test.ts

Pre-merge Checklist

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

🤖 Generated with Claude Code

…headless runs can exit

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shaunandrews
shaunandrews requested review from a team, bcotrim and sejas July 10, 2026 19:22
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 46a8dd0 vs trunk

app-size

Metric trunk 46a8dd0 Diff Change
App Size (Mac) 1419.35 MB 1419.35 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 46a8dd0 Diff Change
load 1067 ms 1032 ms 35 ms ⚪ 0.0%

site-startup

Metric trunk 46a8dd0 Diff Change
siteCreation 6961 ms 6973 ms +12 ms ⚪ 0.0%
siteStartup 2383 ms 2387 ms +4 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@bcotrim
bcotrim merged commit 1b622f9 into trunk Jul 11, 2026
13 checks passed
@bcotrim
bcotrim deleted the fix-code-headless-daemon-socket-leak branch July 11, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants