fix(debate): make pump restart handoff deterministic - #13
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the Windows debate pump stop→start handoff deterministic by tightening lifecycle semantics around the heartbeat and singleton mutex, so start only reports success after observing a truly running pump and stop waits for the exact prior process identity to exit.
Changes:
- Release the Windows singleton mutex before removing the heartbeat on clean pump exit.
- Make
debate_ops_windows.cmd_start()require an observed running heartbeat before returning success. - Make
debate_ops_windows.cmd_stop()track and wait on the captured(pid, create_time)identity, and avoid signaling stop when already stopped.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_debate_windows_adapter.py | Adds regression tests covering deterministic stop/start handoff and singleton explicit release behavior. |
| hooks/debate_pump.py | Releases the pump singleton mutex prior to heartbeat removal on Windows clean exit to avoid restart races. |
| debate_ops_windows.py | Adds _wait_for_pump_running(), makes start wait for running heartbeat, and makes stop wait for captured process identity while avoiding stale stop signals. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+336
to
+338
| target_heartbeat = _read_heartbeat() | ||
| target_live = bool(target_heartbeat and _heartbeat_pid_live(target_heartbeat)) | ||
| if not target_live: |
Comment on lines
357
to
360
| while time.monotonic() < deadline: | ||
| state = pump_state() | ||
| if not state.get("pid_live"): | ||
| if not _heartbeat_pid_live(target_heartbeat): | ||
| state = pump_state() | ||
| print( |
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.
What changed
startreturns successRoot cause
The clean shutdown removed its heartbeat immediately before interpreter teardown released the named mutex. The lifecycle command treated the missing heartbeat as full process exit, so an immediate replacement could lose the singleton race and exit while
startstill reported success.Impact
Central
stop -> startis deterministic; agent sessions do not need restarting. Event-driven targeted wake remains primary and/loopremains backup-only.Validation
python -m ruff check debate_ops_windows.py hooks/debate_pump.py tests/test_debate_windows_adapter.pypython -m pytest tests/test_debate_windows_adapter.py -q(25 passed)python -m pytest -q -k debate(474 passed, 28 skipped)