Skip to content

feat(ts-sdk): add restart() and autoDeleteSeconds to Sandbox#1122

Open
berstpander wants to merge 4 commits into
alibaba:masterfrom
berstpander:feat/ts-sdk-restart
Open

feat(ts-sdk): add restart() and autoDeleteSeconds to Sandbox#1122
berstpander wants to merge 4 commits into
alibaba:masterfrom
berstpander:feat/ts-sdk-restart

Conversation

@berstpander

Copy link
Copy Markdown
Contributor

Summary

  • Add restart() method to Sandbox class, matching Python SDK behavior: POST /restart, then poll until alive with error stage detection
  • Extract waitForAlive() private helper from start() to share polling logic between start() and restart() (OOP reuse)
  • Add parseErrorMessageFromStatus() to detect failed/timeout stages during restart polling (mirrors Python's _parse_error_message_from_status)
  • Extend getStatus() to support includeAllStates parameter
  • Add autoDeleteSeconds optional field to SandboxConfig with >= 0 validation, included in start_async request body

Test plan

  • 7 new unit tests for restart(): no sandboxId guard, 4xxx/5xxx error codes, generic error, timeout, happy path, failed-stage detection
  • All 466 existing unit tests pass with zero regressions
  • Manual verification via npm link in rockcli

Closes #1121

berstpander and others added 2 commits June 16, 2026 17:50
@Timandes

Copy link
Copy Markdown
Collaborator

整体看下来没有发现阻断合并的问题。实现范围清晰,restart()autoDeleteSeconds 与 Python SDK 的已有能力基本对齐。

有一个小的可用性问题:restart() 超时时复用了 start 的错误文案,会影响排障。waitForAlive() 同时被 start()restart() 复用,但超时错误固定写成 Failed to start sandbox...。当 restart() 调用走到这里时,用户会看到 start 失败,排查方向容易偏。建议给 waitForAlive() 增加 operation 参数,或让 restart() 使用专门的超时文案,比如 Failed to restart sandbox within ...

另外建议补一下 autoDeleteSeconds 的 config schema 单测,覆盖 null/undefined/0/正数/负数,并同步更新 README/开发文档里的 SandboxConfig 示例。

本地验证说明:我尝试运行 pnpm test -- --runTestsByPath src/sandbox/client.test.ts,但当前工作区没有 node_modules,失败于 jest: command not found,因此没有完成本地 Jest 验证。

… add autoDeleteSeconds tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Timandes

Copy link
Copy Markdown
Collaborator

重新看了最新更新,上一轮提到的 waitForAlive() 超时文案、autoDeleteSeconds 配置测试和基础文档缺口基本都修了。

但现在文档里有一个新的状态语义问题:README 在 await sandbox.start() 后马上示例 await sandbox.restart(),Developer Guide 也写成 restart() “需已启动”。实际后端 SandboxManager.restart_async() 明确只允许 State.STOPPED,Python SDK docstring 也写的是 restart a stopped sandbox / must be in STOPPED state。因此用户照抄当前 README 示例会在 running 状态下调用 restart,并收到 BadRequestRockError

建议把 README 示例改成 start -> stop -> restart,并把 Developer Guide 的描述改成“重启已停止的沙箱”或类似表述。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@berstpander

Copy link
Copy Markdown
Contributor Author

重新看了最新更新,上一轮提到的 waitForAlive() 超时文案、autoDeleteSeconds 配置测试和基础文档缺口基本都修了。

但现在文档里有一个新的状态语义问题:README 在 await sandbox.start() 后马上示例 await sandbox.restart(),Developer Guide 也写成 restart() “需已启动”。实际后端 SandboxManager.restart_async() 明确只允许 State.STOPPED,Python SDK docstring 也写的是 restart a stopped sandbox / must be in STOPPED state。因此用户照抄当前 README 示例会在 running 状态下调用 restart,并收到 BadRequestRockError

建议把 README 示例改成 start -> stop -> restart,并把 Developer Guide 的描述改成“重启已停止的沙箱”或类似表述。

已完善

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.

[Feature] feat(ts-sdk): add restart() method and autoDeleteSeconds parameter

2 participants