Skip to content

Episodes: track background tasks to prevent GC and enable graceful shutdown #199

@abbudjoe

Description

@abbudjoe

From PR #196 review (Issue #2).

asyncio.create_task() in remember() fires off episode detection/summarization but doesn't hold a reference. The task could be garbage collected before completion.

Recommended fix:

if not hasattr(self, '_episode_tasks'):
    self._episode_tasks = set()

task = asyncio.create_task(
    self._process_episode_async(entry.id, content, embedding)
)
self._episode_tasks.add(task)
task.add_done_callback(self._episode_tasks.discard)

This also enables graceful shutdown by awaiting pending tasks.

Part of Episode Memories (#190).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions