feat(work): persist queued tasks before device acceptance

This commit is contained in:
ex_tianzy
2026-11-23 15:49:50 +08:00
parent 1e7307e45d
commit 93739a6089
10 changed files with 294 additions and 19 deletions
+5 -3
View File
@@ -48,7 +48,7 @@ class TaskDelivery:
remote_approvals=auth.s.work_remote_approvals_enabled)
broker.task_cards=self.cards
def current(self, body, *, read_receipt=False):
def current(self, body, *, read_receipt=False, read_queue=False):
self.auth.require_binding(body.host_id,body.binding_owner,body.binding_generation)
task=self.state.task(body.task_id)
if (not task or
@@ -65,6 +65,8 @@ class TaskDelivery:
and (known or (files and files.output_receipts(task)))):
return task
raise HTTPException(403,'task_not_recoverable')
if read_queue and task['status']=='queued':
return task
if not known and task['status'] not in {'inflight','unknown'}:
raise HTTPException(403,'task_not_recoverable')
return task
@@ -82,14 +84,14 @@ class TaskDelivery:
}
return {'task_id':task['turn_id'],'status':row['status'] if row else task['status'],
'progress_protocol':'work-progress-v1',
'execution_state':execution['execution_state'] if execution else 'unknown',
'execution_state':execution['execution_state'] if execution else 'queued' if task['status']=='queued' else 'unknown',
'status_sequence':execution['status_sequence'] if execution else 0,
'result_received':bool(row),'result_digest':row['digest'] if row else None,
'deadline':task['deadline'],'delivery':delivery}
async def status(self,body:TaskRequest,request:Request):
await self.auth.authenticate(body,request)
task=self.current(body)
task=self.current(body,read_queue=True)
pending=self.broker.pending.get(body.task_id)
if pending and pending.host==body.host_id:pending.progress.set()
return no_cache(JSONResponse(self.receipt(task)))