← Back to Pull requests

feat(checkpoint): production PostgreSQL LangGraph checkpointer lifecycle #26

Closed
unknown closed this pull request without merging on Oct 02, 2026 06:12 UTC
View on GitHub
unknown unknown commented on Oct 01, 2026 20:48 UTC
Author

Closes #25

目标


把 LangGraph Checkpoint 从进程内 MemorySaver 升级为生产可持久化 PostgreSQL Checkpointer(官方 langgraph-checkpoint-postgres),不改动 graph 拓扑与业务逻辑。

为什么


MemorySaver 只存在当前进程:多 worker / 多副本不共享、重启即丢,与水平扩展声明不符。

改动


  • core/checkpointer.py:CheckpointRuntime + build_memory_checkpointer / build_postgres_checkpointer(AsyncPostgresSaver + psycopg 异步池,官方 setup() 建表)+ probe/close。

  • core/config.py:LANGGRAPH_CHECKPOINT_BACKEND(memory|postgres,留空按环境自动)、LANGGRAPH_CHECKPOINT_DATABASE_URL(安全复用 DATABASE_URL,只接受 postgres 协议、剥离 SQLAlchemy +driver)、pool/setup 参数;生产 fail-closed 校验。

  • core/container.py:显式 _init_checkpointer() / _close_checkpointer(),build_graph 前 ready;生产缺失/失败 fail closed,开发降级显式 degraded。

  • core/graph_builder.py:仍 compile(checkpointer=...);make_graph 走容器生命周期。

  • api/routes/monitoring.py:/api/health 返回脱敏 langgraph_checkpoint {backend,status};postgres 不健康 -> overall unhealthy。

  • api/routes/sessions.py:/checkpoint 兼容异步 saver(aget_tuple)+ 会话归属校验。

  • requirements.txt:langgraph-checkpoint-postgres + psycopg[binary] + psycopg-pool。

  • 测试 + 文档(current-state / architecture / checklist / .env.example / README)。
  • 测试


  • tests/unit/test_checkpointer.py:配置解析、DSN 安全转换、生产拒绝 memory、memory round-trip、thread 隔离/重建恢复、close、postgres 不可用生产 fail-fast。

  • tests/integration/test_checkpoint_postgres.py(gated TEST_POSTGRES_CHECKPOINT_URL):真实 PG,invoke -> 落库 -> 销毁 saver/pool -> 重建 -> 同 thread 恢复。

  • tests/unit/test_api_routes.py / test_modules.py / graph_builder / app_factory 通过。
  • 证据边界


    本地单测 + 受控真实 PostgreSQL 集成测试 = LOCALLY VERIFIED;真实多副本生产恢复 NOT_VERIFIED,不宣称生产级。

    Diff: 205 lines (+153 / -52) across 2 files Reviewer: Xander-Xai Review duration: 564m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 205 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.319
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #26"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.3% (MEDIUM) · Higher = larger blast radius
    36.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.3% · Safe to merge
    14.3%