#13103·qwen-code

test(managed-agent): pin the sixteen lines of the Broker provider control that survive mutation

Author: wenshaoCreated Sep 30, 2026Updated Sep 30, 2026
Labelspriority/P3category/integrationscope/testingtype/enhancementstatus/ready-for-agentscope/sdk

Follow-up to #12868, from round 7 of its real-stack verification (report, section 6). The mutation matrix of that round ran 200 mutants over the Broker provider control (Java Broker and TypeScript worker); 184 were killed by the suites, 16 survived. Every survivor's line still exists, unchanged, on main e263741eb0.

Problem

Sixteen lines of the provider control have no test that fails when they are broken. Twelve of them guard a rule the code means to enforce; the other four cannot be reached today or change nothing observable, and are listed so that nobody looks for them again. None of the sixteen is a rule the real stack was seen to break: each line was probed on the real chain and holds. What is missing is the test that keeps it so.

The twelve, with the line on main and the test that would kill the mutant:

Id Line on main Mutation that survives A test that kills it
L11 managed-runtime-provider-worker.ts:153 retire swallows the errors of its steps instead of throwing AggregateError a released Session whose runtime.dispose() rejects: the retirement is logged as failed (retireReleased warns), the entry still becomes a tombstone, the release still answers true
L20 managed-runtime-provider-worker.ts:353 while → if: a release retires at most one Session two released Sessions past RETAINED_RELEASED_SESSIONS at one release (hold two with pending work, then let both go): both are retired
Q6 managed-runtime-provider-worker.ts:180 a directory realpath cannot resolve is admitted (catch returns true) a Shell prepare naming an absolute directory that does not exist is refused
H8 managed-runtime-provider-worker.ts:535 status ignores afterSequence a status with a cursor answers only the progress after it (the real stack does: U4, progress 1 to 4, after 3 only 4)
N17 managed-runtime-provider-worker.ts:659 a ManagedToolConflictError answers the catch-all managed_runtime_provider_operation_failed instead of its own code an operation that raises a conflict (a second prepare of the same reference, or a release over pending work) answers 409 with the conflict's code
T18 managed-runtime-provider-worker.ts:632 a response above the body limit is sent anyway a result that is still above the limit after the fitter answers 413 managed_runtime_provider_too_large
T2 managed-runtime-provider-worker.ts:283 release does not call closeSessionAdmission after a provider release, a raw-path call with the same Session id is refused (assertLegacySession)
T8 managed-runtime-provider-worker.ts:278 a release over pending controls is allowed a release while a control is in flight answers the conflict "still owns unfinished work" and the Session stays
L35 RuntimeBrokerService.java:2380 the ownership check of a terminal record no longer compares the binding's generation a terminal record whose runtimeGeneration differs from its binding's answers runtime_execution_conflict "Saved execution ownership differs"
P5 HttpRuntimeTransport.java:726 a status cursor above 2^53 − 1 is accepted a worker status whose lastSeq or firstAvailableSeq is 2^53 is refused as an invalid cursor
I6 ProviderRuntimeProtocol.java:22 the Session id pattern loses CASE_INSENSITIVE, which the comment above it calls load-bearing a provider reference or control whose sessionId is an uppercase UUID passes the identity check (ProviderRuntimeProtocol.identity)
L34 HttpRuntimeTransport.java:1363 the response buffer grows to the needed size only, without doubling none observable: the bytes are the same, only the number of copies differs. Listed for completeness; may stay

The four that need no test:

  • Q4 (managed-runtime-provider-worker.ts:174), a relative directory is admitted: equivalent, core refuses a relative directory before this line is reached.
  • K39 (RuntimeBrokerService.java:454), a failed acquire counts as a live Session: equivalent, a failed acquire is removed from the map before its future fails.
  • K36 (RuntimeBrokerService.java:443), a DRAINING binding counts as one that can no longer answer: no code sets that state today.
  • H3 (managed-runtime-tool-executor.ts:209), unclaimProviderSession also reopens a released Session: its only caller runs after a claim that a released Session cannot obtain, so the line is not reachable yet.

Requested change

One test per row of the table, in the suite that owns the line: managed-runtime-provider-worker.test.ts for the worker, RuntimeBrokerServiceTest and HttpRuntimeTransportTest for the Broker; ProviderRuntimeProtocol has no test class yet. Where the same mutant can be killed from the real stack only (H8, T2), a unit test of the worker route with the in-process executor is enough.

Acceptance criteria

  • Each of the twelve mutants, applied as in harness/mutants*.mjs (the find and replace of its id), makes at least one test fail.
  • The new tests pass on main unchanged, and are not sensitive to host load (the matrix ran under load; L11 was checked three times against the flake).
  • Q4, K39, K36 and H3 are left as they are, or the dead condition is removed with its comment.

