Add event-driven reporting and durable failure recovery hooks

This commit is contained in:
aiagent
2026-10-19 03:13:33 -07:00
parent 579dece104
commit a4cf70d82b
18 changed files with 711 additions and 8 deletions
+2
View File
@@ -260,6 +260,7 @@ def work(cfg, once=False):
if state.get('inflight'):
raise RuntimeError('Previous execution was interrupted; inspect its thread and side effects before explicit retry')
response = client.call('/api/worker/claim', {'worker_id': worker_id, 'session_id': session_id, 'lease_seconds': 120})
atomic_json(state_path.parent/'worker-health.json',{'status':'ok','updated':time.time()})
if response.get('needs_reconciliation'):
raise RuntimeError('Server session requires reconciliation; no message will be executed')
message = response.get('message')
@@ -269,6 +270,7 @@ def work(cfg, once=False):
state['inflight'] = {**lease, 'started_at': datetime.now(timezone.utc).isoformat()}
atomic_json(state_path, state)
def renew():
atomic_json(state_path.parent/'worker-health.json',{'status':'ok','updated':time.time()})
try:
client.call('/api/worker/renew', {**lease, 'lease_seconds': 120})
except APIError as exc: