refactor(runtime): 引入上下文预算控制面并收敛运行时事件协议#413
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,其中模块边界划分、方案设计思路等等也是你的分析范围,找出所有漏洞,不许输出正向表扬。 |
@xgopilot 忽略第四点、第一点自动迁移是有意为之,但放在 Loader.Load() 里确实不是理想位置,可以尝试放在其他层;第二点迁移时如果发现 auto_compact.enabled:false,自动升级配置仍继续,但记录明确的 migration note,例如“旧 auto_compact.enabled 已废弃,新预算门禁不可关闭;第三点修改注释与实际行为一致;第五点第六点由你来给方案,不许兼容或兜底旧代码。给出一套完整方案 |
@xgopilot 第五点有特别说明:可以做,但要把语义说清楚:低置信估算不能直接硬停,但也不是“预算内”。 规则建议: estimated <= prompt_budget -> allow estimated > prompt_budget && accurate=true: estimated > prompt_budget && accurate=false: TurnBudgetDecision.EstimateAccurate |
已完成改造按你确认的 1/2/3/5/6 已落地到当前 PR 分支( 变更摘要
测试已执行并通过:
未执行项
|
- move config migration side effects from Loader to bootstrap preflight - add migration notes for deprecated auto_compact.enabled:false - wire budget decision to estimate accuracy with reason constants - add estimate_accurate to budget_checked payload - enforce payload_version=3 in TUI stream decode - update docs and tests for new behavior Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
@xgopilot 做一轮审查性review,主要检查修复方案有没有落实到位、有没有引入新的问题,以及对整体PR的评估 |
@xgopilot 评估以下方案:## 收敛预算门禁语义并加固启动迁移写盘 Summary
Key Changes
Public Interfaces
Test Plan
Assumptions
|
@xgopilot 执行方案,注意风险:[高] 你这版方案如果继续沿用 payload_version=3,会形成新的协议断裂但无版本信号 当前分支里 budget_checked 仍是 estimate_accurate:internal/runtime/events.go:31-40。 [中] 迁移原子写盘方案还缺关键持久化细节,仍可能出现掉电/异常窗口 当前迁移仍是覆盖写:internal/config/context_budget_migration.go:68-73。 |
完成情况已按你给的方案实现并推送到当前 PR 分支,核心目标全部落地:
测试已运行并通过:
新增/调整了以下关键回归:
推送信息
|
- replace Accurate with GatePolicy in budget estimate and decisions - set builtin provider estimates to local+gateable - switch budget_checked payload to estimate_gate_policy - bump runtime/tui payload_version to 4 - add atomic config write helper and use it in migration/loader - add migration failure safety tests and provider/runtime regressions Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
refactor(runtime): gate budget policy and harden config writes
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,其中模块边界划分、方案设计思路等等也是你的分析范围,找出所有漏洞,不许输出正向表扬。 |
@xgopilot 只修复第二、三、四点,其中第二点先采取把三个providerGatePolicy降级为 advisory即可,第三点采取估算和发送都用同一份请求 |
结果已按要求仅处理第 2/3/4 点,并已提交推送。 提交: 本次改动
测试已补充/更新并通过:
新增/更新关键测试覆盖:
未做内容
|
…use and stream fail-fast Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime/provider/tui): advisory gate, request reuse, and gateway fail-fast
|
/code 给“估算失败”加降级通道。 |
|
已按你的要求实现“估算失败降级通道”,并推送到当前 PR 分支。 变更摘要
测试新增并通过:
同时回归通过:
提交信息
未做项:未改动你未要求的协议兼容策略与其他模块。 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
@xgopilot 审查性review |
/code 修复问题 |
@xgopilot 修复问题 |
修复完成已按你要求修复这两个问题,并推送到当前 PR 分支对应的 fork 分支。 本次修复
测试已新增/更新回归测试并通过:
新增覆盖重点:
提交与推送
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): reconcile partial usage observation
|
/review |
| return compactErr | ||
| } | ||
| if mode == contextcompact.ModeProactive || mode == contextcompact.ModeReactive { | ||
| state.compactCount++ |
There was a problem hiding this comment.
compactCount 在进入 proactive/reactive 分支后无论 compact 是否真正生效都会递增。这样当 runCompactForSession 返回 Applied=false 时,下一次预算决策会被当作“已经 compact 过一次”,可能直接跳过本应继续 compact 的分支,或提前进入 stop/allow-after-compact 逻辑。建议把计数递增移动到 if result.Applied 内,确保计数语义与“实际生效的 compact 次数”一致。
There was a problem hiding this comment.
修复结果
已修复你在 internal/runtime/run.go:498 指出的计数语义问题。
变更内容
- 调整
applyCompactForState:compactCount只在result.Applied=true且 mode 为proactive/reactive时递增。 - 新增回归测试
TestApplyCompactForStateDoesNotIncreaseCompactCountWhenNotApplied,覆盖Applied=false分支,确保不会误增计数。
测试
go test ./internal/runtime -run "TestApplyCompactForStateDoesNotIncreaseCompactCountWhenNotApplied|TestServiceRunStopsAfterProactiveCompactWhenEstimateGateable|TestServiceRunAllowsAfterProactiveCompactWhenEstimateAdvisory"
提交与推送
- Commit:
6ab4ba7 - 已推送分支:
phantom5099/neo-code:fork-pr-413-1776912961 - Fork PR: fix(runtime): compact count only increments on applied compact phantom5099/neo-code#56
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): compact count only increments on applied compact
|
@xgopilot 提高测试覆盖率并进行一轮审查性review |
审查发现(仅问题)
覆盖率提升(已执行)
验证
提交与推送
|
…output Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
test: improve estimator and migration script coverage
@xgopilot 修复 |
修复结果已按你在触发评论中指出的两项问题完成修复并推送到当前 PR 分支。
测试已新增/更新并通过以下测试:
提交与推送
未做事项:未扩展到触发评论以外的其他评审点,仅修复本次明确要求的两项问题。 |
…ro usage observation Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): hard-fail deterministic estimate errors and preserve zero usage semantics
Summary
本 PR 将原有
context.auto_compact机制切换为更明确的context.budget控制面,并围绕 provider 真实模型窗口、runtime 预算快照、token ledger、session 持久化和 TUI 事件消费完成闭环改造。核心目标是让主链路在发送模型请求前就能判断上下文预算风险,避免预算逻辑散落在 UI、runtime 或 provider 边界之外,同时统一当前事件协议,不保留旧协议兜底分支。
Changes
context.budget配置模型,替代原context.auto_compact。migrate context-budgetCLI,用于将现有配置升级到新预算结构。TurnBudgetSnapshotbudget_checked事件STOP_BUDGET_EXCEEDED停止原因EstimateInputTokens,由 provider 层负责按自身协议估算请求 token,避免厂商细节泄漏到 runtime/TUI。has_unknown_usage、session totals 等字段。has_unknown_usage字段迁移。STOP_COMPLETEDSTOP_USER_INTERRUPTSTOP_FATAL_ERRORSTOP_BUDGET_EXCEEDEDtoken_usagepayloadDesign Notes
Risk
context.auto_compact的本地配置需要迁移到context.budget。Testing
gofmtgit diff --checkgo test ./internal/session -run "TestSQLiteStoreMigratesSchemaV1ToV2|TestSQLiteStoreInitializationRejectsUnsupportedSchemaVersion"go test ./internal/runtime -run "TestServiceRunReactiveCompactLimitAppliesAcrossTurns|TestServiceRunReactiveCompactRetriesWithinSameRun"go test ./internal/tui/services ./internal/tui/core/appgo test ./...Notes
完整测试在 Windows 本地环境中通过。初次沙箱运行全量测试时遇到临时目录
EvalSymlinks权限限制,改用工作区内.cache目录后全量测试通过。