跳到主要内容

目标 A:控制面全在 ECS — 迁回 checklist

目标 A:登录、Copilot、项目/数据 API、埋点、管理、工具入队 全部走 ECS platform-server (:3011) + RDSDell 仅 Worker + R/py 算力(见 architecture-target.md)。

当前(2026-06):nginx 临时把 /api/platform/auth/ai/admin/analytics/public/ 指到 Dell :3001,因 ECS 上 deasync + 同步 PG 会挂请求。这是止血,不是终态。

P0 已落地(2026-06-07)

  • db.js: getUserByUsernameAsync / getUserByIdAsync / createUserAsync
  • auth.js: login / register / me → async
  • permissions.js: copilot gate → _enforceAsync when isPg()
  • helpers/conversations-async.js + agent 会话 create/append user msg(BIOF3_P2_PG=1
  • ECS 127.0.0.1:3011 login ~0.15s(401 错密)
  • nginx auth + ai → 3011(2026-06-07);公网 login ~0.19s,agent 首包 ~3s
  • agent 登录用户全链路(snapshot/facts/plans 仍 sync shim)
  • admin / analytics / public 仍 Dell → 下一批 P1

1. 完成定义(Done)

#验收项方法
D1公网 POST /api/platform/auth/login < 2s 返回 JSONcurl,仅 ECS 路径(nginx 无 Dell 例外)
D2公网 POST /api/platform/ai/agent < 3s 出现首条 SSEcurl -N
D3登录用户 GET /api/platform/ai/conversations 200admin JWT
D4GET /api/platform/admin/top-ips 200admin JWT
D5POST /api/platform/analytics/page-view 200(可匿名)无 token
D6nginx `platform/authai
D7Dell biof3-r-serverworker 或仅算力路由;不再承担全站 API 网关pm2 + BIOF3_RUN_MODE

2. 阻塞项(按优先级)

P0 — 不修则 ECS platform 不可用

说明主要文件
deasync 热路径getSqliteForLegacyModules() + BIOF3_P2_PG=1 在 HTTP 里 deasync.loopWhile 查 PGdb.js, db-p2-pg-shim.js
auth/login同步 getUserByUsernameauth.js(P0 用户已 async PG,但 platform 进程仍可能卡在 P2 初始化/混用)
ai-agent 入口建会话、facts、summary、plans 同步查routes/ai-agent.js, helpers/conversations.js

方向(二选一或组合)

  • 短期:platform 上 P2 热路径改为 async 路由async (req,res) + await pgPool.query),不再经 sync shim。
  • 中期:Copilot/会话类表专用 db-p2-async.js 模块,platform 只引 async 版;worker 仍可 sync/aux 至 cutover 完成。

P1 — 已部分修;迁回前全量扫

说明
db vs sqlite路由里 const {db} = require('../db') + db.prepare 会炸(db 是 better-sqlite 连接对象)。统一 sqlite = getSqliteForLegacyModules() 或 async PG。已修:conversations, ai-plans, ai-memory, chat-summary需 grep 扫全 r-server/routes
PG boolean / timestamptzadmin 统计等 SQL 勿写 undone=1substr(ts,1,10)
ECS envDATABASE_URL, JWT_SECRET, BIOF3_P2_PG=1, BIOF3_RUN_MODE=platform, 不要依赖本机 biof3.db 写用户

P2 — 体验与运维

说明
docs-indexagent 启动拉 copilot-index.json(公网),慢但不致命;可缓存/内置
frp迁回 ECS 后,frp 仅需 Dell 算力端口(3001 若只给 /api/r/ worker API)
RDS 内网ECS 与 RDS 同 VPC 内网连接,Dell worker 可继续公网或专线
platform 与 Dell JWT必须同一 JWT_SECRET(已要求)

3. nginx 回切步骤(D6)

文件infra/nginx/biof3.conf → 同步到 ECS /opt/biof3/app/nginx/biof3.conf(注意必须是文件不是目录)。

删除或注释(在 D1–D5 全绿后):

  • location /api/platform/auth/ → 3001
  • location /api/platform/ai/ → 3001
  • location /api/platform/admin/ → 3001
  • location /api/platform/analytics/ → 3001
  • location /api/platform/public/ → 3001

保留

  • location /api/platform/172.17.0.1:3011/api/
  • location /api/r/ → 3001(算力)
  • location /api/py/ → 3002
docker exec biof3-nginx nginx -t && docker exec biof3-nginx nginx -s reload

4. Dell 降级(D7)

  1. ECS platform 已通过 D1–D5。
  2. Dell:BIOF3_RUN_MODE=worker(或 api 仅保留 task 消费所需最小路由,见 config.js / server.js 分支)。
  3. pm2:biof3-r-worker 保持;biof3-r-server 若仍 all,改为 worker-only 或 demote 脚本(scripts/ecs-demote-r-server.sh 等)。
  4. 文档更新 ARCH-api-worker.md 与 steering infrastructure.md

5. 建议实施顺序

Week 1 P0: auth + ai/agent async PG(或 platform 专用 async 层)
P1: routes 全量 db→sqlite/async 扫描 + 单测/smoke
Week 2 ECS 压测 D1–D5 → nginx 回切 D6
Dell worker 模式 D7
删 nginx Dell 例外,监控 24h

Smoke 脚本(可扩展):test/smoke-platform-split.mjs、对 https://biof3.com/api/platform/* 的 curl 列表。


6. 不在目标 A 范围内

  • R site-library / Seurat 全部迁到 ECS(算力仍 Dell 或大内存云)。
  • 去掉 frp 算力通道(除非 worker 改公网/VPN 专线另一种组网)。

7. 相关文档

AI 陪学

让 AI 陪我学这一篇

AI 会读这篇文章后给你 3-5 步学习计划, 逐步陪你学完,最后出 1-3 道题验证你掌握得怎么样。 登录后 AI 才能记住你的进度。

静态文件

离线资料下载

手册 HTML / PDF 已在后台预生成,点击后直接下载网站静态资源。