fix(issue-6): fail-closed registry timeout and TUI turn handshake

- Introduce finalize_unfinished in multi-agent-mux-delegate-job for fail-closed atomic transitions
- Enforce CAS dispatch_token and attempt_id pinning across engine, CLI, and lifecycle scripts
- Integrate Herdr wait_for_agent_idle turn handshake to prevent prompt loss and race conditions
- Resolve bash 3.2 set -u empty array expansion compatibility in lib.sh
- Preserve Issue #5 R2 contract in CAS transition engine (engine.py, publish_event.py, service.py)
- Add comprehensive regression suites (test_issue6_fail_closed.py, test_issue6_turn_handshake.py)
- Bump lockstep framework and skills to v4.4.1 across lib.sh, eager.py, VERSIONS.md, 8 SKILL.md
- Synchronize documentation (IMPROVEMENTS.md, MESSAGING.md, state-transitions.md, task.md, phase5-e2e.md)
- Unanimous PASS achieved across 4 reviewer team leaders (Claude, Codex, OpenCode, Grok)

Closes #6
This commit is contained in:
Godopu committed 2026-09-09 14:02:47 +09:00
1 parent 7b761be7b8
commit ec61511699
51 files changed
+3477 -293

No files matched your search

+39 -3
View File
@@ -46,18 +46,54 @@ class DelegationService(object):
registry_dir=self.registry_dir, **kw
)
def publish_event(self, job_id, event, detail="", data=None, attempts=3):
"""Publish one event. Returns the same exit status as the CLI (0 / 2)."""
def publish_event(self, job_id, event, detail="", data=None, attempts=3,
expect_dispatch_token=None, attempt_id=None):
"""Publish one event. Returns the same exit status as the CLI (0 / 2 / 4)."""
eff_dispatch_token = expect_dispatch_token
eff_attempt_id = attempt_id
if data and isinstance(data, dict):
if eff_dispatch_token is None:
eff_dispatch_token = data.get("dispatch_token")
if eff_attempt_id is None:
eff_attempt_id = data.get("attempt_id")
try:
rec = self.load_job(job_id)
actual_tok = rec.get("dispatch_token")
rec_attempt = rec.get("attempt_id", rec.get("iteration", 1))
except FileNotFoundError:
rec = None
actual_tok = None
rec_attempt = 1
if rec is not None and actual_tok is not None:
if eff_dispatch_token is None and eff_attempt_id is None:
if event in ("completed", "error", "cancelled") and rec_attempt > 1:
logger.error("dispatch token required: redispatched job %s carries a dispatch token "
"but none was provided", job_id)
return 4
elif eff_dispatch_token is not None and actual_tok != eff_dispatch_token:
return 4
elif eff_attempt_id is not None and rec_attempt != eff_attempt_id:
return 4
elif eff_dispatch_token is not None and actual_tok != eff_dispatch_token:
return 4
prepared = publish_event.prepare_event(
job_id=job_id, event=event, detail=detail,
data=data, registry_dir=self.registry_dir,
dispatch_token=eff_dispatch_token, attempt_id=eff_attempt_id,
)
publisher = self._publisher
if publisher is None:
from lib_py.delegation.publisher import OneShotPublisher
publisher = OneShotPublisher()
ok, error = publisher.publish_with_retry(prepared, attempts=attempts)
publish_event.record_outcome(prepared, self.registry_dir, ok, error)
publish_event.record_outcome(
prepared, self.registry_dir, ok, error,
expected_dispatch_token=eff_dispatch_token,
expected_attempt=eff_attempt_id,
)
return 0 if ok else 2
def ensure_subscriber_daemon(self, job_id, workdir=None):