mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-02-02 15:23:37 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -429,5 +429,8 @@ def get_db() -> Session:
|
|||||||
db = _session_maker()
|
db = _session_maker()
|
||||||
try:
|
try:
|
||||||
yield db
|
yield db
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ def get_db_session(project_dir: Path):
|
|||||||
session = SessionLocal()
|
session = SessionLocal()
|
||||||
try:
|
try:
|
||||||
yield session
|
yield session
|
||||||
|
except Exception:
|
||||||
|
session.rollback()
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ def _get_db_session(project_name: str) -> Generator[Tuple[Session, Path], None,
|
|||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
yield db, project_path
|
yield db, project_path
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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
|
## What You CAN Do
|
||||||
|
|
||||||
**Codebase Analysis (Read-Only):**
|
**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
|
## Creating Features
|
||||||
|
|
||||||
When a user asks to add a feature, gather the following information:
|
When a user asks to add a feature, use the `feature_create` or `feature_create_bulk` MCP tools directly:
|
||||||
1. **Category**: A grouping like "Authentication", "API", "UI", "Database"
|
|
||||||
2. **Name**: A concise, descriptive name
|
For a **single feature**, call `feature_create` with:
|
||||||
3. **Description**: What the feature should do
|
- category: A grouping like "Authentication", "API", "UI", "Database"
|
||||||
4. **Steps**: How to verify/implement the feature (as a list)
|
- 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.
|
You can ask clarifying questions if the user's request is vague, or make reasonable assumptions for simple requests.
|
||||||
|
|
||||||
**Example interaction:**
|
**Example interaction:**
|
||||||
User: "Add a feature for S3 sync"
|
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]
|
[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.
|
You: Done! I've added "S3 Sync Integration" to your backlog. It's now visible on the kanban board.
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ class ExpandChatSession:
|
|||||||
"allow": [
|
"allow": [
|
||||||
"Read(./**)",
|
"Read(./**)",
|
||||||
"Glob(./**)",
|
"Glob(./**)",
|
||||||
|
*EXPAND_FEATURE_TOOLS,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user