Skip to content

perf(java): share immutable transcript page snapshots - #17115

Merged
wenshao merged 1 commit into
QwenLM:mainfrom
Afloat16:fix/java-transcript-shared-snapshot
Nov 14, 2026
Merged

wenshao merged 1 commit into
QwenLM:mainfrom
Afloat16:fix/java-transcript-shared-snapshot

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

What this PR does

Keeps one deeply immutable event snapshot per Hosted Harness transcript page. getEvents() and the events member of getRaw() now share the parsed response instead of retaining separately copied maps and lists.

Why it's needed

JsonSupport.parseObject already recursively freezes the response, and getTranscript extracts its immutable events list. The page constructor then recursively copied the entire response again while retaining the first events list. This duplicated the event containers for every retained page and repeated the traversal. The constructor is package-private and its only call site supplies that already immutable response.

Reviewer Test Plan

How to verify

  1. Serve a transcript page containing nested event maps and content lists through the Hosted Harness HTTP route, then call the public Java client.
  2. Confirm both accessors reference the same event list and nested events. Try to modify the raw root, either list view, an event map, its content list and a content map; each must reject mutation.
  3. Confirm the session ID, cursor, event contents and hasMore value are unchanged.

The new HTTP regression fails on unchanged production because the page retains distinct event graphs. It passes with the fix. The full HostedHarnessClient test class, Java 11 release compilation, Checkstyle and formatting checks pass.

Evidence (Before & After)

An independent fixture uses a real loopback HTTP server and the public SDK with a 256-event page, matching the route's limit. It walks Map/List identities rather than estimating heap bytes or using a timing threshold.

Observation Before After
Unique event containers retained across both views 2,050 1,025
Containers shared by both views 0 1,025
Event contents Equal Equal
Nested mutation through either view Rejected Rejected

This removes one copy of the event container graph. The counts are specific to the fixture and do not claim that total JVM heap usage is halved.

Tested on

OS Status
🍏 macOS ⚠️ not tested
🪟 Windows ⚠️ not tested
🐧 Linux ✅ tested

Environment

Temurin JDK 21.0.13+9, Maven 3.10.0, and the unchanged Java 11 release compilation target. Tests use controlled HTTP responses and the real SDK parser and page API.

Risk & Scope

  • Main risk or tradeoff: the package-private constructor relies on its caller supplying the parser's deeply immutable snapshot. The HTTP regression covers that invariant, including nested maps and lists.
  • Not validated / out of scope: no production heap or latency benchmark; no live model or managed service run. Earlier full TypeScript monorepo checks exited 137 in this environment; the affected Java checks passed.
  • Breaking changes / migration notes: no method signatures, serialized fields or pagination semantics change.

Linked Issues

Refs #13313, R1-20, and its original review finding.

中文说明

此 PR 的改动

让每个 Hosted Harness transcript 分页只保留一份深度不可变事件快照。getEvents() 与 getRaw() 中的 events 成员共享已经解析的响应,不再各自保留复制后的 Map 和 List。

为什么需要

JsonSupport.parseObject 已递归冻结响应,getTranscript 从中取得不可变事件列表。原分页构造器又递归复制整个响应,同时仍保留第一份事件列表,因此每个保留的分页都重复持有事件容器并多进行一次遍历。构造器仅在包内可见,其唯一调用点提供的正是已经不可变的响应。

审阅者验证计划

如何验证

  1. 通过 Hosted Harness HTTP 路由提供带嵌套事件 Map 和内容 List 的分页,再调用公开 Java 客户端。
  2. 确认两个访问器引用相同的事件列表及嵌套事件。尝试修改原始根 Map、两个列表视图、事件 Map、内容列表和内容 Map,均应拒绝修改。
  3. 确认会话编号、游标、事件内容和 hasMore 不变。

新增 HTTP 回归在原生产代码上因保留两套独立事件对象图而失败,修复后通过。完整 HostedHarnessClient 测试类、Java 11 release 目标编译、Checkstyle 和格式检查通过。

修改前后证据

独立夹具使用真实回环 HTTP 服务、公开 SDK 和符合路由限制的 256 条事件分页。它按对象身份遍历 Map/List,没有估算堆字节数,也没有用计时阈值判定。

观测 修改前 修改后
两个视图合计保留的独立事件容器 2,050 1,025
两个视图共享的容器 0 1,025
事件内容 相等 相等
通过任一视图修改嵌套内容 拒绝 拒绝

这消除了一份重复事件容器图。上述数量对应夹具数据,不代表整个 JVM 的堆占用减半。

测试平台

系统 状态
🍏 macOS ⚠️ 未测试
🪟 Windows ⚠️ 未测试
🐧 Linux ✅ 已测试

环境

Temurin JDK 21.0.13+9、Maven 3.10.0,保留 Java 11 release 编译目标。测试使用受控 HTTP 响应和真实 SDK 解析器及分页 API。

风险与范围

  • 主要风险或取舍:包内构造器依赖调用方提供解析器生成的深度不可变快照。HTTP 回归覆盖该约束,包括嵌套 Map 和 List。
  • 未验证或范围外:没有生产环境堆占用或延迟基准,也未运行真实模型或托管服务。此前 TypeScript 全仓检查在当前环境以 137 退出;受影响 Java 检查通过。
  • 破坏性变更或迁移:无方法签名、序列化字段或分页语义变更。

关联问题

关联 #13313 的 R1-20 及其原始审阅发现。

@qwen-code-review-bot

qwen-code-review-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Qwen Triage finished — view run. See the stage comments in this thread for the result.

✅ Qwen Triage 已完成 —— 查看运行。结果见本线程中的各阶段评论。

@qwen-code-review-bot

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Template looks good ✓ — every required heading is filled in, and the Risk & Scope section is honest about what was not measured.

Problem: observed, not theoretical. I checked the redundancy against main rather than taking the description's word for it: JsonSupport.parseObject already ends in immutableObject(parsed), which freezes the whole response recursively, and JsonSupport.optionalList(json, "events") hands back the same list instance living inside that map. The page constructor then ran immutableObject(raw) on top of it — a second full recursive copy — plus an unmodifiableList wrapper around an already-unmodifiable list. So yes, every retained page really did hold two event graphs. This is also R1-20 in the open backlog #13313, which a maintainer filed from the #12654 post-merge review, so the finding is ours, not invented here.

Direction: aligned. It is internal Java SDK memory hygiene coming out of our own review backlog, with no surface change for callers. For a direction signal, the upstream CHANGELOG (2.1.323) carries retained-transcript memory work of its own — "a finished subagent's transcript is freed sooner instead of staying in memory" — which is a different codebase, so no direct reference, but the area is clearly a live concern rather than a novelty.

Size: not applicable — no core paths (packages/core/src/**, packages/*/src/{auth,providers,models,config,tools,services}/**) are touched, and all three files sit inside the single packages/sdk-java package. For scale: 7 production lines in one Java file, 2 README lines, 36 test lines.

Approach: this is what I would have written. Reading only the title and the "Why it's needed" section, my own proposal was: delete the constructor's re-copy, retain the caller's already-frozen values, document that the sole package-private call site must supply them, and pin it with a regression test. The diff does exactly that, in 7 lines, with no drive-by edits and no unrelated churn. Nothing I would cut. One question worth answering before merge, not a blocker: the README addition turns "both views share one snapshot" from an implementation detail into a documented SDK guarantee. That is a reasonable thing to promise — it is the memory-relevant part for SDK users — but it does become something we have to keep honouring in future refactors of this class. If that commitment is deliberate, good; if it was only meant as an internal note, the class Javadoc is the narrower home for it.

Risk: no elevated risk signals — none of the changed files match the high-risk paths we track for post-merge reverts. The real risk here is not the diff, it is the evidence: see the code review comment for the CI situation, which is the one thing blocking a clean verdict.

Moving on to code review. 🔍

中文说明

感谢贡献!

模板完整 ✓ —— 所有必填小节都写了,Risk & Scope 也如实说明了哪些没有实测。

问题: 是已观测到的问题,不是理论加固。我没有只看描述,而是对照 main 核实过:JsonSupport.parseObject 最后一步就是 immutableObject(parsed),会递归冻结整个响应;JsonSupport.optionalList(json, "events") 返回的正是该 map 内部的同一个 list 实例。而分页构造器又调了一次 immutableObject(raw)——第二次完整递归拷贝——并对已经不可变的 list 再包一层 unmodifiableList。所以每个被保留的分页确实持有两份事件对象图。这也正是维护者在 #12654 合并后复审中提出、记录在开放 backlog #13313 里的 R1-20,也就是说这个问题出自我们自己的复审,不是凭空构造的。

方向: 对齐。这是源自我们自身复审 backlog 的 Java SDK 内部内存优化,对调用方没有任何接口面变化。方向信号方面,上游 CHANGELOG(2.1.323)也有针对 transcript 常驻内存的改动——"已完成子代理的 transcript 会更早释放,不再驻留内存"——虽然是不同代码库、不构成直接对应,但说明这个方向是当下真实关注点。

规模: 不适用 —— 未触及核心路径(packages/core/src/**、packages/*/src/{auth,providers,models,config,tools,services}/**),三个文件都在 packages/sdk-java 单个包内。体量上:一个 Java 文件 7 行生产代码、README 2 行、测试 36 行。

方案: 换成我来写也是这样。只读标题和"为什么需要"两节时,我自己的方案是:删掉构造器里的重复拷贝,直接保留调用方已冻结的值,注明唯一的包内调用点必须传入已不可变的对象,并补一个回归测试。这个 diff 正是如此,7 行,没有夹带无关改动或顺手重构。没有想砍的部分。合并前有一个问题值得回答(不是阻塞项):README 的新增内容把"两个视图共享同一份快照"从实现细节变成了对外的 SDK 承诺。这个承诺本身合理(对 SDK 使用者来说这正是与内存相关的关键点),但以后重构这个类时就必须一直遵守。如果是有意的,很好;如果只是想写内部说明,类的 Javadoc 是更收敛的位置。

风险: 无升级风险信号 —— 改动文件均未命中我们跟踪的易回滚高风险路径。这里真正的风险不在 diff,而在证据:CI 情况见代码审查评论,那是目前唯一影响结论的因素。

进入代码审查 🔍

— Qwen Code · qwen3.8-max-2026-09-02

Reviewed at d1cf3f3107b7dd81457ebc88db4152c8e1958a84 · re-run with @qwen-code /triage

@qwen-code-review-bot

qwen-code-review-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Code review

No blockers. The change is correct, and I verified the load-bearing part by reading main rather than trusting the description.

What makes dropping both copies safe:

  • JsonSupport.parseObject returns immutableObject(parsed), which rebuilds every nested Map/List as unmodifiableMap/unmodifiableList recursively. The response getTranscript holds is therefore already deeply immutable before the page is constructed.
  • JsonSupport.optionalList(json, "events") does no copying — it casts and returns the list instance inside that same map. So the events argument and raw.get("events") were always the same object; only the constructor's immutableObject(raw) forked them into a second graph.
  • Dropping the second immutableObject also drops its value-type validation (unsupported JSON types, null keys, non-finite numbers). That is not a loss here, because parseObject already ran the identical validation over the same values.

Downstream consumers — all four read contents only, and none depends on wrapper identity or on being able to mutate:

  • HostedHarnessClient.getTranscript (line 1637) — the only construction site.
  • managed-agent-server/adapters/.../QwenHostedHarnessConnector.java (1175-1177) — production consumer, calls .getEvents().isEmpty().
  • managed-agent-server/verification/.../HostedHarnessMySqlIT.java (556-559) — streams getEvents() into json.valueToTree(value).
  • QwenHostedHarnessConnectorTest.java (3292, 3350) — Mockito mocks of the page, which bypass the constructor entirely; plus HostedHarnessClientTest.java (1373-1381), which only reads size/cursor/hasMore.

The new test is genuinely load-bearing, not decorative: on base code getEvents() is a fresh unmodifiableList wrapper while getRaw() is a deep copy, so both assertSame calls fail there and pass only with the fix. I confirmed that by reading the base constructor, not by running anything. The mutation assertions walk the nested levels (root map, both list views, event map, content list, content map), which is the right shape for pinning "deeply immutable" rather than "shallowly immutable".

Two non-blocking notes, neither a reason to hold this PR:

  1. The constructor used to enforce immutability and now trusts its caller to supply it. That is fine for a package-private constructor with exactly one call site, and the added comment states the invariant — but the invariant is now the only thing standing between this class and a future caller passing a mutable map. Worth remembering if a second call site ever appears.
  2. The identical redundant re-copy still exists next door: HostedHarnessClient.java:1563 passes a parseObject result to HarnessSessionStatus, whose constructor (line 18) calls immutableObject(raw) again; DaemonCapabilities is the same shape. Please do not widen this PR to cover them — the status object is small, R1-20 names only the transcript page, and keeping this diff at 7 production lines is what makes it easy to review and revert. Flagging it only so the maintainer knows the pattern is not unique to this class.

Test evidence

This is the weak point, and it is not the author's fault: no CI has run on this PR at all. All four pull_request workflow runs on the reviewed commit completed as action_required, i.e. they are queued behind a maintainer's "Approve and run workflows" for this fork. The Java lane that would actually compile the module, run Checkstyle and execute HostedHarnessClientTest is SDK Java (fast), called from Managed Agent gate — and that run is one of the blocked ones. sdk-java.yml has no pull_request trigger of its own, so there is no other path to that signal.

The only completed checks on this commit are bot orchestration (assign, authorize, label, precheck-pr, triage, review-pr), which say nothing about whether this Java compiles.

Final CI results for d1cf3f3 (auto-updated by the triage finalize job after CI completed):

Check Conclusion
Managed Agent fast tier ❌ failure
SDK Java (fast) / ubuntu-latest / Java 21 ❌ failure
Build and verify reference distribution ✅ success
Build unit-test tree (Linux, Node 22.x) ✅ success
Check TUI impact ✅ success
Classify PR ✅ success
Integration Tests (no-AK, No Sandbox) ✅ success
Integration Tests (no-AK, shard 1/2) ✅ success
Integration Tests (no-AK, shard 2/2) ✅ success
Lint & Static (ubuntu-latest, Node 22.x) ✅ success
Linux unit tests (shard 1/2) ✅ success
Linux unit tests (shard 2/2) ✅ success
SDK Java (fast) / Flyway migration version uniqueness ✅ success
SDK Java (fast) / Real daemon E2E / Java 11 ✅ success
Select the Managed Agent tier ✅ success
Test (ubuntu-latest, Node 22.x) ✅ success

One row per check name (latest run); skipped checks omitted; failures sort first. / 每个检查名一行(取最新一次运行),省略 skipped,失败项排在最前。

So, stated plainly: not verified — no CI ran on this commit. The PR description reports that the full HostedHarnessClientTest class, Java 11 release compilation, Checkstyle and formatting checks pass locally, and that an earlier full TypeScript monorepo run exited 137 in the author's environment. Those are the author's claims, not evidence I can reproduce or attribute to CI, and I am not counting them as test results. Nothing about them looks implausible — the diff is 7 production lines and the new test's helpers (createSessionRoute(), newClient(), sendSessionJson, createSession) and imports (java.util.List, java.util.Map, plus the added assertSame) all exist in the file it lands in — but "looks like it compiles" is not a compile.

Sandboxed verification would settle this: @qwen-code /verify — that the new sharesOneDeeplyImmutableTranscriptSnapshot regression actually fails on the base build and passes on this head, and that the Java fast tier (compile + Checkstyle + HostedHarnessClientTest) is green, is exactly what no check on this commit currently substantiates. The author has read access only, so this would be a sponsored run: a maintainer's @qwen-code /verify comment approves the head it was written against, and that run carries a pre-execution risk screen plus a full workspace wipe before any PR code executes. Please read the resulting report with the same skepticism as this fork's own CI logs — the code under verification is adversarial input, so a crafted PR can shape what a report says even though the sandbox bounds what it can do. /tmux does not apply (no TUI surface here) and is unavailable to a read-access author in any case.

中文说明

代码审查:没有阻塞项。 关键前提是照着 main 核实过的,不是采信描述:JsonSupport.parseObject 返回的就是 immutableObject(parsed),会递归重建每一层 Map/List 为不可变视图;optionalList(json, "events") 不做拷贝,直接返回该 map 内部的同一个 list 实例。也就是说 events 参数与 raw.get("events") 本来就是同一个对象,只是构造器里那次 immutableObject(raw) 把它们分叉成了第二份对象图。去掉第二次 immutableObject 同时去掉了它的取值类型校验(非法 JSON 类型、null key、非有限数),但这里不构成损失,因为 parseObject 已对同样的值做过完全相同的校验。

四个下游消费者都只读内容,没有谁依赖包装对象身份或依赖可修改性:HostedHarnessClient.getTranscript(1637,唯一构造点)、QwenHostedHarnessConnector.java(1175-1177,生产消费者,只调 .getEvents().isEmpty())、HostedHarnessMySqlIT.java(556-559,把 getEvents() 流转成 JsonNode)、QwenHostedHarnessConnectorTest.java(3292、3350,Mockito mock,绕过构造器),以及 HostedHarnessClientTest.java(1373-1381,只读 size/cursor/hasMore)。

新增测试是有承重作用的,不是摆设:在 base 代码上 getEvents() 是新包的一层 unmodifiableList,getRaw() 是深拷贝,两个 assertSame 都会失败,只有打了这个修复才会通过——这一点我是读 base 构造器确认的,没有执行任何代码。修改类断言逐层走了根 map、两个列表视图、事件 map、内容 list、内容 map,用来钉住"深度不可变"而非"浅层不可变",形状是对的。

两条非阻塞提醒:一是构造器过去是强制不可变,现在改为信任调用方传入不可变对象;对只有一个调用点的包内构造器来说没问题,注释也写明了这个约束,但将来若出现第二个调用点要记得这层依赖。二是同样的重复拷贝在旁边还在:HostedHarnessClient.java:1563 把 parseObject 的结果传给 HarnessSessionStatus,其构造器(第 18 行)又调了一次 immutableObject(raw),DaemonCapabilities 同理。请不要为此扩大本 PR——status 对象很小,R1-20 只点名了 transcript 分页,把这个 diff 保持在 7 行生产代码正是它好审、好回滚的原因。提这一点只是让维护者知道这个模式不止这一处。

测试证据:这是薄弱环节,而且不是作者的问题——本 PR 完全没有跑过 CI。 被审 commit 上四个 pull_request 工作流全部以 action_required 结束,即卡在该 fork 的"维护者批准运行工作流"这一步。真正会编译模块、跑 Checkstyle、执行 HostedHarnessClientTest 的 Java 通道是 SDK Java (fast),由 Managed Agent gate 调用,而它正是被卡住的那一个;sdk-java.yml 自身没有 pull_request 触发器,所以没有别的路径能拿到这个信号。当前 commit 上唯一完成的检查是机器人编排类(assign、authorize、label、precheck-pr、triage、review-pr),与这段 Java 能否编译无关。

明确说明:未验证——该 commit 没有任何 CI 运行。 PR 描述称本地完整 HostedHarnessClientTest、Java 11 release 编译、Checkstyle 与格式检查通过,并称此前 TypeScript 全仓检查在作者环境以 137 退出。这些是作者的自述,不是我能复现或归到 CI 的证据,我没有把它们当作测试结果计入。它们看起来并不可疑——diff 只有 7 行生产代码,新测试用到的辅助方法(createSessionRoute()、newClient()、sendSessionJson、createSession)与 import(java.util.List、java.util.Map,以及新增的 assertSame)在目标文件里都存在——但"看起来能编译"不等于编译过了。

沙箱验证可以定这件事:@qwen-code /verify —— 新增的 sharesOneDeeplyImmutableTranscriptSnapshot 回归是否在 base 构建上失败、在本 head 上通过,以及 Java fast tier(编译 + Checkstyle + HostedHarnessClientTest)是否为绿,正是当前该 commit 上没有任何检查能证实的内容。作者只有 read 权限,因此这将是一次由维护者赞助的运行:维护者发 @qwen-code /verify 评论即批准其所针对的 head,该运行在执行任何 PR 代码前带有执行前风险筛查与完整工作区清理。请以看待该 fork 自身 CI 日志的同样怀疑态度阅读其报告——被验证的代码属于对抗性输入,精心构造的 PR 虽然无法突破沙箱边界,却可能影响报告说什么。/tmux 在此不适用(没有 TUI 界面),且对 read 权限作者本身也不可用。

— Qwen Code · qwen3.8-max-2026-09-02

Reviewed at d1cf3f3107b7dd81457ebc88db4152c8e1958a84 · re-run with @qwen-code /triage

@qwen-code-review-bot

Copy link
Copy Markdown
Collaborator

Confidence: 3/5 — the diff itself I would merge without hesitation; the 3 is entirely about missing evidence and a maintainer decision that only a human can make, not about doubt in the code.

Stepping back: my independent proposal, written before I read the diff, was to delete the redundant copy, document the invariant on the package-private constructor, and pin it with a regression test. The PR is that, in 7 production lines. It matches rather than falls short of what I would have done, and I did not find a simpler path — there is nothing to cut, no drive-by edits, no scope creep. If I were maintaining this class in six months I would thank the author: the constructor stops doing a recursive copy of a structure that was already frozen two calls earlier, and the comment says why, which is the non-obvious part.

I also satisfied myself that the problem was real rather than assumed. The duplication is verifiable from main by reading three methods, and it is R1-20 in #13313, a backlog a maintainer filed from the #12654 post-merge review. This is not theoretical hardening dressed up as a fix.

So why not approve? Because there is no test evidence, and I am not willing to attest to a result that does not exist. Every pull_request workflow on this commit finished as action_required — the Java lane (SDK Java (fast): compile, Checkstyle, HostedHarnessClientTest) has never started, and sdk-java.yml has no other route onto a PR. The author's local results are plausible and I found nothing in the diff that contradicts them, but plausible is the author's word, not a green check. Approving now would be exactly the failure mode this gate exists to prevent: a clean-looking fork PR waved through on a static read alone.

I am also not leaving a deferred approval instruction for the finalize job to act on. The pending-run count for this head is 0 — the runs are "completed" as action_required rather than in flight — so there is nothing for that job to wait on. Releasing the workflow runs is a human action, and the verdict should be revisited once that has happened, not pre-committed now.

One thing the maintainer should see beyond this PR: the author has 13 open PRs, 12 of them opened today, each one a small fix lifted from a recorded review backlog. Judged alone, this one is clean and I would take it. Judged as a stream, it deserves a deliberate pass — 12 independent auto-approvals is not the same decision as one maintainer choosing to land a batch, and the backlogs are large enough that more of these will keep arriving. I am evaluating this PR on its own merits and recommending it on those merits; I am flagging the volume so the pattern is a choice rather than a default.

What would move me to approve, in order:

  1. Approve the pending workflow runs on this head (or sponsor @qwen-code /verify) so the Java fast tier produces real compile / Checkstyle / test evidence, then re-run @qwen-code /triage. That is the only genuine gap.
  2. Confirm the README line is meant as a public SDK guarantee that both views share one snapshot, rather than an internal note that belongs in the class Javadoc. Either answer is fine; I just would not want the commitment made by accident.
  3. Decide how the batch of backlog-derived PRs from this author should be sequenced — that is a maintainer call, not something this PR should absorb.

Deferring to the maintainer on that basis. Nothing here needs rework from the author as far as the code goes.

中文说明

信心度:3/5 —— diff 本身我会毫不犹豫合并;打 3 分完全是因为缺少证据、以及只有人能做的维护者决定,而不是对代码有疑虑。

退一步看:我在读 diff 之前写下的独立方案就是——删掉那次多余拷贝、在包内构造器上写明约束、再补一个回归测试钉住它。这个 PR 正是如此,7 行生产代码。它达到甚至不亚于我自己的做法,我也没找到更简的路径:没有可砍的部分、没有夹带改动、没有范围蔓延。半年后维护这个类我会感谢作者——构造器不再对一个两层调用之前就已冻结的结构做递归拷贝,而注释讲清了"为什么",也就是那个不显然的点。

我也确认了问题真实存在,而不是被假定的:这个重复拷贝在 main 上读三个方法就能验证,并且它就是 #13313 里的 R1-20 ——那份 backlog 是维护者从 #12654 合并后复审中整理出来的。这不是把理论加固包装成修复。

那为什么不批准?因为没有测试证据,而我不愿为一个并不存在的结果背书。该 commit 上所有 pull_request 工作流都以 action_required 结束——Java 通道(SDK Java (fast):编译、Checkstyle、HostedHarnessClientTest)从未启动,而 sdk-java.yml 在 PR 上没有别的入口。作者的本地结果看起来合理,diff 里也没有与之矛盾之处,但"合理"是作者的自述,不是一个绿色检查。此刻批准恰恰是这个 gate 要防的失败模式:一个看起来干净的 fork PR 仅凭静态阅读就被放过。

我也没有留下让 finalize 任务据以批准的延后指令。该 head 的待运行数为 0——这些工作流是以 action_required 状态"已完成",而不是在飞——所以那个任务没有任何东西可等。放行工作流是人的动作,结论应在其发生后重新评估,而不是现在预先承诺。

有一件超出本 PR 的事需要维护者看到:该作者有 13 个开放 PR,其中 12 个是今天开的,每一个都是从已记录的复审 backlog 中取出的小修复。单独看,这一个干净,我会收。当作一股流量看,它值得一轮有意识的处理——12 次各自独立的自动批准,与维护者主动选择合并一批,不是同一个决定;而这些 backlog 足够大,后续还会不断产生同类 PR。我是按本 PR 自身的价值评估并按此推荐的;点出数量是为了让这种模式成为一个选择,而不是默认结果。

能让我转向批准的条件,按顺序:

  1. 批准该 head 上待运行的工作流(或赞助 @qwen-code /verify),让 Java fast tier 产出真实的编译 / Checkstyle / 测试证据,然后重跑 @qwen-code /triage。这是唯一实质缺口。
  2. 确认 README 那一行是要作为对外 SDK 承诺(两个视图共享同一份快照),还是本应放在类 Javadoc 里的内部说明。两种答案都可以,我只是不希望这个承诺是无意间做出的。
  3. 决定这位作者这批源自 backlog 的 PR 应如何排序推进——这是维护者的判断,不该由本 PR 承担。

据此转交维护者。就代码而言,作者这边没有任何需要返工的地方。

— Qwen Code · qwen3.8-max-2026-09-02

Reviewed at d1cf3f3107b7dd81457ebc88db4152c8e1958a84 · re-run with @qwen-code /triage

@qwen-code-review-bot

Copy link
Copy Markdown
Collaborator

⏸️ Deferring to the maintainers — needs a human call on this one.

Escalating to a maintainer — the code review is clean and I would land this diff, but I cannot approve it on a static read alone.

Why this needs a human:

  1. No CI has run on this head. All four pull_request workflow runs on d1cf3f3107b7dd81457ebc88db4152c8e1958a84 completed as action_required, awaiting workflow approval for this fork. The Java lane that would compile the module, run Checkstyle and execute HostedHarnessClientTest is SDK Java (fast) under Managed Agent gate, and sdk-java.yml has no pull_request trigger of its own — so releasing those runs (or sponsoring @qwen-code /verify, since the author has read access only) is the one action that turns the author's local results into evidence. Re-run @qwen-code /triage afterwards and it should approve on its own.
  2. A documented SDK guarantee is being added. The README now promises that getEvents() and getRaw().get("events") expose one shared deeply immutable snapshot. That is reasonable and memory-relevant for SDK users, but it becomes a contract future refactors of HarnessTranscriptPage must honour. Worth a deliberate yes rather than an incidental one.
  3. Volume context. The author has 13 open PRs, 12 opened today, each a small fix taken from a recorded review backlog (this one is R1-20 of [Backlog] sdk-java Hosted Harness client — 49 deferred review findings from #12654 post-merge review #13313). Individually this PR is clean; as a stream it deserves one deliberate maintainer decision about sequencing rather than a series of independent approvals.

What I did verify, so the call is not being handed over blind: JsonSupport.parseObject already returns a recursively frozen map, and optionalList returns the same list instance inside it, so the constructor's immutableObject(raw) really was a second full copy of the event graph — the finding is real and statically provable on main. All four downstream consumers (the single construction site in HostedHarnessClient.getTranscript, QwenHostedHarnessConnector, HostedHarnessMySqlIT, and the Mockito-based connector tests) read contents only and depend on neither wrapper identity nor mutability. The new regression is load-bearing: both assertSame calls fail on base and pass only with the fix. Non-blocking, and explicitly not a request to widen this PR: the same redundant re-copy remains in HarnessSessionStatus and DaemonCapabilities.

中文说明

转交维护者——代码审查是干净的,这个 diff 我会合,但仅凭静态阅读我不能批准。

为什么需要人来定:

  1. 该 head 上完全没有跑过 CI。 d1cf3f3107b7dd81457ebc88db4152c8e1958a84 上四个 pull_request 工作流全部以 action_required 结束,等待对该 fork 批准运行工作流。真正会编译模块、跑 Checkstyle、执行 HostedHarnessClientTest 的 Java 通道是 Managed Agent gate 下的 SDK Java (fast),而 sdk-java.yml 自身没有 pull_request 触发器——因此放行这些运行(或赞助 @qwen-code /verify,因为作者只有 read 权限)是把作者本地结果变成证据的唯一动作。之后重跑 @qwen-code /triage,它应能自行批准。
  2. 正在新增一条对外 SDK 承诺。 README 现在承诺 getEvents() 与 getRaw().get("events") 共享同一份深度不可变快照。这对 SDK 使用者合理且与内存相关,但它会成为将来重构 HarnessTranscriptPage 必须遵守的契约,值得明确点头,而不是顺带成立。
  3. 数量背景。 该作者有 13 个开放 PR,其中 12 个今天开出,每个都是从已记录复审 backlog 中取出的小修复(本 PR 对应 [Backlog] sdk-java Hosted Harness client — 49 deferred review findings from #12654 post-merge review #13313 的 R1-20)。单独看这个 PR 干净;作为一股流量,它值得维护者就排序做一次有意识的决定,而不是一连串各自独立的批准。

我已核实的部分,以免把这个判断完全空白地交出去:JsonSupport.parseObject 返回的本就是递归冻结的 map,optionalList 返回的正是其内部同一个 list 实例,所以构造器里的 immutableObject(raw) 确实是事件对象图的第二次完整拷贝——该问题真实存在,且在 main 上可静态证明。四个下游消费者(HostedHarnessClient.getTranscript 中唯一的构造点、QwenHostedHarnessConnector、HostedHarnessMySqlIT,以及基于 Mockito 的 connector 测试)都只读内容,既不依赖包装对象身份也不依赖可变性。新增回归是有承重作用的:两个 assertSame 在 base 上失败,只有打了修复才通过。非阻塞、且明确不是要求扩大本 PR:同样的重复拷贝仍存在于 HarnessSessionStatus 与 DaemonCapabilities。

— Qwen Code · qwen3.8-max-2026-09-02

Reviewed at d1cf3f3107b7dd81457ebc88db4152c8e1958a84 · re-run with @qwen-code /triage

@qwen-code-review-bot qwen-code-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Downgraded from Approve to Comment: CI still running. Reviewed.

中文说明

⚠️ 已从批准降级为评论:CI still running。 已审查。

— deepseek-v4.1-flash-1017 via Qwen Code /review (v0.27.2)

@wenshao

wenshao commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

PR 17115 round 1 verification — Verdict: merge-ready — 45/45 scripted assertions passed, 0 failed; full SDK-Java suite 429/429 on the head and 430/430 on the trial merge with origin/main (9 skipped each). Verified head: d1cf3f3107b7dd81457ebc88db4152c8e1958a84. Open blocking review threads: 0 of 0, 0 left unmeasured; one non-blocking Low documentation finding.

中文摘要

结论:merge-ready。 改动成立:分页构造器不再复制已经冻结的解析结果,getEvents() 与 getRaw().get("events") 在 head 上指向同一份事件对象图,深度不可变性与取值都保持不变。base 臂的同一套探针给出两份对象图(500 条事件的最大分页上容器数 5003 对 2502,共享容器 0 对 2501),A/B 承重。

  • A/B:作者新增回归在 base 上按预期断言失败、head 与合入 main 后的树通过;独立探针在 3 条、空、深层嵌套、500 条四种分页形状上逐层按身份遍历,43 条断言全绿。证据见 01-ab-snapshot-identity.png。
  • 变异:6 个有意义的变异全部被杀,另 1 个等价变异(JDK 的 unmodifiableList 对已不可变列表返回同一实例)已实测说明,不算覆盖缺口。见 02-mutation-matrix.png。
  • 门禁:head 全模块 429 测试全绿;与 origin/main(62 个提交,其中 1 个提交改到本 PR 所改的测试文件与 HostedHarnessClient.java)的试验合并无冲突,430 测试全绿;Checkstyle 两臂成功;README 过 Prettier。
  • findings:1 条 Low——PR 正文把 256 条事件的分页称作「matching the route's limit」,实际路由默认 100、上限 500;结论不受影响,改文案或按 500 重测即可。
  • 未覆盖:未跑 fast tier 尾部的 mvn install 与 managed-agent-server runtime-broker H2 套件(公共 API 未变,消费者只读 getEvents());无堆/延迟基准;本 head 上的 PR CI 从未运行,本轮即为该缺口的 Java 车道证据。

Central claim and A/B

The PR's central claim: HarnessTranscriptPage should retain one deeply immutable event snapshot, shared by getEvents() and getRaw().get("events"), instead of retaining a second recursively copied event graph. JsonSupport.parseObject already returns immutableObject(parsed), and optionalList returns the list instance inside that frozen map, so the removed immutableObject(raw) was a second full copy of the same values.

Claim Oracle base 84b5b53f head d1cf3f31 trial merge c56f3da5
Both accessors expose one snapshot getEvents() == getRaw().get("events") through the public SDK no yes yes
One retained event graph, 500-event max page distinct Map/List containers reachable from the page, by identity 5003 (0 shared) 2502 (2501 shared) 2502 (2501 shared)
Same relation, 3-event page same walk 33 (0 shared) 17 (16 shared) 17 (16 shared)
Empty and deeply nested pages same walk two views, 3 and 19 containers one view, 2 and 10 containers one view
Deep immutability mutate every retained container; UnsupportedOperationException required all guarded all guarded all guarded
Values unchanged SHA-256 of JsonSupport.encode(raw) and of the events view fed4d0337aa2… fed4d0337aa2… fed4d0337aa2…
New regression test HostedHarnessClientTest#sharesOneDeeplyImmutableTranscriptSnapshot fails at line 1328 passes passes

The union counts include the raw root map, which is why base is 2 × (head − 1) + 1 rather than exactly 2 × head. The probe drives the real public client against a loopback com.sun.net.httpserver fixture serving the transcript route, then walks Map/List identity — no heap estimate and no timing threshold. Witness: 01-ab-snapshot-identity.png.

A/B: one shared event snapshot at the route maximum, base vs head vs trial merge

The removed copy really is the whole event graph: JsonSupport.parseObject ends in immutableObject(parsed) (JsonSupport.java:321-332), immutableObject rebuilds every nested map and list (JsonSupport.java:417-426), and optionalList casts the list already inside that frozen map (JsonSupport.java:520-529). On base the constructor ran immutableObject(raw) again and wrapped the original list in Collections.unmodifiableList; on head it retains both references the caller supplied.

Existing review findings

review-threads.json at the verified head: 0 threads, 0 change requests, no unresolved or blocking thread — nothing to measure. The review bot's three stage comments are not threads; they deferred for (a) the absence of any CI run on the head and (b) a maintainer decision on the new README guarantee. Neither names a code defect. This round answers both: the Java lane now has executed evidence (below), and the documented guarantee is measured true for small, empty, deeply nested and maximum-size pages.

Corrections

The bot's stage-2 note says the redundant re-copy "still exists next door" in HarnessSessionStatus and DaemonCapabilities. That is accurate for HarnessSessionStatus — its constructor calls JsonSupport.immutableObject(raw) — but not for DaemonCapabilities, which uses shallow Collections.unmodifiableList / unmodifiableMap wrappers (DaemonCapabilities.java:22-26), not a second recursive copy. This is a correction to the description, not a request to widen the PR; the transcript page remains the only double deep copy the bot named.

Findings

L1 — Low — the evidence fixture is not the route's limit. The Pull Request body says the independent fixture uses "a 256-event page, matching the route's limit"; the transcript route's default limit is 100 and its maximum is 500 (packages/core/src/services/session-transcript-reader.ts:101-102). 256 is neither, so the 2,050 → 1,025 table is not a maximum-page measurement. The identity mechanism is independent of payload size, and the independent probe at the 500 cap reproduces the same doubling (5,003 → 2,502 union containers), so the conclusion stands and no code change is needed; only the sentence (or the fixture size) needs correcting. Reproduce: grep -n "SESSION_TRANSCRIPT_\\(DEFAULT\\|MAX\\)_LIMIT" packages/core/src/services/session-transcript-reader.ts.

What ran

  • SDK-Java module, head: mvn -o --batch-mode -Dmaven.repo.local=<repo> test in packages/sdk-java/qwencode — 429 tests, 0 failures, 0 errors, 9 skipped; the new sharesOneDeeplyImmutableTranscriptSnapshot is in the Surefire XML and passed.
  • SDK-Java module, trial merge with origin/main c56f3da5: git merge-tree --write-tree d1cf3f31 origin/main exited 0 (tree 9c3a0161); the merged module has both this PR's page change and main's hosted-workspace-shell/4 profile change. Full suite 430 tests, 0 failures, 9 skipped; the new regression passed.
  • Focused A/B: the PR's own test file copied byte-for-byte into the base arm fails at HostedHarnessClientTest:1328 with expected: …UnmodifiableRandomAccessList@10ed037a… but was: …UnmodifiableRandomAccessList@76e4212…; the same test passes on head and on the merge.
  • Probe: 43/43 assertions (probe-results.json), covering one shared view, exact container counts, zero mutable containers at every nesting level, and SHA-256 equality of the encoded raw and events values across base, head and merge.
  • Checkstyle: mvn -o --batch-mode checkstyle:check — BUILD SUCCESS on head and merge. The project's checkstyle:check covers main sources; the changed test file is not in its scope.
  • Formatting: npx prettier --check packages/sdk-java/qwencode/README.md — pass.
  • Mutation matrix (mutations.json, witness 02-mutation-matrix.png): M1 restore immutableObject(raw) — killed at line 1328; M2 re-wrap events in Collections.unmodifiableList — equivalent, because that call returns the same instance for an already unmodifiable list (measured same_instance=true, class Collections$UnmodifiableRandomAccessList), so the two forms are behaviourally identical; M3 the base shape — killed; M4 mutable raw root — killed because put no longer throws (line 1336); M5 new ArrayList<>(events) — killed; M6 getRaw() returning a copy — killed; M7 control (getNextCursor() → null) — killed at line 1333, which proves the test actually executes and its later assertions are live. Meaningful mutations: 6/6 killed, 1 equivalent.

Mutation matrix: 6/6 meaningful mutations killed; M2 is equivalent by JDK identity

Trial merge

origin/main was 62 commits ahead of the PR base; one of them (f3dc48c79e, the fixed-interval /loop work) modified HostedHarnessClientTest.java — the file this PR adds its test to — and HostedHarnessClient.java. merge-tree reports no conflict, and the merged tree still contains this PR's constructor change, its new test, and main's new lifecycle profile. The merged module compiles, passes its full suite, its probe cells and Checkstyle, so the change carries forward without resolution work.

Not covered

  • The fast tier continues after the SDK suite with mvn install and the managed-agent-server runtime-broker H2 suite; this local round stopped at the SDK module. The change alters no public signature, field or serialization — only where an existing immutable value is retained — and the one production consumer reads getEvents().isEmpty(), which the probe exercises.
  • No heap or latency benchmark was run; the PR explicitly makes none, and the retained-container identity counts are the mechanism evidence.
  • No live model, daemon or managed-service run; the fixture is a loopback HTTP server and the public SDK.
  • The PR's own CI never ran on the verified head: every pull_request workflow completed as action_required (awaiting fork workflow approval), so the only checks on the commit were bot orchestration. This round supplies the Java evidence that gate was meant to produce, but it does not substitute for the maintainer releasing those runs.

Reproduce

cd packages/sdk-java/qwencode
mvn --batch-mode --no-transfer-progress test
mvn --batch-mode --no-transfer-progress checkstyle:check
mvn --batch-mode --no-transfer-progress -Dtest='HostedHarnessClientTest#sharesOneDeeplyImmutableTranscriptSnapshot' test

Publishing under the explicit --publish consent of this round 1.

— DeepSeek-V4.1-Flash-1017@fda99a87 via Qwen Code /verify-pr (v0.27.3; skill 87a82685e114)

@wenshao
wenshao enabled auto-merge (squash) November 14, 2026 13:58

@yiliang114 yiliang114 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: APPROVE

Single-call-site invariant clean-up — the constructor is package-private, and its only caller (getTranscript) passes a deeply immutable parsed response from JsonSupport.parseObject and its events view extracted via castList (pure cast). The old Collections.unmodifiableList + JsonSupport.immutableObject were redundant re-copies on top of already-frozen data.

The test walks the real loopback HTTP + SDK stack: assertSame confirms list and element identity sharing, and six assertThrows(UnsupportedOperationException) probes nested immutability at five container levels — root map, events list, event map, content list, and content map — plus the documented hasMore mutation guard.

No P0/P1 findings. This is a clean, well-scoped optimization.

CI: compile-lane checks (Build unit-test tree, Lint & Static) are queued at this head. The Java module tests passed on Linux per the PR body (Temurin JDK 21, Java 11 target, Maven 3.10.0). No CI regression is expected for this 3-file, +42/−3 change.

@wenshao
wenshao merged commit 8937085 into QwenLM:main Nov 14, 2026
117 of 124 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Managed Agent gate failed

Run 43367968653 · commit d1cf3f3107b7

Failing tests

  • com.alibaba.qwen.code.managedagent.persistence.AliyunToolPublicationReadRetryTest.transientReadsRecoverWithTheRealSdk(String, int, String)[4]
  • com.alibaba.qwen.code.managedagent.persistence.AliyunToolPublicationReadRetryTest.transientReadsRecoverWithTheRealSdk(String, int, String)[5]

@github-actions

Copy link
Copy Markdown
Contributor

Managed Agent gate failed

Run 43602749599 · commit d1cf3f3107b7

Failing tests

  • com.alibaba.qwen.code.managedagent.WorkspaceSessionCloseMySqlIT.closeCommitsBeforeQueuedTurnAndActionAdmissionsCanInspectTheSession
  • com.alibaba.qwen.code.managedagent.HostedWorkspaceToolTurnIT.malformedShellUnicodeIsCorrectableBeforeAcquisition(String)[2]
  • com.alibaba.qwen.code.managedagent.HostedPublicWorkspaceIT.publicShellV2DeletionTriggersCollectionWithoutRetirementSeams
  • com.alibaba.qwen.code.managedagent.HostedAutomationFaultGatesIT.fg11fPublicationFaultsSettleOnceOnMySql
  • com.alibaba.qwen.code.managedagent.HostedShellLifecycleRecoveryIT.publicDeletionRecoversOriginalResources(String)[1]
  • com.alibaba.qwen.code.managedagent.HostedShellLifecycleRecoveryIT.publicDeletionRecoversOriginalResources(String)[2]
  • com.alibaba.qwen.code.managedagent.HostedShellLifecycleRecoveryIT.publicDeletionRecoversOriginalResources(String)[3]
  • com.alibaba.qwen.code.managedagent.HostedShellLifecycleRecoveryIT.publicDeletionRecoversOriginalResources(String)[4]
  • com.alibaba.qwen.code.managedagent.EventTransportBrokerGate.thePostCommitPathDoesNotRegress

@qwen-code-review-bot

Copy link
Copy Markdown
Collaborator

Released in v0.27.4.

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.

4 participants