Files
life-echo/api/alembic/versions/0017_segment_narrative_defer.py
Kevin 59d4b19d7d feat(api): 回忆录管线简化、路由延迟池与相关加固
- Phase1/2:移除 MemoirOrchestrator.run 与 process_memoir_segments 别名;文档改为 process_memoir_phase1。
- 槽位校验集中到 stage_constants(filter_stage_slots),批处理与顺序路径及 state_service 写库一致。
- StoryRoute:no_llm/parse_error/invalid_target 保守 new_story;短篇护栏不覆盖这些 fallback。
- Phase2 低置信单路径可选延迟(StoryPipelineResult.deferred):不写 Chapter/Story,Segment 记录 defer 元数据,冷却内不重复消费;上限后停自动重试,Phase1 同类目新段唤醒池内段。
- Alembic 0017:segments 表 narrative_defer_* 列。
- ProfileAgent:经 LlmGateway/注入 Provider 统一聊天与 JSON,新增测试。
- ImagePromptOrchestrator:LLM 初始化失败可依配置降级或硬失败;补充策略测试。
- 配套单测与 README/本地开发文档表述更新。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-06 13:18:02 +08:00

76 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""segmentsPhase2 低置信路由延迟元数据
Revision ID: 0017_segment_narrative_defer
Revises: 0016_memory_pipeline_status
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0017_segment_narrative_defer"
down_revision: Union[str, None] = "0016_memory_pipeline_status"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def _column_names(table_name: str) -> set[str]:
bind = op.get_bind()
inspector = sa.inspect(bind)
return {column["name"] for column in inspector.get_columns(table_name)}
def upgrade() -> None:
columns = _column_names("segments")
if "narrative_deferred_until" not in columns:
op.add_column(
"segments",
sa.Column(
"narrative_deferred_until",
sa.DateTime(timezone=True),
nullable=True,
),
)
if "narrative_defer_count" not in columns:
op.add_column(
"segments",
sa.Column(
"narrative_defer_count",
sa.Integer(),
nullable=False,
server_default=sa.text("0"),
),
)
if "narrative_defer_reason" not in columns:
op.add_column(
"segments",
sa.Column(
"narrative_defer_reason",
sa.String(),
nullable=True,
),
)
if "narrative_last_attempt_at" not in columns:
op.add_column(
"segments",
sa.Column(
"narrative_last_attempt_at",
sa.DateTime(timezone=True),
nullable=True,
),
)
def downgrade() -> None:
columns = _column_names("segments")
for column in (
"narrative_last_attempt_at",
"narrative_defer_reason",
"narrative_defer_count",
"narrative_deferred_until",
):
if column in columns:
op.drop_column("segments", column)