Context

  • The matrix and its summary: results/mutation/matrix.log, summary.json; the mutant definitions with their anchors: harness/mutants.mjs, mutants-r6.mjs, mutants-r7.mjs, mutants-r7c.mjs, mutants-r7d.mjs.
  • The verdicts were measured on the PR head (ebea694e4e for Java, 760174073b for TypeScript, whose TypeScript sources and tests are the head's). They were not rerun on main e263741eb0; the sixteen anchors match there exactly once each, checked statically.
  • The nine older survivors (H3, H8, I6, K36, K39, N17, T18, T2, T8) kept their verdict through rounds 4 to 7; the seven new ones (L11, L20, L34, L35, P5, Q4, Q6) edit lines of e94f781523, 50fb28301e and 9cb9dc86e8.
中文说明

#12868 的后续,来自其真实环境验证第七轮(报告第 6 节)。该轮的变异矩阵在 Broker provider 控制(Java Broker 与 TypeScript worker)上跑了 200 个变异体,184 个被测试套件杀死,16 个存活。每个存活体所在的行在 main e263741eb0 上仍原样存在。

问题

provider 控制里有 16 行代码,改坏之后没有任何测试会失败。其中 12 行守着代码本意要执行的规则;另外 4 行目前走不到或改了也没有可观察的差别,列出来是为了以后不用再查一遍。这 16 行没有一条是真实栈上被观察到违反的规则:每一行都在真实链路上探测过、都成立。缺的是让它一直成立的测试。

12 行的变异与能杀死它的测试(main 上的行号链接见上面英文表格):

Id 存活的变异 能杀死它的测试
L11 retire 吞掉各步骤的错误,不再抛 AggregateError 已释放 Session 的 runtime.dispose() 拒绝:retire 被记录为失败(retireReleased 打 warn),条目仍变成墓碑,release 仍返回 true
L20 while → if:一次 release 最多 retire 一个 Session 一次 release 时有两个已释放 Session 超出 RETAINED_RELEASED_SESSIONS(先用未完成的工作扣住两个,再一起放开):两个都被 retire
Q6 realpath 解析不了的目录被放行(catch 返回 true) Shell prepare 指定一个不存在的绝对目录时被拒绝
H8 status 忽略 afterSequence 带游标的 status 只返回游标之后的进度(真实栈上如此:U4,进度 1 到 4,游标 3 之后只有 4)
N17 ManagedToolConflictError 返回兜底的 managed_runtime_provider_operation_failed 而不是自己的错误码 引发冲突的操作(同一引用第二次 prepare,或在有未完成工作时 release)返回 409 且错误码为冲突自身的码
T18 超过 body 上限的响应照样发出 经过 fitter 后仍超限的结果返回 413 managed_runtime_provider_too_large
T2 release 不调用 closeSessionAdmission provider release 之后,同一 Session id 的 raw 路径调用被拒绝(assertLegacySession)
T8 有未完成控制操作时允许 release 控制操作在飞时 release 返回“still owns unfinished work”冲突,Session 仍在
L35 终态记录的归属检查不再比较 binding 的 generation runtimeGeneration 与其 binding 不一致的终态记录返回 runtime_execution_conflict“Saved execution ownership differs”
P5 大于 2^53 − 1 的 status 游标被接受 worker 的 status 中 lastSeq 或 firstAvailableSeq 为 2^53 时按非法游标拒绝
I6 Session id 正则去掉 CASE_INSENSITIVE,而上方注释说这个标志是承重的 sessionId 为大写 UUID 的 provider 引用或控制操作能通过身份校验(ProviderRuntimeProtocol.identity)
L34 响应缓冲区只按需增长、不翻倍 无可观察差别:字节相同,只是拷贝次数不同。列出仅为完整,可以不管

不需要测试的 4 个:Q4(相对目录被放行)等价,core 在到达这行之前就拒绝相对目录;K39(失败的 acquire 算作存活 Session)等价,失败的 acquire 在其 future 失败之前就已从 map 移除;K36(DRAINING binding 算作无法应答)目前没有代码会设置该状态;H3(unclaimProviderSession 顺带重开已释放的 Session)唯一调用点发生在已释放 Session 拿不到的认领之后,目前走不到。

期望的改动

表中每行一个测试,放在拥有该行的套件里:worker 用 managed-runtime-provider-worker.test.ts,Broker 用 RuntimeBrokerServiceTest 和 HttpRuntimeTransportTest;ProviderRuntimeProtocol 目前还没有测试类。只能在真实栈上杀死的(H8、T2),用进程内 executor 对 worker 路由做单元测试即可。

验收标准

  • 12 个变异体按 harness/mutants*.mjs 里对应 id 的 find/replace 施加之后,至少各有一个测试失败。
  • 新测试在未改动的 main 上通过,且不受宿主负载影响(矩阵是在负载下跑的;L11 针对抖动核对过三次)。
  • Q4、K39、K36、H3 保持原样,或连同注释一起删掉那个死条件。

背景

  • 裁决是在 PR head 上测的(Java 为 ebea694e4e,TypeScript 为 760174073b,其 TypeScript 源码与测试与 head 相同),没有在 main e263741eb0 上重跑;16 个锚点在其上经静态核对各恰好命中一次。
  • 9 个较早的存活体(H3、H8、I6、K36、K39、N17、T18、T2、T8)从第四轮到第七轮裁决未变;7 个新的(L11、L20、L34、L35、P5、Q4、Q6)改的是 e94f781523、50fb28301e、9cb9dc86e8 的行。矩阵、摘要与变异体定义的链接见上面英文部分。