Repository navigation
feat(task): a run records its result on its task instance under versioned rules, and names the eval slot it fills - #954
Conversation
…oned rules, and names the eval slot it fills task/result.py decides a finished run's result once for every worker: RESULT_RULES maps a version to a function of the run's steps, context, error and cancellation, and version 0 is the bundle classifier as it stood (cancelled; ungraded, cause unclassified; graded; passed; below_threshold). record_run_result keeps it on the task instance as a top-level result list outside the context, a compact grade version per grading, fenced by attempt epoch. Task.run records it when a call ends the run, the bundle's outcome comes from the same decision, and a submitter's eval_slot metadata becomes the instance's eval_instance_id, slot and attempt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and a late cancel mark is fenced A cancel that lands while Task.run writes the run's result now waits for that write, records the run cancelled and is raised, so the result agrees with every caller, which takes a Task.run that raises CancelledError as cancelled. The bundle's and an episode's cancel marks after their loop pass the run's own attempt epoch, so a newer attempt's result stands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…can't separate it from the run's end LocalRunner cancels a run twice, and the second cancel could cut short the wait-then-record-cancelled step, leaving a passed result beside a CANCELED run. Task.run now records the result synchronously, as it registers the run, so no cancel lands between the run ending and its result; a cancel itself still records the run cancelled, both writes in one thread. record_run_result logs a result it couldn't record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed cancel hand-off Writing the result on the event loop held up every other run for as long as the store took. The write runs on a thread again (to_thread, so namespace routing carries over), and a cancel can't stop it: whichever of the thread and the cancelled run sees the other second records the run cancelled after the write, and the cancel is raised. A second cancel only cuts the wait short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shared, and the end writes share one retry record_run_end, the cancellation-safe result write, moves into task/result.py beside record_run_result, for a worker that runs steps itself to await, and record_cancelled_run is the one place a run is marked cancelled with its result (Task.run, a bundle's late mark and an episode's), each fenced by the run's attempt epoch. The synchronous end writes share one retry helper, registering validates the eval slot once, and a test holds the grade copy's fields to the named grade's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… write that would fail the same way With MongoDB paused, a cancel took 202 s: the cancel mark and then the result each spent three tries on a store that wasn't there. record_task_cancelled now says whether the store took the mark, and record_cancelled_run tries the result only when it did; record_run_end follows a run's result with the cancel only when that result landed. A result left missing is logged, never wrong. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… cancel follows a result whatever its answer Skipping the cancelled result when a write was answered as failed trusted an answer that can be wrong: a write may land with its reply lost. record_task_cancelled now sets the run's cancelled result in the same compare-and-swap as its status (the result fenced by attempt epoch alone, so a run cancelled as it ended is recorded cancelled), so the two never disagree and a store that is down costs one write's retries; record_run_end records the cancel after the run's result whatever that write was answered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review. Context from another open PR: #950 (
If both PRs merge as they stand, a reaped orphan ends up Generated by Claude Code |
…ne forced past them The latest job ran `uv pip install --upgrade openenv`, which upgraded past the project's mcp<2 and fastmcp<4 pins: OpenEnv 0.15 needs mcp 2, which agent-env can't import, so the job failed on every branch while an install of agent-env resolves 0.14. It now upgrades OpenEnv through the resolver (`uv lock --upgrade-package openenv`), so it tests what an install gets and moves on by itself once the pins allow a newer OpenEnv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
The eval engine's second piece: every run records its result on its task instance, decided in one place, and a run an eval submits names the slot it fills. No score moves: the rules are today's bundle classifier.
task/result.pydecides a run's result and records it.RESULT_RULESmaps a version to a function of the run's steps, context, error and whether it was cancelled. A run's own grading usesRESULT_RULES_VERSION, 0. A stored result keeps the version it was decided under, so a later version adds an entry here and changes nothing already stored.cancelled;ungraded, causeunclassified, when the run raised or a step failed that no retry recovered (run_outcome, unchanged);gradedwhen it recorded no score;passedwhen every score is at least 1;below_thresholdotherwise.grade_versionbuilds one entry:result_rules_version,result,cause, thescoresit was decided on, each named grade's score,min_passing_score,passed, status, verifier type, version and settings, andat. A grade's rows, output and judge calls stay where they are, in the context's grades.record_run_resultkeeps that entry on the instance asresult, a top-level list outside the context, so it never travels with the context between a worker's steps. It is fenced by attempt epoch: an attempt a later one replaced can't write it, and a run that ends again, as a resumed one does, replaces it. A store error is retried, then logged, like the other end writes, and a result it couldn't record is logged too.Task.runrecords the result when a call ends the run: its last step, a failure, or a cancel. A call thatend_stepstops short records nothing, and a re-register clears the result until the run ends again.Task.runthat raisesCancelledErroras cancelled (LocalRunner marks it CANCELED, a bundle prints it cancelled), so a cancel that lands during the write lets the write finish, then records the runcancelledand is raised. Whichever of the thread and the cancelled run sees the other second records it, under a lock, whatever the first write was answered (a write answered as failed may have landed), and a second cancel only cuts the wait short.record_task_cancelledsets thecancelledresult in the same compare-and-swap as the status, so the two never disagree and a store that is down costs one write's retries. The result is fenced by attempt epoch alone, so a run cancelled as it ended is recordedcancelledwhile its status stayscompleted.record_run_endwhen its run ends, the same cancellation-safe writeTask.runuses, and callsrecord_cancelled_runwhen it marks a run cancelled, so the run gets the same result. AgentEnvHub's worker has such a path (it callsstep.executeper step); wiring it is a change in the hub.passed,scored below 1,unscored,failed,cancelled) now comes from the same decision, soagent-env run's summary and the stored result can't disagree. A bundle or episode run marked cancelled after its loop closes is marked throughrecord_cancelled_runtoo, status and result fenced by the run's own attempt epoch, so a newer attempt's stand (the bundle's status mark wasn't fenced before).context.metadata["eval_slot"],{eval_instance_id, slot, attempt}, and registering the run keeps those as the instance's own fields. A malformed one is refused before anything is written. A re-register without one keeps the slot recorded, as a run continued outside its eval still fills it.recorded_scoresmoves totask/result.py, with its callers.RunRecord,run_outcome, andeval run's summary, which moves wheneval runmoves onto the engine.Choices made here
statuscan then still readcompleted, as it could before when a cancel landed after the last step; the result and the run record agree.Tests
tst/unit/task/result_test.py:Task.run,LocalRunner(aseval runandtask runuse it) and a worker that runs the steps itself and then callsrecord_run_resultrecord the same result for the same run.tst/integration/cli/run_bundle_test.py: the shipped hello recordspassedwith its score and compact grade, twice; a run stopped by SIGINT or SIGTERM recordscancelled.Tested on a Linux host
On fresh EC2 hosts at df50188, with the stores on SQLite, MongoDB 7 (a one-node replica set) and DynamoDB Local. No model spend beyond a few cents.
The kit:
agent-env runof a bundle of 12 tasks, two of each outcome: each run's stored result is the outcome it printed;bundle register, thentask runof each task andeval run --k 2, 18 runs per backend: every run of a task records the same result, equal to the bundle's;record_run_endrecords the same results again.ungraded), continued at its next step, ends with one result (below_threshold), and a write from the attempt it replaced is refused.passedwith both scores, each grade compact and equal to the context's, the judge's calls kept in the context only.Chaos aimed at the end of a run, where its result is written. After each round the stored result was checked against what the run reported; it was never wrong, and missing only where logged:
agent-env runat a random moment after the step before the last, 40 rounds: each stored result is the printed outcome (29passed, 11cancelled).cancelled.runningwith no result (56),completedandpassed(62), orcompletedwith no result where the kill fell between the last step's write and the result's (2); never anything else.cancelled; back after 240 s, the cancel took 111 s (one write's retries) and nothing was stored, logged. On an earlier head the second case took 202 s, which is why a cancelled run's status and result became one write.Not in this PR
record_run_resulton its own step loop.unclassified, and regrades.CI
The Harness contract's
capture (openenv latest)job forced OpenEnv past the project's own pins (uv pip install --upgrade openenv), and OpenEnv 0.15 needsmcp2, which agent-env can't import, so it failed on every branch touching training code. It now upgrades OpenEnv through the resolver (uv lock --upgrade-package openenv), testing the newest OpenEnv an install of agent-env gets (0.14.0 today,mcp1.28.1) and moving on by itself once the pins allow a newer one. Every check is green.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues remain.Summary
Runs now save versioned results on their task instances and keep the eval slot they fill.
All four earlier review concerns are addressed in the current code. No new actionable issues were found.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Run ends] --> B[Shared result rules] B --> C[Save result on a thread] C --> D{Attempt still owns instance?} D -->|Yes| E[Replace stored result] D -->|No| F[Leave newer attempt unchanged] C --> G{Cancelled during write?} G -->|Yes| H[Save cancelled result after first write] B --> I[Bundle outcome]Reviews (14) · Last reviewed commit: "ci(harness): test the latest OpenEnv thi..." · Reviewed by Greptile