Repository navigation
Conversation
An agent session can now hand back token-level training data that was captured outside Gym's model server, for example by a component that records the harness's model calls next to the task sandbox. `AgentCloseSessionResponse` gains an optional `token_capture` field holding a `TokenCapture`: the captured ATIF trajectories, capture metrics, and a masked flag with its reason. After the agent session closes, the single_agent_turn environment server adds the capture to the episode result: `atif_trajectories` and `_ng_token_capture` at the top level, and `mask_sample` only when the capture is masked. The reward is unchanged and an unmasked capture never clears a mask the verifier set. The single_agent_turn_legacy flat-row wrapper keeps these fields at the top level of the row. Signed-off-by: Ananth Subramaniam <[email protected]>
Rollout collection rejected every `_ng_*` key in an environment server's typed result, so any SingleAgentTurnRequest episode that carried `_ng_token_capture` from a capture outside Gym's model server failed. Allow exactly that key; identity, failure, and assembled observation keys remain reserved for rollout collection. Co-authored-by: yaoyu-33 <[email protected]> Signed-off-by: Ananth Subramaniam <[email protected]>
Agents that drive an external harness each decide on their own where the harness sends model calls: a Gym model server with the rollout capture prefix, or a directly configured OpenAI-compatible base URL. A later session component that records model calls needs to substitute its own endpoint, and agents should be able to run without a Gym model server when another endpoint is supplied. SimpleResponsesAPIAgent.model_endpoint now makes that choice in one place. It returns a ModelEndpoint (base URL and an optional model name) in this order: an endpoint the caller passes for the episode's session, the model server through resolve_model_base_url (keeping the rollout prefix and the training token capture route), then the agent's configured base URL verbatim. It raises ValueError when none is set. No agent is changed here; each adopts the helper in its own change. Signed-off-by: Ananth Subramaniam <[email protected]>
…ifecycle Some training setups record a harness's model calls, with their token ids, from a component that runs next to the harness inside the task sandbox, for example a proxy the harness calls instead of the model. SandboxSession, the execute, stop, collect and release lifecycle shared by the Codex, Hermes and Pi agents, now runs such a component when one is configured, so agents do not each implement its start, collection and cleanup ordering. A capture implements the new SessionCapture interface: start returns the ModelEndpoint the harness must call, collect stops the component and returns a TokenCapture, and abort stops it without collecting. SessionCaptureConfig selects the implementation by import path with keyword options and a collect timeout; the class and its options are validated when the configuration loads, so a bad path, a class that is not a complete SessionCapture, or unknown options fail at agent startup. The adapter awaits start_session_capture before it builds the harness command and passes the endpoint to model_endpoint. Close collects the capture after the harness has stopped and before the sandbox is released (an owned sandbox is stopped, a borrowed one is handed back), at most once, and token_capture returns it for the agent's close response. A borrowed session whose harness cleanup is not confirmed defers collection to the retried close, because the harness may still be calling the component. Capture problems never fail the episode: a start that fails or is cancelled, a collection that raises or exceeds its timeout, or a session closed before the capture ran produce a masked TokenCapture with the reason, and the component is aborted under a shield so a cancelled caller cannot interrupt it. When the capture did not start, execute refuses to run the harness and session_capture_failed tells the adapter to answer the activation without it. Without a configured capture the lifecycle is unchanged. No agent opts in here; each does in its own change. Signed-off-by: Ananth Subramaniam <[email protected]>
…ailing the episode When a sandbox session's capture does not start, execute refuses to run the harness, but raising from the activation would fail the whole episode for a capture problem. harness_not_run_response gives every agent the same answer instead: a failed response with an empty assistant message, the request's model and tool fields, and the reason as its error message. harness_not_run_observations returns the matching observations, one harness_not_run gap whose detail is the reason, so the close response does not report an unrelated observation failure. The environment server then still verifies and closes the episode, its result shows why the harness did not run, and the session's masked token capture keeps the sample out of training. Signed-off-by: Ananth Subramaniam <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
The capture runs only inside a SandboxSession, and agents refuse it on every other path. Naming it after the sandbox session says so where it is configured and in its error messages. The module moves to nemo_gym/agent_utils/sandbox_session_capture.py. SandboxSession keeps its session_capture field and start_session_capture method, which are already scoped by the class. Signed-off-by: Ananth Subramaniam <[email protected]>
Codex agent sessions can now send their model calls through a session capture: a component started in the task sandbox that serves the model endpoint and records every call. The new session_capture config field selects it, and model_server must then be null; a config naming both is rejected when it loads, and the session seed accepts a missing model server only when a capture is configured. The session's SandboxSession builds its own capture instance and starts it at seed, after the Codex runtime is installed, so its endpoint is known when the activation writes the Codex config. The provider base URL now comes from model_endpoint, which prefers the capture's endpoint over the model server; when the capture names a model, the config and the response use it. Codex calls the streaming Responses API, so the capture endpoint must serve it. The host path keeps its URL choice through the same helper and rejects session_capture, since it cannot capture calls. When the capture does not start, Codex does not run: the activation returns a failed response with an empty assistant message and records a harness_not_run gap, so the episode is still verified. Session close returns the capture, or the masked one, as token_capture. Without session_capture nothing changes. Signed-off-by: Ananth Subramaniam <[email protected]>
…capture Follows the rename of SessionCapture to SandboxSessionCapture. The field only takes effect in sandbox sessions, and Codex refuses it elsewhere, so the name now says where it applies. Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/codex-session-capture
branch
from
October 9, 2026 13:20
5242575 to
39fd081
Compare
7 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
Codex agent sessions can now send their model calls through a sandbox session capture: a component started inside the task sandbox, for example a proxy next to the harness, that serves the model endpoint and records every call with its token ids. Session close returns what it recorded, so a training run can use token-level data from the calls Codex actually made. Without the new setting, Codex behaves exactly as before.
CodexAgentConfig.sandbox_session_capture(aSandboxSessionCaptureConfig) selects the capture implementation. A capture replaces the Gym model server for the session's calls, so a config that sets bothmodel_serverandsandbox_session_capturefails when it loads ("set model_server: null to use sandbox_session_capture"). The session seed still requires a sandbox-reachablemodel_serverunless a capture is configured, and still rejectsopenai_base_url,cwd, andextra_configoverrides.POST <base_url>/responseswithwire_api = "responses"). The capture endpoint must serve that API; the requirement is documented on the config field and in the README rather than adapted in the agent.SandboxSessiongets the capture config and builds its own capture instance. The seed awaitsstart_session_capture()after the Codex runtime is installed and keeps the returnedModelEndpointon the session state.base_urlin the generated Codex config now comes fromSimpleResponsesAPIAgent.model_endpoint(...), which prefers the capture's endpoint over the model server. When the capture names a model, the Codex config, the request model check, and the response use that model; otherwise the existing model choice is kept. The legacy direct-agent path keeps its URL choice through the same helper (model server, thenopenai_base_url, then the OpenAI API) and rejectssandbox_session_capture, because it runs Codex on the agent-server host where no capture runs.harness_not_run_response(...)(a failed response with an empty assistant message) and recordsharness_not_run_observations(...), so the environment server still verifies and closes the episode instead of failing it.AgentCloseSessionResponse.token_capturecarriessession.token_capture(): the collected capture, a masked one when start or collection failed, orNonewithout a capture.model_call_join_key_unavailablegap), so calls served by a capture need no change there.flowchart TD A["Seed: install Codex runtime"] --> B["start_session_capture()"] B -->|"endpoint"| C["Activation: model_endpoint(session_endpoint=capture)"] C --> D["Write Codex config with the capture base_url and model"] D --> E["Run Codex in the task sandbox"] B -->|"did not start"| F["Activation: harness_not_run_response, harness_not_run gap"] E --> G["Close: collect capture, return token_capture"] F --> H["Close: return masked token_capture"]Dependencies
Depends on #4279, and transitively on #4276 (
model_endpoint,ModelEndpoint) and #4278 (TokenCapture,AgentCloseSessionResponse.token_capture). Review after those land; this branch is based on #4279.Linked issue
None; this adopts the sandbox session capture interface from #4279 in the Codex agent.
Validation
New tests in
responses_api_agents/codex_agent/tests/test_native_sessions.pyuse a fakeSandboxSessionCaptureselected by import path. They cover the config rejection ofmodel_serverwithsandbox_session_capture; a session whose Codex config uses the capture's base URL and model (and the configured model when the capture names none) and whose close returns the collectedtoken_capture; a capture that does not start, where Codex never launches, the activation returns a failed response, theharness_not_rungap is recorded, the episode is not failed, and close returns a maskedtoken_capture; a session without a capture closing with notoken_capture; and the legacy direct-agent path rejectingsandbox_session_capture. With the agent changes reverted, every new test except the no-capture case fails.Rollouts
N/A: no capture implementation ships in Gym, and without
sandbox_session_capturethe agent's behavior is unchanged (its existing session and legacy tests pass unmodified). Rollouts through a real capture belong with the change that adds an implementation.Compatibility
No change for existing configs.
sandbox_session_captureis a new optional field;_sandbox_inputnow takes the expected model as a keyword argument (internal).