Source Pass 插件怎样改代码又不偷 Authority
一句话
纯 AST pass 只能在没有 capability 和 workspace 的 exact Guest(与目标 artifact/profile 一致的受限分析环境)中改写完整 source;最终 fresh Guest 会从原始 RunRequest 重新验证并选择同一 patch,需要外部 effect 的优化必须另建 Host-owned adapter。
先看一个例子
下面的程序重复计算一个纯标量表达式:
seed = 7
left = seed * seed + 3
right = seed * seed + 3
result = [left, right]
pure_scalar_cse 可以把第二个右值替换为 left;pure_scalar_fold 可以把已知表达式折成 52。这些变化只处理 closed top-level bool/int64 程序,不需要读取文件、调用网络或共享 workspace。
如果表达式里出现函数调用、属性访问、控制流、未知 mutation、整数溢出风险或 compiled-code introspection,整个 pass 返回 not_applicable,原始 source 照常执行。系统不会猜测哪一小段“可能仍然安全”。
真实机制
runtime/passplugin.Registry 保存普通 Go plugin value。Registry 对一个 Host build 是静态的:没有动态 shared-library loader,也不会运行不受信任的 Host plugin code。新 registry 默认 all-off,Host 只显式 enable 命名 pass。
一个 SourcePatchPlugin 暴露 immutable registration,并实现 Transform(...)。执行链是:
unchanged RunRequest
→ authority-free exact Guest 解析完整 source
→ plugin 返回 original/derived source 与 AST identity
→ Host 校验 registration、digest、status 和 replacement count
→ fresh final Guest 再验证 unchanged request
→ Guest 重新推导并选择同一 patch
→ derived program 开始执行
Transform Guest 没有 capability Broker 或 mounted workspace。Patch schema 只接受 applied 或 not_applicable;applied patch 必须带 derived source body、source/AST digest 和非零 replacement count,not-applicable 不能夹带 derived identity。
Registry 在 pass disabled、transform error 或 not_applicable 时调用普通 runner 执行原始 request,因为此时 Agent execution 和 authority-bearing work 尚未开始。Derived execution 一旦开始,就没有“失败后自动回放原程序”的 fallback。
当前两个 runnable pass 都很窄:
pure_scalar_cse只替换相邻、结构相同且静态值一致的+、-、*bool/int64 RHS;pure_scalar_fold只把 closed scalar program 中 total 的+、-、*表达式折成等值 literal。
它们保留 source byte length 与 line layout。Import、call、attribute、control flow、unsupported assignment、heap value、division、int64 overflow 与可观察 compiled-code path 都让整条 pass 不适用。两个 pass 独立运行;没有自动排序或组合。
Exact-Guest correctness fixtures 中,CSE 与 fold 的 pass-off/pass-on result 相同,negative controls 均走 unchanged source。Matched timing 结果却是负的:CSE fixture treatment 慢 14.61%,fold 的保留 run 慢 4.49%。这些 pass 证明静态注册、exact-Guest transform 和 common selector 能工作,不证明性能收益。
Effectful paper pass 不能借纯 patch seam 偷渡。例如 parallel tool call 需要 source-order exception、sibling cancellation 和 late/orphan accounting;batch fusion 需要 per-occurrence budget、receipt 和 item failure;prepared literal hoisting 需要 patch 与 Prepared Family object 的 typed join。缺少这些 Host owner 时,pass 保持 Deferred。
为什么重要
技术上: 纯 AST rewrite 获得了真实、可扩展的 pass 入口,同时把 authority-bearing optimization 留给有明确生命周期的 Host adapter。Transform failure 可以安全回到原始 source,但 effect 可能开始后的 replay 仍被禁止。
产品和业务上: 研究者可以逐个吸收论文中的窄、exact kernel,先测适用范围和真实成本。一个 pass 没有加速或不适用时,平台保留原始执行语义,不必承诺完整论文系统。
不能推出什么
- Static plugin registry 不是动态插件市场、package manager 或 untrusted code loader。
- 两个 scalar pass 不是通用 Python optimizer,也没有自然 workload prevalence 证据。
- 当前结果不能支持 stratum 全套 DataOp、projection、vectorization、batching 或 cross-pipeline reuse。
not_applicable前的原始执行 fallback 不能推广为 effect 发生后的安全 retry。
术语卡
- SourcePatchPlugin:在 whole-program stage 生成受验证 source patch 的静态 Go plugin。
- Exact Guest:与最终目标 artifact/profile 绑定、用于解析和重推导 patch 的 authority-free Guest。
not_applicable:pass 在 Agent execution 前拒绝改写,随后执行 unchanged source。- Pure scalar CSE:对极窄 closed scalar program 消除一个相邻重复表达式的 pass。
- Pure scalar fold:把极窄 total scalar 表达式折成等值 literal 的 pass。
继续阅读
- 前置:为什么纯 AST 优化现在真的是 Pass
- 回到:如何阅读 Pysolate 的证据
- 说明文档:
implementation/10-source-bound-pass-pipeline.md、evidence/current-runtime-94fab78.md、papers/README.md - 源码 owner:
runtime/passplugin/registry.go、runtime/sourcepatch/sourcepatch.go、runtime/engine/wazero/engine.go、guest/bootstrap/agent_runtime/source_pass.py