File size: 12,280 Bytes
7ec48b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
"""t18 rubric v0 — the tutorial's falling water drop, rebuilt in Friction.

Flow: /root/tutorial holds the captioned "Introduction to Friction" tutorial
(+ transcript, chapter frame sheets); no footage. In Friction: new scene
1920x1080 @ 30 fps, 60 frames → circle → Object to path → top node pulled up
→ flat blue fill, no stroke → Y-translation keyframes: fully above the canvas
at frame 0, fully below at frame 30 → graph editor ease-in (accelerating) →
save /root/edit/project.friction → render /root/Desktop/final.mp4.

Grading decisions (2026-09-03):
  * Everything is read from the RENDER, decoded once to 61 RGB thumbs
    (TW×TH). "Blue" pixels (b > BLUE_MIN, b - r > BLUE_R_GAP, b - g >
    BLUE_G_GAP) are the drop; everything else is background. Per frame:
    area fraction, centroid, bounding box, edge contact.
  * Motion is graded like the t04–t06 Natron animation tasks: centroid track
    across frames (monotonic descent), enter/exit timing (invisible at frame
    0, gone by frame 30+slack), and easing as a ratio of distance covered in
    the last vs first third of the visible fall (ease-in ⇒ > 1).
  * Shape is a loose proxy: a drop is taller than wide (bbox h/w ≥
    DROP_ASPECT) on frames where it is fully inside the frame; a circle
    (skipped the top-node pull) is ~1.0 and fails.
  * Friction's project format is binary and it has no headless renderer, so
    the .friction checkpoint is existence/size only, and the oracle cannot
    make one at all — see environment/reference/README.md.

RUBRIC CHANGE 2026-09-21 (rubric v1, deliberate, affects comparability):
"Friction project saved" is now REPORTED BUT UNSCORED (weight 0.00) and its
0.10 moved into the two motion checks — "falls straight down" 0.15 -> 0.20,
"eases in" 0.10 -> 0.15. Reason: it was the only checkpoint the oracle could
not earn, so the oracle capped at 0.90 and every run had to be read against a
0.90 ceiling rather than against 1.0. It was also the only *existence* check
in an otherwise fidelity-based rubric, and the 0.10 lands more usefully on
the two things the tutorial actually teaches (keyframing the fall, easing it
in the graph editor).

The cost, stated plainly: nothing in the reward now requires the agent to
have used Friction at all. A render produced by any other means scores the
same. The check is still run and still printed, so a reviewer sees whether a
project was saved, and `task.toml` artifacts still pull the .friction back
for human inspection — but it no longer moves the number. The real fix is
still environment/reference/oracle.friction (a GUI-saved reference project,
README pending item 2): with that in place the checkpoint can be scored again
AND the oracle reaches 1.0. Scores from before this date are on rubric v0 and
are not comparable check-for-check; v0 totals differ by at most 0.10.

Rubric shape (scored weights sum to 1.0):
  0.05  final.mp4 exists, readable, has a video stream
  0.05  final is 1920x1080
  0.10  final duration 2.0 s ± DUR_TOL
  0.05  solid background: after the drop has left, ≥ 98 % of pixels share one colour
  0.10  a blue blob is present mid-fall (AREA_MIN ≤ area ≤ AREA_MAX of the frame)
  0.10  the blob is blue (mean b - r ≥ 40, b - g ≥ 20 on visible frames)
  0.10  drop shape: bbox taller than wide on fully-visible frames
  0.20  falls straight down: centroid y non-decreasing across visible frames,
        x drifts < X_DRIFT of the width
  0.10  timing: invisible at frame 0, touches the top edge first, the bottom
        edge last, invisible again by frame EXIT_FRAME
  0.15  eases in: distance in the last third of the visible fall ≥ EASE_RATIO ×
        the first third
  0.00  Friction project saved (/root/edit/project.friction or any *.friction
        ≥ 1 KB) — reported for review, not scored

Do-nothing floor: 0.00. Static drop (no keyframes): 0.45 max, unchanged by
the reweight (it fails both checks that gained weight and never earned the
one that was removed). Linear fall (no graph-editor easing): 0.85 max, was
0.90 under v0.
"""
import glob
import json
import os
import subprocess

from _vedit_verifier import Rubric, duration, probe, video_size

