Skip to content

feat(task): a run records its result on its task instance under versioned rules, and names the eval slot it fills - #954

Merged
earakely-scale merged 9 commits into
mainfrom
edgararakelyan/task-instance-result
Nov 30, 2026
Merged

earakely-scale merged 9 commits into
mainfrom
edgararakelyan/task-instance-result

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

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.py decides a run's result and records it.
    • RESULT_RULES maps a version to a function of the run's steps, context, error and whether it was cancelled. A run's own grading uses RESULT_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.
    • Version 0 is the bundle classifier as it stood, under the eval design's names:
      • cancelled;
      • ungraded, cause unclassified, when the run raised or a step failed that no retry recovered (run_outcome, unchanged);
      • graded when it recorded no score;
      • passed when every score is at least 1;
      • below_threshold otherwise.
    • grade_version builds one entry: result_rules_version, result, cause, the scores it was decided on, each named grade's score, min_passing_score, passed, status, verifier type, version and settings, and at. A grade's rows, output and judge calls stay where they are, in the context's grades.
    • record_run_result keeps that entry on the instance as result, 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.run records the result when a call ends the run: its last step, a failure, or a cancel. A call that end_step stops short records nothing, and a re-register clears the result until the run ends again.
    • The write runs on a thread, so a slow store holds up no other run on the loop.
    • A cancel can't separate a run from its result. Every caller takes a Task.run that raises CancelledError as 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 run cancelled and 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.
    • A cancelled run's status and result are one write: record_task_cancelled sets the cancelled result 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 recorded cancelled while its status stays completed.
    • With the store reachable, the result agrees with how the caller takes the run. With it down throughout, the result may be missing, or the run's own if that write landed unanswered; both are logged.
  • A worker that runs the steps itself awaits record_run_end when its run ends, the same cancellation-safe write Task.run uses, and calls record_cancelled_run when it marks a run cancelled, so the run gets the same result. AgentEnvHub's worker has such a path (it calls step.execute per step); wiring it is a change in the hub.
  • The bundle's outcome (passed, scored below 1, unscored, failed, cancelled) now comes from the same decision, so agent-env run's summary and the stored result can't disagree. A bundle or episode run marked cancelled after its loop closes is marked through record_cancelled_run too, 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).
  • The eval slot: a submitter names it in 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_scores moves to task/result.py, with its callers.
  • The store's synchronous end writes (the cancel mark and the result) share one retry helper.
  • Unchanged: RunRecord, run_outcome, and eval run's summary, which moves when eval run moves onto the engine.

