Skip to content

feat(sandbox-kubernetes): expose claim lifetime in harness options - #4170

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
ningmao-hlyz:feat/sandbox-claim-ttl
Nov 18, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
ningmao-hlyz:feat/sandbox-claim-ttl

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

A sandbox whose host process is killed stays claimed until someone deletes the SandboxClaim by hand. This exposes the SDK's existing shutdownAfterSeconds option through the Kubernetes harness client and the filesystem spec, so an application can hand reclamation to the controller when it exits without shutting its sandbox down. The default stays null, i.e. claims are created without a lifecycle exactly as before.

  • KubernetesSandboxClientOptions.setShutdownAfterSeconds(Long) rejects zero and negative values; KubernetesFilesystemSpec.shutdownAfterSeconds(Long) exposes the same option while building a filesystem.
  • create(...) writes spec.lifecycle = {shutdownTime, Delete} only when the value is set. copy(...) and merge(...) preserve it, and a per-call null inherits the client template.
  • The lifetime starts at creation; resuming a claim does not renew it.
  • docs/dev/{en,zh}/docs/harness/{sandbox,filesystem}.md describe the setting and the workspace/snapshot boundary it interacts with.

Validation

  • Windows, Java 17, repository Windows CI flags: mvn -o -B -T1C -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Djacoco.skip=true -DskipDurableWindowsTests=true clean verify — 12,977 tests, 0 failures/errors, 246 skipped. An unfiltered run fails in unchanged durable-sandbox tests because this shell has no sh.
  • spotless:apply and spotless:check clean for the module.
  • Six regression tests in KubernetesClaimLifetimeTest cover the request body, per-call overrides, null inheritance and invalid values; removing the create-time forwarding fails four of them.
  • Docs: 20 tests and site validation pass; local broken-link output matches the base (2,750 entries, no additions or removals).
  • CI: ubuntu-latest and windows-latest pass on eb1899403; License, Module Sync and CLA pass too.

Known limits

The tests assert the SandboxClaim POST body through Fabric8. Controller-side expiry and PVC reclamation need a real cluster and are not covered here.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@mintlify

mintlify Bot commented Nov 14, 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 eb18994.

Approve preview

@ningmao-hlyz
ningmao-hlyz force-pushed the feat/sandbox-claim-ttl branch from 9e21629 to 8999647 Compare November 14, 2026 17:02
@iluv7

iluv7 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Locally validated PR head 899964797cac3a17c229fca0ac44608df5ab0ee2. No issues found with the claim lifetime configuration/forwarding addressed by #4169.

Validation:

  • Compiled the PR's changed Java sources with javac --release 17 using JDK 21 and available dependencies; executed all six added regression tests with their setup/teardown and JUnit assertions: 6 passed, 0 failed.
  • Ran a connected resource-lifecycle integration test using a real envtest API server/etcd (Kubernetes 1.37.0), real SandboxClaim and Sandbox controllers from agent-sandbox 454d3353, and the official Kubernetes garbage collector from k8s.io/kubernetes v1.37.1.
  • A Java subprocess used the PR's actual KubernetesFilesystemSpec / KubernetesSandboxClient against that API server. Tested a 25-second client-template TTL inherited by per-call options, a 12-second per-call override, and an unset-TTL control.
  • Harness create() returned successfully in all three cases. Verified stored Claim lifecycle values and Claim → Sandbox → Pod ownership. Also called resume() and verified that the Claim spec/lifecycle remained unchanged.
  • The Java subprocess then exited without calling shutdown/delete. After expiry, both TTL Claims and their Sandboxes returned NotFound, and their Pod objects were gone. The no-TTL Claim, Sandbox and Pod remained present. Integration test passed (~31 seconds including setup/teardown).

Scope: this validates the connected Harness → API server → agent-sandbox controller → Kubernetes GC resource cleanup path. Envtest has no scheduler/kubelet, so a fixture supplied Pod Ready/IP status; no actual containers were started. Runtime command execution, termination of running container processes, and PVC data cleanup were not tested. This was targeted validation, not a full Maven build.

The two accessors and the spec builder sit next to setters that carry no
Javadoc, so the blocks only restated the signatures. The lifetime rule they
documented is in `docs/dev/*/docs/harness/sandbox.md`.
@jujn jujn added the P2 重要不紧急 label Nov 16, 2026
@jujn
jujn merged commit 58d051f into agentscope-ai:main Nov 18, 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.

3 participants