Enforce zero reward for format violations across custom environments
Terminal model format violations should remain trainable samples with reward zero across all environments. Today that policy depends on each scoring and environment reward writer checking Trace.is_format_violation.
#3059 skips task scoring and rollout scoring callbacks, leaving rewards = {} so the ordinary reward sum is zero. Environment code can still attach rewards afterward, in run() or finalize(). #3070 adds local guards for best-of-n judging and the code-golf, proposer-solver, and Kuhn poker examples, but third-party environments can repeat the same mistake.
Concrete failures before those guards:
- Three tied format-invalid best-of-n attempts received 0.5 each.
- A format-invalid proposer could receive a 1.0 learnability reward in
finalize(). - Poker attached a nonzero payoff to a format-invalid player after the interaction closed.
Provide a framework-level way to enforce the policy across custom reward writers, without requiring every environment to reproduce the same check. Choose and document the enforcement boundary, including what happens when rewards are written before a trace becomes format-invalid and when an environment mutates the reward mapping directly. Preserve normal reward summation rather than hiding contradictory stored rewards behind a special accessor result.
Acceptance criteria:
- A format-invalid trace remains eligible as a training sample and has no effective task, judge, or environment reward, including rewards assigned after rollout scoring.
- The contract for stored reward entries is explicit and remains consistent through serialization and rescoring. The current implementation uses an empty rewards mapping for invalid traces.
- Valid traces retain their existing rewards, weights, and mixed-group behavior.
- Metrics, diagnostics, and artifacts can still be recorded for invalid traces.
- Provider failures, timeouts, and context overflow retain their distinct handling.
- Existing end-to-end coverage exercises task scoring, scoring callbacks, and custom
run()/finalize()reward assignment for valid, mixed, and all-invalid groups.
Once the shared guarantee is in place, remove redundant per-environment reward guards where safe. Environment-specific control flow may still need its own handling; for example, an invalid proposer should not be parsed into a solver task.
I have a branch ready for this: a write guard in Trace.record_reward, plus a seal that empties a format violation's rewards when each agent run concludes (before Env.finalize()) and again on every return path of Env.run_episode. It also removes the reward-only guards from #3070.
Before I open it: draft #3098 records a skipped/format_violation reward valued at the task range's low, which conflicts with the rewards = {} contract described here. Should the PR target {}, or keep only the skipped/* entry and wait for #3098 to land?
You're assigned here, so asking before I send anything. Would a PR along these lines help, or would you rather keep this one?
The check would live in Env.run_episode (verifiers/v1/env.py): a finally after run() and another after finalize() clear rewards on every trace where is_format_violation is true. The first pass means finalize() never sees an invalid trace's reward (best-of-n-judge computes best from trace.reward there). The second runs after all env code, so it also catches a reward written before the trace turned invalid and one set on the mapping directly. Stored rewards for an invalid trace are always {}, so serialization and Task.rescore agree, Trace.reward sums as before, and metrics and info stay. Other stop reasons are untouched.
Repro on d295ca8 with no model: an env that rewards in run() and finalize() without checking the flag, run through the real run_episode, ends with 7 format-invalid traces holding a nonzero reward across all-invalid, mixed and all-valid groups. With the change, 0. The openenv and textarena tasksets still record their reward in run() with no check (verifiers/v1/tasksets/openenv/taskset.py:134, verifiers/v1/tasksets/textarena/taskset.py:84), so they would be covered too.
It is 18 lines in env.py plus a unit test, and it still applies cleanly on today's main. Dropping the #3070 reward guards would be a separate commit; the control flow checks in code-golf and proposer-solver stay.
Thanks @zuraiz-anjum. I opened #3106 for this yesterday. It's a draft only because of the #3098 question above. The core is the same as what you describe: invalid traces leave run_episode with rewards == {}, metrics and info stay, and other stop reasons are untouched. It also adds a write guard in Trace.record_reward, seals each trace when its agent run concludes, and removes the reward-only #3070 guards (the control-flow checks in code-golf and proposer-solver stay).
Your point about clearing before finalize() caught a gap: a reward written straight into trace.rewards in run() after the agent run had ended stayed visible to finalize() until the exit seal. I've pushed that extra pass, with an integration assertion that finalize() sees zero reward on invalid traces. The openenv and textarena tasksets write through record_reward, so the write guard already covers them.
@hallerite, #3106 merges cleanly on today's main if you'd like to review it.