DSH / Atlas
2026-09-07implementedsimplificationarchived 2026-09-30

Scan file content without per-array callbacks

文件内容扫描不为每个数组创建回调

Every model dispatch checks complete message content for files, including tool-role result content. A request-history CPU profile attributes 23.540 ms of self time to `contentHasFile` and 5.584 ms to its callback. This traversal remains necessary even after [loop-owned freeze evidence](2026-09-06-agent-request-freeze-evidence.md) removes repeated request freezing. The hot LLM source is identical at both sampled maste

English

Problem

Every model dispatch checks complete message content for files, including tool-role result content. A request-history CPU profile attributes 23.540 ms of self time to contentHasFile and 5.584 ms to its callback. This traversal remains necessary even after loop-owned freeze evidence removes repeated request freezing. The hot LLM source is identical at both sampled master revisions and the measured V3 integration revision; these observations do not establish PR causality.

Decision

contentHasFile uses direct iteration instead of recursive Array.some callbacks. It preserves early exit, tool-role result traversal, and false results for other block kinds. It stores no identities, validation results, or freeze proofs. Image detection, file projection, and request construction keep their existing behavior. The request-freeze evidence owns the request-history budget.

Measurement evidence

Apple M4 Pro, Node 24.19.0: nine alternating original/candidate pairs run the unchanged request-history worker in fresh plain-Node processes. Each process receives a copy of one native-V3 seed. Only the built LLM entry changes; every sample completes 40 requests, zero live tools, and 13,925 events. All totals below are milliseconds, in pair order.

VariantRaw totalsMedian
Original61.772167, 66.480917, 63.590042, 62.250333, 63.804875, 62.504208, 61.887958, 61.062959, 67.12012562.504208
Direct iteration53.655375, 56.223416, 57.078125, 54.559250, 54.271459, 55.288917, 55.400416, 56.191916, 54.87704155.288917

The median improves 11.54%; all nine pairs improve, by 4.871–12.243 ms. User CPU medians are 82.019/76.150 ms. A separate five-pair scan probe uses the same synthetic history: 5,601 frozen messages, 13,600 blocks, and 8,801 content arrays scanned 40 times. Original totals are 17.188584, 17.944000, 16.869458, 17.437750, 17.459708; direct iteration totals are 8.726333, 8.373000, 8.851750, 8.479167, 9.074083. These local measurements establish an implementation gain, not a hosted-CI pass or a new calibration.

Alternatives considered

A weak negative-result cache needs proof that every relevant descendant is immutable; a shallow-frozen root is insufficient. Direct iteration provides measured savings without introducing that ownership or invalidation problem. Optimizing image traversal or system-prompt projection lacks evidence from this experiment and is outside this change.

Consequences

The scan remains linear in visited blocks and rereads mutable nested content on each call. Content tests cover empty, frozen, nested, and subsequently mutated arrays; service tests preserve file-handle projection, and request-freeze, reconstruction, and resume tests preserve native-history semantics. No model-visible text or Session format changes. The freeze-evidence and backend-baseline notes retain independent ownership; neither is superseded.

中文

Problem

每次模型分发都检查完整消息内容中的文件,包括 tool-role 结果内容。请求历史 CPU profile 将 23.540 ms 自身时间归于 contentHasFile,将 5.584 ms 归于其回调。即使循环自有冻结证据消除了重复请求冻结,这次遍历仍然必需。两次抽样的 master 修订与实测的 V3 集成修订 的 LLM 热点源码完全相同;这些观察不能证明 PR 因果关系。

Decision

contentHasFile 使用直接迭代,替代递归的 Array.some 回调。它保留提前退出、tool-role 结果遍历,以及其他块类型返回 false 的行为。它不存储身份、校验结果或冻结证明。图片检测、文件投影和请求构建保持既有行为。请求冻结证据拥有请求历史预算。

Measurement evidence

Apple M4 Pro、Node 24.19.0:九组交替原始/候选配对在全新的普通 Node 进程中运行不变的请求历史 worker。每个进程接收同一个原生 V3 种子的副本。只有构建后的 LLM 入口变化;每个样本均完成 40 次请求、零次实时工具调用与 13,925 个事件。以下全部总耗时单位为毫秒,按配对顺序排列。

变体原始总耗时中位数
原始61.772167, 66.480917, 63.590042, 62.250333, 63.804875, 62.504208, 61.887958, 61.062959, 67.12012562.504208
直接迭代53.655375, 56.223416, 57.078125, 54.559250, 54.271459, 55.288917, 55.400416, 56.191916, 54.87704155.288917

中位数改善 11.54%;全部九组均改善,幅度为 4.871–12.243 ms。用户 CPU 中位数为 82.019/76.150 ms。独立的五组配对扫描探针使用相同的合成历史:5,601 条冻结消息、13,600 个块和 8,801 个内容数组,扫描 40 次。原始总耗时为 17.188584, 17.944000, 16.869458, 17.437750, 17.459708;直接迭代总耗时为 8.726333, 8.373000, 8.851750, 8.479167, 9.074083。这些本地测量证明实现改善,不代表托管 CI 通过或新的校准。

Alternatives considered

弱引用的否定结果缓存需要证明每个相关后代均不可变;浅冻结根对象并不足够。直接迭代提供实测收益,无需引入此类所有权或失效问题。本实验没有提供优化图片遍历或系统提示词投影的证据,因此它们不在此次变更范围内。

Consequences

扫描仍与访问块数呈线性关系,每次调用都重新读取可变的嵌套内容。内容测试覆盖空数组、冻结数组、嵌套数组与后续变更的数组;服务测试保留文件 handle 投影,请求冻结、重建与恢复测试保留原生历史语义。模型可见文本与 Session 格式均不改变。冻结证据与后端基线记录仍各自拥有独立决策;两者均未被取代。