Tracking and Controlling Budget Awareness in Coding Agents追踪与控制编码智能体的预算意识
Setup设置
We replay 144 five-hour coding trajectories across 48 FrontierCS 2 tasks from three open-weight agents, namely DeepSeek-V4.1-Flash-1017 on DSH, GLM-5.3-Flash on ZCode, and MiniMax-M3.1-Flash on Claude Code. Each trajectory is teacher-forced once through the exact open weights of the model that produced it in a patched vLLM engine, recording full-vocabulary entropy, stop-token probability, counterfactual frontier-submit continuations, and decision-point residual states. Every internal signal is measured against a leave-one-task-out baseline fit on observable trajectory features: turn index, log context length, prior submissions, token counters, and the remaining runtime returned by frontier-submit status. We compare held-out Spearman rank correlation on elapsed fraction of the five-hour budget and on log hours until the end of the run, within-run partial correlation with wall-clock hours, and AUROC for imminent final submission within five turns. All scoring, probing, and intervention scripts are in a repository that is private for now.
我们在 48 道 FrontierCS 2 任务上回放三个开放权重编码智能体的 144 条五小时正式轨迹,分别为 DSH 框架下的 DeepSeek-V4.1-Flash-1017、ZCode 框架下的 GLM-5.3-Flash,以及 Claude Code 框架下的 MiniMax-M3.1-Flash。每条轨迹都在打过补丁的 vLLM 引擎中由产生它的原模型权重做一次教师强制预填充打分,同时记录全词表精确熵、停止词元概率、反事实 frontier-submit 分支概率以及关键位置的残差流向量。所有内部指标都与留一任务交叉验证的可观测轨迹基线对照,后者读取轮次编号、对数上下文长度、已提交次数、词元余量与 frontier-submit status 返回的剩余秒数。本页比较留出任务上五小时已用比例和距运行结束对数小时数的 Spearman 秩相关、单次运行内控制可见特征后与真实小时数的偏相关,以及五轮内发起最终提交的 AUROC。全部打分、探针与干预代码目前在私有仓库中。
Each model scores its own trajectory once in vLLM, recording full-vocabulary entropy, stop-token probability at the decision point, counterfactual final-submit probability after thinking, and residual states at the three blue markers.每个模型在 vLLM 中对自身轨迹做一次预填充打分,记录全词表精确熵、决策点停止词元概率、思考结束处的反事实提交概率,以及三个蓝点位置的残差流状态。
An external monitor sees only turn counts, context length, prior train or final submissions, the last remaining runtime printed by status, and visible bash messages, fit with leave-one-task-out cross-validation.外部监控器只能读取轮次数、上下文长度、已有训练或最终提交次数、status 最近返回的剩余秒数及可见命令文本,按留一任务交叉验证训练。
Details详细说明
Across the 48 tasks, DeepSeek-V4.1-Flash-1017 spans 7,728 requests with 7,671 tool turns and 43 final stops; GLM-5.3-Flash spans 9,001 requests with 8,916 tool turns and 44 final stops; and MiniMax-M3.1-Flash spans 11,345 requests with 11,040 tool turns and 24 final stops. Every task README states the 5-hour answering budget once, and the agent sees a live clock only when it calls frontier-submit status, which prints remaining_runtime_s and remaining_train_calls; Claude Code also appends <total_tokens>N tokens left</total_tokens> out of a 15M-token budget after each tool result, of which MiniMax uses a median 1.32%. Leave-one-task-out regressions use HistGradientBoostingRegressor with max_leaf_nodes = 15 across 48 folds and 1,000 task-cluster bootstrap resamples for 95% confidence intervals. Within-run partial correlations regress both the metric and elapsed hours on a quadratic in log context length plus turn index, submission count, and seen remaining runtime inside each task, because monotonic growth makes rank-only partials degenerate.
在 48 道任务上,DeepSeek-V4.1-Flash-1017 共有 7,728 次请求,含 7,671 个工具轮和 43 次最终停止;GLM-5.3-Flash 共有 9,001 次请求,含 8,916 个工具轮和 44 次最终停止;MiniMax-M3.1-Flash 共有 11,345 次请求,含 11,040 个工具轮和 24 次最终停止。任务说明只在开头写明一次五小时作答时限,智能体只有主动调用 frontier-submit status 才能看到 remaining_runtime_s 和 remaining_train_calls;Claude Code 还会在每次工具返回后附上 1,500 万词元总额中的剩余词元数,MiniMax 中位仅消耗 1.32%。留一任务回归使用 max_leaf_nodes = 15 的梯度提升树,在 48 个任务簇上做 1,000 次自助重采样计算 95% 置信区间。单次运行内偏相关在每个任务内对对数上下文长度的二次项、轮次编号、已提交次数与已读剩余时间做线性残差化,避免单调递增序列上纯秩偏相关退化为零。
Experiments实验
Answered已有结论Does end-of-message probability at the decision point track the remaining budget?决策点的消息结束概率能追踪剩余预算吗?
No. On tool turns, end-of-message probability at the decision point stays between a millionth and a billionth across all five hours, and its slight within-run rise disappears once visible context length, turn index, prior submissions, and seen remaining time are controlled.
不能。在所有工具调用轮中,决策点的消息结束概率在整个五小时内始终停留在百万分之一到十亿分之一之间;控制可见上下文长度、轮次编号、已提交次数与已见剩余时间后,它与已用时间的微弱相关性完全归零。
Details详细说明
Status note for Question 1: all three 48-run output-scoring sweeps are complete. Reading stop probability right after thinking rather than at the decision point gives the same zero residual after visible controls: -0.001 [-0.030, +0.038] on MiniMax-M3.1-Flash and -0.005 [-0.019, +0.018] on GLM-5.3-Flash. Visible-text stopping hazard across tokens inside assistant prose also collapses to -0.036 [-0.078, +0.057] on MiniMax and +0.006 [-0.032, +0.059] on GLM once visible trajectory counters are controlled.
问题 1 状态记录:三个模型的 48 轨迹输出打分已全部完成。把读取位置从决策点前移到思考结束处,控制可见特征后的偏相关同样为零:MiniMax-M3.1-Flash 为 -0.001 [-0.030, +0.038],GLM-5.3-Flash 为 -0.005 [-0.019, +0.018]。助手可见文本内部的逐词元停止风险率在控制可见计数后同样归零,MiniMax 为 -0.036 [-0.078, +0.057],GLM 为 +0.006 [-0.032, +0.059]。
Answered已有结论Do thinking entropy, token surprisal, or counterfactual submit probability beat visible behavior?思考熵、词元惊讶度或反事实提交概率能超过可见行为基线吗?
No. Adding all nine output-distribution metrics to visible trajectory features leaves held-out predictions unchanged on elapsed budget and on time to stop across all three models. Counterfactual final-submit probability stays flat near zero until the exact turn that submits, and raw drops in thinking entropy come from context growth.
不能。在三个模型上,把全部九项输出分布指标并入可见轨迹特征后,对已用预算比例和剩余停止时间的留出预测没有任何提升。反事实最终提交概率在真正提交前始终平坦接近零,而思考词元熵的原始下降完全来自上下文增长。
Details详细说明
Why held-out predictability of time-to-end from visible features differs across the three models (0.157 on DeepSeek, 0.445 on GLM, 0.575 on MiniMax): the three harnesses and models occupy three distinct stopping regimes. DeepSeek-V4.1-Flash-1017 queries frontier-submit status earliest at a median 0.33 h across 44 of 48 runs and stops voluntarily across a wide 0.08 to 4.61 h span with median 1.49 h and 0 of 48 runs reaching 4.8 h. GLM-5.3-Flash queries status in all 48 of 48 runs at median 0.69 h and stops voluntarily in a tighter mid-budget band with median 2.48 h, interquartile range 1.79 to 3.40 h, and 0 of 48 runs reaching 4.8 h. MiniMax-M3.1-Flash queries status late at median 2.07 h across 36 of 48 runs and hits the 5 h ceiling on 20 of 48 runs with median end 4.73 h, where remaining runtime is simply 5 h minus elapsed time.
为什么三个模型上仅凭可见特征预测剩余停止时间的留出相关依次为 0.157、0.445 和 0.575:三者处于截然不同的停止机制区间。DeepSeek-V4.1-Flash-1017 最早调用 frontier-submit status(48 次运行中有 44 次调用,中位首次调用时间 0.33 小时),并在 0.08 至 4.61 小时的宽区间内自主提前结束(中位结束时间 1.49 小时,无一跑到 4.8 小时以上)。GLM-5.3-Flash 在全部 48 次运行中均调用了 status(中位首次调用 0.69 小时),并在更集中的中段区间自主提交结束(中位 2.48 小时,四分位距 1.79 至 3.40 小时,同样无一触顶)。MiniMax-M3.1-Flash 很晚才调用 status(36/48 次运行,中位首次调用 2.07 小时),48 次运行中有 20 次撞上五小时硬上限(中位结束时间 4.73 小时);当结束时间近似固定在五小时上限时,已用进度自然决定了剩余时间。
Testing检验中Do residual-stream neurons encode budget state or imminent wrap-up?残差流神经元编码了预算状态还是临近收尾?
So far on DeepSeek-V4.1-Flash-1017 final-layer states across all 48 runs and 7,714 non-failed turns: linear probes carry no internal wall-clock signal beyond visible context and turn counts, trailing visible features on elapsed fraction at 0.805 against 0.912 and collapsing to +0.021 partial correlation within runs. On imminent final submission within five turns, however, the probe reaches 0.933 AUROC, beating visible counters at 0.841 and a bag-of-ngrams baseline over visible prompt text plus counters at 0.885; exposing private <think> text to that same n-gram classifier reaches 0.932 and accounts for almost the entire gap. Mid-layer extraction on DeepSeek-V4.1-Flash-1017 and full four-layer sweeps on MiniMax-M3.1-Flash and GLM-5.3-Flash are queued.
目前在 DeepSeek-V4.1-Flash-1017 全部 48 次运行、7,714 个非失败轮次的末层残差状态上:线性探针不包含超出可见上下文与轮次数的内部时钟,预测已用时间比例的留出相关为 0.805(低于可见基线的 0.912),单次运行内控制可见特征后的偏相关降至 +0.021。但在预测五轮内即将发起最终提交(final_soon)时,末层探针达到 0.933 AUROC,显著超过可见计数基线(0.841)以及“可见提示文本 n-gram 加可见计数”的强文本基线(0.885);将私有 <think> 思维链文本开放给同一个 n-gram 分类器后,AUROC 升至 0.932,解释了几乎全部探针优势。DeepSeek 中间层重提取与 MiniMax-M3.1-Flash、GLM-5.3-Flash 的多层隐状态提取作业正在队列中等待运行。
Details详细说明
Queue status and hook fix for Question 3: in the first hidden-state extraction pass on DeepSeek-V4.1-Flash-1017 (w5124, completed) and GLM-5.3-Flash (w5125, segment 1), patch_vllm_hidden.py attached intermediate hooks to the first nn.ModuleList with at least 8 blocks, which hit the 32-layer and 24-layer vision encoders rather than the 61-layer and text-backbone decoders, leaving only the post-RMSNorm final vector (dimension 5,120 on DeepSeek) populated. fix_hidden_layer_discovery.py and patch_vllm_hidden.py now skip vision and audio modules and match the language backbone hidden size; MiniMax-M3.1-Flash (w5123, 33 of 48 traces done at layers 14, 29, 44, and 59), GLM-5.3-Flash (w5125), and DeepSeek mid-layer rerun (w5137) are queued to finish.
问题 3 队列进度与钩子修复说明:在 DeepSeek-V4.1-Flash-1017(w5124,已完成)与 GLM-5.3-Flash(w5125 第一段)首次提取隐状态时,patch_vllm_hidden.py 选取了首个长度不少于 8 的 nn.ModuleList,误挂到 32 层和 24 层的视觉编码器而非文本解码主干上,因此 w5124 仅保存了末层 RMSNorm 之后的 final 向量(维度 5,120)。现已在 patch_vllm_hidden.py 中跳过视觉与音频子模块并校验隐藏层维度;MiniMax-M3.1-Flash(w5123,已完成第 14、29、44、59 层的 33/48 条轨迹)、GLM-5.3-Flash(w5125)以及 DeepSeek 中间层补采作业(w5137)均已在队列中等待完成。
Testing检验中Does injecting remaining time or steering activations control stopping behavior?注入剩余时间提示或引导激活方向能否控制停止行为?
Counterfactual remaining-time injection on DeepSeek-V4.1-Flash-1017 is running: 290 of 960 prompts are complete, yielding 1,160 sampled next turns across 58 decision points in 15 tasks, with 232 completions per condition, and resumable job w5129 is queued for the remaining 670 prompts. Lowering the stated remaining time from no notice or 4 hours down to 5 minutes raises explicit time reasoning in <think> from 25.4% to 98.3% and lifts immediate wrap-up calls, namely frontier-submit final or store-final, from 1.7% to 25.0%. Activation steering is approved and its vLLM residual-stream hook and sampler are verified across five decoder topologies, awaiting the queued mid-layer hidden-state runs before launch.
DeepSeek-V4.1-Flash-1017 上的反事实剩余时间注入实验正在进行:960 条提示已完成 290 条,覆盖 15 道任务的 58 个决策轮次、共 1,160 次完整采样(每种条件 232 次),可续跑作业 w5129 正在队列中等待完成剩余 670 条提示。在已有样本上,把提示的剩余时间从“无提示”或“4 小时”压低到“5 分钟”,会让模型在 <think> 中主动讨论剩余时间的比例从 25.4% 升至 98.3%,并使立即执行的收尾动作(frontier-submit final 或 store-final)从 1.7% 跃升至 25.0%。激活引导实验已获批准,vLLM 残差流注入补丁与采样脚本已在五种解码层拓扑上通过单元测试,待队列中的中间层隐状态提取完成后启动。
Details详细说明
Activation-steering readiness: scripts/patch_vllm_steer.py injects alpha * v into the decoder residual stream entering layer k + 1, skipping vision and audio encoders and handling forward_input_norm (MiniMax), positional 3-argument residuals (DeepSeek and GLM), keyword residuals, and 2-argument decoder layers (Step), verified to fp32 precision (max |delta - alpha * v| <= 4.2e-7). At DeepSeek's post-RMSNorm final layer, raw difference-of-means has in-sample AUROC 0.664 because top principal components carry 30x larger standard deviation than tail components (39.7 vs 1.26), whereas the whitened logistic probe reaches 0.933 held-out AUROC; steering sweeps will therefore run covariance-regularized directions at intermediate decoder layers once w5123 and w5137 complete.
激活引导就绪状态:scripts/patch_vllm_steer.py 在进入解码器第 k + 1 层前向残差流加上 alpha * v,自动跳过视觉与音频编码器,并兼容 forward_input_norm(MiniMax)、三位置参数残差(DeepSeek 与 GLM)、关键字残差及双参数解码层(Step),单测最大误差不超过 4.2e-7。在 DeepSeek 末层 RMSNorm 之后,由于主成分方差高度各向异性(第一主成分标准差 39.7,第 256 主成分 1.26),未白化的均值差方向样本内 AUROC 仅为 0.664,而协方差正则化探针在留出任务上达 0.933;因此待 w5123 与 w5137 提取出中间层激活后,引导扫描将采用协方差正则化方向按该层中位范数的比例系数注入。
Answered已有结论Is teacher-forced prefill scoring faithful and causal on agent trajectories?智能体轨迹上的教师强制预填充打分是否忠实且满足因果性?
Yes. Truncating a turn inside its thinking changes earlier assistant token log-probabilities no more than scoring the identical full sequence twice, and single-step serving matches prefill scoring to within mixture-of-experts routing noise. Reconstructed chat renderers match provider token counts across every scored model.
是。在思考片段内部截断未来词元后,前序助手词元对数概率的变化幅度与同一完整序列重跑两次的数值底噪完全一致,单步在线生成路径也与预填充打分吻合。所有已打分模型的对话模板重建均与服务商词元统计精确对齐。
Every scored request runs through vLLM V1 prefill with a custom logits hook that records the actual next-token log-probability, exact full-vocabulary Shannon entropy in nats before temperature scaling, fixed stop and tool-opener token log-probabilities, top-20 token log-probabilities, and token-level span labels distinguishing system, user, tool output, header, thinking, visible text, tool call, and end-of-message tokens.
每次请求都通过挂载了自定义对数几率钩子的 vLLM V1 预填充路径计算,一次前向同时记录真实下一词元的对数概率、温度缩放前的全词表精确香农熵(单位 nats)、固定停止词元与工具起始词元的对数概率、前 20 高概率词元,以及区分系统提示、用户、工具返回、轮首、思考、可见正文、工具调用与结束符的词元级标签。
Before any GPU scoring, each model's prompt renderer was checked against the provider token counts recorded in the raw HTTP traffic across checkpoints of batch_local_counting.
在启动任何 GPU 打分前,我们将每个模型的本地对话模板重建结果与原始 HTTP 流量中服务商返回的词元计数在多个检查点上逐一核对。
| Model and harness模型与框架 | Renderer渲染脚本 | History thinking历史思考处理 | Match against provider token count与服务商词元计数的吻合度 |
|---|---|---|---|
| DeepSeek-V4.1-Flash(-1017) (DSH) | prepare_ds.py | Kept保留 | Exact across all 6 checkpoints (e.g. 330,172 = 330,172)全部 6 个检查点零误差吻合(如 330,172 = 330,172) |
| GLM-5.3(-Flash) (ZCode) | prepare_glm.py | Kept保留 | Exact across all 6 checkpoints全部 6 个检查点零误差吻合 |
| MiniMax-M3.1-Flash (Claude Code) | prepare_minimax.py | Dropped丢弃前序思考 | +3% to +5% from Anthropic tool-schema formatting; keeping thinking is ~4x too high工具模式格式化相差 +3% 至 +5%;若保留历史思考则高出约 4 倍 |
| Step-5-Preview | prepare_step.py | Kept保留 | Constant +63-token header offset, zero per-turn drift固定 +63 词元头部常数偏移,逐轮零漂移 |
| Inkling-2-Small (Claude Code) | prepare_inkling.py | Dropped丢弃前序思考 | 438/440 output counts exact to 0 tokens; prompt +124 to +127 tokens (+0.10% to +0.81%), zero drift438/440 轮输出零误差;提示固定相差 +124 至 +127 词元(+0.10% 至 +0.81%),零漂移 |
| Inkling-2-Small (pi / OpenCode) | prepare_inkling.py | Kept保留 | Gateway synthesized usage with cl100k_base omitting tools (340/340 exact); true model input keeps thinking网关用不含工具定义的 cl100k_base 合成计数(340/340 轮完全复现);真实输入保留历史思考 |
Ending a message without a tool call does not always end an agent episode: in Claude Code, a background-job notification or an empty-output nudge resumes the conversation after an end_turn message, and ZCode compacts long histories into a new segment after an intermediate stop. We therefore separate tool calls, true episode-ending stops, harness-resumed stops, and retried failures.
不带工具调用的消息结束并不总是代表整局任务终止:在 Claude Code 中,后台任务通知或空输出提醒会在 end_turn 之后继续唤醒对话;ZCode 则会在上下文接近百万词元时借一次中间停止压缩历史并开启新片段。因此我们将每轮结果严格区分为工具调用、真实终局停止、框架续接停止与重试失败四类。
| Model模型 | Total requests总请求数 | Tool turns工具轮 | Final stops终局停止 | Resumed stops续接停止 | Failed / cut失败或超长重试 |
|---|---|---|---|---|---|
| DeepSeek-V4.1-Flash-1017 | 7,728 | 7,671 | 43 | 0 | 14 |
| GLM-5.3-Flash | 9,001 | 8,916 | 44 | 3 | 38 |
| MiniMax-M3.1-Flash | 11,345 | 11,040 | 24 | 12 | 269 |
Details详细说明
On MiniMax-M3.1-Flash, the 12 resumed stops comprise 10 empty-output nudges ([Your previous response had no visible output...]) and 2 background-task wait notices, and the 269 failed requests comprise 252 zero-token provider errors and 17 128k-token thinking loops, all retried by Claude Code on the identical history. On GLM-5.3-Flash, the 3 resumed stops mark ZCode conversation compactions near 0.79M to 1.02M tokens on bbq_packet_scheduling, ragen_multi_turn_rl, and ckks_composable_noise, and the 38 failed requests comprise 28 empty errors and 10 length cuts. In w5087 on MiniMax-M3.1-Flash, switching vLLM KV cache from BF16 to FP8 raised English-prose control NLL from 5.32 to 5.77 nats, so every scoring and hidden-state job uses BF16 KV cache (--kv_dtype auto).
在 MiniMax-M3.1-Flash 上,12 次续接停止包含 10 次空输出提醒与 2 次后台任务等待通知;269 次失败请求包含 252 次零输出网关错误和 17 次 12.8 万词元思考死循环,均由 Claude Code 在相同历史下自动重试。在 GLM-5.3-Flash 上,3 次续接停止对应 ZCode 在 79 万至 102 万词元处触发的对话压缩,38 次失败请求含 28 次空响应与 10 次长度截断。此外,w5087 对比发现将 MiniMax-M3.1-Flash 的键值缓存量化为 FP8 会使英文散文对照组的平均负对数似然由 5.32 升至 5.77 nats,因此全部正式打分与隐状态提取统一采用 BF16 键值缓存(--kv_dtype auto)。
Takeaways核心结论
Acknowledgements致谢
The author is pleased to acknowledge that the work reported on in this post was substantially performed using the Princeton Research Computing resources at Princeton University. Princeton Research Computing is a consortium of groups including the Princeton Institute for Computational Science and Engineering (PICSciE) and Research Computing at Princeton University.
本文报告的工作主要使用普林斯顿大学 Princeton Research Computing 的计算资源完成。Princeton Research Computing 是由普林斯顿计算科学与工程研究所(PICSciE)和普林斯顿大学 Research Computing 等团队组成的联合体。
Experiment record实验记录
Citation
@misc{chai2026budgetsignal,
title = {Tracking and Controlling Budget Awareness in Coding Agents},
author = {Chai, Wenhao},
year = {2026},
howpublished = {Blog post},
url = {https://wenhaochai.com/exps/budget-signal.html}
}