Repository navigation
fix(collector): take the write lock at the start of every state transaction - #71
Merged
Merged
Conversation
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.
问题
本机采集器的状态库有两个写入进程,每分钟的同步和常驻的 OTEL 中继。同步的写事务用默认的延迟模式,先读后写。如果读取之后中继提交了新记录,同步升级写锁时 SQLite 立即返回
database is locked,不经过busy_timeout等待,整轮同步失败。多个 Claude Code subagent 同时运行、中继提交密集时更容易撞上。数据不会丢,下一轮会重读,但日志里会出现同步失败。改动
CollectorState.write()用BEGIN IMMEDIATE开启写事务,事务开始就拿写锁,冲突时按busy_timeout排队。采集器里所有写事务(Claude Code、Codex、omp、OpenCode、Antigravity 读取,出队、确认、重新归属、OTEL 入队)都改用它。tests/collector-agy.test.ts里 omp 额度的重置时间是 2026-11-06 的固定值,现在已经过期,额度被当作失效清空,测试在 main 上已经失败。把这些重置时间改到 2100 年。验证
bun test tests620 个通过,bun run typecheck、bun run build通过。