Skip to content

feat: add single-agent-turn environment server - #3487

Closed
ananthsub wants to merge 1 commit into
mainfrom
ananthsub/episode-orchestration-06-single-agent-processor
Closed

ananthsub wants to merge 1 commit into
mainfrom
ananthsub/episode-orchestration-06-single-agent-processor

Conversation

@ananthsub

@ananthsub ananthsub commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Implements the standard resources-backed single-agent-turn Environment Server protocol by composing Agent and Resources session APIs. The Environment Server assigns participant session IDs and registers cleanup before seeding, so a lost seed response cannot hide the identity needed for cleanup. Responses verification binds the generic Resources request to a concrete payload.

Single-agent interaction flow

This diagram shows the built-in single-agent use case. Other Environment Server protocols may coordinate different participants and use different request, result, and lifecycle flows.

sequenceDiagram
    participant C as Rollout collector
    participant E as Environment Server
    participant R as Task / Resources Server
    participant A as Agent Server
    participant M as Model Server
    participant S as Task sandbox

    C->>E: POST /run
    E->>R: Seed task session
    R-->>E: Tool access and optional SandboxAccess
    E->>A: Seed agent session
    A->>S: Connect as borrower when supplied
    E->>A: Invoke /v1/responses
    A->>M: Model and capture requests
    A-->>E: Agent response
    E->>A: Close agent session
    E->>R: Verify response
    E->>R: Close task session
    E-->>C: Episode result
Loading

The Environment Server coordinates ordering and the final result. Agent and Task/Resources Servers retain ownership of the state and resources they create.

This is part 8 of 13 in the Environment Server stack. Previous: #3544. Next: #3488.

Validation

  • uv run pytest environment_servers/single_agent_turn/tests/test_app.py -q
  • uv run pytest tests/unit_tests/test_ci_environment.py::test_shared_change_classifier_matches_gym_docs_and_server_paths -q

Rollouts

See the final PR for end-to-end rollout evidence.

Compatibility and benchmark impact

No rollout is redirected by default.

Production wire serialization

Session requests are serialized with model_dump(mode="json") before dispatch. This preserves the kind and transport discriminators and converts Pydantic URL values to JSON strings. The fake client now encodes with orjson and validates the Agent seed using AgentSeedSessionRequest.model_validate_json.

A Resources close failure after successful verification is logged and retried by final cleanup without replacing the verified result.

@copy-pr-bot

copy-pr-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

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.

@ananthsub
ananthsub added this pull request to stack #3493 September 17, 2026 16:31
@ananthsub ananthsub changed the title ananthsub/episode orchestration 06 single agent processor feat: add single-agent episode processor Sep 17, 2026
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from fd58713 to a8acd5d Compare September 17, 2026 20:17
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch 2 times, most recently from 95288cf to 0305d46 Compare September 18, 2026 00:55
@ananthsub ananthsub changed the title feat: add single-agent episode processor feat: add single-agent environment server Sep 18, 2026
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from 0305d46 to 7aaa944 Compare September 18, 2026 01:06
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from 7aaa944 to 7f8501a Compare September 18, 2026 01:32
@ananthsub
ananthsub marked this pull request as ready for review September 18, 2026 19:45
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team September 18, 2026 19:46
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from 7f8501a to 8abf896 Compare September 18, 2026 20:44
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from d2579a8 to b50198a Compare September 18, 2026 22:37
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-06-single-agent-processor branch from b50198a to 8109092 Compare September 18, 2026 22:42
@yaoyu-33 yaoyu-33 added area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:high Cross-component or shared-contract change with a large review surface labels Sep 18, 2026

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

Overall LGTM. I think we need tests - our CI checks all server dirs and can't detect any here. I also added two small suggestions re documenting the code

Comment thread environment_servers/single_agent/app.py Resolved
Comment thread environment_servers/single_agent/app.py Resolved
yaoyu-33
yaoyu-33 previously approved these changes Sep 22, 2026
Comment thread environment_servers/single_agent/app.py Resolved
Comment thread environment_servers/single_agent/app.py Resolved
@ffrujeri

Copy link
Copy Markdown
Contributor

Question about seed-time cancellation and remote session ownership:

There appears to be an uncertainty window before either cleanup callback is registered. For example:

  1. The Environment Server sends POST /seed_session.
  2. The Resources Server creates its session/sandbox.
  3. The episode is cancelled or times out before the HTTP response is received and parsed.
  4. The Environment Server never learns resources_session_id or the session cookies, so it cannot register or issue /close_session.
  5. The remotely created resources remain orphaned.

The same sequence seems possible for POST /v1/agent_sessions. Cancelling the client-side HTTP await does not guarantee that the remote creation was rolled back.

What is intended to guarantee cleanup in this case? For example, do participant servers reap sessions after a TTL, or should seeding/closing be idempotent and keyed by the client-known episode_id so cleanup/retry remains possible when the seed response is lost? If abandoned-session reaping is already a protocol requirement, could we document that invariant here?


resources_server: ResourcesServerRef
agent_server: AgentServerRef
resources_tool_transports: list[Literal["direct_http", "mcp"]] = Field(default_factory=list)

@ffrujeri ffrujeri Sep 22, 2026 •

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.

Should a resources-tool transport be enabled by default here (for example, direct_http)? With the current [] default and no override in configs/single_agent.yaml, the standard configuration sends tool_accesses=[] when seeding the Agent even if the Resources Server returns MCP metadata. If explicit opt-in is intentional, could we document that requirement and show an example? The README currently says this server grants task-scoped tool access.

@ananthsub

ananthsub commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@ffrujeri Addressed the seed-response-loss window.

The Environment Server now assigns Resources and Agent session IDs before either POST and registers both cleanup callbacks first. Seed requests are idempotent under those IDs: close is idempotent and an unknown close leaves a tombstone that prevents a racing late seed.

SWE Pro, Hermes, Simple Agent, and the example Resources Server serialize seed/close per ID, and resource-owning sandboxes retain bounded TTL cleanup for process/host loss.

ffrujeri
ffrujeri previously approved these changes Sep 23, 2026
@ananthsub

Copy link
Copy Markdown
Contributor Author

Closing to recreate the remaining Environment Server work as one correctly ordered GitHub Stack. Branch commits are preserved; a replacement PR will follow.

This branch was previously deployed

1 inactive deployment
public — f84ad7cc Deployed Sep 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #3711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer 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.

4 participants