Skip to content

fix(selfHosted): align worker lifecycle behavior - #11

Merged
ark-hand[bot] merged 1 commit into
mainfrom
sync/handfix-f328f80ce1
Sep 2, 2026
Merged

fix(selfHosted): align worker lifecycle behavior#11
ark-hand[bot] merged 1 commit into
mainfrom
sync/handfix-f328f80ce1

Conversation

@ark-hand

@ark-hand ark-hand Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Hand-written change from the internal SDK repository — not produced by make vendor.

  • source subject: fix(selfHosted): align worker lifecycle behavior
  • reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.

简述

对齐 Java self-hosted worker 的 SSE 生命周期和工具执行超时语义。

修改前

  • self-hosted SSE 复用普通 OkHttp client,整次 call timeout 可能终止长时间 session。
  • EnvironmentWorker.Options 无法直接配置单次工具执行超时。
  • timeout 只进入 ToolContext,非协作 custom tool 如果不主动检查 isCancelled,仍会阻塞 SessionToolRunner。
  • 初版 SSE 修复同时关闭 readTimeout,会让静默网络断流永久挂起。

修改后

  • 为 self-hosted SSE 创建独立 OkHttp 和 Retrofit client,保留认证、代理、拦截器及调用方 read timeout,仅将整次 callTimeout 设为 0。
  • EnvironmentWorker.Options 增加 toolTimeoutMillis;正值覆盖 ToolContext,非正值保留原 120s 默认值或用户配置。
  • SessionToolRunner 使用 daemon executor 执行工具,并在外层强制 deadline;以 50ms 间隔观察 worker 和父 context 取消,超时后立即返回 error result,不等待忽略中断的工具。
  • timeout 和取消会同步到执行用 ToolContext;配合型工具可及时释放进程和资源。
  • WorkPoller 文档明确 AutoStop 是串行 iterator 语义;并发 dispatch 必须关闭并自行维护 heartbeat 和 stop。

边界

  • 非协作工具线程可能继续运行到自身返回,但结果会被丢弃;该行为语义对齐 Anthropic Go/Python 的 abandon-on-cancel 实现,工具仍应响应 isCancelled 或线程中断。
  • 本 MR 不修改 SIGTERM 时 force-stop 行为,不实现 work 迁移、release 或 requeue。

验证

  • Java 全量单测:47 passed
  • Checkstyle 通过
  • Maven package 通过
  • test/run.sh --sdk:Go、Python、Java 真实 STG worker 3/3 通过
  • test/run.sh --all:真实 STG 全量默认套件通过,Docker 和直接 work-contract 用例按独立模式开关跳过

See merge request: !88

Sync-Source-Commit: f328f80ce14608dfc1e0b62436ccbbfd0727e3bf
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.

## 简述

对齐 Java self-hosted worker 的 SSE 生命周期和工具执行超时语义。

## 修改前

- self-hosted SSE 复用普通 OkHttp client,整次 call timeout 可能终止长时间 session。
- EnvironmentWorker.Options 无法直接配置单次工具执行超时。
- timeout 只进入 ToolContext,非协作 custom tool 如果不主动检查 isCancelled,仍会阻塞 SessionToolRunner。
- 初版 SSE 修复同时关闭 readTimeout,会让静默网络断流永久挂起。

## 修改后

- 为 self-hosted SSE 创建独立 OkHttp 和 Retrofit client,保留认证、代理、拦截器及调用方 read timeout,仅将整次 callTimeout 设为 0。
- EnvironmentWorker.Options 增加 toolTimeoutMillis;正值覆盖 ToolContext,非正值保留原 120s 默认值或用户配置。
- SessionToolRunner 使用 daemon executor 执行工具,并在外层强制 deadline;以 50ms 间隔观察 worker 和父 context 取消,超时后立即返回 error result,不等待忽略中断的工具。
- timeout 和取消会同步到执行用 ToolContext;配合型工具可及时释放进程和资源。
- WorkPoller 文档明确 AutoStop 是串行 iterator 语义;并发 dispatch 必须关闭并自行维护 heartbeat 和 stop。

## 边界

- 非协作工具线程可能继续运行到自身返回,但结果会被丢弃;该行为语义对齐 Anthropic Go/Python 的 abandon-on-cancel 实现,工具仍应响应 isCancelled 或线程中断。
- 本 MR 不修改 SIGTERM 时 force-stop 行为,不实现 work 迁移、release 或 requeue。

## 验证

- Java 全量单测:47 passed
- Checkstyle 通过
- Maven package 通过
- test/run.sh --sdk:Go、Python、Java 真实 STG worker 3/3 通过
- test/run.sh --all:真实 STG 全量默认套件通过,Docker 和直接 work-contract 用例按独立模式开关跳过

See merge request: !88

Sync-Source-Commit: f328f80ce14608dfc1e0b62436ccbbfd0727e3bf
Hand-Written-Reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.
Release-Version: 0.4.0
@ark-hand
ark-hand Bot merged commit 4471db4 into main Sep 2, 2026
1 check passed
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.

0 participants