Commit 61111cf
fix(criteria): fix declaration-order regression, judge-sandbox leak, and silent misuse scoring
Addresses the second review pass on PR #60 — three real scoring/correctness
blockers plus the contract/API-surface follow-ups:
- check_all_async now splits criteria into maximal CONTIGUOUS runs of the
same kind (sync vs native-async) and executes the runs strictly in
declaration order, instead of always running the whole sync batch before
any async criterion. The previous scheme inverted declaration order for
e.g. [llm_judge, run_command] — the judge, though declared first, always
ran after run_command, silently grading post-mutation sandbox state
instead of the pre-mutation state check_all's serial order would give it.
Adjacent judges in the same run still gather concurrently (the actual
GH #55 fix); results are built from a dict proven total over all runs,
replacing the previous assert-guarded cast with a real KeyError on any
future gap. Every captured sibling exception in a run is now logged (not
silently dropped) before the first is re-raised.
- SubAgentRunner.run_async no longer leaks a full sandbox copy when
cancelled mid-copytree: judge_dir is bound with a plain synchronous
tempfile.mkdtemp (one syscall, not cancellable, not worth to_thread's
cancellation-window cost), and the copytree/rmtree to_thread calls are
wrapped in asyncio.shield + tracked in a pending list that `finally` awaits
BEFORE its own rmtree — so an orphaned worker thread can no longer
recreate files after cleanup already ran. Applied the same
await-in-finally fix to simulation/user_simulator.py's scratch-dir
teardown (same class of leak, previously only fixed in sub_agent.py).
- BaseCriterion._check_impl's derived asyncio.run bridge now detects a
running event loop and raises a new CheckerMisuseError (which
handle_criterion_errors(_async) escalate, like JudgeInfrastructureError)
instead of letting asyncio.run's RuntimeError get silently swallowed into
a scored-0.0 CriterionResult — a library/embedder calling the public sync
check()/check_all() on an async-only checker from async host code now
gets a loud, named error instead of a wrong score.
- __init_subclass__ now enforces "exactly one", not just "at least one": a
checker overriding BOTH _check_impl and _check_impl_async is also
rejected (two live implementations that could drift into different scores
depending on which entry point ran). Added an `abstract=True` class-kwarg
escape hatch for intentional abstract intermediate bases, and a __new__
guard so BaseCriterion itself can't be instantiated directly (lost when
@AbstractMethod was dropped).
- Promoted the native-async capability check to a public, typed
BaseCriterion.is_native_async() classmethod; SuccessChecker._is_native_async
and test_registry.py now call it instead of comparing `_check_impl_async`
identity across package boundaries. Decorated check()/check_async() with
@typing.final so the "these are FINAL" docstring contract is
pyright-enforced. Extracted the duplicated 18-line error-capture tail out
of handle_criterion_errors/_async into one shared _failed_result() helper.
- Tests: reversed-declaration-order regression test (real llm_judge +
run_command checkers) proving the contiguous-run fix; a cancel-during-copy
test on SubAgentRunner reproducing and closing the leak; a
loud-CheckerMisuseError-from-a-running-loop test; both-overridden /
abstract=True / direct-instantiation tests for the tightened
__init_subclass__ contract; a thread-affinity assertion (not just score)
for the derived async bridge; replaced two inert TestNativeAsyncDetection
tests (injected into _checker_instances, which classification never reads)
with registry-based ones that actually exercise the class-based dispatch
rule; a checker-__init__-failure test closing the last uncovered branch in
_check_single_async; one check_all_async happy-path test each for
llm_judge/agent_judge (production's actual entry point — every other test
in both files still drives the derived sync bridge).
- Fixed stale ``check_all`` (vs check_all_async) mentions in CLAUDE.md,
early_stop.py, reports.py, and orchestrator.py; documented the
must-not-block-the-loop obligation and the CheckerMisuseError caveat in
docs/EXTENDING.md.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent a3c46a1 commit 61111cf
15 files changed
Lines changed: 681 additions & 140 deletions
File tree
- docs
- src/coder_eval
- criteria
- errors
- evaluation
- orchestration
- simulation
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
190 | 204 | | |
191 | 205 | | |
192 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 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 | + | |
55 | 85 | | |
56 | 86 | | |
57 | 87 | | |
| |||
78 | 108 | | |
79 | 109 | | |
80 | 110 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
84 | 115 | | |
85 | 116 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 117 | + | |
103 | 118 | | |
104 | 119 | | |
105 | 120 | | |
| |||
123 | 138 | | |
124 | 139 | | |
125 | 140 | | |
126 | | - | |
| 141 | + | |
127 | 142 | | |
128 | 143 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 144 | + | |
146 | 145 | | |
147 | 146 | | |
148 | 147 | | |
| |||
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
172 | | - | |
| 171 | + | |
173 | 172 | | |
174 | 173 | | |
175 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
209 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
210 | 225 | | |
211 | 226 | | |
212 | 227 | | |
213 | 228 | | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
217 | 245 | | |
218 | 246 | | |
219 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
220 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
221 | 269 | | |
| 270 | + | |
222 | 271 | | |
223 | 272 | | |
224 | 273 | | |
| |||
283 | 332 | | |
284 | 333 | | |
285 | 334 | | |
286 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
287 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
288 | 352 | | |
289 | 353 | | |
290 | 354 | | |
| |||
295 | 359 | | |
296 | 360 | | |
297 | 361 | | |
| 362 | + | |
298 | 363 | | |
299 | 364 | | |
300 | 365 | | |
| |||
0 commit comments