File size: 3,360 Bytes
891c713
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Score-blind visibility: from which unit did the agent have submission n's result?

v2 (v49lib.deliver_index / echo_index) decides delivery partly by checking whether the text shows n's *true* score.
For a submission still pending at the cut, that true score is post-cut information, so a coincidental number in the
pre-cut text can flip it to "seen" and leak its score (found by v3/audit_counterfactual.py).

This rule uses only the text and the submission's id and submit time:
  - id_state:  a single-submission segment (v49 segmentation) with n's id and a terminal state (DONE regex) or a
               labelled score of any value ("score"/"raw_score": number; for Pumpkin, its result markers), and no
               running/queued state for n in that segment;
  - poll_reply: a tool result with no submission ids, answering a lone tool call that polled only n's id, carrying a
               terminal state or a labelled score of any value.
It never reads n's score, status, verifier summary or result time. Assistant echoes are not used.
"""
import re

import v49lib as L

ANY_SCORE = re.compile(r'\\?"?(raw_score|score)\\?"?\s*[:=]\s*-?\d+(?:\.\d+)?', re.I)


def _delivers(seg, fam):
    sc = L.SHELL_WRAP_DONE.sub('', seg)
    if L.RUNNING.search(sc) or L.PLAIN_RUN.search(sc):
        return False
    return bool(L.DONE.search(sc) or ANY_SCORE.search(sc) or (fam == 'C' and L.C_RESULT.search(sc)))


def deliver_index_blind(n, units, fam, pre, N):
    nid = n['id'].replace('job_', '') if fam == 'C' else n['id']
    segs_by_u, all_ids_by_u = pre['segs_by_u'], pre['all_ids_by_u']
    prev_asst_by_u, sib_groups = pre['prev_asst_by_u'], pre['sib_groups']
    for ui, u in enumerate(units):
        if u['kind'] in ('assistant', 'response') or u['t'] < n['t_submit']:
            continue
        tx = u['text']
        if L.is_sidecar(tx):
            continue
        my = [seg for i_s, seg in segs_by_u[ui] if i_s == nid]
        if my:
            if any(_delivers(seg, fam) for seg in my):
                return ui
            continue
        if nid in all_ids_by_u[ui]:
            continue
        if u['kind'] in ('tool', 'user') and not all_ids_by_u[ui] and ui in prev_asst_by_u \
                and not tx.startswith('The following is a <SYSTEM_MESSAGE>'):
            aui = prev_asst_by_u[ui]
            if len(sib_groups[aui]) != 1:
                continue
            atx = units[aui]['text']
            if '<tool_call' not in atx:
                continue
            if fam != 'C':
                polled = 'frontier-submit' in atx and set(L.VID_RX.findall(atx)) == {nid}
            else:
                jobs = set(re.findall(r'sandboxctl\s+status\s+(\d+)\b', atx))
                # synchronous `sandboxctl call train` returns the result of the latest train submission made by then
                sync = (not jobs and re.search(r'sandboxctl\s+call\s+train\b', atx)
                        and not any(m['mode'] == 'train' and n['t_submit'] < m['t_submit'] <= u['t'] for m in N))
                polled = jobs == {nid} or bool(sync)
            if polled and _delivers(tx, fam):
                return ui
    return None


def compute_vis_blind(fam, U, N):
    if not U:
        return {}
    pre = L.precompute_units(U, fam)
    return {n['idx']: deliver_index_blind(n, U, fam, pre, N) for n in N if n['mode'] == 'train'}