FLAG-1 unified task_attempts schema (single canonical DDL + 3-shape migration)

User decision 2026-11-05: unified schema, rejecting the rehearsal
runtime column-union workaround and a ledger rename. One definition
(cloud.attempt_ledger.TASK_ATTEMPTS_DDL, 12 columns) shared by
cloud.attempts and cloud.db.POSTGRES_SCHEMA; ensure builds the
unified table fresh and migrates old resume, gap-3 ledger, and
rehearsal shapes in place with rows intact. aggregate counts
ledger rows only (outcome NULL = resume row, never counted).
SQLite verified by 8 new tests; Postgres real-DB upgrade path
explicitly NOT verified (see batch summary). Local commit only:
no merge, no push, no deploy.
This commit is contained in:
host committed 2026-11-05 02:22:47 +00:00
1 parent 6d009af48f
commit 6a70775ad9
6 files changed
+467 -113

No files matched your search

+11 -12
View File
@@ -65,6 +65,12 @@ import time
from abc import ABC, abstractmethod
from contextlib import contextmanager
# 统一 schema:task_attempts 的 PG 新库定义与台账定义是同一
# 字符串(cloud.attempt_ledger.TASK_ATTEMPTS_DDL),不在此另
# 写一份。attempt_ledger 只依赖标准库 time,与本模块无循环
# 导入;层规则上它也不属于 orchestration 模块集合。
from cloud.attempt_ledger import TASK_ATTEMPTS_DDL as _TASK_ATTEMPTS_DDL
# 与 server.py 旧 _connect 的 timeout=30s 保持一致的连接级等待;
# PRAGMA busy_timeout 是语句级等待,两者不冲突,后者以毫秒为单位
# 在每个连接上单独设置(不随库文件持久化,见 connect 的注释)。
@@ -876,18 +882,11 @@ POSTGRES_SCHEMA = (
"created_at DOUBLE PRECISION)",
"CREATE INDEX IF NOT EXISTS idx_task_steps_task"
" ON task_steps(task_id, step_no)",
# 尝试账本(v6,见 cloud/attempts.py):(task_id, attempt_no)
# 唯一;PG 新库一次建齐,老库走 server/worker ensure。
"CREATE TABLE IF NOT EXISTS task_attempts("
"task_id TEXT, "
"attempt_no INTEGER, "
"kind TEXT, "
"interrupted_reason TEXT, "
"checkpoint_round INTEGER, "
"result_text TEXT, "
"error_text TEXT, "
"created_at DOUBLE PRECISION, "
"PRIMARY KEY(task_id, attempt_no))",
# 尝试账本(统一 schema,见 cloud/attempt_ledger.py):
# (task_id, attempt_no) 唯一;PG 新库一次建齐,老库走
# server/worker ensure 迁移到同一列集。此处是导入的统
# 一定义本身,不是第二份 DDL。
_TASK_ATTEMPTS_DDL,
# 审计循环状态(audit loop):task_id 单行主键;PG 新库一次
# 建齐,老库走 server/worker ensure(见 cloud/audit_loop.py)。
"CREATE TABLE IF NOT EXISTS task_audit_loop_state("