Skip to content

fix(agents-api): remove agent participants from session_lookup on agent delete#1597

Open
haroldfabla2-hue wants to merge 1 commit intojulep-ai:devfrom
haroldfabla2-hue:fix/delete-agent-session-lookup
Open

fix(agents-api): remove agent participants from session_lookup on agent delete#1597
haroldfabla2-hue wants to merge 1 commit intojulep-ai:devfrom
haroldfabla2-hue:fix/delete-agent-session-lookup

Conversation

@haroldfabla2-hue
Copy link
Copy Markdown

@haroldfabla2-hue haroldfabla2-hue commented Mar 23, 2026

Summary

When deleting an agent, session_lookup rows with that agent as participant were not removed.
This leaves orphan session-participant mappings and causes inconsistent session state.

Changes

  • Add deleted_session_lookup CTE in delete_agent query
  • Delete rows where:
    • participant_type = 'agent'
    • participant_id = agent_id
    • developer_id = developer_id
  • Keep existing delete flow intact (tools/files/docs/agent)

Why

Issue #1550 reports orphan sessions after delete_agent.
This fix ensures participant references are cleaned up atomically in the same query.

Fixes #1550

Fixes orphan sessions when delete_agent is called.

When an agent is deleted, its session_lookup entries were not being removed,
causing orphan sessions that reference a deleted agent. This adds a CTE to
delete session_lookup entries where participant_type='agent' and
participant_id=agent_id before deleting the agent itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agent delete doesn't delete associated sessions

1 participant