fix(selfHosted): align worker lifecycle behavior - #14
Merged
Conversation
## 简述 补齐 Python self-hosted worker 的工具超时配置,并对齐 Anthropic 的长连接和工具执行生命周期语义。 ## 修改前 - EnvironmentWorkerOptions 无法直接配置单次工具执行超时。 - timeout 只进入 ToolContext,非协作 custom tool 如果不主动检查 cancel_event,仍会阻塞 SessionToolRunner。 - SSE timeout 处理不清晰,误设为 None 会让静默断流无法及时退出。 - 新字段若插入 dataclass 中间会改变既有位置参数含义。 ## 修改后 - EnvironmentWorkerOptions 增加 tool_timeout_seconds,并透传 SessionToolRunner 和 ToolContext。 - 正值覆盖 ToolContext;None、0、负值保留用户 ToolContext 或 120s 默认值。 - SessionToolRunner 在 daemon thread 中执行工具,并在外层强制 deadline;超时后立即返回 error result,不等待忽略取消的工具,对齐 Anthropic anyio.fail_after 与 abandon_on_cancel 行为。 - 超时或 worker 停止时设置组合 cancel_event,配合型工具可及时释放进程和资源。 - SSE 保留 30s 读空闲 timeout;httpx 不设置整次 stream 总时长限制,静默断流仍可触发重连。 - WorkPoller 文档明确 AutoStop 是串行 iterator 语义;并发 dispatch 必须关闭并自行维护 heartbeat 和 stop。 - 新字段放在 dataclass 尾部,保持原位置参数顺序。 ## 边界 - 非协作工具的后台线程可能继续运行到自身返回,但结果会被丢弃;这是 Anthropic abandon-on-cancel 的相同行为,工具仍应响应 cancel_event 释放资源。 - 本 MR 不修改 SIGTERM 时 force-stop 行为,不实现 work 迁移、release 或 requeue。 ## 验证 - Python 全量单测:52 passed - Ruff 全量检查通过 - wheel 和 sdist 构建成功 - test/run.sh --sdk:Go、Python、Java 真实 STG worker 3/3 通过 - test/run.sh --all:真实 STG 全量默认套件通过,Docker 和直接 work-contract 用例按独立模式开关跳过 See merge request: !92 Sync-Source-Commit: 71cc0eae2668d0f5dc0fa57d1f450ef63d40d910 Hand-Written-Reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation. Release-Version: 0.4.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hand-written change from the internal SDK repository — not produced by
make vendor.fix(selfHosted): align worker lifecycle behaviorSync-Source-Commit: 71cc0eae2668d0f5dc0fa57d1f450ef63d40d910
Hand-Written-Reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.
Release-Version: 0.4.0
Created by ark-hand.