Repository navigation
Phase 2: Core workflow nodes #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d05ef8f
37274db
df11c38
7e24da3
cfc2f6a
43d9c31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
| PostgresSaver checkpointer setup for production workflow persistence | ||
| """ | ||
|
|
||
| from contextlib import AbstractContextManager | ||
| from typing import Optional | ||
|
|
||
| from langgraph.checkpoint.postgres import PostgresSaver | ||
|
|
||
| from src.config import settings | ||
| from src.utils.logging import logger | ||
|
|
||
| _checkpointer_ctx: Optional[AbstractContextManager[PostgresSaver]] = None | ||
| _checkpointer: Optional[PostgresSaver] = None | ||
|
|
||
|
|
||
| def setup_checkpointer() -> PostgresSaver: | ||
| """Create and initialize PostgresSaver with connection string from settings.""" | ||
| global _checkpointer_ctx, _checkpointer | ||
|
|
||
| _checkpointer_ctx = PostgresSaver.from_conn_string(settings.database_url) | ||
| _checkpointer = _checkpointer_ctx.__enter__() | ||
| _checkpointer.setup() | ||
| logger.info("checkpointer_ready", backend="postgres") | ||
| return _checkpointer | ||
|
Comment on lines
+17
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🌐 Web query:
💡 Result: For production environments, using a ConnectionPool is the recommended practice for PostgresSaver, as it provides robust resource management, handles concurrent requests, and prevents connection timeouts often encountered with long-running workflows [1][2][3]. The two methods differ primarily in their scope and production suitability: 1. PostgresSaver.from_conn_string(conn_string) This helper method is convenient for local development, testing, or quick prototyping [4][5]. Internally, it creates and manages its own connection, but it is generally not recommended for high-concurrency production deployments because it does not provide the sophisticated pooling needed to efficiently handle multiple persistent connections [2][6]. 2. PostgresSaver(pool) with ConnectionPool This is the standard approach for production. By passing a psycopg_pool.ConnectionPool instance to the PostgresSaver, you gain control over critical connection parameters such as minimum and maximum pool size, connection lifetime, and idle timeouts [7][1][8]. When implementing ConnectionPool in production: - Ensure autocommit=True and row_factory=dict_row are configured in the pool's kwargs to satisfy PostgresSaver requirements [7][9][10]. - The.setup method must be called once (often via CI/CD or a migration script, not during every application startup) to initialize the necessary database tables [3]. - Avoid using pipeline mode with a ConnectionPool, as it is designed for use only with a single dedicated connection [11][1]. Example Production Configuration: from psycopg.rows import dict_row from psycopg_pool import ConnectionPool from langgraph.checkpoint.postgres import PostgresSaver pool = ConnectionPool( conn_string, min_size=2, max_size=10, max_idle=300.0, max_lifetime=3600.0, kwargs={ "autocommit": True, "row_factory": dict_row, "prepare_threshold": 0 }) checkpointer = PostgresSaver(pool) # checkpointer.setup # Run once as a migration, not in app runtime[3] graph = builder.compile(checkpointer=checkpointer) Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Files:"
git ls-files | rg '(^|/)(checkpointer\.py|main\.py|pyproject\.toml|requirements|poetry\.lock|uv\.lock)$' || true
echo
echo "checkpointer.py:"
cat -n src/graph/checkpointer.py
echo
echo "main.py relevant checkpointer usages:"
rg -n "_checkpointer|checkpointer|triage|lifespan|PostgresSaver|setup_checkpointer|close_checkpointer" src/main.py || true
echo
echo "Relevant graph/build lines in main.py:"
sed -n '1,240p' src/main.py | cat -n
echo
echo "Dependency declarations mentioning langgraph/psycopg:"
rg -n 'langgraph|postgres|psycopg|psycopg_pool' pyproject.toml poetry.lock uv.lock requirements*.txt setup.py setup.cfg 2>/dev/null || trueRepository: IWill29/bug-triage-langgraph Length of output: 8242 Use a pool-backed
♻️ Sketch: pool-backed checkpointer-from contextlib import AbstractContextManager
-from typing import Optional
-
+from psycopg_pool import ConnectionPool
+from psycopg.rows import dict_row
+from typing import Optional
+
from langgraph.checkpoint.postgres import PostgresSaver
from src.config import settings
from src.utils.logging import logger
_checkpointer_ctx: Optional[AbstractContextManager[PostgresSaver]] = None
_checkpointer: Optional[PostgresSaver] = None
def setup_checkpointer() -> PostgresSaver:
"""Create and initialize PostgresSaver with connection string from settings."""
global _checkpointer_ctx, _checkpointer
+ _pool = ConnectionPool(
+ conninfo=settings.database_url,
+ min_size=2,
+ max_size=16,
+ kwargs={"autocommit": True, "row_factory": dict_row, "prepare_threshold": 0},
+ )
+ _checkpointer = PostgresSaver(_pool)
+ _checkpointer.setup()
+ logger.info("checkpointer_ready", backend="postgres")
+ return _checkpointer
-def setup_checkpointer() -> PostgresSaver:
- """Create and initialize PostgresSaver with connection string from settings."""
- global _checkpointer_ctx, _checkpointer
-
- _checkpointer_ctx = PostgresSaver.from_conn_string(settings.database_url)
- _checkpointer = _checkpointer_ctx.__enter__()
- _checkpointer.setup()
- logger.info("checkpointer_ready", backend="postgres")
- return _checkpointer🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def close_checkpointer() -> None: | ||
| """Release PostgresSaver connection on shutdown.""" | ||
| global _checkpointer_ctx, _checkpointer | ||
|
|
||
| if _checkpointer_ctx is not None: | ||
| _checkpointer_ctx.__exit__(None, None, None) | ||
| _checkpointer_ctx = None | ||
| _checkpointer = None | ||
| logger.info("checkpointer_closed") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,35 @@ | ||
| """ | ||
| Graph nodes - Individual workflow step implementations | ||
| """ | ||
|
|
||
| from src.graph.nodes.preprocess import preprocess_node | ||
| from src.graph.nodes.risk_check import risk_check_node | ||
| from src.graph.nodes.triage import ( | ||
| fast_triage_node, | ||
| premium_retry_node, | ||
| route_confidence, | ||
| ) | ||
| from src.graph.nodes.validate import validate_node | ||
| from src.graph.nodes.duplicate import duplicate_check_node | ||
| from src.graph.nodes.gitea import ( | ||
| create_issue_node, | ||
| create_feature_node, | ||
| comment_duplicate_node, | ||
| human_review_node, | ||
| route_issue_creation, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "preprocess_node", | ||
| "risk_check_node", | ||
| "fast_triage_node", | ||
| "premium_retry_node", | ||
| "route_confidence", | ||
| "validate_node", | ||
| "duplicate_check_node", | ||
| "create_issue_node", | ||
| "create_feature_node", | ||
| "comment_duplicate_node", | ||
| "human_review_node", | ||
| "route_issue_creation", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Add an upgrade migration for existing databases.
CREATE TABLE IF NOT EXISTSleaves an existingvector(3072)column unchanged, so the newly configured 1536-dimensional embeddings will fail to persist after upgrade. The existing same-named IVFFlat index also will not be replaced by this HNSW definition. Add a versioned migration that re-embeds/backfills existing rows and replaces the index.🤖 Prompt for AI Agents