Skip to content

fix(env): send the control token to the REST routes behind the gateway - #820

Draft
andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/legacy-rest-callers-send-token
Draft

andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/legacy-rest-callers-send-token

Conversation

@andrewpark-scaleai

Copy link
Copy Markdown
Contributor

Why

The gateway's data plane calls send the control token. This PR makes agent-env's calls to the older REST state routes send it too, so a later gateway change can require it there.

What changed

  • reset_via_rest, add_via_rest, export_state and reset in legacy_protocol take headers. Without them, each call sends the run's grant (request_headers).
  • The legacy loads and resets of MCP servers and websites send their record's token (data_plane_headers).
  • service_state and the snapshot step send the deployment's token to /export-state and to a streamed /export-snapshot.
  • granted_headers matches a URL to a grant only when the URL resolves under the grant's address, by whole path segments.
  • A legacy reset that the server refuses with 401 or 403 now raises instead of falling back to the <name>_reset MCP tool.

Scope

  • Covers every caller in this repo of /api/reset, /api/add, /export-state and /export-snapshot.
  • Leaves the gateway as it is.

Verification

  • New unit tests check the Authorization header on each legacy route when a token exists, and its absence when none does.
  • pytest packages/agentenv-protocol/tests tst/unit/env tst/unit/task_step -n 4: 7808 passed, 1 skipped, 0 failed. ruff check is clean.
  • tst/integration/env/envs/multi_env_local_test.py passed on local Docker.

The legacy REST helpers (reset_via_rest, add_via_rest, export_state, reset)
take headers and default to the run's grant. Legacy loads, resets, state reads
and streamed snapshots send the deployment's token. A grant covers a URL only
when it resolves under the grant's address, by whole path segments. A legacy
reset refused with 401 or 403 raises instead of falling back to the MCP tool.

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.

1 participant