Choices made here

  • Each grade version keeps a compact copy of each grade. The instance already carries the full grades inside its context, and DynamoDB caps an item at 400 KB, so copying rows, outputs and judge calls again would roughly double what grades take for nothing a reader needs today. A regrade decides where its own rows go.
  • A run that ends again replaces its result rather than adding to it. The list holds one entry per grading; regrades will append.
  • The bundle's outcome comes from the same decision rather than a parallel copy, so there is one classifier from now on. A test holds it to the classifier as it stood.
  • The result is its own write after the run's end write, not part of it, so the same function serves every worker. A reader can see a finished run with no result for a moment; an absent result means none was recorded yet, never another result.
  • A run cancelled while its result is written is recorded cancelled, even when its last step had completed, because that is how every caller reports it. The instance's status can then still read completed, 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:
    • v0 gives every combination of cancelled, raised, failed steps (retried or not) and recorded scores (none, at 1, above, below, mixed, non-numeric, unmapped keys) the outcome the bundle gave it before, 160 cases;
    • a run records one grade version on its instance, with compact grades, and nothing in its context or the stored context;
    • a failed step makes the run ungraded, a tolerated one too, and a step a retry recovered doesn't;
    • a cancelled run is recorded cancelled, with the scores it had;
    • a cancel during the result write lets it land, then records the run cancelled; a cancel racing the write's end does too, either side seeing the other first (20 rounds); LocalRunner's cancel during the write ends CANCELED and recorded cancelled; and a result write that hangs holds up no other run;
    • a bundle's late cancel mark leaves a newer attempt's status and result;
    • each field a grade version copies is a field of a named grade;
    • only the call that ends the run records its result, and a resumed run replaces it;
    • an attempt a later one replaced can't record its result, and a re-register clears it;
    • a run an eval submitted names its slot and attempt, a re-register keeps them, and a malformed slot is refused before anything is written;
    • Task.run, LocalRunner (as eval run and task run use it) and a worker that runs the steps itself and then calls record_run_result record the same result for the same run.
  • tst/integration/cli/run_bundle_test.py: the shipped hello records passed with its score and compact grade, twice; a run stopped by SIGINT or SIGTERM records cancelled.
  • The task, bundle, runner and training unit tiers pass unchanged.

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:

  • Unit tests on Linux: the task, bundle and runner tiers, 2,014 passed; the touched integration tests 5 of 5.
  • Every way a run is launched agrees:
    • agent-env run of a bundle of 12 tasks, two of each outcome: each run's stored result is the outcome it printed;
    • bundle register, then task run of each task and eval run --k 2, 18 runs per backend: every run of a task records the same result, equal to the bundle's;
    • a worker that runs the steps itself and then awaits record_run_end records the same results again.
  • Resume through LocalRunner: a run that failed (ungraded), continued at its next step, ends with one result (below_threshold), and a write from the attempt it replaced is refused.
  • Eval slot: named on the instance; a malformed one writes nothing.
  • Attempt fence, 60 rounds per backend: a stale attempt's result writes racing a re-register and the newer attempt's write; the newer result always stands.
  • A real agent and judge: Claude Code on Haiku, graded by a string check and a rubric judge, twice: passed with both scores, each grade compact and equal to the context's, the judge's calls kept in the context only.
  • Network faults through toxiproxy, 180 s per backend of lost replies, resets and latency, all six outcome kinds run concurrently: 3,474 MongoDB runs and 1,079 DynamoDB Local runs recorded exactly as each run decided; on DynamoDB, 6 results whose write didn't land and 1 instance whose create landed answered as failed, all logged and holding no result.

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:

  • Signals: SIGINT or SIGTERM to agent-env run at a random moment after the step before the last, 40 rounds: each stored result is the printed outcome (29 passed, 11 cancelled).
  • LocalRunner cancels at random moments across the run, 300 rounds per backend: every run record agrees with its result; 80 runs were cancelled after their last step had completed, and each is recorded cancelled.
  • kill -9 at a random moment after the step before the last, 40 rounds per backend: running with no result (56), completed and passed (62), or completed with no result where the kill fell between the last step's write and the result's (2); never anything else.
  • Cancels under network faults, 200 rounds per backend, MongoDB's with cut streams too: each result as the run ended.
  • MongoDB paused as a run ends, then the run cancelled: back after 20 s, the cancel took 19 s and the run is stored 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.
  • MongoDB network faults with cut streams, 180 s: 3,544 runs recorded as decided, 2 not recorded (logged).

Not in this PR

  • AgentEnvHub's worker calling record_run_result on its own step loop.
  • Usage and cost in the result, causes beyond 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 needs mcp 2, 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, mcp 1.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.RetriggerView in GreptileConfidence 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.

  • Finished task runs keep a versioned result on their instance.
  • Eval submissions can keep a run’s slot on its task instance.
  • The harness job updates OpenEnv within the project’s allowed dependency pins.

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]
Loading

Reviews (14) · Last reviewed commit: "ci(harness): test the latest OpenEnv thi..." · Reviewed by Greptile

…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>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 29, 2026 18:04
Comment thread src/agent_env/task/task.py Resolved
Comment thread src/agent_env/bundle/run.py Resolved
earakely-scale and others added 3 commits November 29, 2026 10:13
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>
Comment thread src/agent_env/task/task.py Resolved
earakely-scale and others added 3 commits November 29, 2026 10:51
…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>
Comment thread src/agent_env/task/result.py Resolved
… 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>
@earakely-scale

Copy link
Copy Markdown
Collaborator Author

🤖 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 (fix(runner): reap orphaned episode runs and end an orphaned run's instance) adds a run-ending write that this PR's result contract doesn't cover yet. Each PR merges cleanly on its own, and neither one's tests would notice the gap.

If both PRs merge as they stand, a reaped orphan ends up status: failed with result: [], while the same failure going through Task.run records [{"result": "ungraded", "cause": "unclassified", ...}]. Whichever PR lands second could have the reaper pass an ungraded grade version via _end_write(..., also=...), the same way record_task_cancelled_sync does here. The other option is to document a reaped run as one that ends with no result.


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>
@earakely-scale
earakely-scale merged commit 964285d into main Nov 30, 2026
55 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/task-instance-result branch November 30, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant