Skip to content

fix(trace_store): exclude raw training arrays from saved episodes - #2957

Open
salma2vec wants to merge 3 commits into
PrimeIntellect-ai:mainfrom
salma2vec:fix/write-episode-record-exclusions
Open

salma2vec wants to merge 3 commits into
PrimeIntellect-ai:mainfrom
salma2vec:fix/write-episode-record-exclusions

Conversation

@salma2vec

@salma2vec salma2vec commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #2956

Saving an episode containing routed experts, sampling masks, or top logprobs could fail on non-UTF-8 array bytes, or write a row that read_episodes could not load. The default per-trace JSON output in vf-eval had the same problem.

Apply the existing EXCLUDE_FIELDS record exclusions to both paths. write_episode keeps its typed adapter, preserving task/trace subclass fields and the existing float precision. The msgpack wire continues to carry the training arrays.

The branch includes main at e7c847821. The regression assertions use .tolist() for the NumPy streams introduced by #2961.

Validation on Python 3.13.16 with repository-locked dependencies:

  • All four save/reload cases pass: routed-expert bytes, sampling masks, top logprobs, and an ASCII-safe mask that previously wrote successfully but failed to reload. Typed task data, messages, token IDs, and logprobs are retained.
  • The review's four NumPy assertion failures reproduce after merging main and pass with the corrected assertions.
  • Full tests/unit: 235 passed, 19 skipped. Skips: Harbor unavailable (1), Docker unavailable (9), missing PRIME_API_KEY (9).
  • Repository-wide Ruff check, Ruff format, and the pre-push type check pass. Full pre-commit setup is blocked by the installed npm rejecting markdownlint's local Git package (EALLOWGIT); the Python hooks pass independently. No Markdown files change in this PR.

Live model/runtime integration tests were not run.

Note

Exclude raw training arrays from saved episodes and eval CLI trace output

  • Applies EXCLUDE_FIELDS when serializing traces in trace_store.py write_episode, so raw training-array fields are omitted from saved episode JSONL while task data, messages, token IDs, and logprobs persist
  • Applies the same exclusion to non-rich JSON trace output in the eval CLI entrypoint main.py
  • Adds a parameterized regression test test_saved_episode_omits_raw_training_arrays in test_trace.py covering routed-expert data, sampling masks, and completion top-logprob data
  • Behavioral Change: reloaded episodes and eval CLI JSON traces no longer contain the raw training-array fields listed in EXCLUDE_FIELDS

Macroscope summarized 702ec3e.

write_episode dumped routed-experts, sampling-mask and top-logprob arrays
through the msgpack byte serializer into JSON, so saving a train-client
trace raised on non-UTF-8 bytes or wrote a row read_episodes could not
load. Apply the EXCLUDE_FIELDS record contract that Episode.to_record
already uses, and the same exclusion when vf-eval prints traces.

Fixes PrimeIntellect-ai#2956
@salma2vec
salma2vec force-pushed the fix/write-episode-record-exclusions branch from 9e342fa to 71c35e2 Compare October 23, 2026 21:03

@YidaWeng YidaWeng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The production fix is correct, but the new test is not compatible with current main after rebase. Requesting changes for that test failure.

Verification

On main (e7c847821), the issue's exact save/reload matrix fails:

  • routed_experts / sampling_mask / top_logprobs: PydanticSerializationError: invalid utf-8 sequence...
  • sampling_mask=[[1]]: write succeeds, read_episodes raises TypeError: a bytes-like object is required, not 'str'
  • The CLI path (trace.model_dump_json(indent=2, exclude_none=True)) fails the same way.

On this PR head, all four cases save and reload successfully, raw fields are absent from traces.jsonl, node arrays are None, and logprobs is preserved. The CLI dump with EXCLUDE_FIELDS also succeeds. write_episode's nested exclude={"traces": {"__all__": EXCLUDE_FIELDS}} does not over-exclude typed task data or normal trace fields.

Problem after rebase

This branch is based on c134007 and is behind main. I merged current main into a local scratch branch. The four new parametrizations then fail at:

assert saved.nodes[-1].token_ids == [10, 20]

with ValueError: The truth value of an array with more than one element is ambiguous, because main now stores token_ids / logprobs as numpy arrays (from #2961). The full merged suite reports 254 tests, 4 failed, 19 skipped.

Applying this compatibility change makes the test pass:

-    assert saved.nodes[-1].token_ids == [10, 20]
-    assert saved.nodes[-1].logprobs == [-0.5]
+    assert saved.nodes[-1].token_ids.tolist() == [10, 20]
+    assert saved.nodes[-1].logprobs.tolist() == [-0.5]

With that change:

  • the four new params: 4 passed
  • full merged tests/unit: 254 tests, 235 passed, 19 skipped, 0 failed
  • pre-commit run --files tests/unit/test_trace.py: ruff check/format pass

Please rebase onto current main and apply the tolist() assertions. I did not push to your branch.

Copy link
Copy Markdown
Author

Thanks, reproduced all four NumPy assertion failures after merging main at e7c847821. Fixed both assertions with .tolist() in 702ec3e.

The four save/reload cases now pass, and the full unit suite is 235 passed, 19 skipped. Ruff check/format and the pre-push type check pass across the repository. Full pre-commit setup hits an npm EALLOWGIT error while installing markdownlint, so I ran the Python hooks separately. The skips require Harbor, Docker, or Prime credentials; live integration tests remain unrun.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write_episode can't save or reload traces with routed-experts, sampling-mask or top-logprob arrays

2 participants