fix: exit cluster run process after terminal state#28
Merged
Conversation
Both `zeroshot run` and `zeroshot run -d` kept their process alive indefinitely after CLUSTER_COMPLETE. Foreground hung at the shell prompt; daemon mode accumulated orphaned processes because there was no completion-wait path at all. - orchestrator: add `async shutdown()` that clears safety timeouts, stops snapshotters, and closes each cluster's messageBus/ledger. Legacy `close()` flag-only path kept for backwards-compat callers. - message-bus: `close()` now removes EventEmitter listeners before the ledger closes so lingering subscribers can't pin the instance. - cli/index.js: extract `waitForTerminalState` polling helper used by both modes. Add `waitForDaemonCompletion`; daemon path now waits, shuts down, and exits. Foreground path shuts down after stream ends. - tests: new integration/daemon-exit-on-complete.test.js covers terminal-state wait, shutdown releasing ledger, and idempotency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
zeroshot runandzeroshot run -dkept their process alive indefinitely afterCLUSTER_COMPLETE. Foreground hung at the shell; daemon mode accumulated 30+ orphans.Orchestrator.shutdown()that clears safety timeouts, stops snapshotters, and closes each cluster's messageBus/ledger. Legacy flag-onlyclose()retained.MessageBus.close()now drops EventEmitter listeners before ledger close so lingering subscribers can't pin the instance.waitForTerminalStatehelper used by both modes, addswaitForDaemonCompletion. Daemon path now waits → shuts down →process.exit(0). Foreground path shuts down after stream ends.Test plan
tests/integration/daemon-exit-on-complete.test.js— 3 cases: terminal-state wait, shutdown closes ledger, idempotency.zeroshot run --config code-review-bell "..." -d— cluster reachedstopped, daemon process exited,[DAEMON] Cluster ... reached terminal statein daemon log, no orphan inps.Cluster ... completed.without Ctrl+C.🤖 Generated with Claude Code