Skip to content

fix(v4.6): three P0s surfaced by stress testing - #2

Merged
HeiGeAi merged 1 commit into
mainfrom
feat/v4.6-p0-fixes
May 26, 2026
Merged

fix(v4.6): three P0s surfaced by stress testing#2
HeiGeAi merged 1 commit into
mainfrom
feat/v4.6-p0-fixes

Conversation

@HeiGeAi

@HeiGeAi HeiGeAi commented May 26, 2026

Copy link
Copy Markdown
Owner

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 后端两个深坑

  1. `StorageFactory.create("sqlite", base_dir=...)` 之前忽略 `base_dir`,db 永远落到 `Path.cwd() / data / opc.db`。修:从 `base_dir.parent` 派生 opc.db 路径。
  2. 多 storage_type 共享同一 db 时,agent_ops legacy 迁移会把 task `T001` 误当成旧版 agent 搬到 `default/T001`。修:给 SQLiteStorage 加 namespace 透明前缀(`tasks::T001` / `agents::default/ceo` / `decisions::T001_D001`)。

Performance impact (file backend)

Operation v4.5 v4.6 Δ
`create_task` 21.2 ops/s 112.4 +5.3×
`assess_task` 5.7 ops/s 30.2 +5.3×
`get_status` 9490 19293 +2.0×
`risk_assess` 4369 4410 flat

SQLite 现在和 file 后端表现一致(v4.5 显示 SQLite assess=296 ops/s 是 corruption 后的伪速度)。

Tests (45 → 58)

  • `tests/test_agent_catalog_cache.py` — 缓存命中 / mtime 失效 / 显式 invalidate / cached vs cold 速度下限
  • `tests/test_sync_hook_resilience.py` — create / assess / transition / progress 在 sync 钩子稳定抛 SystemExit 时仍能正常完成
  • `tests/test_sqlite_backend.py` — StorageFactory 路径推导 / 完整 SQLite 生命周期 / read-after-write / 跨 storage_type 共享 db / namespace 隔离

Test plan

  • 本地 58/58 通过(macOS Py 3.9,0.36s)
  • ruff clean
  • stress baseline rerun 确认 5× 性能提升
  • SQLite baseline lifecycle 之前失败现在通过
  • CI 矩阵自动跑(Ubuntu + macOS × Py 3.9/3.11/3.12 + ruff)

Upgrade notes

  • 文件后端:零影响
  • SQLite 后端:`opc.db` 位置从 `cwd/data/opc.db` 改到工作目录的 `data/opc.db`;老数据可 `sqlite3 .dump` 迁移(key 需加 namespace 前缀)

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>
@HeiGeAi
HeiGeAi merged commit 5e1330a into main May 26, 2026
7 checks passed
@HeiGeAi
HeiGeAi deleted the feat/v4.6-p0-fixes branch May 26, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants