Severity: P1 - HIGH
Component: API - DeleteSession Handler
Report: BUG_REPORT_P1_TERMINATION_FIX_INCOMPLETE.md
Issue
Session termination handler has multiple issues preventing proper cleanup.
Problems
1. NULL Handling
Query doesn't handle NULL agent_id values:
var agentID string // Cannot scan NULL
err := db.QueryRow("SELECT agent_id FROM sessions WHERE id = $1", id).Scan(&agentID)
2. Wrong Column Name
Code uses controller_id instead of agent_id:
SELECT controller_id FROM sessions // Wrong, should be agent_id
3. Missing agent_id Population
Sessions created without agent_id being set, always NULL in database.
Impact
- Session termination fails
- Orphaned sessions in database
- Agent never receives termination command
- Resources not cleaned up
Fix Required
Fix 1: NULL Handling
var agentID sql.NullString
err := db.QueryRow("SELECT agent_id FROM sessions WHERE id = $1", id).Scan(&agentID)
if err != nil {
return err
}
if agentID.Valid {
// Send termination command to agent
hub.SendCommand(agentID.String, terminateCmd)
}
Fix 2: Column Name
// Change all references:
controller_id → agent_id
Fix 3: Populate agent_id on Creation
In CreateSession handler:
_, err := db.Exec(`
INSERT INTO sessions (id, user_id, template_id, agent_id, state, ...)
VALUES ($1, $2, $3, $4, 'pending', ...)
`, sessionID, userID, templateID, selectedAgentID, ...)
Files to Fix
api/internal/handlers/sessions.go (DeleteSession)
api/internal/handlers/sessions.go (CreateSession)
- Any other references to
controller_id
Testing
Effort: 2-3 hours
Source: .claude/reports/BUG_REPORT_P1_TERMINATION_FIX_INCOMPLETE.md
Severity: P1 - HIGH
Component: API - DeleteSession Handler
Report:
BUG_REPORT_P1_TERMINATION_FIX_INCOMPLETE.mdIssue
Session termination handler has multiple issues preventing proper cleanup.
Problems
1. NULL Handling
Query doesn't handle NULL
agent_idvalues:2. Wrong Column Name
Code uses
controller_idinstead ofagent_id:3. Missing agent_id Population
Sessions created without
agent_idbeing set, always NULL in database.Impact
Fix Required
Fix 1: NULL Handling
Fix 2: Column Name
Fix 3: Populate agent_id on Creation
In CreateSession handler:
Files to Fix
api/internal/handlers/sessions.go(DeleteSession)api/internal/handlers/sessions.go(CreateSession)controller_idTesting
Effort: 2-3 hours
Source:
.claude/reports/BUG_REPORT_P1_TERMINATION_FIX_INCOMPLETE.md