Skip to content

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

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

salma2vec wants to merge 2 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.

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

Rebased onto main at f5f5c9a. vf-eval was removed in #2610, so the earlier change to its per-trace JSON output is dropped; vf-run does not print traces. The regression assertions use .tolist() for the NumPy streams introduced by #2961.

Validation on Python 3.14.2 with uv sync --frozen:

  • 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.
  • Full tests/unit: 238 passed, 19 skipped. Skips: Harbor unavailable (1), Docker unavailable (9), missing PRIME_API_KEY (9).
  • Ruff check, Ruff format and ty check verifiers pass. The markdownlint hook could not be installed locally (nodeenv rejects the alpha Node release); no Markdown files change in this PR.

Live model/runtime integration tests were not run.

Note

Exclude raw training arrays from episodes written by trace_store.write_episode

  • write_episode in trace_store.py now passes EXCLUDE_FIELDS to the JSON dump for every trace, so routed experts, sampling masks, and top logprobs are not saved in episode files
  • Task data, messages, token IDs, and logprobs remain in the reloaded episodes
  • Adds a parameterized regression test test_saved_episode_omits_raw_training_arrays in test_trace.py that writes and reloads an episode and checks the excluded fields stay unset
  • Behavioral Change: previously saved episode JSON contained these raw training arrays; new episodes omit them

Macroscope summarized 2c72e01.

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

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.

Fixes PrimeIntellect-ai#2956
@salma2vec
salma2vec force-pushed the fix/write-episode-record-exclusions branch from 702ec3e to 2c72e01 Compare November 3, 2026 10:19

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