Commit Graph

14 Commits

Author SHA1 Message Date
ericwyuan
d75c745b95 fix: dispatcher crash on invalid failure_stage + per-task error isolation
Two fixes:
1. db_layer.update_task_status: map invalid failure_stage values (e.g.
   'process' from Edge) to 'callback' before DB write, preventing
   MariaDB ENUM DataError (1265 "Data truncated")
2. dispatcher._poll_once: wrap each task dispatch in try/except so one
   task's failure doesn't skip remaining tasks in the batch

Root cause: Edge returns failure_stage='process' but DB ENUM only allows
  download/extract/vlm_visual/vlm_fusion/callback. The DataError crashed
  _poll_once(), causing all subsequent PENDING tasks to be skipped.
2026-08-20 11:09:10 +08:00
ericwyuan
babf5b09a9 [架构重构] 移除本地Ollama融合,云端直出JSON直存DB,Q&A三模型降级
1. 视频摘要链路:云端VLM直出结构化JSON → Edge format_cloud_result格式化校验 → 直存NAS DB(移除run_text_fusion本地融合)
2. 智能问答链路:Gemini→NVIDIA→Ollama降级,新增chat()纯文本问答方法
3. 适配器重构:base/gemini/nvidia/ollama adapter新增chat();gemini多图单请求结构化JSON;nvidia逐帧调用聚合
4. 端点变更:/api/edge/chat → /api/edge/chat/ask,调orchestrator.run_qa()
5. chat_handler改经Edge Q&A编排,不再直连Ollama
6. 配置更新:ollama_url → qa_url,Ollama role注释改为Q&A兜底
7. README同步更新架构描述、拓扑图、时序图、模块表
2026-08-20 10:21:09 +08:00
ericwyuan
486eee4feb fix(db): frame_timestamp ISO8601 归一化 + perf(edge): ollama num_predict 1024→512
- db_layer._dt_or_none 支持 ISO 8601(带 T/Z/时区偏移) 归一化为 MariaDB DATETIME 标准格式, 修复 1292 Incorrect datetime value
- edge config ollama num_predict 512: qwen2.5:7b 在 ARM 上 1024 token 融合需 200s, 降到 512 加速且输出足够
2026-08-20 09:26:42 +08:00
ericwyuan
6a9d1626fb fix(event-time): event_end_time/frame_timestamp NOT NULL 列兜底
- Edge push 模式: event_end_time 未提供时用 start+视频时长推算
- fam-core db_layer: insert_event 空值兜底(end→start→NOW)
- insert_event_detail: frame_timestamp 空值兜底 NOW
解决 1048 Column cannot be null 落库失败
2026-08-20 02:20:01 +08:00
ericwyuan
c635dd69f1 fix(db): 空字符串datetime归一化为NULL,兼容MariaDB严格模式
monitor_events.event_end_time / event_details.frame_timestamp 收到空串时
插入 NULL 而非 '',避免 1292 Incorrect datetime value 报错
2026-08-20 02:10:37 +08:00
ericwyuan
e7c1641b72 fix(dispatcher): resp.json(silent=) 是 Flask API,requests 不支持会抛 TypeError
Edge 返回结果解析时 TypeError 逃逸到轮询循环,任务卡死 PROCESSING
2026-08-20 01:59:10 +08:00
ericwyuan
3a195d69b9 fix(dispatcher): 僵尸PROCESSING任务回收 + fam-core文件日志
- db_layer 新增 reclaim_stale_processing: PROCESSING 超过 push_timeout+120s 重置 PENDING
- dispatcher 轮询前先回收僵尸任务(进程重启/Edge重启导致 in-flight 请求丢失的场景)
- logger 增加 fam-core/logs/fam-core.log 文件输出(daemon 模式 stdout 不可见)
2026-08-20 01:42:59 +08:00
ericwyuan
727642d38b feat: adaptive keyframe count based on video duration
- Replace fixed 5-8 keyframe limit with duration-based adaptive sizing
- Candidate frames: clamp(duration_min × 2, 30, 120)
- Keyframe cap: clamp(duration / 150s, 8, 30)
- 30min video → 12 keyframes (was 8), 60min → 24, 120min → 30
- Short videos (<12min) still get floor of 8 keyframes
- Add Ollama keep-alive config doc to PROGRESS.md (OLLAMA_KEEP_ALIVE=-1)
- Update config.yaml and config.yaml.example with new video params
2026-08-20 01:29:14 +08:00
ericwyuan
40944428d1 feat: video analysis switched to push mode (upload whole video, sync response)
Rationale: Oracle cannot reach NAS (Tailscale userspace mode on NAS, no TUN),
the old pull+webhook design requires Edge to download video from NAS and
callback to NAS - both blocked. New design is one-way NAS -> Oracle:

