Skip to content

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

Merged
earakely-scale merged 2 commits into
mainfrom
andrewpark/legacy-rest-callers-send-token
Nov 24, 2026
Merged

earakely-scale merged 2 commits into
mainfrom
andrewpark/legacy-rest-callers-send-token

Conversation

@andrewpark-scaleai

@andrewpark-scaleai andrewpark-scaleai commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge order for this pair:

  1. fix(env): send the control token to the REST routes behind the gateway #820 (callers send the token) merges first, any time.
  2. The internal caller PRs merge and deploy.
  3. feat(gateway): take the control token on the older /svc REST state routes #822 (the gateway requires the token) merges last. Merging it earlier makes every caller that doesn't send the token get a 401.

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.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.

Summary

Sends control tokens on legacy REST loads, resets, and state exports.

  • Legacy loads send tokens to reset and add routes.
  • State captures send tokens to legacy export routes.
  • Grants follow resolved addresses, not raw URL prefixes.
  • A rejected REST reset no longer falls back to the MCP tool.
  • The provider test uses a gateway deployment record.

Reviews (6) · Last reviewed commit: "refactor(env): one record method for a t..." · Reviewed by Greptile

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.
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-callers-send-token branch from 58f18f0 to f3ff3b3 Compare November 20, 2026 17:14
@earakely-scale

Copy link
Copy Markdown
Collaborator

🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review.

Context from outside this diff: #776 (open, non-draft) is a second, independent implementation of this same change — same five source files — and the two disagree in ways only visible when you hold them side by side.

Raising it only because none of this is visible from this diff alone; which of the two is the one to keep is yours to call.


Generated by Claude Code

Five call sites spelled `(deployed.control_headers_for(url) or None)`, where
the `or None` is what lets a record with no token for the url fall back to
the run's grant; an empty dict would send nothing. control_headers_or_grant
says that once, and each site calls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 4843784 into main Nov 24, 2026
36 checks passed
@earakely-scale
earakely-scale deleted the andrewpark/legacy-rest-callers-send-token branch November 24, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants