From 6609a0f7d6b6ab910f38cf27816b16f39890256b Mon Sep 17 00:00:00 2001 From: Auto Date: Sun, 1 Feb 2026 09:15:24 +0200 Subject: [PATCH] fix: prevent PendingRollbackError and add MCP tool support for sessions - Add explicit session.rollback() in exception handlers for database context managers in features.py, schedules.py, and database.py get_db() to prevent SQLAlchemy PendingRollbackError on failed transactions - Add EXPAND_FEATURE_TOOLS to expand session security settings allow list so the expand skill can use the MCP tools it references - Update assistant session prompt to direct the LLM to call MCP tools directly for feature creation instead of suggesting CLI commands Cherry-picked fixes from PR #92 (closed) with cleaner implementation. Co-Authored-By: Claude Opus 4.5 --- api/database.py | 3 +++ server/routers/features.py | 3 +++ server/routers/schedules.py | 3 +++ server/services/assistant_chat_session.py | 18 ++++++++++++------ server/services/expand_chat_session.py | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/database.py b/api/database.py index 90dc49a..6dd4676 100644 --- a/api/database.py +++ b/api/database.py @@ -429,5 +429,8 @@ def get_db() -> Session: db = _session_maker() try: yield db + except Exception: + db.rollback() + raise finally: db.close() diff --git a/server/routers/features.py b/server/routers/features.py index c4c9c27..a0e1664 100644 --- a/server/routers/features.py +++ b/server/routers/features.py @@ -71,6 +71,9 @@ def get_db_session(project_dir: Path): session = SessionLocal() try: yield session + except Exception: + session.rollback() + raise finally: session.close() diff --git a/server/routers/schedules.py b/server/routers/schedules.py index 2a11ba3..b97ecc8 100644 --- a/server/routers/schedules.py +++ b/server/routers/schedules.py @@ -84,6 +84,9 @@ def _get_db_session(project_name: str) -> Generator[Tuple[Session, Path], None, db = SessionLocal() try: yield db, project_path + except Exception: + db.rollback() + raise finally: db.close() diff --git a/server/services/assistant_chat_session.py b/server/services/assistant_chat_session.py index f15eee8..1fb26e1 100755 --- a/server/services/assistant_chat_session.py +++ b/server/services/assistant_chat_session.py @@ -90,6 +90,8 @@ def get_system_prompt(project_name: str, project_dir: Path) -> str: Your role is to help users understand the codebase, answer questions about features, and manage the project backlog. You can READ files and CREATE/MANAGE features, but you cannot modify source code. +You have MCP tools available for feature management. Use them directly by calling the tool -- do not suggest CLI commands, bash commands, or curl commands to the user. You can create features yourself using the feature_create and feature_create_bulk tools. + ## What You CAN Do **Codebase Analysis (Read-Only):** @@ -134,17 +136,21 @@ If the user asks you to modify code, explain that you're a project assistant and ## Creating Features -When a user asks to add a feature, gather the following information: -1. **Category**: A grouping like "Authentication", "API", "UI", "Database" -2. **Name**: A concise, descriptive name -3. **Description**: What the feature should do -4. **Steps**: How to verify/implement the feature (as a list) +When a user asks to add a feature, use the `feature_create` or `feature_create_bulk` MCP tools directly: + +For a **single feature**, call `feature_create` with: +- category: A grouping like "Authentication", "API", "UI", "Database" +- name: A concise, descriptive name +- description: What the feature should do +- steps: List of verification/implementation steps + +For **multiple features**, call `feature_create_bulk` with an array of feature objects. You can ask clarifying questions if the user's request is vague, or make reasonable assumptions for simple requests. **Example interaction:** User: "Add a feature for S3 sync" -You: I'll create that feature. Let me add it to the backlog... +You: I'll create that feature now. [calls feature_create with appropriate parameters] You: Done! I've added "S3 Sync Integration" to your backlog. It's now visible on the kanban board. diff --git a/server/services/expand_chat_session.py b/server/services/expand_chat_session.py index 58dd50d..6829372 100644 --- a/server/services/expand_chat_session.py +++ b/server/services/expand_chat_session.py @@ -162,6 +162,7 @@ class ExpandChatSession: "allow": [ "Read(./**)", "Glob(./**)", + *EXPAND_FEATURE_TOOLS, ], }, }