fix(issue-30): review - the stall watcher's lifetime is bounded on both sides and it re-checks its dispatch before acting
Round-1 review of PR #41 (claude N1, codex R1/R2). N1 - the wrapper stopped its stall watcher with `kill` followed by an unbounded `wait`. A TERM that lands in the watcher's fork-exec window is swallowed (bash defers terminating signals in the forked child until the exec), the watcher then installs its own handler and lives until the job closes, and the wrapper hung until someone killed the watcher by hand (reproduced twice in test_issue14's ack test; the wrapper trace stops at `kill` + `wait`). R1 - a wrapper that is itself terminated left the watcher orphaned. R2 - a `completed` or a re-dispatch that landed during a blocking herdr wait (up to 60 s) was still followed by the idle notice and the nudge. - multi-agent-mux-delegate-job: `stop_stall_watch` sends TERM, polls up to 5 s, then KILLs and reports "ignored TERM; killed"; `start_stall_watch` passes `--watch-pid $$`. - lib_py/stall_watch.py: `--watch-pid` (rc 0 once that pid is gone, checked between herdr calls); `_dispatch_open()` re-reads the record after every wait and right before the nudge - terminal status, another dispatch token or attempt, or a missing record ends the run without a notice; a refused `stalled:idle` publish withholds the nudge (`_notify` returns False). - delegate-job SKILL.md: the watcher's lifetime contract; exit-code rows 2 and 3 name the idle clock and the wall-clock label; "before v4.7.5" -> v4.8.0 (M5, NB2). - tests/test_issue30_stall_watch.py (M8): the module-wide Linux mark is narrowed to S6 (/proc); r4's stub stamps time.time() so its cross-process comparison holds on macOS too (47 passed, 1 skipped here). - tests/test_issue30_stall_watch_stop.py (new, macOS and Linux): the stop routine against a TERM-ignoring stand-in returns in 4-12 s; the wrapper returns (rc 3) with a TERM-ignoring watcher shim; `--watch-pid` ends the watcher; a TERM to the real wrapper leaves no watcher; a job completed or re-dispatched during the wait is not nudged; a refused notice withholds the nudge. Every one of them hangs or fails on the round-1 code. Not in this commit (follow-ups): M7 test hook in product code (no adapter is unreliable, a seam is needed), M9/B3 public-broker latency (on this host even `started` sometimes never reaches the subscriber), the leading-zero budget parse (NB1) and M1/M2/M4/M6 go on the #17 item 4 list. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VCgu9Fa9iT7TbJUSzdq4Ff
This commit is contained in:
1 parent
1673818bb5
commit
af0a2a2557
5 files changed
+406
-12
No files matched your search
@@ -36,7 +36,8 @@ from lib_py.agents.input_region import extract_input_region # noqa: E402
|
||||
from lib_py import stall_watch # noqa: E402
|
||||
from lib_py.loop import watcher # noqa: E402
|
||||
|
||||
pytestmark = pytest.mark.skipif(not sys.platform.startswith("linux"), reason="real process trees via /proc")
|
||||
# Only S6 needs Linux (/proc); the rest run on macOS too (PR #41 review M8).
|
||||
PROC = pytest.mark.skipif(not sys.platform.startswith("linux"), reason="real process trees via /proc")
|
||||
|
||||
UNREACHABLE = {"MQTT_BROKER": "127.0.0.1", "MQTT_PORT": "9", "MQTT_TLS": "0"}
|
||||
|
||||
@@ -327,6 +328,7 @@ def test_s5_the_adapters_resident_children_change_the_judgement(box, agent_name,
|
||||
# S6 - the heartbeat timer is never background work
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@PROC
|
||||
def test_s6_the_heartbeat_timer_is_not_a_background_child(box):
|
||||
_, state, reg, env = box
|
||||
jid = _job(env, reg)
|
||||
@@ -687,12 +689,14 @@ def test_r4_a_missed_transition_restarts_the_idle_window(mam_sandbox, mock_herdr
|
||||
#!/usr/bin/env python3
|
||||
import json, sys, time
|
||||
from pathlib import Path
|
||||
# time.time(), not monotonic: these stamps are compared across processes,
|
||||
# and macOS gives each process its own monotonic reference.
|
||||
f = Path(__file__).parent.parent / 'observed.json'
|
||||
state = json.loads(f.read_text())
|
||||
args = sys.argv[1:]
|
||||
if args[:2] == ['agent', 'wait']:
|
||||
if not state.get('started'):
|
||||
state['started'] = time.monotonic()
|
||||
state['started'] = time.time()
|
||||
f.write_text(json.dumps(state))
|
||||
print(json.dumps({'result': {'agent': {'agent_status': 'idle', 'state_change_seq': 0, 'pane_id': 'w1:p1'}}}))
|
||||
else:
|
||||
@@ -701,7 +705,7 @@ def test_r4_a_missed_transition_restarts_the_idle_window(mam_sandbox, mock_herdr
|
||||
sys.exit(1)
|
||||
elif args[:2] == ['agent', 'get']:
|
||||
if state['miss'] and not state.get('changed'):
|
||||
state['changed'] = time.monotonic()
|
||||
state['changed'] = time.time()
|
||||
state['seq'] = 2
|
||||
f.write_text(json.dumps(state))
|
||||
print(json.dumps({'result': {'agent': {'agent_status': 'idle', 'state_change_seq': state['seq'], 'pane_id': 'w1:p1'}}}))
|
||||
@@ -712,7 +716,7 @@ def test_r4_a_missed_transition_restarts_the_idle_window(mam_sandbox, mock_herdr
|
||||
elif args[:2] == ['agent', 'read']:
|
||||
print(state['pane'])
|
||||
elif args[:2] == ['agent', 'prompt']:
|
||||
state['prompted'] = time.monotonic()
|
||||
state['prompted'] = time.time()
|
||||
f.write_text(json.dumps(state))
|
||||
print('{}')
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user