Repository navigation
Replies: 1 comment 1 reply
English@Astro-Han I independently audited my recent My main takeaway: we should fix the Code Mode output/input friction in one clean, AX-first pass—consolidating the two conflicting truncation layers properly (including mixed text + media outputs, incremental 1. Local Measurements (Native + External)Excluding single-turn / trivial sessions and this audit session itself:
Key observations:
2. Fair Comparison Against
|
| 指标 | Native (GPT-6.x) | External (Antigravity) | 其中 gemini-4-neon-high |
|---|---|---|---|
exec 超过 7.5K 触发截断 |
24.2% (3,420 / 14,141) | 27.6% (3,162 / 11,464) | 34.6% (367 / 1,060) |
exec 中翻 maka://read/ 或 archive: |
1.3% (184 / 14,312) | 13.9% (纯分页 9.6%) | 18.8% (199 / 1,060) |
wait 占总模型调用比例 |
2.9% (533 / 18,127) | 5.1% (675 / 13,349) | 3.7% (45 / 1,218) |
wait 显式传入 yield_time_ms |
98.9% | 99.4% | — |
exec 显式传入 yield_time_ms |
2.1% | 9.9% | — |
| Prompt Cache 命中率 | 92.3% – 96.0% | 96.3% | — |
几个关键观察:
- 7.5K 在两边都在实打实烧步数,只是症状不同:
- Antigravity 撞上截断后 47.0% 立刻下一页开始翻分页(
gemini-4-neon-xhigh截断率 38.9%、分页率 22.0%)。模型在 2,033 次exec里显式传了max_output_tokens(传15000/20000/25000的近千次),全被外层 7.5K 无声覆写。 - Native GPT-6.x 看着只翻了 1.3% 的页,但对照组显示了隐性重试:前一步
exec <= 7.5KB时,下一步继续碰同一批文件占 26.6%;前一步> 7.5KB被截断后,同文件跟进翻倍到 50.9%,sed -n / tail / head / nl切片从 55.0% 涨到 67.6%(codex/gpt-6.2-sol甚至在 59.4% 的exec里写防御性 JS 过滤)。 - 按未经过内层
clip()截断的 completed cell 原始status.result.bytes分布看(注意不能用originalBytes,那个值已被内层clip()封顶在 ~40KB):超过 7.5KB 的 cell 中,预算提到 20KB 覆盖 81.5%(Native)/ 76.7%(External),30KB 覆盖 91.2% / 88.5%,约 40KB(10_000tokens)覆盖 94.2% / 93.0%(最近 2,000 条原文抽样里超过 40KB 的也仅占 Native 0.4% / External 2.5%)。
- Antigravity 撞上截断后 47.0% 立刻下一页开始翻分页(
- Cell 内
Read远比Shell难用,AX 割裂:Native GPT-6.x 调了 15,919 次Shell,只调了 752 次Read(21:1)。除了搜索和构建本来走Shell,前台Shell本身 stdout/stderr 各保留 64 KiB 尾部,而workspace-files文本Read在exec内依然被锁死在 7.5K(~200 行),JS 想读一个中等文件做切片过滤根本吃不下,模型被迫绕开Read去写Shell("nl -ba ... | sed -n ...")。 wait轮询在我这边没那么重,但源码里有两处细节值得对齐:- Native
wait占比 2.9%(扣掉 206 次模型故意传yield_time_ms: 1000当异步定时器的调用后不到 2%),Antigravity 5.1%(gemini-4-neon-high3.7%),73%–81% 的 wait 链只有 1 步。 plugins/agent/tools/src/cell.rs里exec默认30_000ms,但default_wait_yield()其实是10_000ms(10 秒) 而不是 30 秒——属于照抄 Codex(两者均默认 10s)后漏改的遗留。plugins/agent/tools/src/cell/session.rs已经做了wait增量输出(content.into_iter().skip(display_from)),这块不用重做。
- Native
二、参考 openai/codex 的公正取舍
Codex 的 Code Mode 有三点值得吸收:
- 单一预算所有权:
CodeModeToolOutput声明output_budget_applied() -> true,外层不再叠第二刀截断。 - 数据面与展示面分离:
codex-rs/core/src/tools/context.rs给 Cell 内 JS 保留更完整的结果,只在跨回模型上下文的边界施加 token 预算。 - 溢出时同时可见头尾:编译和测试报错的核心信息几乎都在尾部。
但 Codex 有几处妥协不适合 Maka,不能照搬:
- Codex 是破坏性丢弃截断,没有 Durable Archive:中间裁掉就永久没了,只能重跑命令。Maka 的不可变证据落盘 +
archive:<id>随机回查是明显优势,必须保住。 - Codex 的 10s 默认
yield_time_ms是 OpenAI 自家 SFT 模型特供,且对max_output_tokens不设硬顶——Maka 面向多模型和外部 Agent,既不能用 10s 制造轮询风暴,也必须设明确硬顶。 - Maka 有跨重启 Durable Replay 和严格的 Prompt Cache 约束:本机缓存命中率 92%–96%(刚合了 fix(agent): preserve prompt cache stability across providers and GPT-6.2 Responses #7099)。
plugins/agent/facts/src/archive.rs的One size rule for current and historical results必须守住。
三、最终设计(AX 优先,一次性到位)
先明确不做的部分:
- 不做按轮龄缩水的动态裁剪(原方向 3):新鲜轮给大预算、过期轮缩回 7.5K 会改写历史前缀,直接打穿 92%–96% 的 Prompt Cache;必须保持单条结果的展示规则不变,上下文回收继续交给 Compaction。
- 不加连续
wait自动步进状态机:~99% 的wait已经显式传了yield_time_ms,隐式步进几乎触发不了,徒增状态。
一次性落地的五件事:
- 单层 Cell 出口预算,有效预算随本次 durable return 落盘
- 在
exec/waitadmission 时算好一次有效文本预算并随本次 durable return 持久化:默认沿用10_000估算 token,设明确硬顶(结合主流外部 MCP 客户端上限校准),不设人为下限,尊重模型主动传入的小预算(如500或0)。 - 把预算定义为可选展示正文的上限:空间不足时先省
tailPreview、再收头页,协议必需的state/cell_id/ archive locator 允许占固定开销;一旦判定超限必须走有界展示到底,绝不允许回落吐出全文(特别堵住 imported replay 里prepare_imported_source返回None时回落投影完整原结果的漏洞)。 - 把有效预算带在结果自身上,native replay、external 首发/重送、imported history 四条路径都能 O(1) 读取同一份预算,无需反查
call.input;缺少该字段的历史旧结果保持完整旧格式(7.5K 限制 + 原readInstructions+ 省略tailPreview),升级跨版本也不破老会话的 Prompt Cache。
- 在
- 把内层
clip()收口到外层投影,同时修齐四条真实边界- 现状里
project_observation先用clip()砍掉parts写进projection并宣称[output truncated; full observation is archived],但Read(archive:<id>)(workspace-files/native/src/archive.rs)读的正是projection,导致剪掉的尾巴拿 locator 读不回来。 - 收口后,每份新 return 的归档正文明确为本次 observation 的完整新增展示增量(跳过
display_from,重送时重放该次 return 冻结好的增量而不依赖重启后为空的内存displayed,并优先复用已有 Cell 证据避免存两份大字符串)。 - 异步完成与恢复入口:Cell 异步完成排入的
FinalNotificationQueued(preparation/cell_notification.rs)和 Host 恢复接受的RecoveredCell(driver_model.rs)目前直接把每个CellOutput::Text塞进 prompt,必须复用同一套有界文本展示函数(无对应 return 时走明确恢复预算)。 - 图文混排预算:目前
archive.rs和archive/source.rs见到任意媒体 part 就会整份跳过归档。删clip()必须同步支持外层对Content独立归档/收短文本 part、按原顺序保留媒体 part;且archive:<id>只定位整个 event(无 part 序号),一次 observation 共用一个 locator 和一份总文本预算,不给每个 text part 单独发ReadPage。 - Host 侧按 Cell 全生命周期累计防 OOM:
CellContext::emit把输出追加在 Rust 侧Vec<CellOutput>(不在 V8 64 MiB 堆内),且take_output()后先前输出仍在live.output中并于结尾合并。防 OOM 字节上限必须按整个 Cell 生命周期累计,超限直接明确报错,绝不静默截断还承诺完整归档。
- 现状里
- 在
ArchivedPlaceholder上增加受控的tailPreview(不动ReadPage契约)- 预算拉到 ~40KB 后仍溢出的那 ~2% 恰好是最痛的场景:前面一堆 warning、报错在最后 30 行的
cargo test/ 构建日志,以及totalLines == 1无法按行号跳读的单行超大 JSON。 - 保持
ArchivedPlaceholder.page(ReadPage+page.next)严格顺序分页契约不变,在 canonical placeholder 上增加可选tailPreview字段(缺省省略,无需改 MCP schema)。环形尾缓冲(固定 ~2–4 KiB、按 UTF-8 字符边界收尾)直接接在生成page.content的同一条展示字符流上且仅在归档首页启用(不从原始 hash 字节流截出 JSON 转义或媒体占位符、不增加一次源扫描),按 canonical 序列化后实际开销给头尾分账,并配合可执行的offset跳读说明。
- 预算拉到 ~40KB 后仍溢出的那 ~2% 恰好是最痛的场景:前面一堆 warning、报错在最后 30 行的
- 把 Cell 内普通 workspace 文件
Read扩到 65,536 UTF-16 单位- Host 已经把可信
ToolOrigin::CodeCell传给workspace-files,且executor.read(...)调用点本身就带页预算参数。只把普通 workspace 文件分支在 Cell 内的页目标拉到65_536UTF-16 code units(沿用ReadPage现有计量语义,自然覆盖文件续页,不误放大archive:/attachment:/session页,不碰 MCP schema、Skill或RecallMaterial),让 JS 能原生读完中等源码文件做过滤。恢复侧cell_knowledge.rs的 256 KiB 共享额度(超额会发原始证据引用)保持不动。
- Host 已经把可信
- 拉平
wait默认值并补全描述指引- 把
default_wait_yield()从10_000调到30_000ms 与exec对齐,并在exec/wait描述里注明长任务可显式延长yield_time_ms(受客户端 deadline 约束)。
- 把
Uh oh!
There was an error while loading. Please reload this page.
English
@M4n5ter I audited recent
rust-previewsessions on my machine using Code Mode (mcp_maka_exec/mcp_maka_wait) and compared them against directagyruns on the same model (gemini-4-neon-high). Newer models already use Code Mode well, so staying on the Code-Mode-first /CodeModeOnlydirection looks right to me. That said, two harness frictions showed up heavily in my local traces and ate back most of the round-trip savings Code Mode earns. Since this is only my own machine and workload (mostly Rust builds/tests ongemini-4-neon-high), I'd like to check whether you see the same pattern on your side before deciding what to change.Background & Local Measurements
Across 10 engineering sessions on my machine in
rust-preview(2,119gemini-4-neon-highmodel calls; 1,775execcalls), the model actively orchestrates inside Code Mode:execexeccalls usingPromise.all/allSettledexeccalls doing JS filtering/slicing before emittingexeccalls spent paginatingmaka://read/...archiveswaitpollingNotes: Counts are from my local Antigravity
transcript.jsonllogs and exclude single-turn title sessions, a 2-step smoke session, and the audit session itself. Nested tool counts come from the authoritativetoolCallsarray returned by completed cells (n = 1,299).In my sample, nearly 1 in 5 model round-trips goes to archive pagination or
waitpolling.1. Output Budgeting: Fresh
execOutput Clipped at 7,500 CharsWhat I Found in Code
plugins/agent/facts/src/read.rssetsMAX_PAGE_CHARS = 7_500, inherited fromREAD_PAGE_MAX_BYTES = 7_500onmain.tools.Read/tools.Shellcalls aggregate into a singleexecresult, yet both the external-agent path (plugins/agent/native/src/owner/driver_external_effects.rs,display_projection) and the native-model projection path (plugins/agent/native/src/owner/driver_model/tool_projection.rs,archived_tool_result) unconditionally pass the entireexecoutput throughArchivedPlaceholder::prepareat 7,500 chars.exec's ownmax_output_tokensparameter (default10_000inplugins/agent/tools/src/cell.rs, ~40 KB) is effectively overridden by the outer 7,500-char cap (~1.8k–2k tokens). After JSON wrapping and escaping, only ~5–6 KB of actual payload remains.execcalls to paginatemaka://read/....Reference (
openai/codex)In
codex-rs/core/src/tools/code_mode/mod.rs(handle_runtime_response/truncate_code_mode_result), Codex applies a single truncation layer driven bymax_output_tokens(default10_000tokens, overridable per call via// @exec: {"max_output_tokens": ...}) using middle truncation (keeping both head and tail), with no outer 7.5 KB eager archive split.Possible Directions
execdelivery fromRead's 7,500-char page size: let freshexecoutput followmax_output_tokens(or a dedicated fresh-cell cap aligned with it), while keeping full evidence stored for on-demandReadwhen output actually overflows.2. Wait Polling: Repeated 30s Wake-Ups on Long Commands
What I Found
execandwaitdefault toyield_time_ms = 30_000(plugins/agent/tools/src/cell.rs). During Rust builds (cargo check/cargo nextest), the model rarely overridesyield_time_ms, so long commands trigger repeated 30swaitwake-ups (213 calls, 10.1% of all model steps in my sessions).Reference (
openai/codex)Codex (
codex-rs/code-mode-protocol/src/runtime.rs&description.rs) exposesyield_time_msas an explicit per-call tuning knob on bothexecandwait, and returns only incremental output since the previous yield.Possible Directions
yield_time_msguidance inexec/waitdescriptions: keep the default for quick commands, and pass120000–300000upfront for builds, test suites, or installs.waitcalls: whenwaitis called without an explicityield_time_msand the cell is still active, step the default window (e.g.,30s -> 60s -> 120s, capped) while still waking immediately on completion, steering, oryield_control().What I'd Like You to Check
My numbers only reflect my own machine, Rust-heavy workflows, and external Antigravity (
gemini-4-neon-high). Could you check your own recentrust-previewsessions (especially native models and non-Rust workloads) to verify independently:execresults hitmaka.archived_tool_resultand trigger immediatemaka://read/pagination on your side, and whetherwaitpolling takes a similar share of steps?execoutput withmax_output_tokens(plus head + tail archive preview) and adjustingwait/yield_time_msmakes sense from your side, or if there are existing design constraints I missed.简体中文
@M4n5ter 我最近复盘了自己机器上一批
rust-preview走 Code Mode(mcp_maka_exec/mcp_maka_wait)的真实会话,并和同一模型(gemini-4-neon-high)直接跑agy的数据做了对比。新一代模型已经很会用 Code Mode,继续坚持 Code-Mode-first /CodeModeOnly的长期方向我觉得没问题;但在我本地的记录里,有两个 harness 层的摩擦占比较高,把 Code Mode 本该省下来的往返步数吃掉了大半。因为这只是我单机、偏 Rust 工程和单个模型的样本,不代表整体情况,我想先请你那边独立核实一下,再一起判断要不要改、怎么改。背景与本地实测数据
在我机器上 10 个
rust-preview工程会话中(共 2,119 次gemini-4-neon-high模型调用、1,775 次exec调用),模型对 Code Mode 的使用本身很成熟:exec实际执行的嵌套工具数(均值)Promise.all/allSettled并发maka://read/...归档翻页上的exec占比wait轮询上的总调用占比口径说明:数据取自我本地 Antigravity 的
transcript.jsonl,已排除单轮标题生成、2 步冒烟测试及本次审计会话本身;实际嵌套工具数取自完成态 cell 返回的toolCalls数组(n = 1,299)。在我这份样本里,接近五分之一的模型往返都消耗在了归档翻页和
wait轮询上。1. 输出预算:刚返回的
exec结果在 7,500 字符处被强制归档截断代码里的根因
plugins/agent/facts/src/read.rs中的MAX_PAGE_CHARS = 7_500沿用了main上的READ_PAGE_MAX_BYTES = 7_500。tools.Read/tools.Shell聚合在同一个exec里返回,但外部 Agent 路径(plugins/agent/native/src/owner/driver_external_effects.rs的display_projection)和原生模型投影路径(plugins/agent/native/src/owner/driver_model/tool_projection.rs的archived_tool_result)仍然无条件把整个exec结果过一遍ArchivedPlaceholder::prepare,硬卡在 7,500 字符。exec自己声明的max_output_tokens(plugins/agent/tools/src/cell.rs默认10_000,约 40 KB)被外层的 7,500 字符(约 1.8k–2k tokens)直接架空。扣除 JSON 外壳和转义字符,实际留给正文的空间只剩 ~5–6 KB。exec去翻maka://read/...。参考(
openai/codex)Codex(
codex-rs/core/src/tools/code_mode/mod.rs的handle_runtime_response/truncate_code_mode_result)只有一层截断:直接按max_output_tokens(默认10_000tokens,支持在// @exec: {"max_output_tokens": ...}按需覆盖)执行保头保尾的中间截断,外层没有 7.5 KB 的强制归档分页。可能的调整方向
exec即时返回预算与Read的 7,500 字符单页大小解耦:让刚返回的exec结果以max_output_tokens(或与之对齐的独立新鲜结果上限)为准;完整 evidence 照旧落盘,只有真正超过上限时才走归档分页。2.
wait轮询:长命令下反复每 30 秒硬醒现象与根因
exec与wait默认yield_time_ms = 30_000(plugins/agent/tools/src/cell.rs)。在跑 Rust 构建(cargo check/cargo nextest)等长任务时,模型很少主动传更大的yield_time_ms,导致反复每 30 秒空转醒一次(在我这批会话里累计 213 次,占总调用 10.1%)。参考(
openai/codex)Codex(
codex-rs/code-mode-protocol/src/runtime.rs与description.rs)把yield_time_ms明确作为exec与wait的单次调优参数,且每次只返回上次 yield 之后的增量输出。可能的调整方向
exec/wait工具描述里给出清晰的yield_time_ms分档提示:常规短命令用默认,编译、测试、安装依赖等长任务直接传120000–300000。wait做默认窗口阶梯放大:当模型调用wait未显式传yield_time_ms且 cell 仍在运行时,默认等待窗口逐次拉长(如30s -> 60s -> 120s,设封顶),同时在任务完成、收到 steering 或脚本主动yield_control()时仍立即唤醒。想请你独立核实的部分
我这组数据只代表我单机的 Rust 重度场景和外部 Antigravity(
gemini-4-neon-high),麻烦你也看下自己最近的rust-preview会话记录(特别是原生模型和其他类型任务):exec触发maka.archived_tool_result并立刻翻页maka://read/的频率高不高?wait轮询占总步数的比例是否也类似?exec输出预算对齐到max_output_tokens(加归档头尾预览)以及调整wait/yield_time_ms是否合适,还是这里有我漏掉的既有设计约束?All reactions