Skip to content

feat(sdks): client sandbox pool implementation#393

Open
ninan-nn wants to merge 1 commit intoalibaba:mainfrom
ninan-nn:feature/client_pool_impl
Open

feat(sdks): client sandbox pool implementation#393
ninan-nn wants to merge 1 commit intoalibaba:mainfrom
ninan-nn:feature/client_pool_impl

Conversation

@ninan-nn
Copy link
Collaborator

@ninan-nn ninan-nn commented Mar 9, 2026

Summary

  • Implement Kotlin SDK SandboxPool with client-side idle buffer management and configurable acquire policy (FAIL_FAST / DIRECT_CREATE).
  • Add pool domain model and extensibility points: PoolConfig, PoolCreationSpec, PoolSnapshot, PoolState, PoolStateStore, and InMemoryPoolStateStore.
  • Add reconcile loop with leader-gated replenish behavior for distributed deployments, including:
    • primary lock acquire/renew flow
    • stale idle fallback handling
    • degraded state/backoff tracking
    • lock-loss guard during putIdle
    • best-effort orphan cleanup callback on lock-loss window
  • Improve lifecycle/concurrency safety in SandboxPool:
    • periodic reconcile tick exception guard (prevents scheduler from silently stopping)
    • resize vs shutdown race handling (RejectedExecutionException safe path)
    • graceful shutdown waits for local in-flight operations (bounded by drainTimeout)
  • Remove @Deprecated annotation from SandboxPool to align with README guidance while keeping feature marked experimental in docs.
  • Update Kotlin SDK README (EN/ZH) with pool usage and distributed-store expectations.
  • Add/extend tests:
    • Kotlin unit tests for reconciler/store/pool behavior (including distributed-lock edge cases)
    • Java pool E2E coverage:
      • existing single-node pool suite
      • new pseudo-distributed suite with shared in-process distributed-like store

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Executed:

  • cd sdks/sandbox/kotlin && ./gradlew spotlessApply build
  • cd tests/java && ./gradlew test --tests "*SandboxPool*E2ETest"

Result summary:

  • SandboxPoolSingleNodeE2ETest: 15/15 passed
  • SandboxPoolPseudoDistributedE2ETest: 7/7 passed

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

@ninan-nn ninan-nn force-pushed the feature/client_pool_impl branch 11 times, most recently from 543d870 to 991e526 Compare March 13, 2026 03:50
@ninan-nn ninan-nn changed the title client pool impl feat(sdks): client sandbox pool implementation Mar 13, 2026
@ninan-nn ninan-nn force-pushed the feature/client_pool_impl branch from 991e526 to 9ecdc1f Compare March 13, 2026 04:06
@ninan-nn ninan-nn marked this pull request as ready for review March 13, 2026 04:13
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ecdc1f260

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ninan-nn ninan-nn force-pushed the feature/client_pool_impl branch from 9ecdc1f to 75ca5a8 Compare March 16, 2026 02:51
@hittyt
Copy link
Collaborator

hittyt commented Mar 17, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75ca5a84db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ninan-nn ninan-nn force-pushed the feature/client_pool_impl branch 2 times, most recently from 3495072 to c7519f5 Compare March 17, 2026 07:21
hittyt
hittyt previously approved these changes Mar 17, 2026
Copy link
Collaborator

@hittyt hittyt left a comment

Choose a reason for hiding this comment

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

LGTM

@Pangjiping Pangjiping added feature New feature or request sdk/java labels Mar 17, 2026
Pangjiping
Pangjiping previously approved these changes Mar 17, 2026
Copy link
Collaborator

@Pangjiping Pangjiping left a comment

Choose a reason for hiding this comment

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

LGTM

@ninan-nn ninan-nn dismissed stale reviews from Pangjiping and hittyt via 9c776ed March 18, 2026 02:03
@ninan-nn ninan-nn force-pushed the feature/client_pool_impl branch from c7519f5 to 9c776ed Compare March 18, 2026 02:03
Copy link
Collaborator

@Pangjiping Pangjiping left a comment

Choose a reason for hiding this comment

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

LGTM

@jwx0925
Copy link
Collaborator

jwx0925 commented Mar 21, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c776ed674

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


private fun directCreate(sandboxTimeout: Duration?): Sandbox {
val sandbox = buildSandboxFromSpec()
sandboxTimeout?.let { sandbox.renew(it) }

Choose a reason for hiding this comment

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

P1 Badge Clean up direct-created sandbox when renew fails

If sandboxTimeout is set and sandbox.renew(...) throws (for example on transient API/network errors), directCreate exits by exception without killing or closing the newly created sandbox. Because the caller never receives the Sandbox handle, that instance is orphaned and can keep running until the default 24h TTL, consuming remote capacity and local client resources. Add a failure cleanup path (kill/close best-effort) before rethrowing.

Useful? React with 👍 / 👎.

.sandboxId(sandboxId)
.connectionConfig(connectionConfig)
.connect()
sandboxTimeout?.let { sandbox.renew(it) }

Choose a reason for hiding this comment

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

P2 Badge Close connected sandbox on idle renew failure

The idle acquire path performs connect() and then renew() in one try block; when renew() fails after a successful connect, execution jumps to the catch block and the connected Sandbox object is discarded without close(). Although the code attempts remote kill, the local HTTP client/provider resources for that connected handle are leaked in this failure path, which can accumulate under intermittent renew failures.

Useful? React with 👍 / 👎.

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

Labels

feature New feature or request sdk/java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants