Repository navigation
fix(sandbox-kubernetes): support legacy runtimes by default - #4028
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
utafrali
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
# Conflicts: # agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes/src/main/java/io/agentscope/extensions/sandbox/kubernetes/client/CommandExecutor.java
Summary
Fixes #4027. Existing Kubernetes sandbox runtimes can initialize workspaces and execute commands after an SDK upgrade without new configuration.
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
mvn -T1C -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes -am test -Dtest=CommandExecutorTest,KubernetesSandboxTest,SandboxConnectorRedirectTest -Dsurefire.failIfNoSpecifiedTests=falsepassed (45 tests), including Spotless.npm testpassed (13/13);npm run validatepassed.npm run broken-linksreports Service-page links outside the changed runtime paragraphs.mvn -B -T1C clean verifyon the integration checkout failed inSandboxConnectorRedirectTest.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.