File size: 1,911 Bytes
5ca3c16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Fixed factual messages: no generated thinking or extra model request."""
CHECKPOINT_SECONDS = 100
MESSAGES = {
    'queued': '任务已排队,等待执行',
    'design': '正在整理技术方案',
    'code': '正在生成代码',
    'code_review': '正在审查代码',
    'build': '隔离编译与测试中',
    'test': '正在核验测试结果',
    'preview': '正在核验服务运行',
    'repair': '正在按诊断修复代码',
    'diagnosis': '正在定位失败原因',
    'evidence': '正在保存交付结果',
}


def short_message(stage):
    return MESSAGES.get(stage, '任务执行中,等待结果')


def audit(runtime, run, stage, elapsed):
    """A bounded factual observation; liveness is not proof of forward progress."""
    calls=runtime.store.calls(run['id'])
    pending=[c for c in calls if c['state']=='reserved']
    command=getattr(runtime.sandbox,'command',None)
    health=command.health() if callable(getattr(command,'health',None)) else {'observed':False}
    limits=[getattr(p,'timeout',0) for p in runtime.llm.providers if pending and p.name==pending[-1]['provider']]
    deadline=max(limits) if limits else getattr(runtime.sandbox,'command_timeout',0) if stage=='build' else 0
    return {'stage':stage,'elapsed_seconds':int(elapsed),'lease_valid':runtime.clock()<=run['lease_until'],
            'model_pending':len(pending),'model_unknown':sum(c['state']=='unknown' for c in calls),
            'settled_tokens':sum(c['charged'] or 0 for c in calls),
            'held_tokens':sum(c['reservation'] for c in calls if c['charged'] is None),
            'process':health,'deadline_seconds':deadline or None,
            'assessment':'deadline_exceeded' if deadline and elapsed>deadline else
                         'awaiting_model_receipt' if pending else
                         'sandbox_process_alive' if health.get('alive') else 'awaiting_stage_receipt'}