Reconcile proven completed inputs without replay and hide internal fact notices

This commit is contained in:
aiagent
2026-10-20 00:52:29 -07:00
parent 885d6a842e
commit 43c99e78e2
12 changed files with 173 additions and 34 deletions
+4 -24
View File
@@ -10,7 +10,7 @@ import subprocess
import sys
import time
from control import Client
from worker import atomic_json,session_lock
from worker import atomic_json,session_lock,reconcile_completed
def busy(path):
@@ -19,28 +19,6 @@ def busy(path):
return bool(state.get('inflight') or state.get('pending_completion') or state.get('needs_reconciliation'))
def reconcile_completed(path,client,session_id,thread_id):
"""Clear only a proven terminal original execution, never submit another input."""
state=json.loads(path.read_text(encoding='utf-8'))
record=state.get('inflight') or {}
proof=record.get('submission') or {}
if not record.get('message_id') or not proof.get('input_sha256'):return False
from urllib.parse import quote
rows=client.call('/api/messages?session_id='+quote(session_id,safe=''))['messages']
original=next((m for m in rows if m['id']==record['message_id']),None)
if not original:return False
reply=next((m for m in rows if m['id']==original.get('response_id')),None)
remote=original.get('submission') or {}
if (not reply or original.get('status') not in ('completed','failed')
or remote.get('thread_id')!=thread_id
or remote.get('input_sha256')!=proof['input_sha256']
or (proof.get('turn_id') and remote.get('turn_id')!=proof['turn_id'])):return False
state.setdefault('delivery_receipts',{})[record['message_id']]=remote
for key in ('inflight','pending_completion','needs_reconciliation'):state.pop(key,None)
atomic_json(path,state)
return True
def child_config(base,binding,root):
did=binding['decision_id'];sid=binding['session_id'];thread=binding['thread_id']
if any(not isinstance(v,str) or not re.fullmatch(r'[A-Za-z0-9_.:-]{1,128}',v) for v in (did,sid)):
@@ -116,7 +94,9 @@ class Fleet:
worker_alive=worker is not None and worker.poll() is None
if local_busy and not worker_alive and demand is not None and not demand.get('uncertain',0) and not demand.get('inflight',0):
try:
if reconcile_completed(state_path,Client(self.cfg['control']),binding['session_id'],binding['thread_id']):local_busy=False
identity=json.dumps({'control':self.cfg['control'],'session_id':binding['session_id']},sort_keys=True)
with session_lock(identity):
if reconcile_completed(state_path,Client(self.cfg['control']),binding['session_id'],binding['thread_id']):local_busy=False
except Exception:pass
if demand is None:
problems.append('queue_summary_unavailable:'+did);demand={}