Studio Code: Close daemon socket after per-turn site status check so headless runs can exit#4175
Merged
Merged
Conversation
…headless runs can exit Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
📊 Performance Test ResultsComparing 46a8dd0 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 … --jsonturn on a local site leaves the CLI process alive after it reportsturn.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 resumechild 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
npm run cli:buildnode apps/cli/dist/cli/main.mjs code --json --path ~/Studio/<site> "Reply with only the word OK."turn.completedevent (on trunk it hangs indefinitely and must be killed).npm test -- apps/cli/commands/ai/sessions/tests/resume.test.ts apps/cli/commands/ai/tests/index.test.tsPre-merge Checklist
🤖 Generated with Claude Code