Skip to content

TUI store memory leak: session deletion and message removal leave orphaned data #12351

Closed

Description

@Limme-swe

When a session is deleted in the TUI, only the session entry itself is removed from the store. The associated data in message, part, session_diff, todo, permission, question, and session_status maps are never cleaned up, causing a memory leak that grows with each deleted session.

Similarly, when a message is removed (message.removed event), the corresponding part entries for that message are never deleted.

The web app (packages/app/src/context/global-sync.tsx) already handles this correctly via cleanupSessionCaches() (lines 676-706), but the TUI sync store was never updated to match.

Steps to reproduce:

  1. Open TUI, create several sessions with messages
  2. Delete sessions
  3. Observe that memory usage doesn't decrease — orphaned data remains in the store

Expected behavior:
Deleting a session should clean up all associated keyed data (message, part, session_diff, todo, permission, question, session_status) and remove from fullSyncedSessions. Removing a message should also delete its part entries.

Affected file: packages/opencode/src/cli/cmd/tui/context/sync.tsx

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    perfIndicates a performance issue or need for optimization
    on Feb 5, 2026
  2. github-actions commented on Feb 5, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  3. thdxr commented on Apr 2, 2026

    @thdxr
    Member

    Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.

  4. ego1s1 commented on Oct 9, 2026

    @ego1s1

    Hi — I just ran into this again on current dev and wanted to flag that the gap described here is still present, in case this was closed prematurely.

    In packages/tui/src/context/sync.tsx, the session.deleted handler (~line 273) still only splices the session entry — message, part, todo, session_diff, session_status, permission and question entries for that session are left behind. Same for message.removed (~line 361), which drops the message but never its part[messageID] entries. The web app's cleanupSessionCaches() was never ported over.

    I filed the wider resize-perf side of this as #54112 (with measurements), but the eviction half belongs here. Would you consider reopening? Happy to PR the fix if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

opentuiThis relates to changes in v1.0, now that opencode uses opentuiperfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions