Skip to content

fix(sandbox-kubernetes): support claim lifecycle retention - #2980

Open
guslegend0510 wants to merge 3 commits into
agentscope-ai:mainfrom
guslegend0510:codex/fix-2979-kubernetes-claim-lifecycle
Open

fix(sandbox-kubernetes): support claim lifecycle retention#2980
guslegend0510 wants to merge 3 commits into
agentscope-ai:mainfrom
guslegend0510:codex/fix-2979-kubernetes-claim-lifecycle

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Description

Fixes #2979.

Kubernetes sandbox claims were always treated as client-owned. Releasing a sandbox therefore deleted its SandboxClaim, while the persisted agent state still referenced that claim. The next call attempted to resume the deleted claim and waited for the watch timeout before creating a replacement.

This PR:

  • Exposes claimOwned(boolean) for explicitly controlling deletion on release.
  • Adds shutdownAfterSeconds(long) as a hard controller-managed expiry.
  • Adds ttlSecondsAfterFinished(int) and serializes it to SandboxClaim.spec.lifecycle.
  • Keeps the compatibility default for claims without a hard shutdown deadline.
  • Avoids retaining TTL-only claims implicitly because long-running runtimes may never reach Finished.
  • Fails immediately when a persisted claim no longer exists instead of waiting for the 30-second watch timeout.
  • Preserves the existing public createSandboxClaim overload for source and binary compatibility.
  • Adds unit tests and English/Chinese documentation.

Lifecycle behavior

  • Default: the client deletes the claim on release.
  • With shutdownAfterSeconds: release only disconnects; the controller deletes the claim at the configured deadline.
  • With ttlSecondsAfterFinished only: client ownership remains enabled by default.
  • claimOwned(false) can explicitly retain a claim when the runtime is guaranteed to reach Finished.

Verification

  • Kubernetes module test suite: 44 tests passed.
  • Final focused lifecycle tests: 31 tests passed, 0 failures.
  • Spotless check passed.
  • git diff --check passed.

Checklist

  • Code has been formatted with Spotless
  • All affected-module tests are passing
  • Javadoc comments follow project conventions
  • Related English and Chinese documentation has been updated
  • Code is ready for review

@CryoThrust CryoThrust 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.

I traced the lifecycle paths against the reported resume failure. The ownership resolution and the preserved seven-argument createSandboxClaim overload look consistent with the compatibility goal.

Two points that may be worth making explicit before merge:

  1. For an already-persisted KubernetesSandboxState, claimOwned remains whatever was serialized previously unless the caller supplies an explicit claimOwned option. That is a reasonable migration choice, but it means an existing state created with the old default still deletes its claim on release. Could the documentation or a regression test state this migration behavior explicitly?
  2. ttlSecondsAfterFinished is serialized into spec.lifecycle alongside shutdownTime and shutdownPolicy. Please confirm that the deployed agent-sandbox CRD/controller version accepts this field and ignores it safely when unsupported; a small serialization assertion or compatibility note would make the rollout contract clearer.

The immediate missing-claim failure is a useful improvement for this issue because it removes the 30-second watch wait. I did not find a competing change in the open PR list beyond this PR, so I am leaving this as review feedback rather than opening a duplicate implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:2.0.2版本 k8s sandbox 每次调用后都会删除claim,下一次调用resume不到卡30秒后会重新创建

3 participants