Skip to content

fix(finance): isolate python_exec, stage the EDGAR index, mask unresolved rubrics - #6671

Merged
ffrujeri merged 13 commits into
mainfrom
yifuw/finance-tempdir-edgar-stage-rubric-mask
Nov 30, 2026
Merged

ffrujeri merged 13 commits into
mainfrom
yifuw/finance-tempdir-edgar-stage-rubric-mask

Conversation

@yfw

@yfw yfw commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

This PR brings three finance server changes by Jiaqi Zeng. Each one is its own commit. The later commits make the third change work on main, update the docs, and apply review fixes.

  1. big_finance: python_exec runs the policy's code in a new temporary directory for each call, and removes the directory after the call (ScratchDirPythonExecTool). Before, the code ran in the server's working directory, which is the Gym checkout. Files that the policy's code wrote landed in the Gym tree. The interpreter, its flags, the timeout and the output do not change. A cancelled call now kills the child process, and a folder cleanup error no longer replaces the tool result.
  2. finance_agent_v2: a new setting, local_edgar_stage_dir, is off by default. When you set it, the server copies the local EDGAR index and its metadata sidecar into a node-local directory at startup, and reads the copy. A SQLite database then does not run on shared storage. Each source index gets its own subfolder, named by a hash of its absolute path, so two indexes with the same file name do not overwrite each other. Each version of the index and sidecar gets its own generation folder in that subfolder, named by a hash of their inode, size, modification time and change time. A generation folder never changes after it is staged, so a running server keeps reading its own version when a later server stages a new one. A lock on the subfolder and a copy into a .partial folder, then a rename, make sure that each version is copied once per node. An unchanged source reuses its copy. Each server holds a shared lock on its generation folder, and a later start removes only the generations that no server holds. If the source changes during the copy, the start fails instead of staging a mix of two versions. The stage folder must be on a node-local disk, because on NFS or Lustre file locks can cover only one node. A missing index or a missing configured sidecar fails at startup and names the source path. The WAL is not staged, because the reader opens the index with immutable=1 and never reads a WAL. Both server configurations pass local_edgar_stage_dir from env.yaml.
  3. finance_agent_v2: a row with a criterion that the judge did not resolve is masked, not scored. The next section gives the details.

Commit 4 adapts commit 3 to main. On the source branch, JudgeError takes a failure_kind and judge_failsafe takes a placeholder_reward. main has neither, so with commit 3 alone, 7 tests failed with TypeError. verify now raises a plain JudgeError, and judge_failsafe masks the row as judge_failed. The error message still names the first cause. Commits 5 and 6 update the benchmark README and a configuration comment, and document local_edgar_stage_dir in the server README. Commits 7 to 11 apply the review fixes that this description names. Commit 12 adds a README sentence: each python_exec call runs in a fresh temporary folder, so files do not carry over to the next call.

ScratchDirPythonExecTool.run is adapted from PythonExecTool.run in big_finance_harness/tools/python_exec.py of https://github.com/wowowoxuan1994/big-finance-benchmark at commit dffb39459dbfc96a7b38d179fec420900d616a69 (Apache-2.0). The header of resources_servers/big_finance/app.py records the same source. A test fails when the pinned PythonExecTool.run changes, so the copy does not drift without a signal.

Reward changes in finance_agent_v2

These rows were scored before. They are masked now.

Row Before Now
A criterion is still unresolved after judge_max_attempts. The judge call failed or timed out, the reply had no 0/1 score, or the reply stopped at the judge's max_output_tokens. Scored. The unresolved criterion counted as not passed, so an unresolved must_pass criterion set the reward to 0.0. judge_error was set. The row was trained. verify logs the failed judge replies and raises JudgeError. judge_failsafe returns reward 0.0 with mask_sample: true and failure_kind: judge_failed. The row goes to the failures sidecar. The cause is in failure_reason.
The row has no usable rubric criteria. Reward 0.0 with judge_error. Trained. Masked with failure_kind: verifier_error. judge_error stays.
The server has no judge_model_server. Reward 0.0 with judge_error. Trained. Masked with failure_kind: verifier_error. judge_error stays.

