feat(sdk-java): Add daemon transport - #7463
Conversation
🩺 serve daemon A/BBuilt the PR base vs this PR head ✅ No response changes against the PR base across 4 scenario(s). — Qwen Code · serve A/B |
|
Thanks for the PR — this is a substantial piece of work. Template looks good ✓ Problem: This is a feature addition, not a bug fix. The motivation is clear: the legacy Java stdio API cannot safely reconstruct a prompt after an HTTP response races streamed events or an SSE connection drops. The merged prerequisites (#7386 detach ledger, #7400 exactly-once terminals) already landed, and this builds the Java client on top of those contracts. The problem space is real for anyone integrating Direction: Aligned — the project already ships Size: This is a cross-package change (acp-bridge, cli, sdk-java) touching core infrastructure. Breakdown: ~5,385 production logic lines (additions + deletions, excluding test files) vs. ~3,414 test lines. This is well above the 500-line threshold for maintainer awareness on a Approach: The design is thorough — admission watermarks, per-prompt SSE subscription, terminal correlation, fail-closed ambiguity handling. The ACP bridge changes (admission-aware cancellation handshake, prompt-id-based cancel dedup, removed-prompt terminal flush) are tightly coupled to what the Java client needs, so they belong together. However, the PR also bundles CI workflows, a Maven Central release pipeline, docs, and an E2E harness — consider whether the release workflow and docs could land as a follow-up to keep the reviewable surface smaller. The new Moving on to code review. 🔍 中文说明感谢贡献!这是一个相当大的工程。 模板完整 ✓ 问题: 这是一个功能新增,不是 bug 修复。动机很明确:旧 Java stdio API 无法在 HTTP 响应与流式事件竞态或 SSE 连接中断时安全地重建 prompt。前置 PR(#7386 detach 账本、#7400 精确一次终态)已合并,本 PR 在这些契约之上构建 Java 客户端。对于需要从 Java 集成 方向: 对齐——项目已有 规模: 这是跨 package 改动(acp-bridge、cli、sdk-java),触及核心基础设施。分解:约 5,385 行生产逻辑(additions + deletions,不含测试文件)vs. 约 3,414 行测试。远超 方案: 设计很详尽——admission watermark、per-prompt SSE 订阅、终态关联、fail-closed 歧义处理。ACP bridge 变更(admission-aware 取消握手、基于 prompt-id 的取消去重、已移除 prompt 的终态刷新)与 Java 客户端需求紧密耦合,放在一起合理。但 PR 同时打包了 CI 工作流、Maven Central 发布管线、文档和 E2E 工具——建议考虑将发布工作流和文档作为后续 PR 单独提交,以缩小可审查面。新的 进入代码审查 🔍 — Qwen Code · qwen3.7-max Reviewed at |
Code ReviewIndependent proposal: For a Java daemon transport, I'd build a Comparison with the diff: The PR's approach matches this closely and goes further — bounded semaphores for prompt/stream/future capacity, a separate stream-close pool so stalled closes can't block deadlines, and a No critical blockers found. The code is well-structured and the fail-closed design is consistent throughout. A few observations for the maintainer:
sequenceDiagram
participant P1 as Java SDK
participant P2 as Daemon REST
participant P3 as SSE Stream
participant P4 as ACP Bridge
participant P5 as ACP Child
P1->>P2: POST /session (create)
P2-->>P1: sessionId, clientId
P1->>P2: POST /session/id/prompt (admit)
P2-->>P1: 202 promptId, lastEventId
P1->>P3: GET /session/id/events (Last-Event-ID)
P3-->>P1: stream typed events
P1->>P2: POST /session/id/cancel
P2->>P4: craft/cancelPendingPrompt
P4->>P5: abort + await settlement
P5-->>P4: settled
P4-->>P2: cancelled true
P3-->>P1: turn_complete (stopReason cancelled)
P1->>P2: POST /session/id/detach
P2-->>P1: 204
Files changed (30 of 59 shown)
Real-Scenario TestingNo Java/Maven or tmux in this CI environment. Verified the TypeScript side end-to-end: build, typecheck, all affected tests, and a live daemon serve session exercising the new endpoints. Build and typecheck: Unit tests (PR code): Live daemon serve test (this PR's build): Capabilities correctly advertise Not tested: Java SDK compilation and tests (no JDK/Maven in this environment), real-daemon E2E harness, Maven Central release workflow. CI covers these. 中文说明代码审查独立方案: 对于 Java daemon transport,我会构建一个管理 HTTP/SSE 连接的 与 diff 对比: PR 的方案与此高度一致,并走得更远——用有界信号量管理 prompt/stream/future 容量,独立的 stream-close 线程池防止阻塞 deadline,以及 未发现关键阻塞问题。 代码结构良好,fail-closed 设计贯穿始终。几点供维护者参考:
真实场景测试此 CI 环境无 Java/Maven 和 tmux。已端到端验证 TypeScript 侧:构建、类型检查、所有受影响测试、以及实际 daemon serve 会话验证新端点。 构建和类型检查全部通过。1126 个单元测试全部通过(434 bridge + 300 acpAgent + 392 Session)。实际 daemon serve 测试确认 capabilities 正确广播 未测试: Java SDK 编译和测试(环境无 JDK/Maven)、真实 daemon E2E 工具、Maven Central 发布工作流。CI 覆盖这些。 — Qwen Code · qwen3.7-max Reviewed at |
|
Confidence: 3/5 — clean review across every stage, but the Stage 0 core-module escalation (5,385 production lines, cross-package ACP/CLI changes, new protocol extension, release infrastructure) needs a maintainer's sign-off. This is a well-executed PR. The design doc is thorough, the Java code is clean and well-organized, the fail-closed approach to ambiguity is the right call for an SDK, and the ACP bridge changes are tightly scoped to what the daemon transport actually needs. All 1,126 TypeScript tests pass, build and typecheck are clean, and the live daemon serve test confirms the new endpoints work correctly. Going back to my independent proposal — the PR matches it closely and exceeds it in the capacity management layer (bounded semaphores, separate stream-close pool) and the fault-injection test suite (2,596 lines covering SSE fragmentation, replay, gaps, compression, observer failure). I didn't find a simpler path it missed. The complexity is earned: daemon transport with SSE reconnection, terminal correlation, and ambiguity handling is inherently complex. Why 3/5 and not higher:
None of these are blockers — they're the reason this needs a human maintainer's eye rather than an auto-approve. 中文说明置信度:3/5 — 每个阶段审查都很干净,但 Stage 0 核心模块升级(5,385 行生产代码、跨 package ACP/CLI 变更、新协议扩展、发布基础设施)需要维护者签字确认。 这是一个执行良好的 PR。设计文档详尽,Java 代码干净且组织良好,fail-closed 的歧义处理方式是 SDK 的正确选择,ACP bridge 变更紧密围绕 daemon transport 的实际需求。所有 1,126 个 TypeScript 测试通过,构建和类型检查干净,实际 daemon serve 测试确认新端点工作正常。 回到我的独立方案——PR 与之高度一致,并在容量管理层(有界信号量、独立 stream-close 线程池)和故障注入测试套件(2,596 行,覆盖 SSE 分片、回放、缺口、压缩、observer 失败)上超出预期。我没有找到它遗漏的更简路径。复杂度是合理的:带有 SSE 重连、终态关联和歧义处理的 daemon transport 本身就是复杂的。 为什么是 3/5 而不是更高:
这些都不是阻塞问题——而是需要人工维护者审查而非自动批准的原因。 — Qwen Code · qwen3.7-max Reviewed at |
|
⏸️ Deferring to @pomelo-nwu — this PR is clean across all review stages (no blockers found, all 1,126 TS tests pass, live daemon test confirms correct behavior), but it needs a maintainer's sign-off before merge because:
The code quality is high and the design is sound — this is a policy escalation, not a quality concern. Needs a human call on this one. |
🔬 Local Verification Report — PR #7463PR: Verdict建议修改后合并。 传输层协议实现正确,全部 1,225 个测试通过(含 4 个真实 daemon E2E)。但存在 2 个需要 PR 作者确认的设计问题(见 §5),以及 1 个文档缺陷需要补充。 1. Build
2. TypeScript Unit Tests
覆盖范围: PR 涉及 5 个核心 TS 改动文件,测试覆盖了其中 3 个(bridge.ts、acpAgent.ts、Session.ts)。以下 2 个文件无直接测试覆盖:
3. Java SDK Unit Tests
4. tmux E2E Test(真实 Daemon + Java SDK)通过
验证的事件流: 5. Code Review Findings5.1
|
| 维度 | 状态 | 说明 |
|---|---|---|
| CI 状态 | ❓ 未检查 | gh 认证失效,无法查询。merge 前需确认 CI 绿 |
| 与 main 的冲突 | 无冲突(0 behind),但 base 较旧,建议 rebase | |
| 安全性 | ❓ 未深入 | token 通过 QWEN_SERVER_TOKEN 环境变量传递,--require-auth 强制 bearer 认证。未做渗透测试 |
| 性能 | ❓ 未测量 | ActivePromptCall 每次 prompt 增加 Map set/delete 操作,高频场景开销未量化 |
| 代码覆盖率 | ❓ 未获取 | Java JaCoCo 报告未单独提取 |
7. 测试汇总
| 类别 | 数量 | 结果 |
|---|---|---|
| TS 单元测试 | 1,126(含 PR 新增 10) | ✅ 全部通过 |
| Java 单元测试 | 95 | ✅ 全部通过 |
| tmux E2E(mock 模型) | 4 | ✅ 全部通过 |
| 合计 | 1,225 | ✅ 0 failures |
8. Merge 前建议
- 必须: 确认 CI 绿
- 必须: 作者回复 §5.1(abort signal 响应性)和 §5.2(跨 prompt cancel 竞态)
- 建议: 补充 E2E 前置条件文档(
npm run bundle依赖) - 建议: Rebase 到最新 main(当前落后 100 commits)
Tested locally with tmux on macOS. Full logs available upon request.
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline. Not reviewed: chunk 3, chunk 12, chunk 13, chunk 16, chunk 18, chunk 8, chunk 10, chunk 20, chunk 7, chunk 11, chunk 17, chunk 15, chunk 9, chunk 2, chunk 5, chunk 4, chunk 1, chunk 19, chunk 14, chunk 6 — launched with a prompt that is not the one the CLI built. Not reviewed: Agent 0: Issue fidelity & root-cause ownership, Test coverage matrix (whole-diff), Agent 1b: Removed-behavior audit, Agent 1c: Cross-file tracer, Agent 7: Build & test verification, Invariant agent A: state, timers, collections — packages/sdk-java/qwencode/QWEN.md, Invariant agent B: counters, return values, error taxonomies — packages/sdk-java/qwencode/QWEN.md, Invariant agent C: config fields, early returns — packages/sdk-java/qwencode/QWEN.md — its prompt was built, but no agent on record was launched with it. Not reviewed: reverse audit — an auditor ran and opened its brief, but no agent was launched with the prompt the CLI built — the launch was written by hand, and what the agent was actually asked is not what this skill certifies. Not reviewed: verification — a verifier ran and opened its brief, but no agent was launched with the prompt the CLI built — the launch was written by hand, and the posted findings cannot be counted as verified against it.
— qwen3.7-max via Qwen Code /review
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
05fd7a5 to
9f40201
Compare
|
Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. 中文请勿对活跃的 PR 执行 rebase 或 force-push,因为这会使已有的评审评论失效。另外,供日后参考:作为集成流程的一部分,机器人始终会自动将所有改动压缩(squash)为单个提交。 |
|
@gwinthis Thanks for the detailed review. I addressed the actionable E2E workflow gap and rebased the branch onto the current
Validated at |
|
Follow-up summary for
Validation: relevant TypeScript typechecks passed; ACP Bridge 439/439; CLI 693/693; Maven verification 103 tests with 98 passed and 5 expected skips; real daemon E2E 4/4. Repository-wide build is independently blocked by Web Shell type errors already present in |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Unresolved, please confirm: [Critical] DaemonSessionClient.java:565 — activePrompt not cleared after post-admission observation failure; author defends as intentional fail-closed reuse boundary, verified by test contract Not reviewed: coverage — could not read the agents' transcripts (no subagent transcripts at /home/github-runner/actions-runner-15/_work/_temp/qwen-home/projects/-home-github-runner-actions-runner-15--work-qwen-code-qwen-code/subagents/4c871d68-e283-48ff-961b-8a8689e80e8f (ENOENT: no such file or directory, scandir '/home/github-runner/actions-runner-15/_work/_temp/qwen-home/projects/-home-github-runner-actions-runner-15--work-qwen-code-qwen-code/subagents/4c871d68-e283-48ff-961b-8a8689e80e8f'). The harness writes one per agent; if there are none, either no agents ran or the harness could not write them.), so this run cannot show that any of the diff was read. Not reviewed: verification — could not check that Step 4 and Step 5 ran (no subagent transcripts at /home/github-runner/actions-runner-15/_work/_temp/qwen-home/projects/-home-github-runner-actions-runner-15--work-qwen-code-qwen-code/subagents/4c871d68-e283-48ff-961b-8a8689e80e8f (ENOENT: no such file or directory, scandir '/home/github-runner/actions-runner-15/_work/_temp/qwen-home/projects/-home-github-runner-actions-runner-15--work-qwen-code-qwen-code/subagents/4c871d68-e283-48ff-961b-8a8689e80e8f'). The harness writes one per agent; if there are none, either no agents ran or the harness could not write them.).
— qwen3.7-max via Qwen Code /review
🔬 Delta Review — PR #7463 Update (commit
|
| # | 上轮 Finding | 本轮状态 | 说明 |
|---|---|---|---|
| §1 DX | npm run bundle 前置条件未文档化 |
✅ 已修复 | sdk-java.md、README.md 新增 "Real daemon E2E from source" 章节;run-java-daemon-sdk-e2e.ts 新增 existsSync(cliBundle) 前置检查,缺失时抛出明确错误信息 |
| §5.1 | ActivePromptCall hang 风险 |
✅ 已回应(设计决策) | 设计文档、README、RELEASE.md 均新增段落:明确说明 cancel handshake 故意不设 acknowledgement-only timeout,因为那会让 late session-scoped cancel 到达下一个 prompt。如果 provider/tool 忽略 AbortSignal,session 应被销毁而非复用。这是 alpha 契约的已知限制,不是 bug |
| §5.2 | cancelBroadcastPromptId 跨 prompt 竞态 |
⚪ 未改动 | 上轮评估为低影响(仅产生冗余 SSE 事件,不导致状态错误),作者未修改,可接受 |
| §5.3 | PromptDeadlineExceededError export 路径 |
✅ 上轮已确认无风险 | 无变化 |
| §5.4 | broadcastTurnError mutateTurnState |
✅ 上轮已确认正确 | 无变化 |
新提交代码审查
scripts/run-java-daemon-sdk-e2e.ts (+11/-1):
- 新增
existsSync(cliBundle)检查 ✅ — 错误信息准确("runnpm run build && npm run bundle") path.join(root, 'dist', 'cli.js')提取为cliBundle变量复用 ✅ — 消除了重复路径拼接
文档变更 (sdk-java.md, README.md, RELEASE.md, java-daemon-sdk-alpha.md):
- 三处文档(sdk-java.md、README.md、java-daemon-sdk-alpha.md)新增了相同的 cancel handshake 说明段落,内容一致 ✅
- RELEASE.md 的 "Known alpha limits" 补充了 timeout 设计理由 ✅
- 措辞准确:"a provider or tool that ignores its
AbortSignalcan therefore leave the session unusable until stronger runtime isolation is available" — 明确了责任边界和恢复路径
重新验证结果(最新版本)
| 类别 | 数量 | 结果 | vs 上轮 |
|---|---|---|---|
| TS: bridge.test.ts | 439 | ✅ | +5(rebase 带入) |
| TS: acpAgent.test.ts | 301 | ✅ | +1(rebase 带入) |
| TS: Session.test.ts | 392 | ✅ | 不变 |
| Java 单元测试 | 95 | ✅ | 不变 |
| tmux E2E(mock 模型) | 4 | ✅ | 不变 |
| 合计 | 1,231 | ✅ 0 failures |
结论
上轮 2 个必须项(§1 DX 文档、§5.1 abort 风险)均已解决。 §1 通过代码+文档双重修复;§5.1 通过设计文档明确为 alpha 契约的已知限制(fail-closed 语义:session 不可复用则销毁),这是合理的设计决策。
建议合并。 剩余 §5.2(跨 prompt cancel 冗余事件)为低影响 cosmetic 问题,不阻塞 merge。
Delta review on latest commit 9f4020103. Full verification logs available upon request.
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
9f40201 to
b4c779f
Compare
|
CI follow-up for
The previous failure could occur when the immediate terminal event won the race before |
Code Review —
|
|
Thanks for the thorough review. I checked each item against
No code changes are being added for this review round. |
|
Qwen Code review did not complete successfully. Run review failed. See workflow logs for details. A transient error is retried automatically; if you are seeing this, retry with |
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
|
Review follow-up for
Validation: root build and typecheck passed; Java |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline. Unresolved, please confirm: [Critical] DaemonSessionClient.java:565 — activePrompt not cleared after post-admission observation failure; author defends as intentional fail-closed reuse boundary; the mechanism (activePrompt retained after admission) is present in the code by design, but whether this constitutes a defect or correct behavior requires maintainer judgment Not reviewed: build-and-test — Java build/test could not run (no JDK/Maven on runner); TypeScript tests passed 1134/1134.
— qwen3.7-max via Qwen Code /review
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
|
Review follow-up for
Validation:
|
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline. Unresolved, please confirm: [Critical] DaemonSessionClient.java:571 — activePrompt not cleared after post-admission observation failure; author defends as intentional fail-closed reuse boundary with test assertion (PromptAlreadyActiveException in assertStoppedPromptSettlesWithBlockedClose); requires maintainer judgment on whether this design choice is acceptable Not reviewed: coverage — agent prompts were paraphrased rather than passed verbatim from agent-prompt --roster; agents performed substantive work but check-coverage could not verify prompt fidelity. Not reviewed: chunk 10, chunk 9, chunk 11, chunk 2, chunk 15, chunk 7, chunk 3, chunk 21, chunk 12, chunk 5, chunk 4, chunk 20, chunk 13, chunk 14, chunk 18, chunk 17, chunk 8, chunk 19, chunk 6, chunk 16 — launched with a prompt that is not the one the CLI built. Not reviewed: Test coverage matrix (whole-diff), Agent 1b: Removed-behavior audit, Agent 1c: Cross-file tracer, Agent 7: Build & test verification, Invariant agent A: state, timers, collections — packages/sdk-java/qwencode/QWEN.md, Invariant agent B: counters, return values, error taxonomies — packages/sdk-java/qwencode/QWEN.md, Invariant agent C: config fields, early returns — packages/sdk-java/qwencode/QWEN.md — its prompt was built, but no agent on record was launched with it. Not reviewed: reverse audit — no auditor was launched with a prompt this skill builds — the pass that hunts what the rest of the review missed ran, if at all, without the method its brief carries. Not reviewed: verification — the review posts findings, but no verifier was launched with a prompt this skill builds — they were ruled on, if at all, without the verdict bar its brief carries.
— qwen3.7-max via Qwen Code /review
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
|
Rebased this branch onto Validation:
The updated head is |
4cef807 to
0c3a682
Compare
Code Review —
|
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
No issues found. LGTM! ✅
— qwen3.7-max via Qwen Code /review
|
@wenshao Thanks for the thorough review. I verified the cancellation point against the current code:
I am not adding an arbitrary cancel timeout in this PR: safely expiring it requires an explicit contract choice between preserving the per-session FIFO fence, allowing the documented deadline-style overlapping recovery, or tearing down a possibly shared runtime. Operators that require bounded cancellation should configure a server or per-prompt deadline. A default deadline/cancel-timeout policy needs maintainer design follow-up rather than an implicit alpha behavior change. Following the repository rule for a PR that has already gone through roughly five review rounds, I am recording the remaining non-Critical items without expanding this diff:
The Java 11 migration and SLF4J/Logback change are already called out in the SDK documentation and release guidance. No blocker was identified, and the current SHA is fully green. |
wenshao
left a comment
There was a problem hiding this comment.
Reviewed. Not reviewed: build-and-test — Integration Tests (CLI, No Sandbox) was skipped in CI and its suite did not run locally (pre-existing @xterm/headless environment issue). Not reviewed: build-and-test — Test (macos-latest, Node 22.x) was skipped in CI. Not reviewed: build-and-test — Test (windows-latest, Node 22.x) was skipped in CI. Not reviewed: build-and-test — Java build/test could not run (no Maven on runner). Not reviewed: chunk 19, chunk 11, chunk 20, chunk 5, chunk 15, chunk 1, This PR adds a Java 11 daemon transport to the qwencode-s..., chunk 12, chunk 2, chunk 18, chunk 16, You are review agent verify — Verification agent., chunk 8, chunk 7, chunk 6, chunk 10, chunk 14, chunk 21, chunk 9, chunk 3, chunk 4, chunk 13, chunk 17, You are review agent reverse-audit — Reverse audit agen... — pointed at diff lines it never opened: it made tool calls, but none of them read the diff.
— qwen3.8-max-preview via Qwen Code /review
Code Review — PR #7463
|
|
Thanks for the thorough review. I independently checked each new item at
The frame-progress watchdog, ASCII-only numeric parsing, and workflow/E2E wall-clock guards are valid Low-priority hardening ideas. This PR has already passed roughly five review rounds, so per the repository contribution rule I am deferring non-Critical scope growth; they do not affect the alpha transport's fail-closed correctness. No code change is warranted from this round. |
What this PR does
This PR adds a Java 11 daemon transport to the existing
com.alibaba:qwencode-sdkartifact and prepares version0.1.0-alphawithout introducing a second Maven artifact. The new API creates thread-scoped sessions, separates prompt admission from terminal completion, streams typed and raw daemon events, supports permission responses and session cancellation, and provides a boundedpromptText()convenience API.The transport uses a non-retried
POSTadmission followed by resumable SSE from the returned watermark. It sendsAccept-Encoding: identityandLast-Event-ID, validates UTF-8, JSON and SSE framing strictly, advances cursors only after observer delivery, deduplicates replayed events, rejects gaps and compressed streams, and reports ambiguous mutations or missing reliable terminals through explicit exception types. Client-owned executors, heartbeat scheduling, stream cleanup, detach-once close, and explicit destroy semantics keep resource use and lifecycle outcomes bounded.The daemon and ACP paths now close the reliability contracts the Java client depends on: every admitted prompt receives one correlated terminal, deadlines cover queueing and execution, queued and running cancellation are distinguished, admission-aware cancellation waits for the targeted call to settle, and session teardown flushes prompt terminals before session failure events. The SDK documentation, design record, Java 11 migration guidance, cross-platform CI, real-daemon E2E harness, and protected Maven Central release workflow are included.
Why it's needed
The legacy Java stdio API is not a daemon transport and cannot safely reconstruct a prompt after an HTTP response races streamed events or an SSE connection drops. Requiring each Java application to implement admission watermarks, SSE parsing, replay cursors, reconnect policy, deduplication, terminal correlation, cancellation, and lifecycle cleanup would duplicate difficult protocol code and can surface partial output as a successful answer.
Some guarantees also cannot be repaired in an SDK alone. A client cannot synthesize a trustworthy terminal that the daemon never published, distinguish an old event cursor after a daemon epoch change without a resync signal, or prove which queued prompt an unacknowledged session-scoped cancellation affected. This change therefore closes the daemon/ACP contract first and builds the Java client on top of those explicit guarantees.
Reviewer Test Plan
How to verify
packages/sdk-java/qwencode, runmvn --batch-mode --no-transfer-progress clean verify -Dgpg.skip=true. Expect 103 tests with zero failures or errors, five integration tests skipped outside the E2E harness, zero Checkstyle violations, and main, source, and Javadoc JARs for0.1.0-alpha.npm run build && npm run typecheck && npm run bundle. Expect every workspace to build and typecheck successfully and the CLI bundle to be produced.npx tsx scripts/run-java-daemon-sdk-e2e.ts. Expect four Java E2E tests to pass against a real localqwen serveprocess and model stub, covering create, text/tool/permission streaming, reliable completion, deadline, cancellation, teardown ordering, detach, and destroy.npx vitest run src/bridge.test.tsfrompackages/acp-bridge, thennpx vitest run src/acp-integration/acpAgent.test.ts src/acp-integration/session/Session.test.tsfrompackages/cli. Expect 434 bridge tests and 692 CLI tests to pass.Evidence (Before & After)
N/A — this is a non-UI SDK, protocol, documentation, and release-automation change.
Tested on
Environment (optional)
macOS Darwin 25.4.0 arm64, Java 21.0.8 LTS, Node.js 22.22.3, and npm 10.9.8. The Java CI matrix also targets Java 11, 17, and 21.
Risk & Scope
com.alibaba:qwencode-sdk:0.1.0-alpharaises the minimum Java version for the whole artifact from Java 8 to Java 11 and removes Logback as a runtime dependency. Java 8 applications must remain on0.0.3-alpha; applications should provide their preferred SLF4J backend. The Maven coordinates do not change and the legacy stdio API remains available.Linked Issues
Related: #7386, #7400
中文说明
此 PR 的内容
此 PR 在现有
com.alibaba:qwencode-sdk制品中新增 Java 11 daemon transport,并准备发布0.1.0-alpha,不引入第二个 Maven 制品。新 API 默认创建 thread scope 会话,分别暴露 prompt admission 与 terminal completion,流式提供类型化事件和原始 daemon 事件,支持权限响应与会话取消,并提供有界的promptText()便捷 API。传输流程使用不自动重试的
POSTadmission,然后从响应 watermark 建立可恢复的 SSE。客户端发送Accept-Encoding: identity与Last-Event-ID,严格校验 UTF-8、JSON 和 SSE framing,仅在 observer 成功处理后推进游标,对回放事件去重,并拒绝事件 ID 缺口和压缩流。mutation 结果不确定或缺少可靠终态时通过明确的异常类型返回。客户端自有线程池、heartbeat 调度、流清理、最多一次 detach 的 close 以及显式 destroy 语义共同保证资源使用和生命周期结果有界。daemon 与 ACP 路径补齐了 Java 客户端依赖的可靠性契约:每个已 admission 的 prompt 都会收到一个关联终态;deadline 同时覆盖排队与执行;区分 queued 和 running cancellation;admission-aware cancellation 会等待目标调用结算;session teardown 会先刷新 prompt 终态,再发送 session failure 事件。同时包含 SDK 文档、设计记录、Java 11 迁移说明、跨平台 CI、真实 daemon E2E 工具,以及受保护的 Maven Central 发布工作流。
为什么需要此改动
旧 Java stdio API 并不是 daemon transport,无法在 HTTP 响应与流式事件竞态或 SSE 连接中断时可靠地重建一次 prompt。如果要求每个 Java 应用自行实现 admission watermark、SSE 解析、回放游标、重连策略、去重、终态关联、取消与生命周期清理,会重复大量高风险协议代码,并可能把不完整输出误报为成功答案。
部分保证也无法由 SDK 独立弥补。daemon 未发布终态时,客户端无法凭空生成可信终态;daemon epoch 变化后,如果没有 resync 信号,客户端无法识别旧事件游标;未确认的 session scope cancel 也无法证明实际影响了哪个排队 prompt。因此本改动先闭环 daemon/ACP 契约,再在这些明确保证之上实现 Java 客户端。
Reviewer 验证计划
验证方法
packages/sdk-java/qwencode运行mvn --batch-mode --no-transfer-progress clean verify -Dgpg.skip=true。预期 103 个测试零失败、零错误,E2E harness 外有 5 个 integration 测试跳过,Checkstyle 零违规,并生成0.1.0-alpha的主 JAR、source JAR 和 Javadoc JAR。npm run build && npm run typecheck && npm run bundle。预期所有 workspace 构建和类型检查成功,并生成 CLI bundle。npx tsx scripts/run-java-daemon-sdk-e2e.ts。预期 4 个 Java E2E 测试在真实本地qwen serve进程和模型桩上通过,覆盖 create、text/tool/permission 流、可靠完成、deadline、取消、teardown 顺序、detach 与 destroy。packages/acp-bridge运行npx vitest run src/bridge.test.ts,然后在packages/cli运行npx vitest run src/acp-integration/acpAgent.test.ts src/acp-integration/session/Session.test.ts。预期 434 个 bridge 测试和 692 个 CLI 测试全部通过。证据(Before & After)
N/A——这是非 UI 的 SDK、协议、文档和发布自动化改动。
测试平台
环境(可选)
macOS Darwin 25.4.0 arm64、Java 21.0.8 LTS、Node.js 22.22.3、npm 10.9.8。Java CI 矩阵还覆盖 Java 11、17 和 21。
风险与范围
com.alibaba:qwencode-sdk:0.1.0-alpha将整个制品的最低 Java 版本从 Java 8 提升到 Java 11,并移除 Logback runtime 依赖。Java 8 应用必须继续使用0.0.3-alpha,应用应自行提供所需的 SLF4J backend。Maven 坐标不变,旧 stdio API 继续保留。关联事项
相关:#7386、#7400