Skip to content

refactor: unify session cleanup — move all cleanupSession() calls into hook event handlers #15

@dscv103

Description

@dscv103

Problem

Session cleanup is handled inconsistently across hooks. Most hooks (autoCompact, sessionRecovery, tokenAwareTruncation, contextWindowMonitor, fileOpsTracker, fetchTracker) handle their own cleanup inside their event handler. But others expose a separate cleanupSession() method that src/index.ts calls manually:

// src/index.ts — index.ts shouldn't own this constraintReviewerHook.cleanupSession(sessionId); fetchTrackerHook.cleanupSession(sessionId);

This creates a maintenance risk: any hook added in the future that holds per-session state must also be wired into this block in index.ts, and it's easy to miss.

Fix

Each hook that holds per-session state should clean itself up inside its own event handler, keyed on session.deleted. The index.ts event handler then only fans out to all hooks uniformly via await hook.event({ event }).

The constraintReviewerHook is the main outlier — its cleanupSession can be moved inside its event handler to match the established pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode improvement without behavior change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions