Skip to content

[P1] Session Termination Fix Incomplete (NULL Handling, Wrong Column Name) #136

@JoshuaAFerguson

Description

@JoshuaAFerguson

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_idagent_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

  • Session termination sends command to agent
  • Agent receives and processes termination
  • Session marked as terminated in DB
  • Resources cleaned up properly
  • Works with NULL agent_id (orphaned sessions)

Effort: 2-3 hours
Source: .claude/reports/BUG_REPORT_P1_TERMINATION_FIX_INCOMPLETE.md

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions