feat: 2026-04-15~05-02 累积变更基线 — AI 重构 + Runtime Context + DWS 修复

涵盖(每条对应已存的审计记录):
- AI 模块拆分:apps/backend/app/ai/apps -> prompts/(8 个 APP + app2a 派生)
  audit: 2026-04-20__ai-module-complete.md
- admin-web AI 管理套件:AIDashboard / AIOperations / AIRunLogs / AITriggers / TriggerManager
  audit: 2026-04-21__admin-web-ai-management-suite.md
- App2 财务洞察 prompt v3 -> v5.1 + 小程序 AI 接入(chat / board-finance)
  audit: 2026-04-22__app2_prompt_v5_1_and_miniprogram_ai_insight.md
- App2 prewarm 全过滤器 + AI 触发器 cron reschedule
  audit: 2026-04-21__app2-finance-prewarm-all-filters.md
  migration: 20260420_ai_trigger_jobs_and_app2_prewarm.sql / 20260421_app2_prewarm_cron_reschedule.sql
- AppType 联合类型对齐 + adminAiAppTypes.test.ts
  audit: 2026-04-30__admin_web_ai_app_type_alignment.md
- DashScope tokens_used 提取修复
  audit: 2026-04-30__backend_dashscope_tokens_used_extraction.md
- App3 线索完整详情 prompt
  audit: 2026-05-01__backend_app3_full_detail_prompt.md
- Runtime Context 沙箱(5-1~5-2 主线):
  - 后端 schema/service + admin_runtime_context / xcx_runtime_clock 两个 router
  - admin-web RuntimeContext.tsx + miniprogram runtime-clock.ts
  - migration: 20260501__runtime_context_sandbox.sql
  - tools/db/verify_admin_web_sandbox.py + verify_sandbox_end_to_end.py
  - database/changes: 7 份 sandbox_* 验证报告
- 飞球 DWS 修复:finance_area_daily 区域汇总 + task_engine 调整
  + RLS 视图业务日上界(migration 20260502 + scripts/ops/gen_rls_business_date_migration.py)

合规:
- .gitignore 启用 tmp/ 排除
- 不入仓:apps/etl/connectors/feiqiu/.env(API_TOKEN secret,本地修改保留)

待验证清单:
- docs/audit/changes/2026-05-04__cumulative_baseline_pending_verification.md
  每个主题的功能完整性 / 上线验证几乎都未收口,按优先级 P0~P3 逐一处理
This commit is contained in:
Neo
2026-05-04 02:30:19 +08:00
parent 2010034840
commit caf179a5da
130 changed files with 14543 additions and 2717 deletions

View File

@@ -36,11 +36,12 @@ from app import config
# CHANGE 2026-03-23 | 新增 trigger_jobs 路由(定时任务管理页面 API
# CHANGE 2026-03-24 | P18 任务引擎运营看板:新增 admin_task_engine 路由
# CHANGE 2026-03-29 | DWS_TASK_ENGINE新增 internal_events 路由(按 job_name 执行任务)
from app.routers import auth, execution, schedules, tasks, env_config, db_viewer, etl_status, xcx_test, wx_callback, member_retention_clue, ops_panel, xcx_auth, xcx_avatar, admin_applications, business_day, xcx_tasks, xcx_notes, xcx_chat, xcx_ai_cache, xcx_performance, xcx_customers, xcx_coaches, xcx_board, xcx_config, tenant_auth, tenant_users, tenant_excel, tenant_clues, tenant_site_admins, admin_tenant_admins, admin_registry, internal_ai, admin_ai, admin_dev_trace, trigger_jobs, admin_task_engine, admin_db_health, admin_triggers, internal_events
from app.routers import auth, execution, schedules, tasks, env_config, db_viewer, etl_status, xcx_test, wx_callback, member_retention_clue, ops_panel, xcx_auth, xcx_avatar, admin_applications, business_day, xcx_tasks, xcx_notes, xcx_chat, xcx_ai_cache, xcx_performance, xcx_customers, xcx_coaches, xcx_board, xcx_config, xcx_runtime_clock, tenant_auth, tenant_users, tenant_excel, tenant_clues, tenant_site_admins, admin_tenant_admins, admin_registry, internal_ai, admin_ai, admin_dev_trace, trigger_jobs, admin_task_engine, admin_db_health, admin_triggers, internal_events, admin_runtime_context
from app.services.scheduler import scheduler
from app.services.task_queue import task_queue
from app.services.task_executor import task_executor
from app.ws.logs import ws_router
from app.ws.ai_events import ws_router as ai_ws_router
@asynccontextmanager
@@ -99,6 +100,33 @@ async def lifespan(app: FastAPI):
import logging as _log
_log.getLogger(__name__).warning("启动检查定时任务失败", exc_info=True)
# CHANGE 2026-04-22 | 启动时清理上次进程遗留的孤儿 run_logsworker 被 kill/reload 导致 status 卡在 running
try:
from app.database import get_connection as _get_conn_cleanup
_c = _get_conn_cleanup()
try:
with _c.cursor() as _cur:
_cur.execute(
"""
UPDATE biz.ai_run_logs
SET status = 'failed',
error_message = COALESCE(error_message, '') || ' [orphaned_by_restart]',
finished_at = COALESCE(finished_at, NOW())
WHERE status = 'running'
AND created_at < NOW() - INTERVAL '5 minutes'
"""
)
_cleaned = _cur.rowcount
_c.commit()
if _cleaned:
import logging as _log
_log.getLogger(__name__).info("启动清理 %d 条孤儿 run_logsstatus=running > 5min", _cleaned)
finally:
_c.close()
except Exception:
import logging as _log
_log.getLogger(__name__).warning("孤儿 run_logs 清理失败(忽略)", exc_info=True)
# CHANGE 2026-03-10 | 注册 AI 事件处理器(消费/备注/任务分配 → AI 调用链)
# CHANGE 2026-03-22 | P14 迁移BailianClient → DashScopeClient + AIConfig + 防护层
try:
@@ -127,6 +155,8 @@ async def lifespan(app: FastAPI):
config=_ai_config,
)
register_ai_handlers(_dispatcher)
from app.routers import internal_ai as _internal_ai_router
_internal_ai_router.set_dispatcher(_dispatcher)
except Exception:
import logging as _log
_log.getLogger(__name__).warning("AI 事件处理器注册失败AI 功能不可用", exc_info=True)
@@ -178,6 +208,7 @@ app.include_router(env_config.router)
app.include_router(db_viewer.router)
app.include_router(etl_status.router)
app.include_router(ws_router)
app.include_router(ai_ws_router)
app.include_router(xcx_test.router)
app.include_router(wx_callback.router)
app.include_router(member_retention_clue.router)
@@ -195,6 +226,7 @@ app.include_router(xcx_customers.router)
app.include_router(xcx_coaches.router)
app.include_router(xcx_board.router)
app.include_router(xcx_config.router)
app.include_router(xcx_runtime_clock.router)
app.include_router(tenant_auth.router)
app.include_router(tenant_users.router)
app.include_router(tenant_excel.router)
@@ -210,6 +242,8 @@ app.include_router(trigger_jobs.router)
app.include_router(admin_task_engine.router)
app.include_router(admin_db_health.router)
app.include_router(admin_triggers.router)
app.include_router(admin_runtime_context.router)
app.include_router(admin_runtime_context.config_router)
@app.get("/health", tags=["系统"])