These rows do not change. A rollout without submit_final_result still scores 0 and is not masked, also when the agent stopped on a failed policy call or an aborted tool. A criterion that the judge resolved as not met still counts against the row. The FrontierFinance grader path (frontier_finance_grader) returns before this code, so it does not change.

The answer that goes to the judge is now capped at 50,000 characters, so an answer longer than the judge context does not mask its row. No example answer is longer than 8,224 characters.

The failure kind is judge_failed for every unresolved row. The source branch used judge_unparseable when every failed call got a reply. That needs JudgeError(failure_kind=...), which #6675 adds. After #6675 lands, a one-line follow-up can set that kind.

A follow-up can also mask the no-judge row as judge_skipped instead of verifier_error, so that gym eval recovery treats a dry run as complete. That change exports JUDGE_SKIPPED from nemo_gym.core, which moves a PR out of the server-only CI class, so it is not in this PR.

Benchmark effect

  • benchmarks/finance_agent_v2 (the 27 public questions, on resources_servers/finance_agent_v2/configs/finance_agent_v2.yaml): if the judge resolves every criterion, the numbers do not change. If the judge fails on a row, that row now leaves mean/reward, mean/rubric_partial_credit, mean/rubric_all_pass and mean/rubric_fraction, so these means use fewer rows. Before, the row stayed in the means and its unresolved criterion counted as a miss. The server's reverify mode is stateless, so gym eval recovery can judge the row again from its saved answer.
  • benchmarks/frontier_finance: no change. It uses the FrontierFinance grader.
  • benchmarks/big_finance: no reward change. python_exec returns the same output. A policy that writes a file in one python_exec call and reads it in the next call now gets a file-not-found error, as the tool description already says ("There is no persistent state between calls"). On main, it found the file in the Gym checkout.
  • Training: a masked row leaves the loss. Under NeMo RL's default grpo.masked_reward_policy: include, its placeholder reward 0.0 still counts in its group's baseline and standard deviation. exclude leaves it out. Before, these rows trained as low scores.

Compatibility

  • local_edgar_stage_dir is a new optional setting and is off by default. Existing configurations do not change. A start removes old versions of the same index path only. Copies for other index paths, and flat files that earlier versions of this code left in a stage folder, stay until you delete them.
  • big_finance: the policy's code no longer runs in the Gym checkout. Code that read a file from the checkout by a relative path no longer finds it.
  • finance_agent_v2: tools that removed judge_error rows by hand do not need to. Judge failures now come back as masked failure rows. get_key_metrics no longer promotes rubric/criteria_unresolved and rubric/rollouts_with_judge_error, because masked rows never reach them. Gym reports judge failures as masked failures. compute_metrics keeps both counters for rollouts collected before this PR.

Related PRs and issue

Validation

All runs were on CPU, on the tree of 7e777a4968, in the dev environment (uv sync --extra dev). The head, 88c189830b, adds only the README sentence, and pre-commit run --all-files passed on it.

pre-commit run --all-files                                                              # all hooks passed
gym env test +entrypoint=resources_servers/finance_agent_v2 +should_validate_data=true  # 308 passed, data validated
gym env test +entrypoint=resources_servers/big_finance +should_validate_data=true       # 117 passed, data validated
pytest tests/unit_tests/verification                                                    # 90 passed

With the three source commits only (before commit 4), the finance_agent_v2 run had 7 failed and 295 passed. All 7 failures were TypeError from the JudgeError and judge_failsafe calls.

What the new tests cover:

  • big_finance: two calls run in two different temporary directories. Both directories are removed, and no file lands in the working directory. The output, the empty-code error and the timeout match PythonExecTool. A cancelled call kills its child process. A hash of the pinned PythonExecTool.run source guards the copy.
  • finance_agent_v2 staging: TestLocalEdgarStaging (16 cases) builds a real SQLite index. It covers the staged read, the default and the configured sidecar, one copy for an unchanged source, a new generation for a changed source or sidecar while the old copy stays unchanged, a replacement with equal size and modification time, a running server that keeps its version after another server stages a new one, two sources with the same file name that stay apart, the removal of unused generations, a failed copy, a source that changes during the copy, and the errors for missing files.
  • finance_agent_v2 masking: call failures, timeouts, cut-off replies and replies without a score raise JudgeError, and the message names the cause. judge_failsafe(verify) returns a masked judge_failed row. A criterion that the judge resolved as not met is scored and not masked. Rows with no rubric or no judge are masked as verifier_error.

The CI classifier puts this PR in the server-only class. CI runs the core tests and the tests of big_finance and finance_agent_v2.

Rollout evidence

  • Smoke runs at this head with a hosted policy model and a hosted judge model, CPU only: 8 finance_agent_v2 rows on a 28 GB local EDGAR index (staged with local_edgar_stage_dir) and 6 big_finance rows.
  • Judge forced to fail (16 output tokens, 2 attempts): the 6 rollouts with a submission were masked as judge_failed and went to the failures sidecar ("6 failed (6 masked, not scored as zero)"). The 2 rollouts without a submission scored 0, unmasked. gym eval reverify --judge-failed-only --settle-into-source with the normal judge then scored all 6 (1.0, 1.0, 1.0, 0.958, 0.667, 0.0), with no unresolved criterion.
  • Same saved answers re-judged on main and on this branch with one pinned judge (temperature 0): every rollout that both runs fully resolved scored the same, except one that differed by one judge verdict (0.667 and 0.700). On main, one rollout with an unresolved must_pass criterion scored 0.0 and stayed in mean/reward. This branch masks such a rollout instead.
  • With the failing judge, main reported mean/reward 0.0 over 8 rollouts (6 of them judge outages). This branch reported it over the 2 scored rollouts and 6 masked failures.
  • big_finance: 10 python_exec calls in 6 rollouts created no file in the server folder and left no temporary folder. A file written in one call was not visible in the next call.
  • Staging: two server starts at the same time copied the index once (86 s) and read the same copy. After the source changed, a third start staged a new generation while the first two kept reading theirs. After they stopped, the next start reused the new copy and removed the old one.

Credit

These changes were written by Jiaqi Zeng (@HeyyyyyyG). Commits 4 to 12 adapt them to main, update the docs, and apply review fixes.

🤖 Generated with Claude Code

HeyyyyyyG and others added 6 commits November 23, 2026 14:55
Upstream starts the interpreter in the server's working directory, i.e. the Gym checkout, so files the policy's code
wrote landed in the Gym tree (on shared storage in training). Same interpreter, flags, timeout and output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…local_edgar_stage_dir)

A runtime SQLite database should not be read in place on shared storage. With local_edgar_stage_dir set, the server
copies the local index, its metadata sidecar and WAL into that node-local directory at startup and reads the copy.
Copies go through a .partial name and a rename under a lock on the stage directory, so concurrent server processes on
a node copy each file once. A staged copy is kept only while its size and modification time match the source; an
optional file the source lacks (WAL, default sidecar) is removed from the stage so a stale copy never pairs with a new
index; a missing index or configured sidecar fails at startup naming the source path. Off by default.

Tests: TestLocalEdgarStaging in tests/test_app.py (10 cases).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…olve

Before, a criterion the judge never resolved (transport errors, replies with
no parseable 0/1 verdict, or replies cut at the judge's own max_output_tokens,
after all judge_max_attempts) weighed as a miss: the row was scored (often 0.0
under dealbreaker gating) and trained, flagged only by judge_error. Now verify
raises JudgeError (judge_unparseable when every failed call got a reply,
judge_failed otherwise), so judge_failsafe returns the row masked and routes it
to the failures sidecar.

A row with no usable rubric, or a server with no judge configured, scored 0.0
and was trained; it is now masked with failure_kind verifier_error.

Unchanged: no submit_final_result is the model's failure and still scores 0
unmasked; criteria the judge resolved as not met are still scored and trained.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…form main accepts

