fix(v4.6): three P0s surfaced by stress testing - #2
Merged
Conversation
11 类强度测试在 1500+ 操作的负载下抓到三个 P0 真问题,本提交逐一修掉,并补 13 个回归测试锁住行为。
P0-1 · agent catalog 重复加载(性能 ~5×)
- tools/agent_catalog.py 加 mtime-based 缓存,按 (pack, strict) 维度独立
- 缓存签名 = (dir mtime, [(file_name, mtime, size)…]),文件改动自动失效
- 暴露 invalidate_catalog_cache(pack=None) 供测试和未来手动清理
- 效果:create_task 21 → 112 ops/s, assess_task 5.7 → 30.2 ops/s
P0-2 · except Exception 抓不到 SystemExit
- tools/task_flow.py 全部 7 处 best-effort sync 钩子改成
except (Exception, SystemExit)
- 影响 create_task / assess_task / transition_state / report_progress
内调用 sync_agent_from_task / describe_orchestration_plan /
sync_to_memory_md 的路径
- 之前的症状:sync 钩子内 emit_error 抛 SystemExit 漏出去,
用户看到 success: true 但 task 后续 state/profile/recommended_*
字段没真正落盘
P0-3 · SQLite 后端两个深坑
1. StorageFactory.create("sqlite", base_dir=...) 之前忽略 base_dir,
db 总是落到 Path.cwd() / data / opc.db。修:从 base_dir.parent
派生 opc.db 路径,让工作目录隔离真正生效。
2. 多个 storage_type 共享同一 opc.db 时,agent_ops 的 legacy 迁移逻辑
会把 task 的 "T001" 误当成旧版 agent 记录搬到 "default/T001"。修:
给 SQLiteStorage 加 namespace 透明前缀(tasks::T001 /
agents::default/ceo / decisions::T001_D001),互不干扰。
- 暴露 storage.reset_storage_cache() 给测试和切换 backend 的场景
Tests (45 → 58)
- tests/test_agent_catalog_cache.py: 4 个测试覆盖缓存命中/失效/
invalidate/速度下限
- tests/test_sync_hook_resilience.py: 4 个测试 monkey-patch agent_ops
让其稳定抛 SystemExit,验证主调用仍然正常完成
- tests/test_sqlite_backend.py: 5 个测试覆盖 db_path 推导/完整生命周期/
read-after-write/跨 storage_type 共享 db/namespace 隔离
Upgrade notes
- 文件后端无兼容性影响
- SQLite 后端的 opc.db 位置会从 cwd/data/opc.db 改到工作目录的
data/opc.db;老数据可通过 sqlite3 .dump 迁移(key 需要加 namespace 前缀)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
v4.5 测试套件 + 11 类强度测试发现三个 P0 真问题,本 PR 逐一修掉,补 13 个回归测试锁住行为。
P0-1 · agent catalog 重复加载(性能 ~5×)
写路径每次都重读 20 个 agent .md 把 `assess_task` 拖到 5.7 ops/s。`tools/agent_catalog.py` 加 mtime-based 缓存,按 (pack, strict) 维度独立。缓存签名 = (dir mtime, [(file_name, mtime, size)…]),文件改动自动失效。
P0-2 · `except Exception` 抓不到 `SystemExit`
`sync_agent_from_task` 内 emit_error 抛 SystemExit,被 `except Exception` 漏过,导致用户看到 success: true 但 task 的 state/profile/recommended_* 字段没真正落盘。`tools/task_flow.py` 7 处 best-effort 钩子改成 `except (Exception, SystemExit)`。
P0-3 · SQLite 后端两个深坑
Performance impact (file backend)
SQLite 现在和 file 后端表现一致(v4.5 显示 SQLite assess=296 ops/s 是 corruption 后的伪速度)。
Tests (45 → 58)
Test plan
Upgrade notes