Skip to content

[Feature]: delete session state file when session is deleted #557

@tomasWade

Description

@tomasWade

DCP persists pruned state per session at ~/.local/share/opencode/storage/plugin/dcp/{sessionId}.json. When a session is deleted (via CLI or UI), the corresponding state file remains on disk indefinitely as an orphan. Over time these accumulate and waste space.

The opencode SDK already emits a session.deleted event with the session ID:

type EventSessionDeleted = {
    type: "session.deleted";
    properties: {
        info: Session;
    };
};

The existing event handler in lib/hooks.ts (createEventHandler) currently ignores all events except message.part.updated. Adding a session.deleted branch that unlinks the state file would fix this:

if (input.event.type === "session.deleted") {
    const sessionId = input.event.properties.info?.id
    if (sessionId) {
        const filePath = join(STORAGE_DIR, `${sessionId}.json`)
        await fs.unlink(filePath).catch(() => {})
    }
    return
}

Similarly, on plugin startup or when handling session.created, we could sweep orphaned state files for sessions that no longer exist in the DB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions