Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 17 additions & 25 deletions services/orchestrator/a2a_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,20 +442,18 @@ async def discover_agents(
"WHERE " + " AND ".join(where_conditions) if where_conditions else ""
)

results = await conn.fetch(
f"""
SELECT card_data FROM a2a_agent_cards
_query = f"""
SELECT card_data FROM a2a_agent_cards
{where_clause}
ORDER BY
CASE availability_status
WHEN 'available' THEN 1
WHEN 'busy' THEN 2
ELSE 3
ORDER BY
CASE availability_status
WHEN 'available' THEN 1
WHEN 'busy' THEN 2
ELSE 3
END,
current_task_count ASC
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
results = await conn.fetch(_query, *params)

return [AgentCard(**result["card_data"]) for result in results]

Expand Down Expand Up @@ -740,16 +738,13 @@ async def get_agent_tasks(

where_clause = " AND ".join(where_conditions)

results = await conn.fetch(
f"""
SELECT task_data FROM a2a_tasks
_query = f"""
SELECT task_data FROM a2a_tasks
WHERE {where_clause}
ORDER BY created_at DESC
LIMIT ${param_count}
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
limit,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
results = await conn.fetch(_query, *params, limit)

return [A2ATask(**result["task_data"]) for result in results]

Expand All @@ -770,15 +765,12 @@ async def get_agent_messages(

where_clause = " AND ".join(where_conditions)

results = await conn.fetch(
f"""
SELECT message_data FROM a2a_messages
_query = f"""
SELECT message_data FROM a2a_messages
WHERE {where_clause}
ORDER BY created_at DESC
LIMIT ${param_count}
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
limit,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
results = await conn.fetch(_query, *params, limit)

return [A2AMessage(**result["message_data"]) for result in results]
6 changes: 3 additions & 3 deletions services/orchestrator/claude_code_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import json
import os
import subprocess
import subprocess # nosec B404 -- subprocess used only for running known test runners
import tempfile
import time
from pathlib import Path
Expand Down Expand Up @@ -440,7 +440,7 @@ def _run_tests(self, tmpdir: str, language: str) -> Optional[Dict[str, Any]]:
try:
if language == "python":
# Try to run pytest
result = subprocess.run(
result = subprocess.run( # nosec B603 B607 -- fixed command list, no shell, no user input
["python", "-m", "pytest", tmpdir, "-v"],
capture_output=True,
text=True,
Expand All @@ -458,7 +458,7 @@ def _run_tests(self, tmpdir: str, language: str) -> Optional[Dict[str, Any]]:
# Try to run with node
test_files = [f for f in os.listdir(tmpdir) if f.startswith("test_")]
if test_files:
result = subprocess.run(
result = subprocess.run( # nosec B603 B607 -- fixed command list, no shell, no user input
["node", test_files[0]],
capture_output=True,
text=True,
Expand Down
2 changes: 1 addition & 1 deletion services/orchestrator/claude_sdk_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging
import os
import re
import subprocess
import subprocess # nosec B404 -- subprocess used only for running Claude SDK processes
import time
from dataclasses import dataclass
from datetime import datetime
Expand Down
6 changes: 3 additions & 3 deletions services/orchestrator/container_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,15 @@ async def _get_container_status(self, container) -> ContainerStatus:
started = datetime.fromisoformat(
state["StartedAt"].replace("Z", "+00:00")
)
except:
except: # nosec B110 -- intentional bare except for datetime parsing of Docker timestamps
pass

if state.get("FinishedAt"):
try:
finished = datetime.fromisoformat(
state["FinishedAt"].replace("Z", "+00:00")
)
except:
except: # nosec B110 -- intentional bare except for datetime parsing of Docker timestamps
pass

# Get resource usage (if available)
Expand Down Expand Up @@ -586,7 +586,7 @@ async def _get_container_status(self, container) -> ContainerStatus:
if host_bindings:
for binding in host_bindings:
ports[container_port] = (
f"{binding.get('HostIp', '0.0.0.0')}:{binding.get('HostPort')}"
f"{binding.get('HostIp', '0.0.0.0')}:{binding.get('HostPort')}" # nosec B104 -- container port mapping from Docker API, not user input
)

# Get health status
Expand Down
24 changes: 9 additions & 15 deletions services/orchestrator/conversation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,13 @@ async def get_conversation_history(
params.append(limit)

async with get_db_connection() as conn:
rows = await conn.fetch(
f"""
_query = f"""
SELECT * FROM claude_conversations
WHERE {where_clause}
ORDER BY created_at ASC
{limit_clause}
""", # nosec B608 -- where/limit clauses are fixed fragments with $N placeholders; all values bound as query params
*params,
)
""" # nosec B608 -- where/limit clauses are fixed fragments with $N placeholders; all values bound as query params
rows = await conn.fetch(_query, *params)

return [dict(row) for row in rows]

Expand Down Expand Up @@ -469,14 +467,12 @@ async def get_code_generations(
where_clause = " AND ".join(conditions)

async with get_db_connection() as conn:
rows = await conn.fetch(
f"""
_query = f"""
SELECT * FROM code_generations
WHERE {where_clause}
ORDER BY generated_at ASC
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
rows = await conn.fetch(_query, *params)

return [dict(row) for row in rows]

Expand Down Expand Up @@ -518,14 +514,12 @@ async def get_agent_performance_metrics(
where_clause = "WHERE " + " AND ".join(conditions) if conditions else ""

async with get_db_connection() as conn:
rows = await conn.fetch(
f"""
_query = f"""
SELECT * FROM agent_performance_metrics
{where_clause}
ORDER BY measured_at DESC
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values (incl. interval multiplier) bound as query params
*params,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values (incl. interval multiplier) bound as query params
rows = await conn.fetch(_query, *params)

return [dict(row) for row in rows]

Expand Down
2 changes: 1 addition & 1 deletion services/orchestrator/git_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import json
import logging
import os
import subprocess
import subprocess # nosec B404 -- subprocess used only for git commands with fixed args
import tempfile
from dataclasses import dataclass
from datetime import datetime
Expand Down
11 changes: 3 additions & 8 deletions services/orchestrator/goal_conversation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,7 @@ async def get_goal_conversations(

where_clause = " AND ".join(where_conditions)

conversations = await conn.fetch(
"""
_query = f"""
SELECT id, conversation_type, conversation_title, conversation_summary,
status, last_activity_at, created_at,
COALESCE(array_length(string_to_array(messages::text, '}}'), 1), 0) as message_count,
Expand All @@ -633,12 +632,8 @@ async def get_goal_conversations(
WHERE {where_clause}
ORDER BY last_activity_at DESC, created_at DESC
LIMIT ${param_idx}
""".format( # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
where_clause=where_clause, param_idx=param_idx
),
*params,
limit,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
conversations = await conn.fetch(_query, *params, limit)

return [dict(conv) for conv in conversations]

Expand Down
19 changes: 7 additions & 12 deletions services/orchestrator/goals_management_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,13 @@ async def list_organization_goals(

where_clause = " AND ".join(where_conditions)

rows = await conn.fetch(
f"""
SELECT * FROM organization_goals
_query = f"""
SELECT * FROM organization_goals
WHERE {where_clause}
ORDER BY priority_level DESC, created_at DESC
LIMIT ${param_idx}
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
limit,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
rows = await conn.fetch(_query, *params, limit)

return [self._row_to_goal(row) for row in rows]

Expand Down Expand Up @@ -423,14 +420,12 @@ async def update_goal_progress(

if update_fields:
update_fields.append("updated_at = NOW()")
await conn.execute(
f"""
_query = f"""
UPDATE organization_goals
SET {', '.join(update_fields)}
WHERE id = $1
""", # nosec B608 -- SET built only from fixed column fragments; all values bound as $N params
*params,
)
""" # nosec B608 -- SET built only from fixed column fragments; all values bound as $N params
await conn.execute(_query, *params)

# Record progress tracking entry
await conn.execute(
Expand Down
21 changes: 8 additions & 13 deletions services/orchestrator/knowledge_analytics_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ async def analyze_knowledge_effectiveness(

where_clause = " AND ".join(where_conditions)

knowledge_items = await conn.fetch(
f"""
SELECT
_query = f"""
SELECT
kb.id,
kb.title,
kb.knowledge_category,
Expand All @@ -243,25 +242,22 @@ async def analyze_knowledge_effectiveness(
kb.quality_score,
kb.created_at,
kb.updated_at,
-- Calculate agent adoption rate
COALESCE(agent_usage.adoption_rate, 0.0) as agent_adoption_rate,
-- Calculate team adoption rate
COALESCE(team_usage.adoption_rate, 0.0) as team_adoption_rate,
-- Calculate average relevance from recent usage
COALESCE(recent_relevance.avg_relevance, 0.0) as average_relevance
FROM organization_knowledge_base kb
LEFT JOIN (
SELECT
SELECT
knowledge_id,
COUNT(DISTINCT agent_id)::float / NULLIF(total_agents.count, 0) as adoption_rate
FROM agent_memory am
JOIN (SELECT COUNT(*) as count FROM agents WHERE team_id IN
JOIN (SELECT COUNT(*) as count FROM agents WHERE team_id IN
(SELECT id FROM teams WHERE organization_id = $1)) total_agents ON true
WHERE knowledge_id IS NOT NULL
GROUP BY knowledge_id
) agent_usage ON kb.id::text = agent_usage.knowledge_id
LEFT JOIN (
SELECT
SELECT
source_knowledge_id,
COUNT(DISTINCT team_id)::float / NULLIF(total_teams.count, 0) as adoption_rate
FROM team_knowledge_base tkb
Expand All @@ -270,7 +266,7 @@ async def analyze_knowledge_effectiveness(
GROUP BY source_knowledge_id
) team_usage ON kb.id::text = team_usage.source_knowledge_id
LEFT JOIN (
SELECT
SELECT
knowledge_id,
AVG(relevance_score) as avg_relevance
FROM agent_memory am
Expand All @@ -280,9 +276,8 @@ async def analyze_knowledge_effectiveness(
) recent_relevance ON kb.id::text = recent_relevance.knowledge_id
WHERE {where_clause}
ORDER BY kb.usage_count DESC, kb.success_correlation DESC
""", # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
*params,
)
""" # nosec B608 -- where clause is fixed fragments with $N placeholders; all values bound as query params
knowledge_items = await conn.fetch(_query, *params)

effectiveness_metrics = []

Expand Down
Loading