File size: 6,812 Bytes
832f0f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""Aggregate reviewed predicates; B uses agent text, while actions need runtime evidence.

This is a contract/aggregation layer, NOT a trajectory, vision or semantic judge.
Evidence reviewers must supply predicate verdicts with traceable evidence IDs.
"""


CONTRACTS = {'A': {'name': 'Information acquisition',
       'predicates': {'successful_interaction': 'A real interaction succeeds under the '
                                                'interaction-range rules used by the recorded run. '
                                                'A final self-report cannot substitute for it.',
                      'correct_source': 'The actual responder is the required source. Room and '
                                        'appearance identify and locate the source; they do not '
                                        'earn separate visit credit.',
                      'complete_response_received': 'The complete required information or '
                                                    'materials are received from this source. '
                                                    'Repetition in the final answer is not '
                                                    'required.'}},
 'B': {'name': 'Independent object facts in the final report',
       'predicates': {'object_bound_record': 'Explicit facts about the object appear in the '
                                             'specified single final answer or NPC report. Do not '
                                             'use intermediate notes or combine separate reports.',
                      'required_facts_correct': "Assess semantic agreement between this object's "
                                                'facts and the reference. Errors about other '
                                                'objects do not invalidate this unit. Image '
                                                'comparison is not required.'}},
 'C': {'name': 'Spatial outcome',
       'predicates': {'actual_spatial_event': 'Recorded evidence of a visit, registration, door '
                                              'crossing, stop, or return satisfies the action '
                                              'specified by this spatial subgoal.',
                      'target_geometry_correct': 'Position, floor, door side, or direction '
                                                 'satisfies the supported spatial criteria. '
                                                 'Without a calibrated reference, mark it unknown '
                                                 'rather than guessing distances.',
                      'required_spatial_properties': 'Check only the explicitly required stopping, '
                                                     'surrounding views, route retracing, or '
                                                     'applicable instruction version. Do not add '
                                                     'unstated conditions.'}},
 'D': {'name': 'Independent decision',
       'predicates': {'explicit_decision': 'The required final decision is explicit and bound to '
                                           'the correct object or work order. An ambiguous list of '
                                           'candidates is insufficient.',
                      'decision_correct': 'This decision is correct independently of whether other '
                                          'units received credit.',
                      'required_local_reasoning': 'Explain the key reasons required for this '
                                                  'decision. Requirements shared across multiple '
                                                  'decisions are handled by the whole-task '
                                                  'evaluator.'}},
 'E': {'name': 'Complete delivery',
       'predicates': {'successful_delivery': 'A real delivery occurs. Delivery to an NPC requires '
                                             'a successful report_to_npc; delivery to the user '
                                             'requires a final answer.',
                      'correct_recipient_and_channel': 'The recipient, channel, and material '
                                                       'identity are correct. A final self-report '
                                                       'cannot replace the required NPC delivery.',
                      'one_complete_correct_message': 'A single delivery contains all required '
                                                      'content and reasoning. Do not combine '
                                                      'separate messages or infer success from a '
                                                      'fixed acknowledgement.'}}}


def reduce_predicates(contract_id, verdicts):
    """False requires counterevidence OR an explicitly complete negative search."""
    expected = set(CONTRACTS[contract_id]['predicates'])
    if set(verdicts) != expected:
        raise ValueError('Predicate set must exactly match the shared contract')
    states = []
    for item in verdicts.values():
        state = item['status']
        if state not in {'pass', 'fail', 'unknown'}:
            raise ValueError('Invalid predicate status')
        if state == 'pass' and not item.get('evidence_ids'):
            raise ValueError('A pass needs traceable evidence')
        if state == 'fail' and not (item.get('evidence_ids') or item.get('complete_negative_search')):
            raise ValueError('Missing evidence is not a failure')
        states.append(state)
    if 'fail' in states:
        return 'failed'
    if 'unknown' in states:
        return 'evidence_insufficient'
    return 'completed'


KNOWN = {'completed', 'failed'}


UNKNOWN = {'evidence_insufficient', 'definition_unresolved', 'not_recomputed'}


def summarize_task(definition, statuses):
    ids = {u['id'] for u in definition['milestones']}
    if len(ids) != len(definition['milestones']):
        raise ValueError('Duplicate unit ID')
    if set(statuses) != ids:
        raise ValueError('Do not omit units from the denominator')
    if not set(statuses.values()) <= KNOWN | UNKNOWN:
        raise ValueError('Invalid unit status')
    total = len(ids)
    if not total:
        raise ValueError('Empty task')
    done = sum(s == 'completed' for s in statuses.values())
    failed = sum(s == 'failed' for s in statuses.values())
    unknown = total - done - failed
    return {'task_id': definition['task_id'], 'units': total, 'completed': done,
            'failed': failed, 'unknown': unknown, 'coverage': (done + failed) / total,
            'progress': None if unknown else done / total,
            'lower_bound': done / total, 'upper_bound': (done + unknown) / total}