Skip to content

docs(beta 07/08): Fly.io 部署、双实例、收尾与恢复方案 - #169

Open
hifizz wants to merge 2 commits into
mainfrom
spec/beta-07-flyio
Open

hifizz wants to merge 2 commits into
mainfrom
spec/beta-07-flyio

Conversation

@hifizz

@hifizz hifizz commented Sep 17, 2026

Copy link
Copy Markdown
Owner

范围

flyio-production-deployment OpenSpec + 运行时契约实现:多实例 Generation lease、部署 drain、健康检查、部署文件与隔离环境验证。

可复现构建、环境隔离、健康检查、共享状态和对象存储、部署前 drain、Generation lease/CAS 已落实到代码;区域/规格实测、备份恢复和旧镜像回滚的真实演练未完成。

重点:HTTP 连接空闲不等于后台 Generation 空闲;未验证前关闭可能误停工作实例的 autostop。平台终止窗口不够时不能只靠 signal handler 承诺任务完成。

实现内容(代码完成)

  • Generation leasemessages.generation_owner/generation_heartbeat_at,启动 CAS 认领、周期心跳;同一行 stop_requested_at/superseded_at 作跨实例控制通道。
  • 孤儿清扫:按心跳过期判定(45s 窗口),周期 sweeper 60s;活实例生成不再被其他进程重启误杀;终态仍只由 finalize 的 status CAS 写入。
  • drainPOST /api/internal/drain(CRON_SECRET,{waitMs, abort})关准入+排空;5 个生成入口 drain 中返回 CAPACITY_UNAVAILABLE;SIGTERM/SIGINT 有界收尾(20s)+遥测 flush(5s)+退出;deploy-drain 取消映射 DEPLOY_INTERRUPTED
  • 跨实例:本机无 Session 时属主存活→fly-replay: instance=<owner>;fallback=prefer_self;属主死亡→SESSION_LOST 收敛。
  • 健康检查/healthz(liveness)、/readyz(readiness,drain 中 503 摘除流量,DB 探测短缓存+超时);proxy 放行。
  • 部署文件Dockerfile(standalone)、fly.toml(autostop off、min 2 实例、双检查分层、kill_timeout 30s)、scripts/fly-drain.mjs/fly-migrate.mjsnext.config deploymentId=FLY_IMAGE_REF、环境白名单启动校验、runbook docs/deploy-flyio.md

验证(隔离环境完成)

  • typecheck、定向 ESLint、pnpm build(standalone 产物)通过
  • e2e/runtime/drain-env.test.mjs:drain 状态机+环境白名单
  • e2e/thread-chat/generation-ownership-db.test.mjs:隔离 PG 验证 claim CAS/心跳/停止标志/陈旧接管/终态不回写
  • normalized-generation-db 回归通过(含 sweep 新谓词适配)
  • standalone 冒烟:readyz 200→drain POST→readyz 503;匿名 drain 401
  • openspec validate flyio-production-deployment --strict 通过
  • 新增 fly-runtime CI workflow(含 docker build)与 db:test:push

未完成(不得宣称已验收)

真实 Fly 部署、双实例生产流量、区域/内存/延迟实测、容量压测、RPO/RTO 批准、备份恢复与回滚演练、外部告警送达(依赖 #168)、真实 secrets 配置。tasks.md 仅勾选已验证项(1.2、3.4、4.1–4.3 未勾)。

依赖

根 PR,基于 main。运行时集成依赖 #164 预算、#166 准入、#167 搜索/cursor、#168 观测;最终在 08 发布门禁验收。migration 不在构建或实例启动时执行,由 develop 单一集成生成验证;测试库经 db:test:push 同步。

Generated with Devin

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
thread-chatbot Error Error Sep 18, 2026 1:26pm UTC

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5d7a61a0-50eb-4eae-9094-7b0314cfca5c


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- messages 增加 generationOwner/generationHeartbeatAt lease;
  生成启动 CAS 认领,心跳守望读回 stop/supersede 标志做跨实例中止
- 孤儿清扫改为心跳判定:活实例的生成不再被「本进程重启」误杀,
  周期 sweeper 兜底属主崩溃的场景
- drain 状态机:内部 API(CRON_SECRET)关准入 + 有界排空;
  SIGTERM/SIGINT 走有界收尾 + 遥测 flush;新入口返回 CAPACITY_UNAVAILABLE
- stop/edit/stream 支持 fly-replay 定向到属主实例;
  deploy-drain 取消映射为 DEPLOY_INTERRUPTED 可重试失败
- /healthz、/readyz(drain 中 503 摘除流量、DB 探测短缓存);
  proxy 对健康检查放行;instrumentation 启动环境白名单与信号钩子
- Dockerfile(standalone)+ fly.toml(autostop off、双实例、
  readiness/liveness 分层、30s kill_timeout)+ drain/migrate 部署脚本
- 修复 GenerationOwnership beat 自停死锁;修复存量 e2e 测试
  parts 命令格式与 document_revisions 清理顺序

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant