fix(sync): 修复 Prime Agent 导致快照同步失败 - #72
Open
liuweifeng wants to merge 1 commit into
Open
Conversation
PR cclank#52 合并后,Prime Agent 汇总仍在总量初始化前执行累加,已有 Prime Agent 日志时会让同步脚本退出。与此同时,该采集器未接入持久账本,日志清理后历史也会丢失。 Co-authored-by: Codex <noreply@openai.com>
Contributor
Author
|
@cclank 这次问题我建议优先处理一下。 它不是所有用户都会遇到,但只要设备产生了 Prime Agent 用量,同步任务就会在写快照前失败。普通 JSON 仍然能输出,所以日志看起来像“采集成功”,实际进程已经以 1 退出,新的设备快照也不会生成。未使用 Prime Agent 的设备不受影响;我也没有发现已有快照会被覆盖或 token 被重复累计。 根因是 #52 合并后,Prime Agent Wrapped 汇总仍在 我在本地用真实 Prime Agent 缓存复现并验证了修复:64,512 tokens 可以正常生成 PR:#72。CI 通过后如果没有其他意见,麻烦尽快合并。这个 PR 不包含 DMG 打包或已安装 App 更新。 |
liuweifeng
marked this pull request as ready for review
August 26, 2026 15:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
PR #52 合入 Prime Agent 后,只要本机出现 Prime Agent 用量,
usage.30s.py --json就可能出现“JSON 已输出,但进程退出码为 1”的情况。原因在同步快照的 Wrapped 汇总路径:Prime Agent 汇总块先执行
total_tokens += tok和total_cost += ...,而这两个变量要到所有工具汇总、账本合并完成后才初始化。普通用量计算因此看起来正常,但写同步快照时会触发UnboundLocalError,快照写入根本还没开始。这个问题在没有 Prime Agent 日志时不会出现,所以直到实际产生 Prime Agent 用量才暴露出来。它会让本机同步任务失败,并且让日志里的
json: ok变得容易误导排查。本次改动
scan_prime_agent接入ledger_touch("prime_agent")和ledger_reconcile("prime_agent", live_days)。关键设计
Prime Agent 仍然沿用原来的物理 session 去重和
child_usage_attributed排除规则。这次只是把已经去重后的每日结果接到账本,不重新扫描或重复累计数据。账本按天保存高水位。现存日志的当天数据与账本对账时取较新的完整日结果,日志整天消失后才使用账本回退;不会把实时值和账本值相加。这样既能保留日志清理前的历史,也能让账本随已有的
_ledger快照机制参与多设备同步。用户影响
修复后,有 Prime Agent 用量的设备可以正常完成同步快照写入。没有 Prime Agent 用量的设备行为不变。
本 PR 不包含 DMG 打包、安装包发布或本机 App 更新。
安全与隐私
兼容性
验证
以下命令均在 macOS 本地执行:
结果:
py_compile通过。swift build通过。git diff --check通过。all、today、week汇总均正常。Swift 构建仍会报告仓库原有的未声明资源 warning;没有新增编译错误。
已知限制
检查清单