1
0
mirror of https://github.com/coleam00/Archon.git synced 2026-01-11 17:16:57 -05:00

Fix critical token consumption issue in list endpoints (#488)

- Add include_content parameter to ProjectService.list_projects()
- Add exclude_large_fields parameter to TaskService.list_tasks()
- Add include_content parameter to DocumentService.list_documents()
- Update all MCP tools to use lightweight responses by default
- Fix critical N+1 query problem in ProjectService (was making separate query per project)
- Add response size monitoring and logging for validation
- Add comprehensive unit and integration tests

Results:
- Projects endpoint: 99.3% token reduction (27,055 -> 194 tokens)
- Tasks endpoint: 98.2% token reduction (12,750 -> 226 tokens)
- Documents endpoint: Returns metadata with content_size instead of full content
- Maintains full backward compatibility with default parameters
- Single query optimization eliminates N+1 performance issue
This commit is contained in:
Rasmus Widing
2025-08-26 23:55:58 +03:00
parent 6a1b0309d1
commit f9d245b3c2
8 changed files with 752 additions and 58 deletions

View File

@@ -186,17 +186,36 @@ class TaskService:
return False, {"error": f"Error creating task: {str(e)}"}
def list_tasks(
self, project_id: str = None, status: str = None, include_closed: bool = False
self,
project_id: str = None,
status: str = None,
include_closed: bool = False,
exclude_large_fields: bool = False
) -> tuple[bool, dict[str, Any]]:
"""
List tasks with various filters.
Args:
project_id: Filter by project
status: Filter by status
include_closed: Include done tasks
exclude_large_fields: If True, excludes sources and code_examples fields
Returns:
Tuple of (success, result_dict)
"""
try:
# Start with base query
query = self.supabase_client.table("archon_tasks").select("*")
if exclude_large_fields:
# Select all fields except large JSONB ones
query = self.supabase_client.table("archon_tasks").select(
"id, project_id, parent_task_id, title, description, "
"status, assignee, task_order, feature, archived, "
"archived_at, archived_by, created_at, updated_at, "
"sources, code_examples" # Still fetch for counting, but will process differently
)
else:
query = self.supabase_client.table("archon_tasks").select("*")
# Track filters for debugging
filters_applied = []
@@ -265,7 +284,7 @@ class TaskService:
tasks = []
for task in response.data:
tasks.append({
task_data = {
"id": task["id"],
"project_id": task["project_id"],
"title": task["title"],
@@ -276,7 +295,20 @@ class TaskService:
"feature": task.get("feature"),
"created_at": task["created_at"],
"updated_at": task["updated_at"],
})
}
if not exclude_large_fields:
# Include full JSONB fields
task_data["sources"] = task.get("sources", [])
task_data["code_examples"] = task.get("code_examples", [])
else:
# Add counts instead of full content
task_data["stats"] = {
"sources_count": len(task.get("sources", [])),
"code_examples_count": len(task.get("code_examples", []))
}
tasks.append(task_data)
filter_info = []
if project_id: