Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions cp-agent/cp_agent/api/v1/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,21 +431,10 @@ async def execute_migration(
error_detail = raw_result.get("error", "Unknown error")
logger.error(f"Migration failed for project {project_id}: {error_detail}")
# Add error to agent memory
try:
agent = await get_agent(project_id)
formatted_error = (
f"[Migration Failure via API]\n"
f"Migration Name: {raw_result.get('name', migration.name or 'unnamed')}\n"
f"Error: {error_detail}"
)
await agent.message_manager.add_memory_item(formatted_error)
logger.info(
f"Added API migration failure details for project {project_id} to memory."
)
except Exception as mem_e:
logger.error(
f"Failed to add API migration failure to agent memory: {mem_e}"
)
migration_name = raw_result.get("name", migration.name or "unnamed")
await _add_migration_error_to_memory(
project_id, migration_name, error_detail
)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Migration failed: {error_detail}",
Expand Down Expand Up @@ -479,21 +468,9 @@ async def execute_migration(
f"Error executing migration for project {project_id}: {error_detail}"
)
# Add error to agent memory
try:
agent = await get_agent(project_id)
formatted_error = (
f"[Migration Failure via API]\n"
f"Migration Name: {migration.name or 'unnamed'}\n"
f"Error: {error_detail}"
)
await agent.message_manager.add_memory_item(formatted_error)
logger.info(
f"Added API migration failure details for project {project_id} to memory."
)
except Exception as mem_e:
logger.error(
f"Failed to add API migration failure to agent memory: {mem_e}"
)
await _add_migration_error_to_memory(
project_id, migration.name or "unnamed", error_detail
Copy link

Copilot AI Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider unifying the approach for retrieving the migration name: one location retrieves it using raw_result.get('name', migration.name or 'unnamed') while the other uses migration.name directly. This inconsistency could lead to differences in error details.

Suggested change
project_id, migration.name or "unnamed", error_detail
project_id, migration.name or 'unnamed', error_detail

Copilot uses AI. Check for mistakes.
)
# Raise the original HTTP exception
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=error_detail
Expand Down Expand Up @@ -667,3 +644,28 @@ async def _update_project_title(project_root: str, title: str, project_id: str)
logger.warning(
f"Failed to update index.html title for project {project_id}: {str(e)}"
)


async def _add_migration_error_to_memory(
project_id: str, migration_name: str, error_detail: str
) -> None:
"""Add migration error details to the agent's memory.

Args:
project_id: The ID of the project
migration_name: Name of the migration that failed
error_detail: Error message or details
"""
try:
agent = await get_agent(project_id)
formatted_error = (
f"[Migration Failure via API]\n"
f"Migration Name: {migration_name}\n"
f"Error: {error_detail}"
)
await agent.message_manager.add_memory_item(formatted_error)
logger.info(
f"Added API migration failure details for project {project_id} to memory."
)
except Exception as mem_e:
logger.error(f"Failed to add API migration failure to agent memory: {mem_e}")
Loading