Skip to content
Merged
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
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ The Python SDK installs its execution backend automatically. Preserve the
public `AKERNEL_SERVER_ADDRESS=host[:port]` and `AKERNEL_TOKEN` contract.
Retired backend selector names map to ADX without installing old dependencies.
Native conversions remain under `akernel_sdk._backends`.
`HttpReverseTunnel.http_timeout_seconds` configures both endpoints on fresh
creation through the typed ADX option. Snapshot restores inherit the confirmed
captured setting; reconnecting configures only the local client. Keep HTTP wait
separate from WebSocket setup and preserve the reserved environment-key rules.
Lifecycle wrappers use explicit by-ID lookup/deletion, lazy filtered pagination
and an isolated Client; preserve legacy constructor, id, detached kill and
unchecked CommandResult behavior. close disconnects locally; pause/connect keep
Expand Down
22 changes: 11 additions & 11 deletions builder/managed-docker/qualification-sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"candidate_gitlinks": {
"sandboxd": "fe00128018c0124880f97b565aa0be0f07efc072",
"agent_dx": "4bfeef698cdc12b3993bea51c076dd1c55b5b695"
"agent_dx": "3d8e2f7d77819bc04d9f16907292e52978960acb"
},
"pinned_runtime_artifacts": {
"gvisor": {
Expand All @@ -32,21 +32,21 @@
},
"native_adx_sdk": {
"package": "adx-environment",
"version": "0.1.0rc14",
"publication_commit": "4bfeef698cdc12b3993bea51c076dd1c55b5b695",
"package_source_commit": "4bfeef698cdc12b3993bea51c076dd1c55b5b695",
"note": "The package index dependency is pinned in sdk/python/pyproject.toml."
"version": "0.1.0rc15",
"publication_commit": "027214542f46df625f719cb9279ef55438eb0e0b",
"package_source_commit": "027214542f46df625f719cb9279ef55438eb0e0b",
"note": "The package index dependency is pinned in sdk/python/pyproject.toml. The platform archive bundles identical wheel contents from this SDK source."
},
"afs_enabled": true,
"envd_enabled": false,
"publication_requirement": "The AMD64 platform and Execd archives must come from the same Agent DX build. Verify their SHA-256 checksums, manifests, and ELF architecture before packaging.",
"agent_dx_platform_artifacts": {
"source_commit": "4bfeef698cdc12b3993bea51c076dd1c55b5b695",
"publication": "https://buildkite.com/agent-dx/agent-dx/builds/313",
"platform_url": "https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261126154755-4bfeef698cdc/linux/amd64/adx-release.tar.gz",
"platform_sha256": "f85a04bffb1a1ed1f366a2b7f86a398c2527f4e16b7c91c59f5137ab2c04d9c3",
"execd_url": "https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261126154755-4bfeef698cdc/linux/amd64/adx-execd.tar.gz",
"execd_sha256": "41d8fd1c5c381ad0f852b4cfc8a50530bcb1141034c9d1b9451cf1a13fa53432",
"source_commit": "3d8e2f7d77819bc04d9f16907292e52978960acb",
"publication": "https://buildkite.com/agent-dx/agent-dx/builds/322",
"platform_url": "https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261130094634-3d8e2f7d7781/linux/amd64/adx-release.tar.gz",
"platform_sha256": "856259b545e0eeacf014fbb9e2f43766f442d9f562b8c2b80f3f9c9221414e31",
"execd_url": "https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261130094634-3d8e2f7d7781/linux/amd64/adx-execd.tar.gz",
"execd_sha256": "66eee2e12f8f7835679e8cfb6317b88b3525a456523d3265ca71f56841f93154",
"status": "Verified archive and manifest checksums, AMD64 ELF architecture, and matching Execd and runtime rootfs contents."
}
}
6 changes: 3 additions & 3 deletions builder/node.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ ARG OTELCOL_CONTRIB_URL=
ARG OTELCOL_CONTRIB_SHA256=
ARG AKERNEL_VERSION=unknown
ARG AKERNEL_REVISION=unknown
ARG ADX_VERSION=v0.1.0rc14
ARG ADX_RELEASE_URL=https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261126154755-4bfeef698cdc/linux/amd64/adx-release.tar.gz
ARG ADX_RELEASE_SHA256=f85a04bffb1a1ed1f366a2b7f86a398c2527f4e16b7c91c59f5137ab2c04d9c3
ARG ADX_VERSION=v0.1.0rc15
ARG ADX_RELEASE_URL=https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261130094634-3d8e2f7d7781/linux/amd64/adx-release.tar.gz
ARG ADX_RELEASE_SHA256=856259b545e0eeacf014fbb9e2f43766f442d9f562b8c2b80f3f9c9221414e31

FROM ${AKERNEL_NODE_BASE_IMAGE} AS adx-release
ARG ADX_RELEASE_URL
Expand Down
6 changes: 3 additions & 3 deletions builder/runtime.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0

ARG AKERNEL_RUNTIME_BASE_IMAGE=ubuntu:24.04
ARG ADX_VERSION=v0.1.0rc14
ARG ADX_EXECD_URL=https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261126154755-4bfeef698cdc/linux/amd64/adx-execd.tar.gz
ARG ADX_EXECD_SHA256=41d8fd1c5c381ad0f852b4cfc8a50530bcb1141034c9d1b9451cf1a13fa53432
ARG ADX_VERSION=v0.1.0rc15
ARG ADX_EXECD_URL=https://agent-dx.obs.cn-southwest-2.myhuaweicloud.com/adx/daily/20261130094634-3d8e2f7d7781/linux/amd64/adx-execd.tar.gz
ARG ADX_EXECD_SHA256=66eee2e12f8f7835679e8cfb6317b88b3525a456523d3265ca71f56841f93154

FROM ${AKERNEL_RUNTIME_BASE_IMAGE} AS adx-execd
ARG ADX_EXECD_URL
Expand Down
4 changes: 2 additions & 2 deletions builder/scripts/test_runtime_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def test_sdk_metadata_has_no_actor_runtime_dependency(self) -> None:
normalized = {item.split("=", 1)[0].lower() for item in requirements}
self.assertNotIn("openyuanrong-sdk", normalized)

def test_sdk_uses_the_environment_rc14_dependency(self) -> None:
def test_sdk_uses_the_environment_rc15_dependency(self) -> None:
metadata = tomllib.loads((ROOT / "sdk/python/pyproject.toml").read_text())
self.assertIn("adx-environment==0.1.0rc14", metadata["project"]["dependencies"])
self.assertIn("adx-environment==0.1.0rc15", metadata["project"]["dependencies"])

def test_actor_backend_sources_are_absent(self) -> None:
backend = ROOT / "sdk/python/akernel_sdk/_backends"
Expand Down
18 changes: 17 additions & 1 deletion sdk/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ tunnel = HttpReverseTunnel(
reverse_port=8765,
listen_port=8766,
connect_timeout=60,
http_timeout_seconds=3600,
)

with Sandbox(reverse_tunnel=tunnel) as sandbox:
Expand All @@ -1052,6 +1053,21 @@ the loopback HTTP listener used inside the sandbox. Consequently,
`sandbox.reverse_tunnel.url` is always
`http://127.0.0.1:<listen_port>`, even when `target` uses HTTPS.

`http_timeout_seconds` sets the HTTP wait for a new sandbox's Execd and the
SDK-side tunnel client. It accepts integer seconds from 1 through 86400.
The backend checks server support before creation and requires the server to
confirm the requested value. This is independent of `connect_timeout`, which
bounds WebSocket setup. When omitted, the server keeps its deployment default
and the client uses its `ADX_TUNNEL_HTTP_TIMEOUT` setting (600 seconds by default)
unless the server returns an explicit saved value. Do not pass this reserved
environment variable through sandbox `envs`.

Named creation keeps the existing sandbox's setting and rejects an explicit
timeout that differs. Snapshot restore inherits the captured timeout; it does
not apply the tunnel descriptor's creation-time value. When reconnecting with
`Sandbox.connect`, pass the original timeout to configure the new local client;
reconnecting does not change Execd's saved configuration.

For an HTTPS target, the SDK-side tunnel client performs the TLS handshake and
certificate verification. The sandbox application talks only to its loopback
HTTP listener. AKernel supports one HTTP/HTTPS reverse tunnel per sandbox and
Expand Down Expand Up @@ -1424,7 +1440,7 @@ not part of the default test suite.
| `NodeInfo` | `id`, `status`, `capacity`, `allocatable`, `labels` |
| `S3Config` | `endpoint`, `bucket`, `object`, optional credentials |
| `Mount` | `target`, exactly one of `image_url` / `s3_config` / `host_path`, `type`, `read_only` (default `True`; writable only for HostPath) |
| `HttpReverseTunnel` | `target`, `reverse_port`, `listen_port`, `connect_timeout` |
| `HttpReverseTunnel` | `target`, `reverse_port`, `listen_port`, `connect_timeout`, `http_timeout_seconds` |
| `PortRange` | `first`, `last` |
| `NetworkRule` | action, direction, protocol, peer and sandbox port selectors, priority |
| `TrafficPolicy` | independent ingress/egress defaults, rules, mode |
Expand Down
15 changes: 15 additions & 0 deletions sdk/python/akernel_sdk/_backends/adx.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ def _bind_tunnel(sandbox: Any, tunnel: Any, connection: Any) -> None:
tls = connection.gateway_use_tls
scheme = "wss" if tls else "ws"
safe_id = sandbox._client._safe_id(sandbox.id)
timeout_options = (
{}
if tunnel.http_timeout_seconds is None
else {"http_timeout_seconds": tunnel.http_timeout_seconds}
)
client = TunnelClient(
tunnel.target,
token=connection.resolved_token() if tls else None,
environment_id=sandbox.id,
**timeout_options,
)
sandbox._tunnel_client = client
sandbox._upstream = tunnel.target
Expand Down Expand Up @@ -1602,6 +1608,13 @@ def create(self, spec: SandboxSpec) -> BackendSession:
),
connection=self._connection,
)
if (
spec.reverse_tunnel is not None
and spec.reverse_tunnel.http_timeout_seconds is not None
):
create_args["tunnel_http_timeout_seconds"] = (
spec.reverse_tunnel.http_timeout_seconds
)
if affinities is not None:
create_args["schedule_affinities"] = affinities
try:
Expand Down Expand Up @@ -1660,6 +1673,8 @@ def _restore_snapshot(spec: SnapshotRestoreSpec, connection: Any) -> BackendSess
)
started = time.monotonic()
try:
# The native constructor uses the timeout confirmed from the snapshot;
# the tunnel descriptor's fresh-create value must not override it.
sandbox = _OwnedSandbox.create(
spec.snapshot_id,
idle_timeout=spec.idle_timeout,
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/akernel_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,17 @@ class HttpReverseTunnel:
``reverse_port`` carries the WebSocket tunnel through the AKernel gateway.
Sandbox applications call :attr:`url`, which points at the loopback HTTP
listener on ``listen_port``.
``http_timeout_seconds`` configures the HTTP wait on both tunnel endpoints
when creating a sandbox. It accepts integer seconds from 1 through 86400;
``None`` preserves the existing defaults. Snapshot restores inherit their
captured server setting. Reconnecting sets only the local client's wait.
"""

target: str
reverse_port: int = 8765
listen_port: int = 8766
connect_timeout: float = 60.0
http_timeout_seconds: int | None = None

def __post_init__(self) -> None:
if not isinstance(self.target, str) or not self.target.strip():
Expand Down Expand Up @@ -649,6 +654,13 @@ def __post_init__(self) -> None:
raise TypeError("connect_timeout must be a number") from error
if timeout <= 0:
raise ValueError("connect_timeout must be greater than 0")
if self.http_timeout_seconds is not None:
if isinstance(self.http_timeout_seconds, bool) or not isinstance(
self.http_timeout_seconds, int
):
raise TypeError("http_timeout_seconds must be an integer")
if not 1 <= self.http_timeout_seconds <= 86400:
raise ValueError("http_timeout_seconds must be between 1 and 86400")

@property
def url(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions sdk/python/examples/reverse_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def main() -> None:
target=f"http://127.0.0.1:{local_port}",
reverse_port=8765,
listen_port=8766,
http_timeout_seconds=3600,
)
try:
with Sandbox(
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "akernel-sdk"
version = "0.2.0rc11"
version = "0.2.0rc12"
description = "Python SDK and CLI for AKernel remote sandboxes"
readme = "README.md"
license = "Apache-2.0"
Expand All @@ -28,7 +28,7 @@ classifiers = [
"Topic :: System :: Distributed Computing",
]
dependencies = [
"adx-environment==0.1.0rc14",
"adx-environment==0.1.0rc15",
"idna>=3,<4",
"httpx>=0.27,<1",
"PyYAML>=6,<7",
Expand Down
134 changes: 134 additions & 0 deletions sdk/python/tests/unit/test_reverse_tunnel_timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Copyright (c) 2026 Ant Group Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Per-sandbox HTTP timeout through the real ADX request encoder."""

import json
import unittest
from unittest.mock import MagicMock, patch

import httpx

from akernel_sdk import HttpReverseTunnel
from akernel_sdk._addresses import Endpoint
from akernel_sdk._backends import adx
from akernel_sdk._backends.base import BackendConfig
from tests.unit.test_adx_backend import _spec
from tests.unit.test_restore_failures import restore_spec


class ReverseTunnelTimeoutTest(unittest.TestCase):
def setUp(self):
self.backend = adx.AdxBackend(
BackendConfig(
Endpoint("api.example", 443, "https", True),
Endpoint("gateway.example", 443, "https", True),
"test-only",
True,
)
)

def exercise(self, seconds, *, restore=False):
calls = []
bodies = []

def send(_client, request, **_kwargs):
calls.append((request.method, request.url.path))
if request.url.path.endswith("/capabilities"):
return httpx.Response(
200,
json={"capabilities": ["tunnel-http-timeout-v1"]},
request=request,
)
if request.url.path.endswith("/environments"):
bodies.append(json.loads(request.content))
tunnel = {}
if seconds is not None:
tunnel["httpTimeoutSeconds"] = seconds
payload = {
"environmentId": "default-timeout-test",
"status": "running",
"newlyCreated": True,
"tunnel": tunnel,
}
return httpx.Response(
200,
headers={"content-type": "text/event-stream"},
content="event: final\ndata: " + json.dumps(payload) + "\n\n",
request=request,
)
return httpx.Response(200, json={"processes": []}, request=request)

tunnel = HttpReverseTunnel(
"http://127.0.0.1:9000", http_timeout_seconds=seconds
)
with (
patch.object(httpx.Client, "send", autospec=True, side_effect=send),
patch("adx_environment.tunnel_client.TunnelClient") as client,
):
client.return_value.start.return_value = True
if restore:
session = self.backend.from_snapshot(
restore_spec(reverse_tunnel=tunnel)
)
else:
session = self.backend.create(_spec(reverse_tunnel=tunnel))
client_options = client.call_args.kwargs
session.close()
self.assertEqual(len(bodies), 1)
self.assertNotIn("ADX_TUNNEL_HTTP_TIMEOUT", bodies[0].get("env", {}))
return calls, bodies[0], client_options

def test_fresh_create_confirms_timeout_and_configures_both_ends(self):
calls, body, client = self.exercise(3600)
self.assertEqual(calls[0][1], "/api/environment/v1/capabilities")
self.assertEqual(body["tunnel"]["httpTimeoutSeconds"], 3600)
self.assertEqual(client["http_timeout_seconds"], 3600)

def test_omitted_timeout_preserves_deployment_and_sdk_defaults(self):
calls, body, client = self.exercise(None)
self.assertFalse(any(path.endswith("/capabilities") for _, path in calls))
self.assertNotIn("httpTimeoutSeconds", body["tunnel"])
self.assertNotIn("http_timeout_seconds", client)

def test_snapshot_restore_inherits_without_sending_a_timeout_override(self):
calls, body, client = self.exercise(3600, restore=True)
self.assertEqual(body["snapshotId"], "saved")
self.assertNotIn("httpTimeoutSeconds", body["tunnel"])
self.assertFalse(any(path.endswith("/capabilities") for _, path in calls))
self.assertEqual(client["http_timeout_seconds"], 3600)

def test_rebinding_preserves_explicit_client_timeout(self):
sandbox = MagicMock(id="default-timeout-test")
tunnel = HttpReverseTunnel(
"http://127.0.0.1:9000", http_timeout_seconds=3600
)
with patch.object(adx, "TunnelClient") as client:
client.return_value.start.return_value = True
adx._bind_tunnel(sandbox, tunnel, self.backend._connection)
self.assertEqual(client.call_args.kwargs["http_timeout_seconds"], 3600)

def test_http_timeout_validates_integer_seconds(self):
for seconds in (1, 3600, 86400):
self.assertEqual(
HttpReverseTunnel("localhost:9000", http_timeout_seconds=seconds)
.http_timeout_seconds,
seconds,
)
for seconds in (True, 1.5, "3600"):
with self.subTest(seconds=seconds), self.assertRaises(TypeError):
HttpReverseTunnel("localhost:9000", http_timeout_seconds=seconds)
for seconds in (0, -1, 86401):
with self.subTest(seconds=seconds), self.assertRaises(ValueError):
HttpReverseTunnel("localhost:9000", http_timeout_seconds=seconds)
2 changes: 1 addition & 1 deletion src/agent-dx
Submodule agent-dx updated 260 files
Loading