On main, JudgeError takes no failure_kind and judge_failsafe takes no
placeholder_reward. The previous commit used both, so seven verify tests failed
with TypeError. verify now raises a plain JudgeError, and judge_failsafe masks
the row as judge_failed. The message still names the first cause: a failed
call, a reply with no 0/1 score, or a reply cut at max_output_tokens. The tests
assert that cause. The same rows are masked. Only the judge_unparseable kind is
not set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…ge failures

The benchmark README told readers to filter judge_error rows by hand, and the
server configuration said that an unresolved criterion only flags the question.
These rows are now masked, so both texts say that. The server README also
describes local_edgar_stage_dir.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
The benchmark README now says that a row is masked when the judge did not
resolve one of its criteria.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yfw yfw added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Nov 23, 2026
@yfw

yfw commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8f347b8

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 23, 2026 23:07
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 23, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD — EDGAR staging can silently serve another corpus, and the verifier change lacks required rollout and reward-profile evidence.

Reviewed all seven changed files, surrounding callers, SQLite readers, failure routing, score aggregation, tests and documentation. Existing formal reviews and inline comments were empty.

RISK — Provide real rollout and benchmark reward evidence. The unresolved-criterion change removes previously scored rows from training and the fixed finance benchmark's means. The description explains that intended change, but explicitly reports no real rollout logs or before/after reward profile. The protected contribution requirements require representative model smoke rollouts for behavior changes and reward profiling for fixed benchmarks.

Could you provide a representative model/tool/verifier smoke trace and compare the same saved benchmark answers under a pinned judge configuration? Report before/after reward and rubric means, scored/masked counts and failure reasons. Explain the intended denominator change and confirm fully resolved rows keep their scores. A full training run is not required.

Validation: exact-head CI passed lint, core shards 0–3, Sandbox tests and Changed server tests. The server log confirms 115 BigFinance tests and 302 finance-agent tests passed, with both data validations successful. Repository suites were not rerun locally.

Focused probes ran with Python 3.13.14 in 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:main-offline. Real SQLite readers reproduced the staging defect below. Scripted judge probes confirmed masking and metric exclusion; scratch-execution probes checked cleanup, output and timeout behavior. Probes extracted admitted source definitions where external dependencies were unavailable, so they do not establish full-server or real-model behavior.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@yaoyu-33
yaoyu-33 requested a review from agronskiy November 24, 2026 00:38
yfw and others added 2 commits November 23, 2026 16:38
… copied code's source

A cancelled python_exec call removed its temporary folder but left the child
running, and a folder cleanup error replaced the tool result. The call now kills
a child that is still running in a finally block, and it ignores folder cleanup
errors.

ScratchDirPythonExecTool.run is adapted from PythonExecTool.run of
https://github.com/wowowoxuan1994/big-finance-benchmark at commit
dffb39459dbfc96a7b38d179fec420900d616a69 (Apache-2.0). The file header now
records this. A new test fails when the pinned PythonExecTool.run changes, so
the copy does not drift without a signal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…nd fix judge-failure docs and metrics

Two source indexes with the same file name in one local_edgar_stage_dir
overwrote each other's copy, so a running server read the other index. Each
source index now gets its own subfolder, named by a hash of its absolute path.
A new test stages two such indexes apart.

Other changes:
- Both server configurations pass local_edgar_stage_dir from env.yaml.
- The stage copies only the index and its sidecar. The reader opens the index
  with immutable=1, so it never reads a WAL.
- A failed copy removes its .partial file.
- The default sidecar name comes from default_sidecar_path.
- The answer that goes to the judge is capped at 50,000 characters, so a long
  answer does not mask the row through a judge context error.
- Before the JudgeError, the server logs the failed judge replies.
- get_key_metrics no longer promotes the two judge-failure counters, because
  masked rows never reach them.
- The README and docstring describe judge_error and rows with no submission
  correctly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 220e85a

…ration folder

With one folder per source path, a server that started after the source index
changed copied the new version over the copy that a running server read. The
running server's next connection then opened the new version, and its index and
sidecar did not always come from the same version.

Each version of the index and sidecar now goes into its own generation folder,
named by a hash of their inode, size, modification time and change time. A
generation folder never changes after it is staged. A server holds a shared lock
on its generation for its whole life, and a later start removes only the
generations that no process holds, so old copies do not pile up on the node
disk. New tests cover a source changed while a copy is in use, a replacement
with equal size and modification time, a changed sidecar, two servers on one
node, the removal of unused generations, and a failed copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cfb5b52

secrets-detector reported the SHA-256 of the pinned PythonExecTool.run source
as a "Hex High Entropy String". The hash now sits in its own variable with an
inline "pragma: allowlist secret" comment. The .secrets.baseline file does not
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7013e96

…refuse a source that changes mid-copy

The shared lock sat on an empty <gen>/.in-use file. If a cleaner outside the
server deleted that file, a later start made a new one, got the exclusive lock,
and removed a generation that a running server still read. The lock is now on
the generation folder, opened with O_DIRECTORY, so no file inside it can replace
the locked one.

The generation name is now taken under the stage lock. After the copy, the
stager takes the fingerprint again, and if the source changed, the start fails
instead of staging a mix of two versions. A new test covers this.

The README and the field description now say that the stage folder must be on
a node-local disk, and that copies for other index paths and files from earlier
layouts are not removed automatically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7e777a4

@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Smoke runs at 7e777a4968, with a hosted policy model and a hosted judge model, CPU only: 8 finance_agent_v2 rows on a 28 GB local EDGAR index, staged with local_edgar_stage_dir, and 6 big_finance rows.

Model, tool and verifier trace, with a forced judge failure (16 output tokens, 2 attempts): the policy ran the tools (edgar_search, parse_html_page, retrieve_information, price_history, calculator) on every row. 6 rollouts submitted an answer. Each one was masked as judge_failed and went to the failures sidecar, and the aggregate reported "6 failed (6 masked, not scored as zero)". The 2 rollouts that hit max_steps without a submission scored 0, unmasked. gym eval reverify --judge-failed-only --settle-into-source with the normal judge then scored all 6 (1.0, 1.0, 1.0, 0.958, 0.667, 0.0), with no unresolved criterion.

Same saved answers, re-judged on main and on this branch with one pinned judge (temperature 0, 1 verdict per criterion):

  • Fully resolved rollouts keep their scores. 6 of the 7 rollouts that both runs fully resolved match exactly, and the 7th differs by one judge verdict (0.667 and 0.700).
  • The only rollout that changed had an unresolved must_pass criterion on main. main scored it 0.0 through dealbreaker gating and kept it in mean/reward (0.453 over 8). On this branch, that criterion resolved and the rollout scored 1.0 (0.582 over 8). When a criterion stays unresolved, this branch masks the rollout instead.
  • The intended denominator change, with the failing judge: main reported mean/reward 0.0 over 8 rollouts, 6 of which were judge outages. This branch reported it over the 2 scored rollouts, with 6 masked failures left for recovery.

big_finance: 10 python_exec calls in 6 rollouts created no file in the server folder and left no temporary folder.

The description has the full numbers.

…en calls

Each python_exec call runs in a fresh temporary folder. The README now says so,
and that this matches the tool description, which says there is no persistent
state between calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 88c1898

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 25, 2026
@yfw

yfw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 830ce4d

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Only an unresolved criterion masks the row, so a resolved miss still scores; the python_exec folder is cleaned on every path; and staging is locked per version. One optional note inline. LGTM.

rubric_total=len(criteria),
)

if len(generated_answer) > 50_000:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: could the 50,000-character cap become a named constant, with a test showing that a longer answer is judged on its prefix and scored, not masked? This line keeps an overlong answer from becoming a masked judge failure.

@ffrujeri
ffrujeri added this pull request to the merge queue Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/46532622317

Merged via the queue into main with commit e0f6736 Nov 30, 2026
63 checks passed
@ffrujeri
ffrujeri deleted the yifuw/finance-tempdir-edgar-stage-rubric-mask branch November 30, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants