OpenEnv icon indicating copy to clipboard operation
OpenEnv copied to clipboard

qed_math_env sends the answer-mode reference to the agent; reasoning_gym_env and finqa_env keep scoring answers after done

Open jimmy-holdout opened this issue 1 month ago • 0 comments

Three environments can give reward 1.0 without the task being solved. In qed_math_env answer mode, the get_problem tool returns the grading reference to the agent. reasoning_gym_env and finqa_env reveal the correct answer when the episode ends, but they keep scoring further answers in the same episode. All three reproduce on main (9c63763) with the env's own server and client.

1. qed_math_env: answer mode sends the reference solution to the agent

The code comment gives parity with QED-Nano as the reason. The answer-mode case also came up in the review of #446, which #865 superseded. It was flagged there as possibly intentional for QED-Nano parity, with a request to document it. QED-Nano's rollout puts only problem["task"] in the actor prompt (rollouts.py#L92-L96) and passes problem["answer"] only to the verifier (#L186-L193). Grading here also reads the reference from the server-side problem (#L1286-L1302), so the agent's copy is not needed.

Repro: the shipped create_app call with dataset_path={"hub_id": "HuggingFaceH4/MATH-500", "split": "test"}, served with uvicorn and driven with QEDMathEnv. All 500 rows are routed to answer mode.

Agent action on problem_000202 Result
reset() / call_tool("get_problem") reference_solution = the full worked solution, ending in \boxed{66}
submit_proof(<that reference_solution>) reward 1.0, is_correct True
submit_proof("The answer is \boxed{-12345}.") reward 0.0

The same check over all 500 rows (an in-process loop: reset(problem_id=...), get_problem, then submit_proof with the reference_solution from the payload) gives reward 1.0 on 391 rows and 0.0 on 109.

Impact: a policy that calls get_problem and submits reference_solution verbatim gets full reward on 391 of the 500 MATH-500 rows, without solving anything. RL can learn to copy it, and eval scores measure copying.

Suggested fix: leave the reference out of the reset observation and the get_problem payload in both modes, as proof mode already does. Grading is unchanged.

2. reasoning_gym_env: a second answer in the same episode is scored again

step() scores the answer, returns done=True with correct_answer, and keeps _current_entry. It checks only whether _current_entry is None, so the next step() is scored against the same item (reasoning_gym_environment.py#L213-L252). The env's harness puts correct_answer in the tool result the agent sees (harness.py#L56-L63). StepEnvSessionAdapter.call_tool and SessionMCPBridge pass later calls through (rollout.py#L481-L492, #L546-L593), and _resolve_env_reward takes the last non-None reward in the trace (#L329-L360).

Repro: reasoning_gym_env.server.app under uvicorn, leg_counting, seed 1. The harness rows use ReasoningGymSessionFactory behind SessionMCPBridge, and the reward is resolved with _resolve_env_reward.

Calls in one episode Rewards Resolved reward
ReasoningGymEnv: step("x"), then step("292") (the revealed correct_answer) 0.0, then 1.0 -
harness: answer("x"), then answer("292") 0.0, then 1.0 1.0
harness: answer("292") (correct), then one extra answer("x") 1.0, then 0.0 0.0

Impact: under a loop that does not stop at done (for example a black-box runner behind SessionMCPBridge, a custom loop, or a raw WebSocket client), any wrong first answer followed by the revealed one scores 1.0. The last row is the reverse case: a correct answer followed by one extra call loses its reward. The white-box MCPHarnessAdapter stops at done (#L689-L691), so it is not affected.

Suggested fix: after the first scored answer, return that same final observation (same reward) for later steps until reset(), without scoring. Then the session's verify(), _resolve_env_reward and loops that read the last step all keep the scored answer's reward.

3. finqa_env: submit_answer is scored again after the episode ends, including after max_steps

In both step() and step_async(), the submit_answer branch scores the answer and returns done=True with ground_truth in the metadata. Nothing records that the episode ended, and the branch runs before the max_steps check (finqa_environment.py#L245-L294, #L296-L343). The README says submit_answer ends the episode (README.md#L114).

Repro: finqa_env.server.app under uvicorn with the snorkelai/finqa-data dataset and FINQA_MAX_STEPS=3, driven with FinQAEnv over the WebSocket session, reset(seed=1).

Calls in one episode Rewards
submit_answer("0"), then submit_answer("\boxed{0.783}") (the returned ground_truth) 0.0, then 1.0
3 × get_descriptions (the third returns done=True, "Max steps (3) reached"), then submit_answer("\boxed{0.783}") None, None, 0.0, then 1.0
control: submit_answer("0") only 0.0

The env's Docker image (built from envs/finqa_env/server/Dockerfile) gives the same rewards over /ws. That image installs openenv 0.3.1 from the env's uv.lock, and that version does not send observation metadata, so there ground_truth does not reach the client. The second submission is still scored.

Impact: the same as section 2 for loops that keep stepping after done. Even where ground_truth is not shown, a policy can keep resubmitting after a wrong answer. The step budget is also not enforced for submissions.

Suggested fix: keep the terminal observation when an answer is submitted or max_steps is reached, and return it for any later step until reset(), without running tools or scoring.

Showing the answer once the episode is over is fine (reasoning_gym_env documents correct_answer), as long as nothing is scored after it within that episode.

I have a PR with the three fixes and tests.

jimmy-holdout avatar Nov 03 '26 04:11 jimmy-holdout