Skip to content

fix(debate): make pump restart handoff deterministic - #13

Merged
RMANOV merged 1 commit into
mainfrom
hotfix/debate-pump-stop-start-race
Jul 22, 2026
Merged

fix(debate): make pump restart handoff deterministic#13
RMANOV merged 1 commit into
mainfrom
hotfix/debate-pump-stop-start-race

Conversation

@RMANOV

@RMANOV RMANOV commented Jul 22, 2026

Copy link
Copy Markdown
Owner

What changed

  • wait for the exact old pump PID/create-time identity to exit before a restart is reported safe
  • release the Windows singleton mutex before removing the heartbeat
  • require an observed running heartbeat before start returns success
  • avoid leaving a stop event signaled when the pump is already stopped

Root 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 start still reported success.

Impact

Central stop -> start is deterministic; agent sessions do not need restarting. Event-driven targeted wake remains primary and /loop remains backup-only.

Validation

  • python -m ruff check debate_ops_windows.py hooks/debate_pump.py tests/test_debate_windows_adapter.py
  • python -m pytest tests/test_debate_windows_adapter.py -q (25 passed)
  • python -m pytest -q -k debate (474 passed, 28 skipped)
  • live central pump handoff PID 37008 -> 32572, doctor ok=true
  • live addressed smoke: commit->wake 146ms; one EXECUTOR_1 binding, one claim, one spawn, exact reply_to

Copilot AI review requested due to automatic review settings July 22, 2026 12:20
@RMANOV
RMANOV merged commit 0bbed83 into main Jul 22, 2026
3 checks passed
@RMANOV
RMANOV deleted the hotfix/debate-pump-stop-start-race branch July 22, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 thread debate_ops_windows.py
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 thread debate_ops_windows.py
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(
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