Skip to content

Add dispatch prune to clean stale session config entries #277

Description

@jongio

Problem

Dispatch keys a lot of per-session state in config.json: aliases, tags, notes, favorites, hidden sessions, and launch stats. Sessions come and go as the Copilot CLI store is rebuilt or old sessions age out, but the config entries that point at them never get cleaned up. Over time the file fills with tags, aliases, and notes for sessions that no longer exist. The README even notes that tags on missing sessions are ignored, so the cruft is real and already visible, there is just no way to clear it.

flowchart TD
    A[dispatch prune] --> B[Load config + session store]
    B --> C[Collect live session IDs]
    C --> D[Scan aliases, tags, notes, favorites, hidden, launches]
    D --> E{ID in store?}
    E -->|no| F[Mark entry stale]
    E -->|yes| G[Keep]
    F --> H{--apply?}
    H -->|no| I[Report what would be removed]
    H -->|yes| J[Remove stale entries, save config]
Loading

Proposed solution

Add a dispatch prune command that removes session-keyed config entries whose target session is no longer in the store:

  • Scans SessionAliases, SessionTags, SessionNotes, FavoriteSessions, HiddenSessions, and SessionLaunches.
  • Defaults to a dry run: it prints a per-category summary of how many entries would be removed and a small sample, and does not touch the file.
  • --apply performs the cleanup and saves the config through the existing save path so validation and migrations still run.
  • --json prints the same summary as a stable object for scripting.

Keep it conservative: only remove entries that clearly reference a missing session ID. Never touch scalar settings, views, or color schemes.

Acceptance criteria

  • dispatch prune reports, per category, how many entries reference sessions that are no longer in the store, and changes nothing.
  • dispatch prune --apply removes those entries and saves the config.
  • dispatch prune --json prints a stable JSON summary.
  • Entries for sessions that still exist are always kept.
  • With nothing to prune, the command says so and exits 0.
  • Unit tests cover dry-run, apply, json, and the nothing-to-do cases using the existing seam pattern.

Notes

The live session IDs can come from the same ListSessions path the other subcommands use. Config load/save seams (configLoadFn/configSaveFn) are already in place in cmd/dispatch/config.go for test substitution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestideaFeature idea from the idea pipeline

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions