Commit Graph

23 Commits

Author SHA1 Message Date
iomgaa 1cbfa97b8d fix: cover httpx disconnect family in transient error set 2026-07-16 05:26:52 -04:00
iomgaa 200053fbdc fix: treat SSE stream without [DONE] as truncated (retry, no cache) 2026-07-16 05:26:21 -04:00
iomgaa 7cc6aa5b23 fix: reject REDIS_CACHE_TTL<=0 (kill implicit never-expire) 2026-07-16 05:25:36 -04:00
iomgaa 564c92a043 feat: add cache_salt dimension to LLM response cache 2026-07-16 05:23:58 -04:00
iomgaa 3a8dd5c167 fix: add close/context-manager to diagnosis store; tighten import boundary 2026-07-15 12:06:29 -04:00
iomgaa 6b85fcbe1c feat: add baseline diagnosis signal store 2026-07-15 12:01:30 -04:00
iomgaa 1f83da9eb7 fix: embedding 改 cuda + OCR 超时 300s + 重试退避 20s 起 + jitter 防雷群
- config/default.yaml: embed.device cpu → cuda
- adapters/ocr.py: _TIMEOUT_S 15 → 300(5 分钟)
- adapters/llm.py: 指数退避加 ±50% jitter 避免 24 路同时重试
- .env: LLM_RETRY_BASE_DELAY 2→20s, LLM_RETRY_MAX_DELAY 30→120s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-09 22:14:57 -04:00
iomgaa d6ae0d85cd fix: Redis 缓存构造修正 + TTL=0 永不过期支持
- main.py: 先创建 aioredis 客户端再传入 RedisResponseCache
- redis_cache.py: ttl_s=None 时不设过期时间
- .env: REDIS_CACHE_TTL=0(永不过期)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-09 13:52:33 -04:00
iomgaa 4612123ec4 style: ruff format telemetry + repair_trees, remove unused SRTEntry import 2026-07-09 00:25:36 -04:00
iomgaa f733c13dd1 fix(llm): call_id 移入重试循环,每 attempt 独立
消除重试时遥测主键冲突的根因。每次 attempt 独立记录,
parent_call_id 不受影响(循环外固定),更利于事后诊断重试轨迹。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-09 00:12:38 -04:00
iomgaa 5a91f392f0 fix(telemetry): INSERT OR IGNORE + WAL + try/except 三层防御加固
根治遥测写入主键冲突(UNIQUE constraint)和并发写锁(database is locked)
导致的异常冒泡,遥测侧信道错误不再污染 LLM 重试链。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-09 00:11:54 -04:00
iomgaa 224c75ba9e feat(adapters): OCRProvider Protocol + MonkeyOCRClient 异步适配器
- app/ports.py: 新增 OCRProvider Protocol(runtime_checkable,与
  EmbeddingProvider 同级),定义 async transcribe_frames 端口
- adapters/ocr.py: 从 TRM4 core/tree/ocr.py 保真迁移 MonkeyOCRClient
  - assert → ValueError(P5 防御性校验)
  - 公开方法改 async(asyncio.to_thread 包装同步 HTTP)
  - 内部逻辑不变:多端点轮询、线程安全 Session、单帧降级、行去重
- tests/unit/test_ocr_adapter.py: 17 个测试覆盖 Protocol 合规、
  构造校验、健康检查、转录、降级、去重、轮询

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-07 05:47:55 -04:00
iomgaa 3e348f5b21 feat(adapters): GovernedVLMClient — VLMProvider 最小可用实现
- 包装 GovernedLLMClient,注入 base64 图片到 OpenAI Vision API 格式
- 复用 LLM 治理栈全部能力(熔断、缓存、重试、遥测)
- 8 项单元测试覆盖协议满足、图片编码、注入逻辑、不可变性
2026-07-07 01:49:55 -04:00
iomgaa 6fd9522bf3 feat(adapters): EmbeddingProvider Protocol + local/remote 双后端实现
- app/ports.py: 添加 EmbeddingProvider Protocol(runtime_checkable,dim 属性 + embed 方法)
- adapters/embedding.py: 从参考代码迁移,拆分为 LocalEmbeddingProvider 和 RemoteEmbeddingProvider
  - Local: sentence-transformers 冻结推理,维度校验
  - Remote: OpenAI 兼容 API,L2 归一化,按 index 排序
  - 两者均提供 embed() 和 embed_tensor() 统一接口
- tests/unit/test_embedding_adapter.py: Protocol 满足性、形状校验、导入测试

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-07 01:45:09 -04:00
iomgaa adf14633e5 chore: lint 修复(TC001/TC003 类型导入优化)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 23:15:06 -04:00
iomgaa ee90fb8e88 fix(adapters): 修复 GovernedLLMClient 流式消费和规格偏差
- _stream_request + _consume_stream 合并为 _call_streaming,
  在 async with self._http.stream() 内直接消费流,
  确保看门狗作用于真实 HTTP 流而非内存列表(Critical 1)
- breaker 检查移到 call_id 生成之前(Critical 2)
- cache/ttft_timeout_s/inter_token_timeout_s 支持 None(Important 1)
- 重试失败路径遥测使用统一 call_id(Important 2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 23:08:52 -04:00
iomgaa cfd3277f80 style: format adapters/llm.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 23:01:06 -04:00
iomgaa f1a0414be8 feat(adapters): 实现 GovernedLLMClient 四层治理栈
流式 SSE + 三层看门狗 + 重试退避 + 熔断 + Redis 缓存 + 遥测。
provider 差异处理(DeepSeek reasoning_content vs Qwen think 标签)。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 23:00:22 -04:00
iomgaa c2ff2855b7 feat(adapters): 实现三层流式看门狗
TTFT / inter_token / total 超时保护。
参考 CHSAnalyzer2 streaming.py。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 22:43:01 -04:00
iomgaa 82f065e4ef feat(adapters): 实现 SQLiteTelemetryRecorder
asyncio.to_thread 桥接 SQLite,字段与 TelemetryRecorder Protocol 一一对应。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 22:40:15 -04:00
iomgaa 14bb60e918 feat(adapters): 实现 CircuitBreaker 内存级熔断器
注入 now 纯确定性,force_open 支持 401/403 直接熔断。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 22:39:57 -04:00
iomgaa 9dae7dda98 feat(adapters): 实现 RedisResponseCache
content-addressed sha256 缓存键,Redis 不可用时静默降级。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 22:39:42 -04:00
iomgaa e60823de1a build: add README, pyproject.toml, package skeletons and smoke test
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-06 11:37:59 -04:00