Skip to content

fix(sandbox-kubernetes): support legacy runtimes by default - #4028

Merged
Buktal merged 2 commits into
agentscope-ai:mainfrom
Buktal:codex/sandbox-legacy-runtime
Nov 17, 2026
Merged

Buktal merged 2 commits into
agentscope-ai:mainfrom
Buktal:codex/sandbox-legacy-runtime

Conversation

@Buktal

@Buktal Buktal commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4027. Existing Kubernetes sandbox runtimes can initialize workspaces and execute commands after an SDK upgrade without new configuration.

GET /capabilities
  200 + valid contract -> send command + timeout_seconds
  404                  -> send legacy command-only request
  other failure        -> reject before submission

Legacy HTTP waiting uses the previous timeout + 30 second allowance plus the connector perAttemptTimeout (addressing review feedback). Submitted commands remain single-attempt; HTTP or protocol failures report an unknown execution outcome. English and Chinese runtime-contract docs describe the negotiated behavior.

Evidence

  • Before: a runtime returning 404 for capabilities is rejected before workspace initialization submits mkdir.
  • After: the legacy-runtime regression verifies a successful command-only POST; another test verifies that a failed legacy POST remains UNKNOWN and is submitted once. Existing capability-validation and modern timeout-contract tests remain in place.
  • Targeted upstream-main tests: mvn -T1C -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes -am test -Dtest=CommandExecutorTest,KubernetesSandboxTest,SandboxConnectorRedirectTest -Dsurefire.failIfNoSpecifiedTests=false passed (45 tests), including Spotless.
  • Docs: npm test passed (13/13); npm run validate passed. npm run broken-links reports Service-page links outside the changed runtime paragraphs.
  • Full-repository mvn -B -T1C clean verify on the integration checkout failed in SandboxConnectorRedirectTest.commandWaitsPastConfiguredPerAttemptTimeoutForHeaders: its capability GET exceeded the 200ms network budget under the parallel build. The full test class passed in the targeted upstream-main rerun; the assertion and production timeout remain unchanged. Full-repository verification has not passed.

Merge Danger

Door: two-way — reverting restores mandatory capability negotiation.

Blast Radius: Kubernetes — legacy fallback bounds client waiting only and cannot guarantee remote process termination. A capability 404 may also be caused by routing; the SDK logs the fallback and preserves subsequent execution failures.

@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit dc00987.

Approve preview

@utafrali utafrali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic is correct: executionRequestTimeout returns null on 404, the caller branches to the legacy payload (no timeout_seconds), submissionAttempted is set before the execute POST so a failed response is correctly UNKNOWN, and 404 is not in RETRYABLE_STATUS so capabilities are only probed once. Two minor points worth addressing: the legacy exchange budget (effectiveTimeout + 30s) is smaller than the modern budget by roughly one perAttemptTimeout, which could cause spurious UNKNOWN outcomes on high-latency runtimes; and the success test is missing a capabilityRequests.get() == 1 assertion that would catch regressions to the retry policy.

Duration requestTimeout = executionRequestTimeout(effectiveTimeout);
boolean legacy = requestTimeout == null;
if (legacy) {
requestTimeout = effectiveTimeout.plus(LEGACY_EXCHANGE_MARGIN);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The legacy exchange budget is effectiveTimeout + 30s, but the modern path adds cleanup_timeout_seconds + connector.getPerAttemptTimeout() on top of the command timeout. With the default perAttemptTimeout of 60s, the modern budget for a 60-second command is roughly 60 + 6 + 60 = 126s, while the legacy budget is only 60 + 30 = 90s. On a slow runtime — where the server takes 40–60s to drain output after the command finishes — the client will time out in legacy mode but not in modern mode.

Since perAttemptTimeout is the configured ceiling for how long slow response headers are tolerated, consider mirroring that ceiling here:

requestTimeout = effectiveTimeout.plus(LEGACY_EXCHANGE_MARGIN).plus(connector.getPerAttemptTimeout());

If keeping 30s fixed is intentional (e.g., to avoid inflating budgets for legacy runtimes known to be fast), a brief comment at the constant explaining why perAttemptTimeout is excluded would prevent future confusion.

assertEquals(0, executor(Duration.ofSeconds(2)).run("echo legacy").getExitCode());
assertEquals("echo legacy", payload.get().path("command").asText());
assertFalse(payload.get().has("timeout_seconds"));
assertEquals(1, executions.get());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verifies the payload and execution count but not the number of capability requests. SandboxConnector.RETRYABLE_STATUS currently excludes 404, so the 404 from /capabilities returns without retry and capabilityRequests.get() will be 1. That behavior is load-bearing: if someone adds 404 to the retryable set in the future, every legacy command would silently absorb three capability round-trips before falling back.

Add:

assertEquals(1, capabilityRequests.get());

after the existing assertions to guard this contract explicitly.

@jujn jujn added the P2 重要不紧急 label Nov 7, 2026
# Conflicts:
#	agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes/src/main/java/io/agentscope/extensions/sandbox/kubernetes/client/CommandExecutor.java
@Buktal
Buktal merged commit ca2d637 into agentscope-ai:main Nov 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes sandbox cannot start with legacy runtimes

3 participants