- FAM-Edge: new POST /api/edge/video/push endpoint accepts multipart video
  upload, reuses existing OpenCV scene-change keyframe selection, analyzes
  synchronously and returns the result payload directly in the HTTP response
  (no webhook callback). Old /api/edge/video/analyze kept for compatibility.
- FAM-Edge: VideoPreprocessor.save_upload() saves the uploaded file
- FAM-Edge: AIOrchestrator.process_push_task() runs the full pipeline
  (health check -> extract -> select -> compress -> VLM -> fusion) and
  returns callback-style payload dict
- FAM-Core: Dispatcher rewritten to push mode - reads local video file,
  uploads with task metadata (camera_name, event_start_time from file mtime,
  known_members_context), applies the result to DB via shared
  event_receiver.apply_success_event()
- FAM-Core: event_receiver success logic extracted into reusable
  apply_success_event() (used by both webhook route and dispatcher)
- config: edge_url -> /api/edge/video/push, push_timeout 1800s, gunicorn
  Edge timeout raised to 1800s for long synchronous analysis
2026-08-20 01:03:48 +08:00
ericwyuan
94a8805045 feat: FAM-Edge chat proxy + PyMySQL migration for FAM-UI + config update
- FAM-Edge: add /api/edge/chat proxy endpoint forwarding to local Ollama
  (Ollama port 11434 not exposed externally, FAM-Edge acts as reverse proxy)
- FAM-Core config: edge_url and ollama_url switched from Tailscale IP to
  Oracle public IP (Tailscale firewall blocking between NAS and Oracle)
- FAM-UI: migrate mysql.connector to PyMySQL (same as FAM-Core)
- FAM-UI: cursor(dictionary=True) replaced with cursorclass=DictCursor
- End-to-end chat verified: FAM-Core -> FAM-Edge proxy -> Ollama -> response
  Answer: 今天没有观察到张三 (no events in DB yet, expected)
2026-08-19 23:59:28 +08:00
ericwyuan
c8cd2f2665 fix: MariaDB JSON path compat for name_member + FAM-Core API verified
- name_member(): replace MySQL-only JSON_REPLACE/JSON_CONTAINS with wildcard
  JSON paths (unsupported in MariaDB 10.11) with Python-side JSON parsing
- FAM-Core venv rebuilt with Python 3.10.20 on NAS
- All API endpoints tested: health, status, member list, unnamed, naming
- POST /api/member/name: 人物A successfully named to 张三
- PROGRESS.md updated with full test results and task completion
2026-08-19 23:48:35 +08:00
ericwyuan
47658fa068 [deploy] PyMySQL 替换 + Tailscale 组网 + config.yaml + 路径修复
- db_layer.py: mysql-connector-python(19MB) → PyMySQL(45KB), 去掉连接池
- config_loader.py: 修复路径解析 (2级→3级 dirname), FAM-Core + FAM-Edge 均修复
- Tailscale 组网完成: Oracle=100.74.137.126, NAS=100.70.234.39, 互通验证通过
- NAS Python 依赖: flask/gunicorn/pymysql/PyYAML 全部安装成功
- NAS 代码部署: /volume1/web/sentinel-home-ai/, FAM-Core 7 模块导入 PASS
- NAS DB 连接验证: PyMySQL → MariaDB 10.11.11, 6 张表可见, PASS
- config.yaml 创建: FAM-Core + FAM-Edge + FAM-UI (Tailscale IP + 密码)
- requirements.txt: mysql-connector-python → PyMySQL
2026-08-19 23:27:28 +08:00
ericwyuan
c45464c3e2 [补全] 各模块 __init__.py 导出 - 确保import链路完整 2026-08-19 22:37:47 +08:00
ericwyuan
da6b1c8d39 [2.1-2.5] FAM-Core 六个子模块 - Scheduler/Dispatcher/Event-Receiver/Chat-Handler/Member-Manager/Video-Server + DB层 + 配置 2026-08-19 22:21:31 +08:00