Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/agent_env/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class DeployedGatewayEnv(DeployedSandboxEnv):
env_provider_type: Optional[str] = "gateway"
gateway_url: str
gateway_mode: str = GatewayMode.PERFORMANCE.value
# pgweb's and db-mcp's direct URLs, which only a record an older deploy wrote carries; nothing writes them now.
# Kept for one release so a consumer can still read an env deployed before then. Remove in the release after.
db_web_url: Optional[str] = None
db_mcp_url: Optional[str] = None
# pgweb and db-mcp behind the gateway, which take the control token (``control_headers_for``); None when its image
Expand Down
28 changes: 3 additions & 25 deletions src/agent_env/providers/env_providers/env_gateway_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
)
from agent_env.env.envs.service_db import (
DATABASE_SERVICE_NAME,
DB_MCP_CONTAINER_PORT,
DB_MCP_PORT,
DB_MCP_SERVICE_NAME,
DB_WEB_PORT,
PGWEB_SERVICE_NAME,
)
from agent_env.env.envs.computer.utils.boot import control_environment
Expand Down Expand Up @@ -143,8 +140,6 @@ class DeployedGateway:

gateway_url: str
mcp_url: str
db_web_url: str
db_mcp_url: str | None = None
db_web_gateway_url: str | None = None
db_mcp_gateway_url: str | None = None
website_frontend_urls: dict[str, str] | None = None
Expand Down Expand Up @@ -721,10 +716,8 @@ async def deploy(
env_version=env.version,
env_provider_type=self.type,
gateway_url=deployed.gateway_url,
db_web_url=deployed.db_web_url,
sandbox_id=self._sandbox.sandbox_id, sandbox_type=self._sandbox.type,
sandbox_ids=self._sandbox_ids(always_name_gateway=topology.names_gateway_on_vm),
db_mcp_url=deployed.db_mcp_url,
db_web_gateway_url=deployed.db_web_gateway_url,
db_mcp_gateway_url=deployed.db_mcp_gateway_url,
environment_card_url=f"{deployed.gateway_url}{WELL_KNOWN_PATH}",
Expand Down Expand Up @@ -883,7 +876,7 @@ async def _deploy_via_vm(
if memory_mb is not None:
vm_kwargs["memory"] = memory_mb
self._sandbox = await sandbox_provider.create_vm(
exposed_ports=[gateway_port, DB_WEB_PORT, DB_MCP_PORT] + [sc.host_port for sc in sidecars],
exposed_ports=[gateway_port] + [sc.host_port for sc in sidecars],
timeout=ttl_seconds,
disk_size_gb=disk_size_gb,
attribution=attribution,
Expand Down Expand Up @@ -1003,13 +996,6 @@ async def _stand_up(_spec):
logger.warning(f"{name} container not found")

gateway_url = sandbox.tunnel_urls.get(gateway_port)
db_web_base_url = sandbox.tunnel_urls.get(DB_WEB_PORT) if PGWEB_SERVICE_NAME in sidecar_names else None
db_web_url = f"{db_web_base_url}/" if db_web_base_url else None
db_mcp_base_url = sandbox.tunnel_urls.get(DB_MCP_PORT) if DB_MCP_SERVICE_NAME in sidecar_names else None
db_mcp_url = f"{db_mcp_base_url}/mcp" if db_mcp_base_url else None
logger.info(f"pgweb URL: {db_web_url}")
if db_mcp_url:
logger.info(f"DB MCP endpoint: {db_mcp_url}")

# Wait for the tunnel to serve the env card, which the deploy records
card = await self._wait_for_tunnel(gateway_url, timeout=120)
Expand All @@ -1030,8 +1016,7 @@ async def _stand_up(_spec):

logger.info(f"Gateway URL: {gateway_url}")
return DeployedGateway(
gateway_url=gateway_url, mcp_url=mcp_url, db_web_url=db_web_url, db_mcp_url=db_mcp_url,
db_web_gateway_url=consoles.get(PGWEB_SERVICE_NAME), db_mcp_gateway_url=consoles.get(DB_MCP_SERVICE_NAME),
gateway_url=gateway_url, mcp_url=mcp_url, db_web_gateway_url=consoles.get(PGWEB_SERVICE_NAME), db_mcp_gateway_url=consoles.get(DB_MCP_SERVICE_NAME),
website_frontend_urls=website_frontend_urls, mcp_server_name=mcp_server_name,
env_state_instance_ids=[state_instance.instance_id],
environment_card=card, environment_card_read_at_utc=card_read_at_utc, control_token=control_token,
Expand Down Expand Up @@ -1113,8 +1098,6 @@ async def _deploy_via_containers(
external: list[ExternalChild] = []

mcp_results: list[tuple[str, "Sandbox"]] = []
pgweb_sb = None
db_mcp_sb = None
consoles: dict[str, str] = {}
errors: list[BaseException] = []
for i, r in enumerate(all_results):
Expand All @@ -1133,10 +1116,8 @@ async def _deploy_via_containers(
if r.private_host:
consoles[spec.name] = f"http://{r.private_host}:{spec.port}"
if spec.name == PGWEB_SERVICE_NAME:
pgweb_sb = r
self._pgweb_sandbox = r
elif spec.name == DB_MCP_SERVICE_NAME:
db_mcp_sb = r
self._db_mcp_sandbox = r

if errors:
Expand Down Expand Up @@ -1186,14 +1167,10 @@ async def _deploy_via_containers(
card_read_at_utc = datetime.now(timezone.utc).isoformat()
await self._refuse_tool_name_clashes(gateway_url)

db_web_url = pgweb_sb.tunnel_urls[DB_WEB_PORT] + "/" if pgweb_sb else None
db_mcp_url = db_mcp_sb.tunnel_urls[DB_MCP_CONTAINER_PORT] + "/mcp" if db_mcp_sb else None
served = await self._served_consoles(gateway_url, consoles, control_token)
return DeployedGateway(
gateway_url=gateway_url,
mcp_url=_mcp_url(gateway_url, card),
db_web_url=db_web_url,
db_mcp_url=db_mcp_url,
db_web_gateway_url=served.get(PGWEB_SERVICE_NAME),
db_mcp_gateway_url=served.get(DB_MCP_SERVICE_NAME),
website_frontend_urls=None,
Expand Down Expand Up @@ -1401,6 +1378,7 @@ async def _provision_sidecar(self, deploy: _ContainerDeploy, spec) -> Sandbox:
command=spec.command,
**_size_kwargs(deploy.cpu, None),
disk_size_gb=deploy.disk_size_gb, timeout=deploy.ttl_seconds,
expose_externally=False,
attribution=deploy.attribution,
private_network=True,
)
Expand Down
12 changes: 2 additions & 10 deletions src/agent_env/providers/env_state/local_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from agent_env.env.envs.service_db import (
DATABASE_SERVICE_NAME,
DB_MCP_CONTAINER_PORT,
DB_MCP_PORT,
DB_MCP_SERVICE_NAME,
DB_NAME,
DB_PASSWORD,
Expand All @@ -30,7 +29,6 @@
PGWEB_SERVICE_NAME,
SERVICE_DB_PORT,
)
from agent_env.providers.sandbox_providers.sandbox import port_bindings
from agent_env.providers.env_state.env_state_provider import (
DatabaseStateProvider,
DEFAULT_STATE_TTL_SECONDS,
Expand Down Expand Up @@ -258,10 +256,8 @@ def render_sidecar_containers(
host_ips: tuple[str, ...] = (),
) -> list[str]:
"""The pgweb + db-mcp direct-SQL browse UIs (VM/compose path), each gated on the
servicedb's health. Beyond the mandatory readiness service."""
# Opened from the host only, so kept off the bridge address containers reach the host through.
host_ips = host_ips[:1]
publish = host_port or (lambda port: port)
servicedb's health. Beyond the mandatory readiness service. Neither publishes a port: only the gateway reaches
them, on the env's network, behind its control token."""
cfg = self.service_db_config
lines: list[str] = []
if cfg.db_web_image:
Expand All @@ -278,8 +274,6 @@ def render_sidecar_containers(
# sidecar_specs for why: Disconnect tore down pgweb's shared
# session and 500'd the changelog export on Save & Next).
" - PGWEB_LOCK_SESSION=true",
" ports:",
*(f' - "{spec}"' for spec in port_bindings(host_ips, publish(DB_WEB_PORT), DB_WEB_PORT)),
" networks:",
" - env-network",
"",
Expand All @@ -295,8 +289,6 @@ def render_sidecar_containers(
" environment:",
f" - DATABASE_URI={self._pg_url(DATABASE_SERVICE_NAME, scheme='postgresql')}",
" command: --transport=streamable-http --streamable-http-host=0.0.0.0 --access-mode=unrestricted",
" ports:",
*(f' - "{spec}"' for spec in port_bindings(host_ips, publish(DB_MCP_PORT), DB_MCP_CONTAINER_PORT)),
" networks:",
" - env-network",
"",
Expand Down
2 changes: 1 addition & 1 deletion tst/integration/env/custom_env_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def deploy(self, **kwargs) -> DeployedEnv:
env_id=self.id, env_version=self.version or 1,
gateway_url=f"https://gw.example/{self.id}",
mcp_url=f"https://mcp.example/{self.id}",
db_web_url=None, sandbox_id=f"sbx-{self.id}",
sandbox_id=f"sbx-{self.id}",
metadata={"deployed_by": type(self).__name__, "flavor": self.flavor},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _assert_journal_matches(instance_id: str, n: int) -> None:
def _env(instance_id: str) -> DeployedEnv:
return DeployedGatewayEnv(
env_id="e", env_version=1, gateway_url="g", mcp_url="m",
db_web_url=None, sandbox_id="s", instance_id=instance_id,
sandbox_id="s", instance_id=instance_id,
)


Expand Down
2 changes: 1 addition & 1 deletion tst/unit/cli/deploy_vm_sizing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def fake_deploy(**kwargs):
captured.update(kwargs)
return DeployedGatewayEnv(
env_id="e1", env_version=1, gateway_url="http://gw", mcp_url="http://mcp",
db_web_url=None, sandbox_id="s1",
sandbox_id="s1",
)

fake_env = MagicMock(id="e1", version=1, type="multi")
Expand Down
4 changes: 1 addition & 3 deletions tst/unit/cli/deployed_env_output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ def test_task_run_prints_a_gateway_record_as_before_and_omits_a_missing_gateway(

_CONSOLES = DeployedGatewayEnv(env_id="e1", env_version=1, gateway_url="https://gw.example",
mcp_url="https://gw.example/mcp", sandbox_id="gw", instance_id="i1",
db_web_url="https://tunnel-8081.example/", db_mcp_url="https://tunnel-18767.example/mcp",
db_web_gateway_url="https://gw.example/svc/pgweb/",
db_mcp_gateway_url="https://gw.example/svc/db-mcp/mcp")


def test_the_cli_prints_the_sql_consoles_at_the_gateway_and_never_their_tunnels():
def test_the_cli_prints_the_sql_consoles_at_the_gateway():
async def fake_deploy(**kwargs):
return _CONSOLES

Expand All @@ -66,7 +65,6 @@ async def fake_deploy(**kwargs):
got = CliRunner().invoke(env_cli, ["get-instance", "--id", "i1"]).output
for output in (deployed, got, _format_env(_CONSOLES)):
assert "https://gw.example/svc/pgweb/" in output and "https://gw.example/svc/db-mcp/mcp" in output
assert "tunnel-" not in output


def test_a_record_outside_our_sandboxes_prints_no_sandbox():
Expand Down
2 changes: 1 addition & 1 deletion tst/unit/cli/env_state_type_parity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def _fake_deployed() -> DeployedEnv:
return DeployedGatewayEnv(
env_id="e1", env_version=1, gateway_url="http://gw", mcp_url="http://mcp",
db_web_url=None, sandbox_id="s1",
sandbox_id="s1",
)


Expand Down
7 changes: 3 additions & 4 deletions tst/unit/env/envs/test_env_card_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def test_a_standalone_env_keeps_the_record_it_deploys(make, module):
env = make()
provider = MagicMock(
spec=EnvironmentGatewayProvider, sandbox=SimpleNamespace(sandbox_id="sb-1", type="vm"),
deploy=AsyncMock(return_value=DeployedGatewayEnv(env_id="e", env_version=1, gateway_url=_GW, mcp_url=f"{_GW}/mcp", db_web_url=None, sandbox_id="sb-1")),
deploy=AsyncMock(return_value=DeployedGatewayEnv(env_id="e", env_version=1, gateway_url=_GW, mcp_url=f"{_GW}/mcp", sandbox_id="sb-1")),
_environment_sandboxes={},
)
provider.environment_sandbox.return_value = None
Expand Down Expand Up @@ -204,7 +204,7 @@ async def test_multi_env_deploy_hands_its_record_to_every_child_env():
container = MagicMock()
provider.environment_sandbox.side_effect = lambda name: container if name == "email" else None # container mode: the server's own
provider.deploy = AsyncMock(return_value=DeployedGatewayEnv(env_id="multi", env_version=1, gateway_url=_GW, mcp_url=f"{_GW}/mcp",
db_web_url=None, sandbox_id="sb-1"))
sandbox_id="sb-1"))

with patch("agent_env.providers.build_env_provider", return_value=provider), \
patch("agent_env.providers.get_env_sandbox_provider", MagicMock()), \
Expand Down Expand Up @@ -297,8 +297,7 @@ async def fetch(client, key, base_url):

def _record(card: dict | None) -> DeployedEnv:
return DeployedGatewayEnv(
env_id="multi", env_version=1, gateway_url=_GW, mcp_url=f"{_GW}/mcp", db_web_url=None,
sandbox_id="sb-1", environment_card_url=f"{_CARD}{WELL_KNOWN_PATH}", environment_card=card,
env_id="multi", env_version=1, gateway_url=_GW, mcp_url=f"{_GW}/mcp", sandbox_id="sb-1", environment_card_url=f"{_CARD}{WELL_KNOWN_PATH}", environment_card=card,
)


Expand Down
2 changes: 1 addition & 1 deletion tst/unit/env/envs/test_mcp_server_container_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ async def deploy_path(sandbox_provider, mcp_servers, mcp_server_images, **kwargs
gp._environment_sandboxes = {"email": sandboxes["srv"]}
gp._db_sandbox, gp._pgweb_sandbox, gp._db_mcp_sandbox = sandboxes.get("db"), sandboxes.get("pg"), sandboxes.get("dm")
gp._container_sandboxes = [sandboxes[i] for i in ("db", "srv", "pg", "dm", "gw") if i in sandboxes]
return DeployedGateway(gateway_url=_GW, mcp_url=f"{_GW}/mcp", db_web_url=None, db_mcp_url=None, mcp_server_name=kwargs["mcp_server_name"],
return DeployedGateway(gateway_url=_GW, mcp_url=f"{_GW}/mcp", mcp_server_name=kwargs["mcp_server_name"],
env_state_instance_ids=["st-1"], environment_card=_CARD, environment_card_read_at_utc="2026-09-26T00:00:00+00:00")

async def server_path(env, sandbox_provider, **kwargs):
Expand Down
5 changes: 2 additions & 3 deletions tst/unit/env/envs/test_multi_env_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ def test_random_default_is_env_plus_four_digits():


def test_deployed_env_records_the_gateway_name():
base = dict(env_id="e", env_version=1, gateway_url="g", mcp_url="m", db_web_url=None, sandbox_id="s")
base = dict(env_id="e", env_version=1, gateway_url="g", mcp_url="m", sandbox_id="s")
assert DeployedEnv.from_dict({**base, "mcp_server_name": "env4821"}).mcp_server_name == "env4821"
assert DeployedEnv.from_dict(base).mcp_server_name is None


@pytest.mark.asyncio
async def test_a_deploy_records_the_mcp_url_and_name_its_gateway_card_gives():
card = {"name": "crm", "additionalInterfaces": [{"url": "/mcp", "transport": "mcp"}]}
result = SimpleNamespace(gateway_url="https://gw.example", mcp_url="https://gw.example/mcp", db_web_url=None, db_mcp_url=None,
db_web_gateway_url="https://gw.example/svc/pgweb/",
result = SimpleNamespace(gateway_url="https://gw.example", mcp_url="https://gw.example/mcp", db_web_gateway_url="https://gw.example/svc/pgweb/",
db_mcp_gateway_url="https://gw.example/svc/db-mcp/mcp",
website_frontend_urls=None, environment_card=card, environment_card_read_at_utc="t",
env_state_instance_ids=[], mcp_server_name="crm", control_token="t0k")
Expand Down
4 changes: 2 additions & 2 deletions tst/unit/env/envs/test_multi_env_plugin_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async def deploy_gateway(self, sandbox_provider, **kwargs):
if len(calls) > 1:
raise RuntimeError("second boom")
self._sandbox = vm
return DeployedGateway(gateway_url="https://gw", mcp_url="https://gw/mcp", db_web_url=None)
return DeployedGateway(gateway_url="https://gw", mcp_url="https://gw/mcp")

env = _multi("gateway", websites=())
with patch.object(EnvironmentGatewayProvider, "_deploy_gateway", deploy_gateway), \
Expand Down Expand Up @@ -434,7 +434,7 @@ async def test_close_after_two_successful_gateway_deploys_terminates_both_vms():

async def deploy_gateway(self, sandbox_provider, **kwargs):
self._sandbox = next(created)
return DeployedGateway(gateway_url="https://gw", mcp_url="https://gw/mcp", db_web_url=None)
return DeployedGateway(gateway_url="https://gw", mcp_url="https://gw/mcp")

env = _multi("gateway", websites=())
with patch.object(EnvironmentGatewayProvider, "_deploy_gateway", deploy_gateway), \
Expand Down
3 changes: 1 addition & 2 deletions tst/unit/env/envs/test_multi_env_snapshot_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ async def test_snapshot_capture_gated_off_for_remote_backend():
early with a clear error — not a cryptic 'servicedb container not found' deep in the capture."""
from agent_env.env.snapshot_store import EnvSnapshot

deployed = DeployedGatewayEnv(env_id="env-1", env_version=1, sandbox_id="sb-1", gateway_url="https://gw", mcp_url="https://gw/mcp",
db_web_url=None)
deployed = DeployedGatewayEnv(env_id="env-1", env_version=1, sandbox_id="sb-1", gateway_url="https://gw", mcp_url="https://gw/mcp")
inst_store = MagicMock()
inst_store.get.return_value = deployed
inst_store.get_environment_universe.return_value = {"id": "universe-1", "version": 1}
Expand Down
4 changes: 2 additions & 2 deletions tst/unit/env/store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_deployed_env_roundtrip_preserves_all_fields():
env_version=3,
gateway_url="https://gw.example/",
mcp_url="https://gw.example/mcp",
db_web_url="https://gw.example/dbweb/",
db_web_gateway_url="https://gw.example/svc/pgweb/",
sandbox_id="sb-abc",
db_mcp_url="https://gw.example/dbmcp/mcp",
db_mcp_gateway_url="https://gw.example/svc/db-mcp/mcp",
website_frontend_urls={"a": "https://gw.example/site/a/"},
sandbox_type="modal",
vnc_url="vnc://example:5900",
Expand Down
2 changes: 1 addition & 1 deletion tst/unit/env/task_step/test_context_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def _env(instance_id: str = "i1") -> DeployedEnv:
return DeployedGatewayEnv(
env_id="e", env_version=1, gateway_url="g", mcp_url="m",
db_web_url=None, sandbox_id="s", instance_id=instance_id,
sandbox_id="s", instance_id=instance_id,
)


Expand Down
4 changes: 2 additions & 2 deletions tst/unit/env/task_step/verify_env_card_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _make_context():
ctx = TaskStepContext()
ctx.deployed_envs = [DeployedGatewayEnv(
env_id="e1", env_version=3, gateway_url="https://gw", mcp_url="https://gw/mcp",
db_web_url=None, sandbox_id="sb", environment_card_url=f"https://gw{WELL_KNOWN_PATH}",
sandbox_id="sb", environment_card_url=f"https://gw{WELL_KNOWN_PATH}",
)]
return ctx

Expand Down Expand Up @@ -154,7 +154,7 @@ class TestWire:
def test_reads_the_card_at_its_address(self, gateway_url):
base = gateway_url.rstrip("/")
ctx = TaskStepContext(deployed_envs=[DeployedGatewayEnv(
env_id="e1", env_version=3, gateway_url=gateway_url, mcp_url=f"{base}/mcp", db_web_url=None, sandbox_id="sb",
env_id="e1", env_version=3, gateway_url=gateway_url, mcp_url=f"{base}/mcp", sandbox_id="sb",
environment_card_url=f"{gateway_url}{WELL_KNOWN_PATH}",
)])
sent = []
Expand Down
4 changes: 2 additions & 2 deletions tst/unit/env/task_step/verify_env_core_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _make_context():
ctx = TaskStepContext()
ctx.deployed_envs = [DeployedGatewayEnv(
env_id="e1", env_version=3, gateway_url="https://gw", mcp_url="https://gw/mcp",
db_web_url=None, sandbox_id="sb", environment_card_url=f"https://gw{WELL_KNOWN_PATH}",
sandbox_id="sb", environment_card_url=f"https://gw{WELL_KNOWN_PATH}",
)]
return ctx

Expand Down Expand Up @@ -154,7 +154,7 @@ class TestWire:
def test_reads_the_card_and_probes_the_data_plane_at_the_cards_address(self, gateway_url):
base = gateway_url.rstrip("/")
ctx = TaskStepContext(deployed_envs=[DeployedGatewayEnv(
env_id="e1", env_version=3, gateway_url=gateway_url, mcp_url=f"{base}/mcp", db_web_url=None, sandbox_id="sb",
env_id="e1", env_version=3, gateway_url=gateway_url, mcp_url=f"{base}/mcp", sandbox_id="sb",
environment_card_url=f"{gateway_url}{WELL_KNOWN_PATH}", control_token="s3cret",
)])
sent = []
Expand Down
Loading
Loading