Skip to content

feat(gateway): take the control token on the older /svc REST state routes - #822

Open
andrewpark-scaleai wants to merge 16 commits into
andrewpark/legacy-rest-callers-send-tokenfrom
andrewpark/legacy-rest-routes-take-token
Open

andrewpark-scaleai wants to merge 16 commits into
andrewpark/legacy-rest-callers-send-tokenfrom
andrewpark/legacy-rest-routes-take-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.

DO NOT MERGE until the scaleapi and synthetic-pipelines caller PRs are merged and deployed. Once this ships in a gateway image, a caller of these routes that does not send the control token gets a 401.

Why

The gateway's data plane routes take the control token. This PR applies the same rule to the older REST state routes behind /svc/<key>/, so every state-changing or state-reading route behind the gateway uses one auth scheme.

What changed

  • LEGACY_STATE_ROUTES in gateway/constants.py lists the older state routes: /api/reset, /api/add, /api/bridge/apply, /export-state, /export-snapshot, /snapshot-dirty, /reset-memory, /validate-rows, /api/_state, /api/_reset and /api/debug/seed.
  • token_paths adds them to every /svc/<key>/ route. Matching reuses reaches, so paths are normalized before the check.
  • A site's /website/<site>/ route serves none of these routes. The harness reaches sites through /svc/<site>/.
  • A gateway booted without a token behaves as before.
  • The verifier that run_bundle_built_envs_test.py embeds sends the run's grant to /export-state.

Rollout

Verification

  • tst/unit/env/gateway/control_token_test.py: 354 passed. tst/unit/env/gateway: 1356 passed. ruff check is clean.
  • Integration tests on local Docker through a token-booted gateway pass.

RetriggerView in GreptileConfidence Score: 5/5

The code appears safe to merge once the stated caller rollout is complete; missing user-sim ATIF copies are non-blocking.

Fix All in CursorFindings

  1. P2 User-sim ATIF copies are missing ▶
Fix with agent prompt
### Issue 1
src/agent_env/task_step/task_steps/prompt_agent.py:570
With `trajectory_formats=["atif/1"]`, `prompt_agent` asks only the solver to build ATIF. It also prompts the user-sim agent and reads its trajectory, but never sends that agent a prescription. The SDK now builds native-only conversations unless told otherwise, so reading the user sim's `atif/1` copy returns `409 format_not_prescribed` despite the run's setting.

Prescribe formats to the user sim before its first message too. The same gap exists in `always_on`. Native trajectories still work, so this is non-blocking.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds control-token checks to older state routes under /svc and blocks those routes through token-protected website routes. The previous website base-path bypass is fixed.

  • Token-enabled gateways now guard legacy state routes reached through service paths.
  • Task lint reports configuration and grading problems before tasks run.
  • Conversations can build selected trajectory formats when a caller asks for them.
  • Computer actions wait for the configured screenshot delay before returning an image.
  • Core model calls share routing and record usage, endpoint, and cost details.
  • Local Docker processes coordinate host-port selection across state roots.
  • Unsorted single-record lookups stop after the first matching store.
  • Supporting configuration, lockfiles, and checks are updated without a separate user-facing behavior change.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  R[Incoming request] --> S{Route}
  S -->|Protected legacy path under /svc| T{Valid control token?}
  T -->|Yes| B[Backing service]
  T -->|No| U[401]
  S -->|Legacy path under /website with token configured| N[404]
  S -->|Ordinary website path| W[Website]
Loading

Reviews (8) · Last reviewed commit: "fix(gateway): read a site route's path u..." · Reviewed by Greptile

@andrewpark-scaleai
andrewpark-scaleai marked this pull request as ready for review November 20, 2026 16:53
@andrewpark-scaleai
andrewpark-scaleai requested a review from a team as a code owner November 20, 2026 16:53
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-callers-send-token branch from 58f18f0 to f3ff3b3 Compare November 20, 2026 17:14
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-routes-take-token branch from ab1fd64 to c614945 Compare November 20, 2026 17:30
Comment thread src/agent_env/env/gateway/gateway.py Resolved
yzabelle-go and others added 9 commits November 20, 2026 11:24
…text remotely, with its tools declared (#841)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…and an agent builds only those (#849)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…elay_ms, so it shows what the input did (#844)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
…utes

LEGACY_STATE_ROUTES lists the older state routes a backing server serves
beside its data plane. On a gateway with a control token, every /svc/<key>/
route takes the token for each of them, after path normalization. A site's
/website route serves none of them. A gateway booted without a token behaves
as before.
A site at http://host/base receives ../base/x as /base/x, which is /x under its base. The route's path check now
reads the path the site receives against the site's own address, decoded, with the base path taken off, so it
matches the same paths the site's card names.
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-routes-take-token branch from c614945 to 475e53d Compare November 20, 2026 23:04
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​openai/​codex@​0.147.0-win32-x64 ⏵ 0.162.1100 +4910093 +14100 +1100

View full report

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.

4 participants