Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f052eba
fix(always_on): an infra-failed turn fails the step instead of scorin…
sarah-chitty-1 Nov 26, 2026
6edb198
fix(verifiers): an all-skipped verifier_ids aggregate is skipped; a f…
sarah-chitty-1 Dec 1, 2026
8992397
Merge branch 'main' into sarahchitty/always-on-infra-failures
sarah-chitty-1 Dec 1, 2026
6ea9f0f
feat(always_on): an always_on step with no retry_config is redone onc…
sarah-chitty-1 Dec 1, 2026
5656dd3
Merge remote-tracking branch 'origin/sarahchitty/always-on-infra-fail…
sarah-chitty-1 Dec 1, 2026
34e8b0b
test: import recorded_scores from task.result after main moved it
sarah-chitty-1 Dec 1, 2026
91a2a16
fix(always_on): keep the default retry in seeded runs; leave rubrics_…
sarah-chitty-1 Dec 1, 2026
85c5510
feat(always_on): a failed wake ends only that wake, and the whole run…
sarah-chitty-1 Dec 1, 2026
5c7cf96
feat(always_on): the next wake tells the agent its last turn ended wi…
sarah-chitty-1 Dec 1, 2026
bf8e40c
fix(always_on): imply the default retry only when its rollback redoes…
sarah-chitty-1 Dec 1, 2026
1334eac
fix(always_on): a judged run whose failed turns stored no trajectory …
sarah-chitty-1 Dec 1, 2026
fe36f38
fix(always_on): the default retry redoes only an infra-failed run
sarah-chitty-1 Dec 2, 2026
1f220a6
revert: the default retry redoes only an infra-failed run
sarah-chitty-1 Dec 2, 2026
b3e77d0
Merge #933's head (sarahchitty/always-on-infra-failures) into sarahch…
sarah-chitty-1 Dec 2, 2026
b833d41
fix(always_on): a verifier leaves an infra-failed always_on run ungra…
sarah-chitty-1 Dec 2, 2026
38c43db
fix(always_on): harness v14's turn cap is a cut-off at the tool-call …
sarah-chitty-1 Dec 2, 2026
2e09297
fix(always_on_agent_verifier): re-grading a run recorded before faile…
sarah-chitty-1 Dec 2, 2026
6c7cb2b
fix(aggregate_verifiers): an always_on run's aggregate of skipped jud…
sarah-chitty-1 Dec 2, 2026
e1747cd
fix(always_on): judge a run with no trajectories only when every turn…
sarah-chitty-1 Dec 2, 2026
91ae270
fix(always_on): episodes take no default retry; a task works out its …
sarah-chitty-1 Dec 2, 2026
8bb31d8
Merge #933's head (91ae270e) into sarahchitty/always-on-carry-on-afte…
sarah-chitty-1 Dec 2, 2026
7098a18
fix(always_on): each task keeps its own default retries and changes n…
sarah-chitty-1 Dec 2, 2026
0ce9ad8
Merge #933's head (7098a184) into sarahchitty/always-on-carry-on-afte…
sarah-chitty-1 Dec 2, 2026
26ae0f9
fix(always_on): a seeded run works its default retries out from its s…
sarah-chitty-1 Dec 2, 2026
c05e0fe
Merge #933's final head (26ae0f92) into sarahchitty/always-on-carry-o…
sarah-chitty-1 Dec 2, 2026
8f6cc28
Merge origin/main (dbbc03f1) into sarahchitty/always-on-carry-on-afte…
sarah-chitty-1 Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/agent_env/agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ terminal state, `completed`, `failed` or `canceled`. Your `run()` is one turn.
`requirements.txt` protocol floor at the first release that has them.
- **Errors:** `agent_error`, the default, means the agent tried and failed; `infra_error` means the run couldn't
happen, and agent-env may retry it. An exception that escapes `run()` becomes an opaque `infra_error`, its text
never sent. prompt_agent fails its step on either. always_on ends its run on either, but grades only an
`agent_error` turn (a rubrics judge's 0): an `infra_error` turn fails the step once the run is recorded
(`AgentTurnInfraError`), so no verifier grades it. always_on's default `retry_config`, which a task's own replaces,
redoes a failed run once from its env deploy, whatever failed it. So a failure that may be the
model's (a limit it ran into, a refusal, a malformed call) is an `agent_error`, not an `infra_error`.
never sent. prompt_agent fails its step on either. always_on goes on past an `agent_error` turn, which ends only
its wake (three in a row end the run), and judges the whole run, the failed turns counted against the agent: an
`infra_error` turn ends the run and fails the step once the run is recorded (`AgentTurnInfraError`), so no verifier
grades it. always_on's default `retry_config`, which a task's own replaces, redoes a failed step once from its env
deploy, whatever failed it. So a failure that may be the model's (a limit it ran into, a refusal, a malformed call)
is an `agent_error`, not an `infra_error`.
- **Context and sessions:** turns of one `context_id` run one at a time; different contexts run concurrently, and the
validator relies on it, so don't serialize them. Return your runtime's conversation id as `session_ref` and the next
turn in that context gets it back; bind it before the runtime starts, so a live trajectory read or a mid-turn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
the deploy record's ``tagged_lines``), the whole ask and raw answers in the object store at its ``object_url``. It never reaches the
agent, the graded conversation, or the verifications.

Not rated, recorded with ``skipped`` and why: a run that ended on an error (always_on's error end reasons; a
prompt_agent run whose agent turn or user sim failed; a run step that failed), and a run whose user sim agent is no
longer deployed. A rating that fails or runs past ``timeout_seconds`` (by default one always_on read's worst case) is
Not rated, recorded with ``skipped`` and why: a run that ended on an error (always_on's error end reasons but its
agent's own failures, a run its failed turns ended being rated as any run is; a prompt_agent run whose agent turn or
user sim failed; a run step that failed), and a run whose user sim agent is no longer deployed. A rating that fails or runs past ``timeout_seconds`` (by default one always_on read's worst case) is
recorded with its error; the step fails only when it can't find the run or its user, and by default
(``fail_task_on_error`` false) that doesn't fail the task.
"""
Expand Down Expand Up @@ -61,13 +61,13 @@
from agent_env.task_step.task_steps.agent.user_sim_common import SATISFACTION_KEY, iso, person_of, task_zone, utc
from agent_env.task_step.task_steps.sandbox_utils.sandbox_utils import ended_turn_error
from agent_env.task_step.task_steps.always_on import (
ALWAYS_ON_KEY,
ERROR_ENDS,
READ_ASKS,
TRAJECTORY_FETCH_SECONDS,
TURN_GRACE_SECONDS,
AlwaysOnTaskStep,
)
from agent_env.task_step.task_steps.always_on_ends import ALWAYS_ON_KEY, record_ended_on_agent_failure
from agent_env.task_step.task_steps.prompt_agent import PromptAgentTaskStep, fetch_native_trajectory, is_prompt_step
from agent_env.task_step.usage import StepUsage

Expand Down Expand Up @@ -349,7 +349,8 @@ def _always_on_session(record: dict) -> _Session:
sim = record.get("user_sim") or {}
session = _Session("always_on record", user_sim=sim.get("name"), context_id=sim.get("context_id"),
time_zone=record.get("time_zone"))
if record.get("end_reason") in ERROR_ENDS:
if record.get("end_reason") in ERROR_ENDS and not record_ended_on_agent_failure(record):
# A run its agent's own failure ended is rated as any run is: she rates the job it did.
session.skipped = f"the run ended on {record['end_reason']}"
return session
timeline = record.get("timeline_tail") or []
Expand Down
192 changes: 151 additions & 41 deletions src/agent_env/task_step/task_steps/always_on.py

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/agent_env/task_step/task_steps/always_on_ends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""What the steps that read an always_on run's record need of how it ended: the key the record is kept under, and the
ends that are the agent's own failure. A leaf that imports nothing of agent-env's, so the verifiers and the
satisfaction rating import it where always_on, which imports their peers, can't be."""

from __future__ import annotations

from typing import Any, Optional

ALWAYS_ON_KEY = "always_on" # each run's record: metadata[ALWAYS_ON_KEY][step_id]
# The error ends that are the agent's own doing: its turns failing always_on's FAILED_TURNS_IN_A_ROW_MAX times in a
# row, or a turn agent-env gave up waiting on. A run that ends on one is judged as a whole (ended_on_agent_failure).
AGENT_FAILURE_ENDS = ("agent_turn_failed", "agent_turn_timeout")


def record_ended_on_agent_failure(record: Any) -> bool:
"""Whether an always_on run's record says the run ended on its agent's own failure (``AGENT_FAILURE_ENDS``)."""
return isinstance(record, dict) and record.get("end_reason") in AGENT_FAILURE_ENDS


def ended_on_agent_failure(metadata: dict, step_id: Optional[str]) -> bool:
"""Whether ``step_id`` is an always_on step whose run ended on its agent's own failure (``AGENT_FAILURE_ENDS``),
its prompt response's ``error_type`` set: such a run is judged as a whole, wakes that ran and turns that failed
alike, each failure counted against the agent, never left unjudged for them. False for any other step's prompt and
any other end (an infrastructure failure, the user sim's, the step's own error)."""
return record_ended_on_agent_failure((metadata.get(ALWAYS_ON_KEY) or {}).get(step_id) if step_id else None)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from agent_env.task_step.context import StepContextError, TaskStepContext
from agent_env.task_step.task_step import TaskStepDependency
from agent_env.task_step.task_steps.always_on_ends import ended_on_agent_failure
from agent_env.task_step.task_steps.verifiers.scoring import ScoreAggregator
from agent_env.task_step.task_steps.verifiers.verifier import Verification, VerifierTaskStep

Expand Down Expand Up @@ -88,7 +89,14 @@ async def verify(self, context: TaskStepContext) -> Verification:
if prompt_response is None:
raise StepContextError(f"PromptResponse with prompt_id='{self.prompt_id}' not found in context")

if prompt_response.error_type:
if _ended_on_infra_failure(context, prompt_response.step_id):
reason = (f"the run's turn failed for an infrastructure reason (error_code={prompt_response.error_code}), "
"not the assistant's")
logger.warning(f"Not checking '{self.verifier_id}': {reason}")
return Verification(skipped=reason)
# An always_on run its agent's own failure ended has a response that stands, every message it sent the user,
# and is checked as any run's is; any other failed prompt scores 0 unchecked.
if prompt_response.error_type and not ended_on_agent_failure(context.metadata, prompt_response.step_id):
logger.warning(
f"Skipping verification '{self.verifier_id}': prompt had error_type={prompt_response.error_type}"
)
Expand Down Expand Up @@ -183,3 +191,11 @@ def _criterion_problems(criterion: Any) -> list[str]:
except re.error as e:
return [f"pattern {pattern!r} doesn't compile: {e}"]
return []


def _ended_on_infra_failure(context: TaskStepContext, step_id: Optional[str]) -> bool:
"""An always_on run that ended on an infrastructure failure is left unchecked, never scored against the agent
(``ended_on_infra_failure``); any other failed prompt scores 0 unchecked."""
from agent_env.task_step.task_steps.always_on import ended_on_infra_failure # here: always_on imports our peers

return ended_on_infra_failure(context.metadata, step_id)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

``verifier_ids``, the older form, names its sources by their ``verifier_id`` and pools the rows of their legacy
``verifications`` entries, as it always has: a source whose entry has no rows adds nothing. It takes none of the
newer fields.
newer fields. In a run of an always_on step, a skipped source is left out and named (``skipped_sources``), and every
source skipped skips it, as the newer form does: an always_on run that ended on an infrastructure failure is left
ungraded by its judges, and pooling no rows would score it 0 against the model. Any other run's aggregate pools as it
always has, a source skipped or not.
"""
from __future__ import annotations

Expand All @@ -20,6 +23,7 @@

from agent_env.task_step.context import TaskStepContext
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
from agent_env.task_step.task_steps.always_on_ends import ALWAYS_ON_KEY
from agent_env.task_step.task_steps.verifiers.rubrics_verifier import RubricsVerifierTaskStep, trajectory_mistakes_key
from agent_env.task_step.task_steps.verifiers.scoring import ScoreAggregator, aggregate_score
from agent_env.task_step.task_steps.verifiers.verifier import (
Expand Down Expand Up @@ -206,6 +210,16 @@ def _pooled_entries(self, context: TaskStepContext) -> Verification:
f"Available: {list(all_verifications.keys())}"
)

output: dict[str, Any] = {"source_verifier_ids": list(self.verifier_ids)}
skipped = {vid: all_verifications[vid]["skipped"] for vid in dict.fromkeys(self.verifier_ids)
if all_verifications[vid].get("skipped") is not None}
if skipped and _grades_always_on_run(context):
if len(skipped) == len(set(self.verifier_ids)):
reasons = "; ".join(f"{vid}: {reason}" for vid, reason in skipped.items())
logger.info(f"AggregateVerifiers '{self.verifier_id}': every source was skipped ({reasons})")
return Verification(skipped=f"every source it pools was skipped ({reasons})", output=output)
output["skipped_sources"] = list(skipped)

merged_results: list[dict] = []
for vid in self.verifier_ids:
merged_results.extend(all_verifications[vid].get("results", []))
Expand All @@ -216,7 +230,12 @@ def _pooled_entries(self, context: TaskStepContext) -> Verification:
f"AggregateVerifiers '{self.verifier_id}': merged {len(self.verifier_ids)} verifier(s), "
f"{len(non_skipped)}/{len(merged_results)} criteria evaluated, score={score}"
)
return Verification(score=score, output={"source_verifier_ids": list(self.verifier_ids)})
return Verification(score=score, output=output)


def _grades_always_on_run(context: TaskStepContext) -> bool:
"""Whether the run's steps include an always_on step, whose record its judges read (``ALWAYS_ON_KEY``)."""
return bool(context.metadata.get(ALWAYS_ON_KEY))


def legacy_entry_writers(steps: Sequence[TaskStep]) -> dict[str, str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
A run that kept no timeline has its turns staged the same way by position, one wake file a turn, so the judge never
reads a trajectory as stored.

A wake whose turn stored no trajectory (a turn agent-env gave up waiting on stores none, nor may a turn that failed) is
staged from the run's record with a line saying its trajectory is missing, which the judge's prompt names too. A run
whose every turn failed is judged so even when no turn stored one (``_judges_without_trajectory``); any other run that
stored none is refused, as rubrics_verifier refuses it.

With full_app_changes (opt-in, with use_trajectory), each staged app change also carries its changed fields in full, an
UPDATE's old and new values, an INSERT's or DELETE's whole row, from the run's ``metadata["env_changes"]`` (what a
snapshot_env step with include_env_changes records, which the task must run after the always_on step and before this
Expand Down Expand Up @@ -44,9 +49,15 @@
from typing import Any, ClassVar, Optional

from agent_env.providers.sandbox_providers.sandbox import into_container
from agent_env.task_step.context import PromptResponse, TaskStepContext
from agent_env.task_step.context import INFRA_ERROR, PromptResponse, TaskStepContext
from agent_env.task_step.task_step import TaskStep
from agent_env.task_step.task_steps.always_on import ALWAYS_ON_KEY, AlwaysOnTaskStep, render_for_judge, stored_timeline
from agent_env.task_step.task_steps.always_on import (
AlwaysOnTaskStep,
ended_on_infra_failure,
render_for_judge,
stored_timeline,
)
from agent_env.task_step.task_steps.always_on_ends import ALWAYS_ON_KEY, ended_on_agent_failure
from agent_env.task_step.task_steps.prompt_agent import PromptAgentTaskStep
from agent_env.task_step.task_steps.verifiers.always_on_staging import (
EVENTS_FILE,
Expand Down Expand Up @@ -338,6 +349,41 @@ async def _judged(self, context: TaskStepContext) -> RubricsVerdict:
output["assistant_harness"] = harness
return dataclasses.replace(verdict, output=output)

def _not_graded_reason(self, context: TaskStepContext, prompt_response: PromptResponse) -> Optional[str]:
"""A run that ended on an infrastructure failure (``ended_on_infra_failure``) is left ungraded, never scored
against the agent: its step failed so a retry could redo it, and this verifier reaches it only when the task goes
on past that failure."""
if not ended_on_infra_failure(context.metadata, prompt_response.step_id):
return None
return (f"the run's turn failed for an infrastructure reason (error_code={prompt_response.error_code}), not "
"the assistant's")

def _judges_failed_run(self, context: TaskStepContext, prompt_response: PromptResponse) -> bool:
"""A run that ended on its agent's own failure (its turns failing too many times in a row, or one agent-env gave
up waiting on) is judged as a whole, like any run: its wakes, failed turns among them, count against the agent.
One the user sim or the step itself broke is still scored 0 unjudged."""
return ended_on_agent_failure(context.metadata, prompt_response.step_id)
Comment thread
sarah-chitty-1 marked this conversation as resolved.
Resolved

def _judges_without_trajectory(self, context: TaskStepContext, prompt_response: PromptResponse) -> bool:
"""A run whose every turn, each wake's and each nudge's, failed as its agent's own failure is judged with
use_trajectory even when no turn stored a trajectory: a turn agent-env gave up waiting on stores none, nor may
a turn that failed, so a run that ended on its opening wake's, or ran failed turns alone, can have none. Each is
staged from the run's record with a line saying its trajectory is missing, as any missing one is, and the judge
is told. A run with any other turn is refused, as rubrics_verifier refuses it: a turn that ran stores its
trajectory, so one that has none lost it to something no failed turn explains (the agent's config, its
trajectory extension), and the run is redone rather than judged without its tool calls. A run recorded before
the record kept ``failed_turns`` that ended on its agent's own failure failed only the turn that ended it, so
it is judged so only when that was its one turn."""
record = self._record(context, prompt_response)
counts = record.get("counts") or {}
turns = (counts.get("wakes") or 0) + (counts.get("nudges") or 0)
if "failed_turns" in record:
failed = len({(f.get("wake"), f.get("turn")) for f in record["failed_turns"] or []
if f.get("error_type") != INFRA_ERROR})
else:
failed = 1 if ended_on_agent_failure(context.metadata, prompt_response.step_id) else 0
return 0 < turns <= failed

def _spec(self) -> JudgeOutputFormatSpec:
"""rubrics_verifier's format; for a run with agent labels or a compaction (``_CONTEXT_LOSS_RUN``), its rows also
take ``context_loss`` and ``context_loss_evidence``."""
Expand Down Expand Up @@ -600,10 +646,14 @@ def _files_note(path: str, staged: StagedRun, *, context_loss: bool = False) ->

def turns_by_position(prompt_response: PromptResponse) -> list[dict]:
"""A timeline for a run that kept none: one wake a turn, in the order the turns ran (a nudge's turn is one of its
own), with its trajectory and the text it was sent (the prompt response keeps each turn's, cut)."""
own), with its trajectory and the text it was sent (the prompt response keeps each turn's, cut). A turn sent that
has no entry among the trajectories (one agent-env gave up waiting on, which ended the run) is one whose
trajectory is missing, never left out."""
sent = prompt_response.source_agent_per_turn_prompt_parts or []
urls = prompt_response.target_agent_per_turn_trajectory_object_urls or []
timeline: list[dict] = []
for n, url in enumerate(prompt_response.target_agent_per_turn_trajectory_object_urls or [], 1):
for n in range(1, max(len(urls), len(sent)) + 1):
url = urls[n - 1] if n <= len(urls) else None
parts = (sent[n - 1] if n <= len(sent) else None) or []
text = "\n".join(p.get("text") or "" for p in parts if isinstance(p, dict) and p.get("kind") == "text")
timeline += [{"event": "wake", "n": n, "parts_text": text},
Expand Down
Loading
Loading