多彩编程 多彩编程MZPH · CODE BLOG
ARTICLE DETAIL

文章详情

深耕前端与后端开发技术的一线实战笔记与踩坑复盘。

omo-senpi 并行延迟节省数学的对抗性验证:诚实标签、变异测试与类型级约束

omo-senpi 并行延迟节省数学的对抗性验证:诚实标签、变异测试与类型级约束 人工智能AI Agent代码智能体多智能体MCP ClientsAgent 编排【免费下载链接】oh-my-openagentOmO: Just type mass ulw keyword with your prompt. Now you are the master of graph engineering.项目地址https://gitcode.com/gh_mirrors/oh/oh-my-openagent点击查看免费下载本篇文章以 oh-my-openagent 仓库中 omo-senpi 包的并行延迟遥测模块telemetry-parallel-latency为背景完整解读其诚实标签化并行节省数学honesty-labeled parallel savings math模块savings-math.ts及其对抗性验证报告。你将理解为什么节省时长必须以波跨距spanMs而非最长单次耗时来建模、(N-1)*mean为什么只能以上界名义暴露、类型系统如何阻止把上界冒充成实测值以及一套可复用的变异探测 独立复算 类型探针三合一验证方法论。验证对象与上下文该验证报告verify-t2.md属于.omo/evidence/telemetry-parallel-latency-v2/证据集针对提交d6dd78b4ffeat(omo-senpi): add honesty-labeled parallel savings math中 todo 2 的交付物进行独立对抗性验证被验证模块savings-math.ts84 行被验证测试savings-math.test.ts12 个测试、31 个expect()调用任务契约文档task-2.md224 行验证者的角色定位值得注意独立验证者没有实现 todo 2也没有修改任何源文件或测试文件所有变异mutation实验都在/tmp/vt2-scratch等临时副本中进行、事后删除。这意味着验证结论verdict: confirmed置信度 0.93完全来自对提交产物的外部审查而非作者自证。核心数学契约三个纯函数savings-math.ts对外暴露三个纯函数契约如下对应 task-2.md 中的 Contract 表函数公式返回类型modeledWallClockSavedMs(wave)sum(dᵢ) - wave.spanMsN1 时为0{ label: modeled; valueMs: number }upperBoundSavedMs(wave)(N-1) * mean(dᵢ)N1 时为0{ label: upper_bound; valueMs: number }savedRoundTrips(waves)Σ max(maxConcurrency_wave - 1, 0)number从源码看三者均为无 IO、无时钟读取的纯函数savings-math.ts模块本身除自身类型声明外零 import——这是验证报告中纯函数、无副作用结论的直接来源。输入契约是结构化子集MeasurableWaveexport type MeasurableWave { readonly calls: readonly MeasurableCall[] // { startMs; endMs }[] readonly spanMs: number readonly maxConcurrency: number }由于wave-assembler.ts导出的ConcurrencyWave恰好是这一结构的超集wave-assembler.ts因此无需任何适配器即可直接传入。验证者用独立 tsgo 工程传入一个声明为ConcurrencyWave的探针三个函数全部零报错从类型层面确认了structural subset契约成立。为什么是spanMs而不是max(duration)4.5 倍夸大的陷阱这是整个模块设计动机的核心也是 todo 2 的 B1 禁令plan 禁止的回归类型重叠型波不保证同时开始。链式波 A(0-5)、B(4-9)、C(8-12) 实际耗时 12msspan 公式报告节省 2ms而max变体报告 9ms即4.5 倍夸大。真正同时启动的批次满足spanMs max(duration)因此诚实的并行批次数值不变。源码第 46 行落实了这一设计return { label: modeled, valueMs: sum(durations) - wave.spanMs }关键点在于wave.spanMs是从波直接读取、绝不重算。grep确认savings-math.ts中不存在minStart/maxEnd计算——边界语义由上游 wave-assembler.ts 的buildWave统一负责spanMs maxEnd - minStart下游若重算会让两处定义静默漂移。验证报告中的 QA 表通过真实assembleWaves复现而非手工 fixture量化了这一差异wave N sum(d) span modeled upperBound maxConc savedRT simultaneous 4 8.20 2.20 6.00 6.150 4 3 long-tail 4 9.90 9.00 0.90 7.425 4 3 chained 3 14.00 12.00 2.00 9.333 2 1 single 1 4.00 4.00 0.00 0.000 1 0四行数据分别印证诚实并行批次数值不变simultaneous 保持 6.00长尾批次 modeled 0.90 与 upperBound 7.425 显著分离链式波 savedRT 为 1 而非 N-12单调用波全零。上界必须以上界的名义存在类型级诚实标签(N-1) * mean(dᵢ)是上界而非测量值因此只能通过upperBoundSavedMs暴露。为防止调用方把上界当成实测值使用两个返回类型携带互斥的字符串字面量标签export type ModeledSavedMs { readonly label: modeled; readonly valueMs: number } export type UpperBoundSavedMs { readonly label: upper_bound; readonly valueMs: number }验证者不满足于看起来像打了标签而是在独立 tsgo 工程中重建了label-probe.ts证明这是双向编译错误label-probe.ts(14,14): error TS2322: Type UpperBoundSavedMs is not assignable to type ModeledSavedMs. Types of property label are incompatible. Type upper_bound is not assignable to type modeled. label-probe.ts(17,14): error TS2322: Type ModeledSavedMs is not assignable to type UpperBoundSavedMs. Type modeled is not assignable to type upper_bound.双向 TS2322 意味着任何把 one 冒充成 the other 的赋值都会在编译期失败且必然留下可 grep 的显式 cast。task-2.md 的 MUTATION PROOF 章节也记录了同一探针在 repo 内产生的原始报错。另外grep确认目前savings-math尚未被仓库其他模块 import——默认路径没有泄漏风险类型品牌为未来 todo 6 接线时提供保障。验收标准表25 项逐条判定验证报告的核心产物是如下验收标准表完整继承于此Deciding observation 均可在源码/测试中定位CriterionVerdictDeciding observationmodeledWallClockSavedMs sum(d) - wave.spanMs, not- max(d)PASSSource line 46:sum(durations) - wave.spanMs.grepfinds noMath.maxin the modeled path. Mutation A proves the test detects themaxvariant.Chained wave pins 2.00 and rejects 9.00PASSTest lines 136-137:toBeCloseTo(2.0, 10)plusnot.toBe(9.0). Under mutation A the test fails alone:Expected: 2, Received: 9.savedRoundTripsusesmax(maxConcurrency - 1, 0), notN - 1PASSSource line 59. Chained wave N3, maxConcurrency2, result 1. Mutation B fails 3 tests.(N-1)*meanexposed only under anupperBoundname, never the defaultPASSOnlyupperBoundSavedMscomputes(durations.length - 1) * mean; it returnslabel: upper_bound. No other export returns that value.Negative results not clampedPASSspan 10 sum 2 returns-8(test line 126). Mutation C (clamp) fails that test.Honesty label enforced at the TYPE levelPASSIndependent tsgo run produced TS2322 inbothdirections (see evidence). Not merely looks branded.ConcurrencyWaveflows in with no adapterPASSProbe passing a declaredConcurrencyWaveinto all three functions typechecked with zero errors.Module readswave.spanMs, does not recomputemaxEnd - minStartPASSsavings-math.tscontains nominStart/maxEndcomputation; it consumeswave.spanMsdirectly.Arithmetic matches independent recomputationPASSRecomputed in Python with no repo code: simultaneous 6.000000, long-tail modeled 0.900000 / upper 7.425000, chained 2.000000 / savedRT 1, N1 - 0, N0 - 0, multi-wave savedRT 4. All match the test expectations.Long-tail upper bound uses tolerance, nottoBe(7.43)PASSTest usestoBeCloseTo(7.43, 2). Exact value is3*(9.9/4) 7.425000000000001;toBe(7.43)would fail (verified:7.425... 7.43isFalse). See caveat below.Malformed input: no throw, no NaN/Infinity leakPASSNine classes fed directly to the exports (empty, NaN end, Infinity end, negative durations, NaN span, Infinity span, NaN/-Infinity maxConcurrency, all-reversed). Zero throws, zero non-finite values in any returned metric.No clock reads / no async in the test filePASSgrep -nE Date\.now\|performance\.now\|setTimeout\|await\|async\|sleep\|Math\.random- NONE, in both module and test.given/when/then naming, no Arrange-Act-AssertPASSEvery block is#given/#when/#then. No AAA markers in the diff.Noas any, nots-ignorePASSGrep over the added lines: none found.kebab-case filenames, no catch-all util/helper namesPASSsavings-math.ts,savings-math.test.ts. Noutil/helperidentifiers.No emojis, no em dashesPASSPython scan reports zero non-ASCII characters in either file.Pure functions, no IO or clock readsPASSNo imports at all insavings-math.tsbeyond its own type declarations. 5 repeated evaluations yield aSetof size 1.Files under 250 pure-LOC ceilingPASSawk !/^[[:space:]]*$/ !/^[[:space:]]*(\/\/)/ \| wc -l- module 75, test 223.Scope: only the two new files plus evidencePASSgit show --statlists exactly 3 files, all additions. No forbidden path touched.Evidence numbers reproducePASSThe QA table intask-2.mdreproduced byte-identically through the realassembleWaves, not hand fixtures. Suite counts reconcile (see note).值得注意的工程约束细节git show --name-only对turn_completed、telemetry-core/、omo-codex/、omo-opencode/等禁止路径的检查全部为NO FORBIDDEN PATHS TOUCHED、git show的 diff 中无turn_completed出现说明该提交的变更范围被严格限制在遥测新模块内部。变异探测证明测试不是同义反复验证报告最有说服力的部分是三组变异探测Mutation probes。所有变异都施加在/tmp/vt2-scratch的副本上仓库内文件全程git status干净。Probe A——把减数翻转为Math.max(...durations)46: return { label: modeled, valueMs: sum(durations) - Math.max(...durations) } Expected: -8 Received: 1 (fail) #then the negative result is surfaced instead of clamped to zero Expected: 2 Received: 9 (fail) #then it uses the wave span and never the longest single duration 10 pass 2 fail这正是 todo 2 禁令中的 B1 回归形态。为排除链式用例是搭了兄弟用例失败的顺风车验证者用-t never the longest single duration单独运行该用例0 pass / 1 failExpected 2, Received 9证明链式用例独立承担验证责任。结论变异被杀灭MUTATION KILLED非同义反复。Probe B——savedRoundTrips改用calls.length - 159: total wave.calls.length - 1 Expected: 0 Received: -1 (fail) #then every metric is zero rather than NaN Expected: 1 Received: 2 (fail) #then it follows max concurrency rather than the call count Expected: 4 Received: 5 (fail) #then single-call waves contribute nothing ... 9 pass 3 fail结论变异被杀灭。链式波N3、maxConcurrency2正确要求 1而非 N-12。这一行源码对应 savings-math.ts 中的total Math.max(wave.maxConcurrency - 1, 0)并且跳过非有限maxConcurrency的波。Probe C——给 modeled 结果加上Math.max(0, ...)钳制46: return { label: modeled, valueMs: Math.max(0, sum(durations) - wave.spanMs) } Expected: -8 Received: 0 (fail) #then the negative result is surfaced instead of clamped to zero 11 pass 1 fail结论变异被杀灭。负结果不钳制是刻意设计——span 宽于时长总和意味着观测数据彼此矛盾隐藏负值就是隐藏异常。测试文件中对应的硬编码断言位于 savings-math.test.ts。攻击尝试寻找缺陷的失败过程验证者主动发起的攻击尝试同样值得记录它展示了什么才算真正的独立验证同义反复猎杀Tautology hunt逐一检查每个断言是否可能从被测代码反推得出。结论是全部强制值都是硬编码字面量6.0、0.9、7.43、2.0、-8、1、4、0。仅有的两处再推导——测试第 143 行expect(CHAINED_THREE.maxConcurrency).toBe(2)fixture 自检和第 145 行not.toBe(CHAINED_THREE.calls.length - 1)冗余的 belt-and-braces——都不替代独立期望且 Probe B 独立证明了真正干活的是第 144 行的toBe(1)。fixture 独立性测试文件用本地waveOf辅助函数重建spanMs/maxConcurrency而非 import 汇编器理论上可能与wave-assembler.ts漂移。验证者用 Python 独立复算并且通过真实assembleWaves重跑场景三源完全一致。upperBoundSavedMs忽略非有限spanMsspanMs: Infinity时 modeled 为 0 但上界为 2——这是设计使然上界只依赖 durations、从不查询 span且无 NaN 逃逸。默认路径泄漏当前 repo 尚无其他模块 importsavings-math类型品牌为未来接线兜底。记录在案的注意事项Caveats验证报告诚实记录了三个非阻塞问题值得全文引用以避免读者被confirmed一叶障目容差余量极薄expect(upper.valueMs).toBeCloseTo(7.43, 2)通过时实际偏差|7.425000000000001 - 7.43| 0.004999999999999005距阈值0.005仅约 1e-18。断言今天正确、toBe(7.43)也确实该避免但余量比看上去薄。toBeCloseTo(7.425, 10)能用真实余量表达同一意图。套件计数与证据不一致task-2.md记录 115 pass / 14 files验证者实测 118 pass / 14 files。差异完全由并发 worker 对wave-assembler.ts/wave-assembler.test.ts的未提交修复解释40 测试行把MAX_TRACKED_CALLS门限从paired.length改为paired.length pending.size。该 diff 只改内部上限条件未触碰ConcurrencyWave类型表面calls/spanMs/maxConcurrency因此不影响 todo 2 契约。证据声称的探针文件已删除task-2.md引用的label-probe.ts已不存在。验证者不轻信该声明而是在独立 tsgo 工程中重建探针、亲自双向复现 TS2322 错误才将其记为独立确证。恶意输入防护九类脏数据的零泄漏保证测试套件覆盖了九类畸形输入见 savings-math.test.ts空 calls 数组、NaN 结束时间、Infinity 结束时间、负 duration反序区间、NaN span、Infinity span、NaN/-Infinity maxConcurrency、全反序列表。防护的底层机制在usableDurations中savings-math.ts只有当起止时间戳均有限且endMs startMs时调用才贡献 duration反序或非有限区间在此被丢弃使 NaN/Infinity 永远无法到达上报指标。任务文档还从四个维度排除了风险对应 task-2.md 的 Adversarial classes 表并发/竞态纯函数 不可变输入、无共享可变状态、IO/文件系统/网络无外部 import、资源耗尽分配只随调用方传入的 wave 线性增长且汇编器以MAX_TRACKED_CALLS 2000封顶见 wave-assembler.ts、隐私泄漏只消费数值时间戳不读取工具名/参数/结果。可复用的对抗性验证方法论从这份报告中可以提炼出一套可迁移到任何数值计算模块的验证清单独立身份验证者不实现被测任务、不修改任何仓库文件全部实验在/tmp副本中进行事后清理并给出 cleanup receiptgit status --short仅剩并发 worker 的脏文件。范围核验用git show --statgit show --name-onlygrep turn_completed确认提交只触碰允许路径、不含禁忌符号。双通道测试模块单测12 pass与整目录套件118 pass / 14 files双重通过叠加tsgo --noEmit类型检查零输出。变异三件套对每个关键公式的相反实现max变体、N-1变体、钳制变体注入变异并确认测试杀灭用-t隔离运行排除搭便车。三源交叉复算测试期望值、Python 独立重算、真实assembleWaves输出三方对齐杜绝 fixture 与实现共谋漂移。类型级约束实证用独立 tsgo 工程重建探针双向证明字面量标签导致 TS2322而非依赖仓库内已被删除的探针文件。失败过程公开记录所有未找到缺陷的攻击尝试与三个 caveats让confirmed的可信度可被读者自行评估。验证命令速查复现验证过程的核心命令均在仓库根目录下执行# 单模块测试与整目录套件 bun test packages/omo-senpi/src/components/telemetry/savings-math.test.ts bun test packages/omo-senpi/src/components/telemetry/ # 类型检查 bun run --cwd packages/omo-senpi typecheck tsgo --noEmit -p packages/omo-senpi/tsconfig.json局限说明上述命令依赖仓库已安装的 bun 与 tsgo 工具链QA 表格复现需通过真实assembleWaves构造场景wave-assembler.ts验证报告中以/tmp/savings-qa.ts临时脚本完成、随后删除仓库内未保留该脚本。结论对抗性验证以 0.93 置信度确认了 todo 2 交付物savings-math.ts的数学契约span 建模、上界隔离、并发回合数与 12 个测试的断言网络经受住了三类变异注入、独立复算与类型级探针的多重考验。这份验证报告的价值不仅在于confirmed这个结论更在于它示范了如何在不触碰被测代码的前提下通过可复现的命令序列与可审计的证据链把测试确实在防住真正的回归这件事从主观信心变成可检验的事实。赞分享人工智能AI Agent代码智能体多智能体MCP ClientsAgent 编排【免费下载链接】oh-my-openagentOmO: Just type mass ulw keyword with your prompt. Now you are the master of graph engineering.项目地址https://gitcode.com/gh_mirrors/oh/oh-my-openagent点击查看免费下载相关推荐oh-my-openagent 并行延迟遥测的对抗性验证parallelism_summary 会话级发射的注册顺序约束与变异测试oh my openagent 并行延迟遥测的对抗性验证 parallelism_summary 会话级发射的注册顺序约束与变异测试 本文围绕 oh my o人工智能AI Agent代码智能体多智能体MCP ClientsAgent 编排omo-senpi 并行度遥测的对抗性验证实战从 wave 装配、注入时钟到会话状态泄漏的边界探测omo senpi 并行度遥测的对抗性验证实战从 wave 装配、注入时钟到会话状态泄漏的边界探测 导读 本文基于 .omo/evidence/telemet人工智能AI Agent代码智能体多智能体MCP ClientsAgent 编排遥测仪表盘对抗性验证实战omo-senpi 原生工具调用并行度卡片如何从 needs-fix 走到 confirmed遥测仪表盘对抗性验证实战omo senpi 原生工具调用并行度卡片如何从 needs fix 走到 confirmed 本文以 oh my openagent人工智能AI Agent代码智能体多智能体MCP ClientsAgent 编排创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表