AI Tools•SOTAAZ Lab••KR

Python-to-Rust Agent Verification: Unit Tests, Full Diffs, and Blind Fingerprints

When Qwen3.6-27B passed all 12 ported Rust unit tests, held-out parity averaged 41.7/80 (41, 41, 43). Full Python-vs-Rust diffs raised parity to 80/80 across all three seeds, blind fingerprints plus a local sandbox reached 53.0/80 (49, 52, 58), and Qwen3-Coder-30B-A3B failed to compile in 4 of 9 runs while its compiled diff-tool runs stayed at 40-44/80.

Python-to-Rust Agent Verification: Unit Tests, Full Diffs, and Blind Fingerprints

When local Qwen3.6-27B ported our 4-stage Python processor to Rust and passed all 12 starter unit tests across all three seeds, exact output parity on 80 held-out cases averaged 41.7/80 (41, 41, 43, or 52.1%).

Adding a differential oracle with full Python-vs-Rust diffs lifted Qwen3.6-27B to 80/80 across every seed (0.00 held-in minus held-out gap), while blind byte fingerprints on the hidden cases, paired with a sandbox that shows full Python and Rust outputs for agent-written inputs, reached 53.0/80 (49, 52, 58).

Under the same setup, Qwen3-Coder-30B-A3B failed to compile in 4 of 9 runs (E0596, E0716, E0428, E0599, E0308) and its four compiled runs with diff tools scored 40 to 44/80, close to the 40/80 it got with unit tests alone.

To isolate the verification loops described in our earlier analysis of Anthropic's Rust migration report, we held weights, decoding (temperature=0.2, top_p=0.95, max_tokens=8192), llama-server flags (-ngl 99 -fa on --parallel 1 -c 98304 --jinja), and the offline Rust toolchain (rustc 1.98.1, serde 1.0.229, serde_json 1.0.151) constant on a single A100 80GB GPU. All 18 runs (2 models x 3 arms x 3 seeds) ported reference/messages_api.py, a 331-line synthetic module we wrote in the shape of the Messages API (validate, build_prompt, parse_stream, and count_usage). Its cases were built to expose Python defaults (round-half-even, float formatting, ensure_ascii, splitlines), so parity measures how many of these traps an agent finds, not a typical porting error rate. Runs were scored against deterministic held_in (80 cases) and held_out (80 cases, SEED = 20261127), with no network tool and no direct reads of either split. These ratios describe two Q4_K_M local models on a 331-line single module rather than frontier cloud models or multi-crate repositories.

Experimental setup across three verification arms

Each run started in an offline Cargo workspace containing read-only reference/messages_api.py, reference/test_messages_api.py, and src/main.rs, plus an editable src/lib.rs holding 4 stubbed serde_json::Value functions plus the process_case wiring and all 12 starter tests (16 assertions) pre-ported into #[cfg(test)] mod tests. We pre-ported the tests so quote-escaping typos during porting could not break them, and disabled write_file so a whole-file overwrite could not delete them, restricting edits to edit_file inside src/lib.rs, and fixed 98,304 context tokens and 60 steps per run (in unlocked repositories, test weakening can compound these parity gaps):

  • Arm 1 (arm1_unit_tests): Verify builds and the 12 unit tests with run_cargo_test (cargo test --offline).
  • Arm 2 (arm2_diff_full): Compile offline and run run_diff_full against 80 held_in.jsonl cases, returning grouped mismatch counts with sample failing inputs and full Python vs. Rust strings.
  • Arm 3 (arm3_diff_blind): Compile and run the same 80 held_in.jsonl cases via run_diff_blind while stripping all text and returning only step, piece, first_diff_byte, py_bytes, rs_bytes, and structural feature_tags (has_cr_sse, has_cache_usage, has_temperature, has_emoji), paired with sandbox_check(case_json), which returns the full Python and Rust outputs for any input the agent writes. Only the held-in corpus stays hidden.

Completion calls (finish or plain-text stops) were rejected up to 3 times if cargo test failed (ending as gave_up(test_fail)) and nudged up to 2 times in Arms 2 and 3 when held_in stayed below 80/80.

Grouped bar and horizontal stage-parity chart comparing held-out accuracy out of 80 cases: Qwen3.6-27B averages 41.7 in Arm 1, 80.0 in Arm 2, and 53.0 in Arm 3 (stage means validate 76/80/76, build_prompt 61.7/80/69, parse_stream 74/80/78, count_usage 64/80/68), while Qwen3-Coder-30B-A3B scores 40.0, 42.0, and 40.5 on compiled seeds with 2/3, 1/3, and 1/3 compile errors

18-run results: full diffs hit 80/80; coder failed to compile 4 of 9

Compile failures (error(compile)) are tallied separately below rather than averaged as zero parity.

ModelArmCompiledStatusesheld_in (/80)held_out (/80)Stages (val/prm/sse/usg)Avg stepsAvg tokensTime (s)
Qwen3-Coder-30B-A3Barm11/31 ok, 2 gave_up39.0 [39]40.0 [40]75.0 / 60.0 / 74.0 / 64.038.0903,903127.0
Qwen3-Coder-30B-A3Barm22/32 ok, 1 gave_up41.0 [39-43]42.0 [40-44]75.5 / 60.5 / 73.5 / 65.041.71,233,632218.5
Qwen3-Coder-30B-A3Barm32/32 ok, 1 gave_up39.5 [39-40]40.5 [40-41]75.5 / 60.5 / 73.5 / 63.543.31,188,223262.1
Qwen3.6-27Barm13/33 ok40.7 [40-42]41.7 [41-43]76.0 / 61.7 / 74.0 / 64.026.7590,736207.1
Qwen3.6-27Barm23/33 ok80.0 [80-80]80.0 [80-80]80.0 / 80.0 / 80.0 / 80.044.01,284,661370.2
Qwen3.6-27Barm33/3max_steps 352.0 [48-57]53.0 [49-58]76.0 / 69.0 / 78.0 / 68.060.02,132,972657.0

Qwen3.6-27B finished every Arm 1 run cleanly in 23 to 34 steps (207.1 s mean) with 12/12 passing unit tests, while missing 37 to 39 of 80 held-out cases. Opening run_diff_full in Arm 2 raised mean cost to 44.0 steps (1,284,661 tokens, 370.2 s) and fixed every bug in four diff rounds per seed: 40 -> 57 -> 72 -> 80 (seed 42), 40 -> 46 -> 68 -> 80 (seed 43), and 40 -> 57 -> 72 -> 80 (seed 44), generalizing 80/80 to held_out (in Arms 1 and 3, held_in - held_out = -1.0 comes from split RNG differences putting one extra edge case inside held_in, showing no overfitting). Arm 3's 53.0/80 represents 60-step progress under the turn cap, with all three seeds hitting MAX_STEPS = 60 while making 14, 17, and 19 sandbox_check calls.

Qwen3-Coder-30B-A3B gained little from differential feedback. Four runs failed cargo test (E0596/E0716 borrows in arm1 s43 and s44, 29 errors including E0428/E0599 in arm2 s42, and E0308/E0428 plus 3 8,192-token truncations in arm3 s44). The four compiled runs that had diff tools scored 40 to 44/80 held-out; arm2 s43, for example, moved 40 -> 43 and then stayed at 43 for three more rounds.

Four silent parity traps behind passing unit tests

Test-fidelity audits found zero tampering: 17 of 18 runs left the 12 starter tests (16 assertions, 0 #[ignore]) byte-identical to scaffold/src/lib.rs, and Qwen3.6-27B arm2 s43 preserved all 12 while appending test_rounding_check (5 assertions on 12.5 -> 12, 13.5 -> 14, 11.5 -> 12). Across all 18 workspaces we found 0 external process calls and 0 hardcoded corpus sentinel strings, and the tool outputs of the 6 Arm 3 runs leaked 0 raw case text.

With unit tests green, Qwen3.6-27B Arm 1 (41/80, seed 42) diverged across all four checkpoints on ordinary Python-vs-Rust language defaults:

StageFailing casesPython vs. Rust gapDiff offset & sizesSample output diff (held_out)
validatevalidate_temp_ties (4)Python round(t, 2) rounds .5 to even (0.625 -> 0.62) vs. Rust .round() (0.63)byte=101-103, 139-141B equal (e.g., 139B == 139B)PY 0.62 vs. RS 0.63
build_prompt<meta> float + json.dumps (11)float(0) prints "0.0" ("1.0") vs. Rust "0" ("1"); json.dumps spacing (", ", ": ") vs. compactbyte=40/42, 45B/233B vs. 43B/221BPY temperature="0.0"/> vs. RS "0"/>
build_promptBMP (6), emoji surrogates (2)json.dumps ensure_ascii=True emits \uXXXX and \ud83c\udf89 vs. Rust raw UTF-8byte=62-125, 182B/131B vs. 168B/117BPY "\ud83c\udf89" vs. RS "🎉"
parse_streamsse_bare_cr_and_spaces (6)splitlines() splits bare \r and lstrip() trims multi-spaces; Rust .lines() missed framesbyte=20, 77B vs. 63BPY 'CR_10 MULTI_10' vs. RS ''
count_usageCache ties (10) + bare \r (6)round(cw * 1.25) rounds 12.5 -> 12 vs. Rust 13; shared SSE parser dropped 6 streamsbyte=25-26, 183-184B equal (e.g., 184B == 184B)PY billable_input_units: 132 vs. RS 133

Qwen3-Coder-30B-A3B (arm1 s42) also missed valid_thinking_disabled (140B vs. 59B, byte=2) by validating budget_tokens when thinking.enabled was false.

Bugs blind fingerprints fixed, and bugs they never found

Line chart of four differential rounds showing Arm 2 full diff (seed 42) climbing 40, 57, 72, 80/80 in 37 steps versus Arm 3 blind diff (seed 44, best of 3 seeds at held_out 49, 52, 58) reaching 40, 46, 48, 57/80 (held_out 58) at the 60-step cap, alongside summary cards listing blind fixes (bare CR SSE 74->80, meta float 47B vs 45B, JSON separators 232B vs 220B) vs stalled equal-length ties (count_usage 183-184B 10 cases, validate 139-141B 4 cases) and 8 escaping cases

Among length-changing bugs, Qwen3.6-27B Arm 3 fixed bare \r framing in 2 of 3 seeds and the JSON spacing and <meta> float display in 2 of 3 seeds without seeing raw text. The 8 non-ASCII escaping cases also change length, and no seed fixed them. Seed 44, the best of the three, shows the flow:

  1. Bare \r SSE framing (seed 44, steps 10-23): Round 1 (40/80) surfaced parse_stream fingerprint d8cef026 (count=6, first_diff_byte=20, py_bytes=75, rs_bytes=63, tags=["has_cr_sse", "has_multiline_sse", "has_stream"]). Inferring Python's bare-\r splitlines() behavior raised round 2 to 46/80 (parse_stream hit 80/80; shared SSE parsing raised count_usage 63 -> 69/80). Seed 42 also solved parse_stream 80/80 blind; seed 43 stayed at 74/80.
  2. JSON separators and "1.0" display (seed 44, steps 24-56): Synthetic sandbox_check inputs exposed 109B vs. 108B spacing (48/80), and a probe with "temperature": 1.0 at step 49 returned first_diff_byte=42, py_bytes=47, rs_bytes=45 on <meta model="claude-sonnet" temperature="1.0"/>, lifting round 4 run_diff_blind to 57/80 (58/80 held-out, build_prompt 61 -> 72).

Where byte lengths matched cleanly, blind fingerprints stalled. On count_usage (10 tie cases, 183-184B equal across Python and Rust at byte=25-26, with seed 42 repeatedly seeing four 183B == 183B and four 184B == 184B mismatches in its top held-in groups) and validate (4 tie cases, 139-141B equal at byte=101-103), seed 42 first suspected JSON key ordering, then switched to a value hypothesis and tried cw=100, 101, and 102 in sandbox_check. cw=102 gives 127.5, a tie that both languages happen to round to 128, so it got "match": true; the agent also wrongly believed Rust's round uses banker's rounding, and spent its 60 steps without finding the .5 tie behavior. All three Arm 3 seeds stalled at validate=76/80, missed all 8 ensure_ascii=True escaping cases, and took 1.8x the wall time (657.0 s vs. 370.2 s) and 1.7x the tokens (2.13M vs. 1.28M) of Arm 2.

Three verification rules for teams

  1. Treat green ported unit tests as wiring checks, not behavioral equivalence. Passing all 12 starter tests left held-out parity at 41.7/80, and unlocked repositories can also suffer from test weakening.
  2. Attach full Python-vs-Rust diffs first whenever fixtures are non-sensitive. Qwen3.6-27B reached 80/80 in 37-52 steps with lower wall time and token cost than blind probing. The diff loop's effect can be near zero for some models: Qwen3-Coder-30B-A3B stayed at 40-44/80 even on compiled runs.
  3. Pre-seed blind sandboxes with easy-to-miss boundary cases whenever raw text must stay hidden. One-digit .5 ties hide behind identical byte lengths and all three blind seeds missed the escaping cases, so explicit boundary seeds for .5 banker's-rounding ties, integer-valued floats (1.0/0.0), bare \r, and UTF-16 emoji pairs are a safer default.

Subscribe below for our next coding-agent verification benchmark.

Stay Updated

Follow us for the latest posts and tutorials

Subscribe to Newsletter