fix: call piSession.dispose() in AgentService.destroySession #62

Closed
opened 2026-03-13 01:35:58 +00:00 by jason.woltje · 0 comments
Owner

Problem

AgentService.destroySession() calls session.unsubscribe() and clears listeners, but never calls session.piSession.dispose(). The Pi SDK's dispose() method is the intended shutdown path — it removes all internal listeners and disconnects from the agent. Without it, the Pi AgentSession object and its underlying agent remain in memory with internal subscriptions alive, preventing GC and potentially leaving background work running.

Location

apps/gateway/src/agent/agent.service.tsdestroySession() method

Fix

Add session.piSession.dispose() after unsubscribe() in the destroy path. Wrap in try-catch consistent with existing error handling.

Found by

Gatekeeper review (communication spine PR #61)

## Problem `AgentService.destroySession()` calls `session.unsubscribe()` and clears listeners, but never calls `session.piSession.dispose()`. The Pi SDK's `dispose()` method is the intended shutdown path — it removes all internal listeners and disconnects from the agent. Without it, the Pi `AgentSession` object and its underlying agent remain in memory with internal subscriptions alive, preventing GC and potentially leaving background work running. ## Location `apps/gateway/src/agent/agent.service.ts` — `destroySession()` method ## Fix Add `session.piSession.dispose()` after `unsubscribe()` in the destroy path. Wrap in try-catch consistent with existing error handling. ## Found by Gatekeeper review (communication spine PR #61)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#62