Skip to content

fix(recover): read oversized saved rows in bounded memory - #6086

Merged
AdamRajfer merged 4 commits into
NVIDIA-NeMo:mainfrom
AdamRajfer:fix/recover-evidence-streaming-memory
Nov 16, 2026
Merged

AdamRajfer merged 4 commits into
NVIDIA-NeMo:mainfrom
AdamRajfer:fix/recover-evidence-streaming-memory

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

gym eval resubmit --recover could not inspect runs with very large saved rows, because the evidence collector parsed every line whole and ran out of memory. A row over 16 MiB is now read in chunks, and strings over 1 KiB inside its ng_trajectory and ng_agent_observations that the collector does not read are replaced by a length marker before parsing; keys are compared after unescaping, invalid JSON strings are still rejected, and every byte read still goes into the source digest. Rows of 16 MiB or less take the unchanged path. A new test collects a 256 MiB row under a 512 MiB memory limit (it fails with MemoryError without the change), and the pruned and whole parses report the same evidence; on real saved rows the collector output was identical with and without pruning. No linked issue: found when recovering a real run ran out of memory.

The recovery evidence collector parsed every rollouts.jsonl line whole.
A harness trajectory repeats each model call's full request, so a row
grows with the square of its conversation and can reach several
gigabytes; one such row needs several times its size in memory, and the
reader ended with MemoryError on a login node.

A line longer than 16 MiB is now read in chunks, and the strings longer
than 1 KiB inside its ng_trajectory and ng_agent_observations values are
replaced by a length marker before the line is parsed. The collector
reads only identities, names, statuses and counts from those values, and
every other value (the response the grading binding hashes included) is
copied byte for byte. Every byte read still goes into the source digest.
Smaller rows take the unchanged path, so the evidence is the same.

Tests: a 256 MiB row is collected under a 512 MiB address-space limit
(it fails with MemoryError without the change), the pruned and whole
parse report the same evidence, and a truncated final row is still
recognised. The test double of the source-read test now offers readline.

Signed-off-by: Adam Rajfer <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 12, 2026 22:10
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

@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.

SHIP WITH CARE

Two RISK findings: pruning can change valid trajectory identities and hide malformed JSON strings. Raw-byte digest handling remains intact.

I inspected all three changed files and the affected producer and recovery paths. This was a static review; I didn't run tests.

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 prokotg November 12, 2026 22:33
…lid strings when pruning a large row

Pruning elided every long string under ng_trajectory and ng_agent_observations,
so a long task or call identity changed with the size of its row, and an
elided string was never checked as JSON, so a malformed escape, invalid UTF-8 or
a raw control byte was accepted only because the row crossed the threshold.

- elide only strings under keys the collector does not read (request input, tool
  output, conversation text); identities, statuses, kinds, names and object keys
  are kept, and one above 1 MiB fails the row instead of being altered
- validate each elided string in pieces with the JSON parser, across chunk
  boundaries, and route an invalid one through the existing malformed-record
  path (a truncated last row is still ignored)

Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 1c355b8

@yuhezhang-ai yuhezhang-ai 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.

Could you address the four cases below before merge? I reproduced two memory regressions, valid payloads rejected only above the pruning threshold, and a malformed record that hides subsequent rows. These checks used synthetic saved records; I did not exercise a production store.

Release the pruner before the rebuilt row is parsed, find the closing quote of a
string with find instead of a regex that keeps state per escape, keep a string
only where the collector reads it instead of under any field with a matching name,
and keep the newline that ends an unfinished elided string.

Signed-off-by: Adam Rajfer <[email protected]>

@yuhezhang-ai yuhezhang-ai 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 for the fixes. I confirmed the buffer-lifetime, escape-dense-memory, and physical-newline issues are addressed. One escaped-key metadata case remains in the existing thread; the inline note below is an optional robustness follow-up.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 13, 2026
…xtra closer when pruning a large row

A key written with escapes (a Windows path in a tool output) was treated as a
kept-metadata ancestor, so the ignored payload below it hit KEPT_MAX. Keys are
now unescaped before they are compared with the paths the collector reads, so
an escaped spelling of a kept name still matches and any other escaped key is
payload.

A corrupt last row with an extra closing brace popped an empty stack; the
parse of the row now rejects it, so it is handled as an incomplete tail.

Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

🤖 Adam’s AI assistant

@yuhezhang-ai thanks for the careful review and the large-row check. Both points are fixed in cd071fe: the pruner unescapes keys before comparing them, and an extra closer no longer pops an empty stack, so that row is handled as an incomplete tail. CI is fully green. Could you take another look?

@yuhezhang-ai yuhezhang-ai 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 for the fixes. I verified the escaped-key handling and extra-closing-brace recovery against the earlier reproductions, and the earlier regressions still pass. The remaining corruption-only comma guard can be a follow-up.

@AdamRajfer
AdamRajfer added this pull request to the merge queue Nov 16, 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/43852197752

Merged via the queue into NVIDIA-NeMo:main with commit a8e553a Nov 16, 2026
93 of 96 checks passed
@AdamRajfer
AdamRajfer deleted the fix/recover-evidence-streaming-memory branch November 16, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants