Skip to content

Avoid env-server trace recopy - #1809

Merged
xeophon merged 1 commit into
feat/nano-as-v1from
codex/remove-env-server-trace-recopy
Jun 21, 2026
Merged

Avoid env-server trace recopy#1809
xeophon merged 1 commit into
feat/nano-as-v1from
codex/remove-env-server-trace-recopy

Conversation

@xeophon

@xeophon xeophon commented Jun 21, 2026

Copy link
Copy Markdown
Member

Overview

Keep completed V1 traces concrete inside env-server response wrappers and defer WireTask conversion to the existing client boundary. This removes a redundant full-trace dump and validation pass before the unchanged wire serializer.

Mechanism

episode.run() already returns typed, trusted Trace objects. The rollout path previously dumped each concrete trace to a dictionary, then response validation rebuilt it as Trace[WireTask]; the response field serializer subsequently dumped that rebuilt trace again for msgpack. Group responses repeated the same work for every trace.

The response wrappers now use model_construct around those trusted concrete traces. Their existing field serializers still produce the wire payload once, and the client continues validating decoded responses into Trace[WireTask]. Request handling, response schemas, msgpack encoding, ZMQ transport, task extras, excluded state, and client-side validation remain unchanged.

Performance

A PEP 723 response-path benchmark used one trace with one node and 1,825,000 token IDs, masks, and log probabilities (5,475,000 list entries total), producing a 27,244,201-byte msgpack response. Values below are medians of three fresh processes after warm-up on macOS.

Metric Previous Current Saved
Wrapper construction 79.289 ms 0.018 ms 79.271 ms (99.98%)
Total synchronous response work 231.703 ms 150.555 ms 81.148 ms (35.02%)
Peak process RSS 399.8 MiB 358.3 MiB 41.5 MiB (10.38%)
Live response RSS growth 135.8 MiB 94.2 MiB 41.6 MiB (30.63%)
Post-cleanup RSS growth 135.8 MiB 94.2 MiB 41.6 MiB (30.63%)

The synchronous time reduction directly shortens the env-server event-loop stall for large responses. Group savings scale with the number and size of completed traces.


Note

Low Risk
Server-only response construction optimization on trusted rollout output; wire encoding and client validation paths are unchanged.

Overview
Rollout and group handlers no longer turn completed traces into dicts before building RunRolloutResponse / RunGroupResponse. They wrap the concrete episode.run() traces with model_construct instead of going through model_dump() plus full Pydantic validation on the way in.

That removes an extra full-trace copy and rebuild on the server while the existing trace / traces field serializers still run once when _handle calls model_dump for msgpack. WireTask re-typing stays on the client via model_validate on the decoded payload.

Group responses get the same treatment per trace, so savings grow with group size and trace payload size.

Reviewed by Cursor Bugbot for commit dd1ea56. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Avoid redundant trace serialization in EnvServer rollout and group responses

In server.py, _run_rollout and _run_group now use model_construct to build responses directly from existing Trace objects instead of calling model_dump() on each trace and re-validating. This skips an unnecessary serialize-then-validate round-trip per trace.

Macroscope summarized dd1ea56.

@macroscopeapp

macroscopeapp Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Performance optimization using Pydantic's model_construct() to avoid redundant serialization and validation of trusted internal trace objects. Change is small, self-contained, and follows a standard Pydantic pattern.

You can customize Macroscope's approvability policy. Learn more.

@xeophon
xeophon merged commit dd97f28 into feat/nano-as-v1 Jun 21, 2026
5 checks passed
pull Bot pushed a commit to Stars1233/verifiers that referenced this pull request Jun 23, 2026
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.

1 participant