Repository navigation
perf(java): share immutable transcript page snapshots - #17115
Conversation
|
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 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 ( 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 也如实说明了哪些没有实测。 问题: 是已观测到的问题,不是理论加固。我没有只看描述,而是对照 方向: 对齐。这是源自我们自身复审 backlog 的 Java SDK 内部内存优化,对调用方没有任何接口面变化。方向信号方面,上游 CHANGELOG(2.1.323)也有针对 transcript 常驻内存的改动——"已完成子代理的 transcript 会更早释放,不再驻留内存"——虽然是不同代码库、不构成直接对应,但说明这个方向是当下真实关注点。 规模: 不适用 —— 未触及核心路径( 方案: 换成我来写也是这样。只读标题和"为什么需要"两节时,我自己的方案是:删掉构造器里的重复拷贝,直接保留调用方已冻结的值,注明唯一的包内调用点必须传入已不可变的对象,并补一个回归测试。这个 diff 正是如此,7 行,没有夹带无关改动或顺手重构。没有想砍的部分。合并前有一个问题值得回答(不是阻塞项):README 的新增内容把"两个视图共享同一份快照"从实现细节变成了对外的 SDK 承诺。这个承诺本身合理(对 SDK 使用者来说这正是与内存相关的关键点),但以后重构这个类时就必须一直遵守。如果是有意的,很好;如果只是想写内部说明,类的 Javadoc 是更收敛的位置。 风险: 无升级风险信号 —— 改动文件均未命中我们跟踪的易回滚高风险路径。这里真正的风险不在 diff,而在证据:CI 情况见代码审查评论,那是目前唯一影响结论的因素。 进入代码审查 🔍 — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
Code reviewNo blockers. The change is correct, and I verified the load-bearing part by reading What makes dropping both copies safe:
Downstream consumers — all four read contents only, and none depends on wrapper identity or on being able to mutate:
The new test is genuinely load-bearing, not decorative: on base code Two non-blocking notes, neither a reason to hold this PR:
Test evidenceThis is the weak point, and it is not the author's fault: no CI has run on this PR at all. All four The only completed checks on this commit are bot orchestration ( Final CI results for
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 Sandboxed verification would settle this: 中文说明代码审查:没有阻塞项。 关键前提是照着 四个下游消费者都只读内容,没有谁依赖包装对象身份或依赖可修改性: 新增测试是有承重作用的,不是摆设:在 base 代码上 两条非阻塞提醒:一是构造器过去是强制不可变,现在改为信任调用方传入不可变对象;对只有一个调用点的包内构造器来说没问题,注释也写明了这个约束,但将来若出现第二个调用点要记得这层依赖。二是同样的重复拷贝在旁边还在: 测试证据:这是薄弱环节,而且不是作者的问题——本 PR 完全没有跑过 CI。 被审 commit 上四个 明确说明:未验证——该 commit 没有任何 CI 运行。 PR 描述称本地完整 沙箱验证可以定这件事: — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
|
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 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 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 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:
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 行生产代码。它达到甚至不亚于我自己的做法,我也没找到更简的路径:没有可砍的部分、没有夹带改动、没有范围蔓延。半年后维护这个类我会感谢作者——构造器不再对一个两层调用之前就已冻结的结构做递归拷贝,而注释讲清了"为什么",也就是那个不显然的点。 我也确认了问题真实存在,而不是被假定的:这个重复拷贝在 那为什么不批准?因为没有测试证据,而我不愿为一个并不存在的结果背书。该 commit 上所有 我也没有留下让 finalize 任务据以批准的延后指令。该 head 的待运行数为 0——这些工作流是以 有一件超出本 PR 的事需要维护者看到:该作者有 13 个开放 PR,其中 12 个是今天开的,每一个都是从已记录的复审 backlog 中取出的小修复。单独看,这一个干净,我会收。当作一股流量看,它值得一轮有意识的处理——12 次各自独立的自动批准,与维护者主动选择合并一批,不是同一个决定;而这些 backlog 足够大,后续还会不断产生同类 PR。我是按本 PR 自身的价值评估并按此推荐的;点出数量是为了让这种模式成为一个选择,而不是默认结果。 能让我转向批准的条件,按顺序:
据此转交维护者。就代码而言,作者这边没有任何需要返工的地方。 — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
|
⏸️ 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:
What I did verify, so the call is not being handed over blind: 中文说明转交维护者——代码审查是干净的,这个 diff 我会合,但仅凭静态阅读我不能批准。 为什么需要人来定:
我已核实的部分,以免把这个判断完全空白地交出去: — Qwen Code · qwen3.8-max-2026-09-02 Reviewed at |
qwen-code-review-bot
left a comment
There was a problem hiding this comment.
中文说明
— deepseek-v4.1-flash-1017 via Qwen Code /review (v0.27.2)
|
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 中文摘要结论:merge-ready。 改动成立:分页构造器不再复制已经冻结的解析结果,
Central claim and A/BThe PR's central claim:
The union counts include the raw root map, which is why base is The removed copy really is the whole event graph: Existing review findings
CorrectionsThe bot's stage-2 note says the redundant re-copy "still exists next door" in FindingsL1 — 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 ( What ran
Trial merge
Not covered
Reproducecd 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' testPublishing under the explicit — DeepSeek-V4.1-Flash-1017@fda99a87 via Qwen Code /verify-pr (v0.27.3; skill 87a82685e114) |
yiliang114
left a comment
There was a problem hiding this comment.
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.
|
|
|
Released in v0.27.4. |


What this PR does
Keeps one deeply immutable event snapshot per Hosted Harness transcript page.
getEvents()and the events member ofgetRaw()now share the parsed response instead of retaining separately copied maps and lists.Why it's needed
JsonSupport.parseObjectalready recursively freezes the response, andgetTranscriptextracts 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
hasMorevalue 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.
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
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
Linked Issues
Refs #13313, R1-20, and its original review finding.
中文说明
此 PR 的改动
让每个 Hosted Harness transcript 分页只保留一份深度不可变事件快照。
getEvents()与getRaw()中的 events 成员共享已经解析的响应,不再各自保留复制后的 Map 和 List。为什么需要
JsonSupport.parseObject已递归冻结响应,getTranscript从中取得不可变事件列表。原分页构造器又递归复制整个响应,同时仍保留第一份事件列表,因此每个保留的分页都重复持有事件容器并多进行一次遍历。构造器仅在包内可见,其唯一调用点提供的正是已经不可变的响应。审阅者验证计划
如何验证
hasMore不变。新增 HTTP 回归在原生产代码上因保留两套独立事件对象图而失败,修复后通过。完整 HostedHarnessClient 测试类、Java 11 release 目标编译、Checkstyle 和格式检查通过。
修改前后证据
独立夹具使用真实回环 HTTP 服务、公开 SDK 和符合路由限制的 256 条事件分页。它按对象身份遍历 Map/List,没有估算堆字节数,也没有用计时阈值判定。
这消除了一份重复事件容器图。上述数量对应夹具数据,不代表整个 JVM 的堆占用减半。
测试平台
环境
Temurin JDK 21.0.13+9、Maven 3.10.0,保留 Java 11 release 编译目标。测试使用受控 HTTP 响应和真实 SDK 解析器及分页 API。
风险与范围
关联问题
关联 #13313 的 R1-20 及其原始审阅发现。