# T18_* env overrides exist ONLY for local rubric calibration; in the
# container the defaults are the real paths.
HOME = os.environ.get("T18_HOME", "/root")
FINAL = os.environ.get("T18_FINAL", os.path.join(HOME, "Desktop/final.mp4"))
REWARD_PATH = os.environ.get("T18_REWARD", "/logs/verifier/reward.txt")
WORK = os.environ.get("T18_WORK", "/tmp/t18-grade")

# --- thresholds (rubric v0, calibrated on the ffmpeg oracle 2026-09-03) ------
WANT_SIZE = (1920, 1080)
FPS = 30
N_FRAMES = 60
DUR_TOL = 0.5              # 60 vs 61 frames, container rounding
TW, TH = 192, 108          # 10x downscale; a 5 %-wide drop is still ~10 px
BLUE_MIN, BLUE_R_GAP, BLUE_G_GAP = 90, 40, 20
AREA_MIN, AREA_MAX = 0.002, 0.15
BG_FRAC = 0.98             # solid-background purity
DROP_ASPECT = 1.05         # bbox h/w on fully-visible frames
X_DRIFT = 0.05             # of the width, across the whole fall
EXIT_FRAME = 36            # frame 30 + slack for a slightly long fall
EASE_RATIO = 1.3           # last-third / first-third distance (ease-in)
VISIBLE_MIN_PX = 12        # below this a frame counts as "no drop"


# ------------------------------------------------------------------ helpers

def decode_thumbs(path, w, h):
    """All frames as rgb24 thumbs (list of bytes), or []."""
    try:
        out = subprocess.run(
            ["ffmpeg", "-v", "error", "-i", path, "-vf", "scale=%d:%d" % (w, h),
             "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
            capture_output=True, check=True).stdout
    except Exception:
        return []
    n = w * h * 3
    return [out[i:i + n] for i in range(0, len(out) - n + 1, n)]


def analyse(frame, w, h):
    """Blue-pixel statistics of one thumb."""
    xs = ys = cnt = 0
    r_sum = g_sum = b_sum = 0
    minx, maxx, miny, maxy = w, -1, h, -1
    for i in range(0, len(frame), 3):
        r, g, b = frame[i], frame[i + 1], frame[i + 2]
        if b > BLUE_MIN and b - r > BLUE_R_GAP and b - g > BLUE_G_GAP:
            p = i // 3
            x, y = p % w, p // w
            cnt += 1
            xs += x
            ys += y
            r_sum += r
            g_sum += g
            b_sum += b
            minx, maxx = min(minx, x), max(maxx, x)
            miny, maxy = min(miny, y), max(maxy, y)
    if cnt < VISIBLE_MIN_PX:
        return {"visible": False, "count": cnt}
    return {"visible": True, "count": cnt, "area": cnt / (w * h),
            "cx": xs / cnt, "cy": ys / cnt,
            "bbox": (minx, miny, maxx, maxy),
            "mean": (r_sum / cnt, g_sum / cnt, b_sum / cnt),
            "touch_top": miny == 0, "touch_bottom": maxy == h - 1}


def background_purity(frame):
    """Fraction of pixels equal (±6 per channel) to the modal colour."""
    hist = {}
    px = [(frame[i] >> 3, frame[i + 1] >> 3, frame[i + 2] >> 3)
          for i in range(0, len(frame), 3)]
    for p in px:
        hist[p] = hist.get(p, 0) + 1
    mode = max(hist, key=hist.get)
    near = sum(v for k, v in hist.items()
               if all(abs(k[c] - mode[c]) <= 1 for c in range(3)))
    return near / len(px)


def find_projects(pattern):
    hits = glob.glob(os.path.join(HOME, "edit", pattern))
    hits += glob.glob(os.path.join(HOME, "**", pattern), recursive=True)
    return sorted(set(hits), key=lambda p: os.path.getmtime(p), reverse=True)


# ------------------------------------------------------------------- rubric

def test_rubric():
    os.makedirs(WORK, exist_ok=True)
    r = Rubric("t18-friction-tutorial", reward_path=REWARD_PATH)

    meta = probe(FINAL)
    dur = duration(meta) if meta else None
    size = video_size(meta) if meta else None
    want_dur = N_FRAMES / FPS

    r.check(0.05, "final.mp4 exists, readable, video stream (%s)" % (size,),
            bool(meta) and bool(dur) and bool(size) and all(size))
    r.check(0.05, "final is %dx%d" % WANT_SIZE, bool(size) and tuple(size) == WANT_SIZE)
    r.check(0.10, "final duration %.2fs within ±%.1fs of %.2fs" % (dur or -1, DUR_TOL, want_dur),
            bool(dur) and abs(dur - want_dur) <= DUR_TOL)

    # Weight 0.00: run and printed so a reviewer can see whether the agent
    # actually worked in Friction, but kept out of the reward -- see the
    # 2026-09-21 rubric change in the module docstring. Section.check adds the
    # weight to both numerator and denominator, so 0.00 is genuinely inert.
    frictions = [p for p in find_projects("*.friction") if os.path.getsize(p) >= 1024]
    r.check(0.00, "[unscored] Friction project saved (%s)" % (frictions[0] if frictions else "none"),
            bool(frictions))

    frames = decode_thumbs(FINAL, TW, TH) if meta else []
    stats = [analyse(f, TW, TH) for f in frames]
    vis = [i for i, s in enumerate(stats) if s["visible"]]
    n = len(frames)

    # background: the last frame (drop long gone) must be one flat colour
    purity = background_purity(frames[-1]) if frames else 0.0
    r.check(0.05, "solid background (%.1f%% of the last frame is one colour)" % (100 * purity),
            bool(frames) and purity >= BG_FRAC and not stats[-1]["visible"])

    mid = [stats[i] for i in vis if AREA_MIN <= stats[i]["area"] <= AREA_MAX]
    r.check(0.10, "blue blob present mid-fall (%d visible frames, %d within the area band)"
            % (len(vis), len(mid)), len(mid) >= 3)

    means = [stats[i]["mean"] for i in vis]
    blue = bool(means) and all(m[2] - m[0] >= 40 and m[2] - m[1] >= 20 for m in means)
    r.check(0.10, "blob is blue (mean rgb %s)" % ((tuple(round(v) for v in means[0]) if means else None),),
            blue)

    full = [stats[i] for i in vis if not stats[i]["touch_top"] and not stats[i]["touch_bottom"]]
    aspects = [(b[3] - b[1] + 1) / max(1, b[2] - b[0] + 1) for b in (s["bbox"] for s in full)]
    r.check(0.10, "drop shape: bbox taller than wide on %d fully-visible frames (h/w %s)"
            % (len(full), [round(a, 2) for a in aspects[:4]]),
            bool(aspects) and min(aspects) >= DROP_ASPECT)

    cys = [stats[i]["cy"] for i in vis]
    cxs = [stats[i]["cx"] for i in vis]
    descends = len(cys) >= 3 and all(b >= a - 0.5 for a, b in zip(cys, cys[1:])) and cys[-1] > cys[0] + TH * 0.3
    straight = bool(cxs) and (max(cxs) - min(cxs)) <= X_DRIFT * TW
    r.check(0.20, "falls straight down (centroid y %s..%s, x drift %.1f px)"
            % (round(cys[0]) if cys else None, round(cys[-1]) if cys else None,
               (max(cxs) - min(cxs)) if cxs else -1), descends and straight)

    first_touch = next((i for i in vis if stats[i]["touch_top"]), None)
    last_touch = next((i for i in reversed(vis) if stats[i]["touch_bottom"]), None)
    timing = (n > 0 and not stats[0]["visible"] and bool(vis)
              and first_touch is not None and first_touch == vis[0]
              and last_touch is not None and last_touch == vis[-1]
              and vis[-1] < EXIT_FRAME)
    r.check(0.10, "timing: invisible at frame 0, enters from the top (frame %s), leaves at the "
            "bottom (frame %s), gone before frame %d" % (vis[0] if vis else None,
                                                        vis[-1] if vis else None, EXIT_FRAME),
            timing)

    ease = None
    if len(cys) >= 6:
        k = len(cys) // 3
        first = cys[k - 1] - cys[0]
        last = cys[-1] - cys[-k]
        ease = last / first if first > 0 else float("inf")
    r.check(0.15, "eases in: last-third distance / first-third = %s (need ≥ %.1f)"
            % (round(ease, 2) if ease is not None else None, EASE_RATIO),
            ease is not None and ease >= EASE_RATIO)

    with open(os.path.join(WORK, "samples.json"), "w") as f:
        json.dump({"frames": n, "visible": vis, "purity": purity, "ease": ease,
                   "track": [{"frame": i, "cx": stats[i]["cx"], "cy": stats[i]["cy"],
                              "area": stats[i]["area"], "bbox": stats[i]["bbox"]} for i in vis]},
                  f, indent=1)

    score = r.report()
    assert score == 1.0, "scored %.4f -- see rubric above" % score


if __name__ == "__main__":
    try:
        test_rubric()
    except AssertionError as e:
        print(e)