公众号旧文
Phase 5 Production Completion Report
#Codex
这是最近用 Codex 做的一个小项目,耗时一周多。
记录一下里程碑。
报告日期:2026-08-21
项目:XXX
阶段结论:
Phase 5 已完成从控制面设计、Shadow 验证,
到第一次安全生产发布的完整闭环。
1. Executive Summary
Phase 5 将已经验证的动态 Queue Worker 集群接入长期生产XX流程,并补齐了 Run 生命周期、验证门、发布门、定时调度、版本一致性、失败恢复、Retry Completion 和 XX-XXX SQLite/API 发布链路。
第一次 Production Run 遇到 3 个 exhausted XXXX,因此原 Run 被 Validation Gate 正确标记为 VALIDATED_REVIEW,未被直接发布。
独立 Retry Run 完成 3/3 后,通过 Retry Completion Gate 将 2100 个原结果与 3 个 retry 结果组成不可变 Completion Artifact,最终覆盖 2103/2103,并安全发布到 XX-XXXX 与 XX-XXX。
最终生产数据:
| Metric | Result |
|---|---|
| XXXX tasks | 2,103 |
| Current XX records | 33,969 |
| History rows in XX-XXX SQLite | 39,190 |
first_seen > last_seen |
0 |
| XX-XXXX publication | PASS |
| XX-XXX sync/import | PASS |
| API health | PASS |
2. Phase 5 Step Status
| Step | Scope | Final status | Outcome |
|---|---|---|---|
| Step 1 | Production loop audit | READY | 识别旧 timer、XX、merge、sync/import 链路及改造边界。 |
| Step 2 | Run Controller design | READY | 设计 Run 状态机、metadata、CLI、active-run、validation/publication gates。 |
| Step 3 | Run Controller MVP | PASS | 实现独立 runs.db、Run CLI、事件审计和 Worker auto-run discovery。 |
| Step 4 | Validation Gate | PASS | 实现 task/result/schema/checksum/duplicate/exhausted 验收与 PASS/REVIEW/FAIL。 |
| Step 5 | Publication Gate | PASS | 实现 staging、backup、atomic replace、health check 和 rollback。 |
| Step 6 | Timer automation | PASS | 实现单实例 Pipeline Runner 与 systemd service/timer 模板。 |
| Step 6.5 | Coordinator preparation | READY | XX-XXXX 部署 Run Controller、Pipeline、Merge、runs.db 与 active-run API。 |
| Step 6.6 | Release baseline/governance | READY/PASS | 建立 release baseline,完成 7/7 Worker auto-run 迁移。 |
| Step 7 | Canary full pipeline | PASS | 验证 Run→Worker→Validation→Merge→隔离 Publication 全链路。 |
| Step 7B | Full validation | REVIEW→PASS via Retry | 全量 2103 中 2102 completed、1 exhausted;独立 retry 成功补齐。 |
| Step 7C | Consumer recovery | PASS | task exception 后 consumer backoff/recover,slot 不再永久减少。 |
| Step 7E | Abort lifecycle | PASS | 实现 RUNNING→ABORTING→ABORTED 与完整事件审计。 |
| Step 8 | Release Gate | PASS | Coordinator/Worker version/hash gate、7/7 rollout、capacity 保持。 |
| Step 9.1 | Retry Completion Audit | READY_FOR_IMPLEMENTATION | 确认单 Run merge/publication 不足,确定安全组合模型。 |
| Step 9.2 | Retry Completion Gate | PASS | 实现 provenance、checksum、immutable manifest 和隔离 composite merge。 |
| Step 9.3 | Completion Execution | PASS | 真实生成 2103/2103 Completion Artifact。 |
| Step 9.4 | Production Publication | REVIEW→PASS on retry | 首次 SSH 失败自动 rollback;修复后 XX-XXXX、XX-XXX、API 全部通过。 |
此外,Step 10 Production Timer 已安装并启用,当前状态为 PASS。
3. Production Architecture Delivered
systemd production timer (06:30 daily)
|
v
run_pipeline.py
|
Run Controller
|
Validation Gate
|
Queue Coordinator
|
7 Workers / 12 slots
|
Result Upload
|
Merge staging
|
Publication Gate
|
XX-XXXX JSON
|
sync-XXXXX.sh
|
XX-XXX import_json.py
|
SQLite + API
当主 Run 存在 exhausted task 时:
Original VALIDATED_REVIEW + Retry VALIDATED_PASS
|
v
Retry Completion Gate
|
v
immutable manifest
|
v
isolated merged artifact
|
v
Publication Gate
4. First Production Run
Run ID:20260820-223004-8128857b
- expected tasks:2,103
- completed:2,100
- exhausted:3
- checksum errors:0
- schema errors:0
- duplicate task IDs:0
- validation:
VALIDATED_REVIEW
安全门按设计阻止了不完整 Run 直接进入 Publication Gate。
原 Run 状态至今保持 VALIDATED_REVIEW,没有被人工改写成 PASS。
5. Retry Run
Retry Run ID:20260820-223004-8128857b-retry-01
- retry tasks:3
- completed:3
- exhausted:0
- checksum/schema errors:0
- validation:
VALIDATED_PASS
retry_task_sources 保存了 retry task 到 original exhausted task 的一一映射。
Retry 没有修改原 task 状态或历史,也没有被单独作为完整生产数据发布。
6. Completion Artifact
Completion ID:20260820-223004-8128857b-completion-01
路径:
/opt/XXXXX-XXXX-XX/shadow/completions/20260820-223004-8128857b-completion-01/
内容:
- Original results:2,100
- Retry results:3
- Composite coverage:2,103/2,103
- merged current:33,969
- merged history artifact:39,025 source records
- duplicate XX:0
- validation:
VALIDATED_PASS - publication performed by completion build:false
Manifest SHA256:
aab7c732bcbb53f0bb4fbaedb72c89ac27dc1d3ccf8078c03b04d884eccc7654
Merged artifact SHA256:
- XXX.json:
3c2778f25238bf8ac570820a0f5486bec7cd896f4d207a8a2142467823435558 - XXXXXXX.json:
352ec53d14a5cb7c61285598db565fa4304c39af7454df6fdb7e3adb51434f4a
7. Production Publication
XX-XXXX
Publication:PASS。
发布后 JSON 与 Completion Artifact hash 完全一致:
| Artifact | Records | Size | SHA256 |
|---|---|---|---|
| XXX.json | 33,969 | 58,394,250 | 3c2778f25238bf8ac570820a0f5486bec7cd896f4d207a8a2142467823435558 |
| XXXXXXX.json | 39,025 source records | 69,053,123 | 352ec53d14a5cb7c61285598db565fa4304c39af7454df6fdb7e3adb51434f4a |
XX-XXX
Sync/import:PASS。
- JSON hashes 与 XX-XXXX 一致
- SQLite XXX:33,969
- SQLite history:39,190(保留已有历史行)
first_seen > last_seen:0- API service:active
API
Health:PASS。
{
”database”: ”ok”,
”XXX”: 33969,
”last_update”: ”2026-08-21 13:48:25”,
”status”: ”ok”
}
8. Failure Recovery Cases
Initial publication attempt
失败原因:
XX-XXXX → XX-XXX scp authentication failure,exit code 255。
结果:
- backup 已创建
- XX-XXXX production JSON 自动 rollback
- rollback 后内容 SHA256/size 与发布前一致
- XX-XXX 未 import
- API 保持旧数据且健康
- rollback:PASS
SSH key 部署并验证后重新发布。
Health-check hardening during retry
后续 retry 暴露两个非数据故障:
- urllib 默认请求被 Cloudflare 返回 403
- API restart 后短暂返回 502
处理:为健康请求增加明确 User-Agent/Accept,并增加有限的 60 秒恢复窗口。每次失败 attempt 均自动回滚 XX-XXXX,使用独立 attempt 目录保留审计证据。最终 attempt sync exit code 0、health PASS。
9. Audit and Rollback Assets
成功 publication attempt:
20260820-223004-8128857b-completion-01-publication-retry-03
备份目录:
/opt/XXXXX-XXXX-XX/shadow/publication-completions/20260820-223004-8128857b-completion-01-publication-retry-03/backup/
审计事件包括:
- publication started
- backup created
- failed attempts and restore result
- final publication success
- sync start/end and exit code
- API health payload
Original 和 Retry 的状态及 task history 均未改变。
10. Current Production Operations Recommendations
Timer
当前实时状态:
- unit:
XXXXX-XXXX-production-pipeline.timer - enabled:yes
- active:yes
- schedule:每天 06:30 CST
- last trigger:2026-08-21 06:30:04 CST
- next trigger:2026-08-22 06:30:00 CST
建议每天在 06:30 后检查 pipeline service、Run 状态、validation 和 publication/sync events。不得恢复旧 03:00 timer,也不要让 timer 直接调用 scanner/import/sync。
Backup strategy
- 每次 publication 必须保留独立 attempt ID。
- 保留 backup manifest、旧 JSON、completion manifest 和全部 checksums。
- 建议制定按数量或天数的保留策略,但在确认远端 SQLite/API 和下一个 Run 稳定前不得删除最新成功 backup。
- 定期执行离线 restore rehearsal,验证 backup JSON 可解析且 hash 匹配。
SSH key maintenance
- 持续使用 XX-XXXX → XX-XXX 非交互专用 key。
- timer 启动前增加
BatchMode=yesSSH/SCP preflight,失败应在替换 production JSON 前停止。 - 记录 key owner、用途、fingerprint、创建/轮换日期;轮换前后都进行 SSH 与小文件 scp 验证。
- 不在脚本、日志或命令参数中保存密码。
Retry process
- 主 Run 非 PASS 时禁止直接 publish。
- exhausted task 必须进入独立 Retry Run。
- Retry 必须单独 Validation PASS。
- 使用
retry_task_sources一一验证来源。 - 通过 Retry Completion Gate 生成新的 immutable completion manifest。
- 仅发布完成组合验证的 artifact;不得修改 Original 为 PASS,也不得发布 Retry-only artifact。
Rollback process
- publication、sync 或 health 任一步失败时停止当前 pipeline。
- 使用该 attempt 的 backup manifest 校验旧 artifacts 后原子恢复 XX-XXXX。
- 如果 XX-XXX 已完成 import 而后续 health 判定失败,应先核对两端 hashes 与 SQLite 状态;必要时使用同一 backup artifact 明确回滚 XX-XXX,而不是只恢复 XX-XXXX。
- rollback 后必须重新检查 JSON hash、SQLite count、API health,并记录 rollback event。
11. Final Acceptance
Phase 5 已形成可审计、可验证、可恢复的自动生产扫描闭环。第一次 Production Run 的 exhausted tasks 没有被忽略或绕过,而是经过独立 Retry、组合验收和 immutable completion publication 安全补齐。最终 XX-XXXX、XX-XXX SQLite 和公开 API 均已验证通过。
PHASE_5_PRODUCTION_STATUS: PASS