Skip to content

fix(gateway): discard abandoned Pi session files on /new - #182

Open
AuYahyire wants to merge 1 commit into
owainlewis:mainfrom
AuYahyire:feat/pi-discard-session-on-rotate
Open

fix(gateway): discard abandoned Pi session files on /new#182
AuYahyire wants to merge 1 commit into
owainlewis:mainfrom
AuYahyire:feat/pi-discard-session-on-rotate

Conversation

@AuYahyire

@AuYahyire AuYahyire commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • On /clear /new /reset, Push already rotates the DB session pointer; for the Pi backend it now also deletes the matching abandoned *_<session-id>.jsonl under ~/.pi/agent/sessions (or $PI_CODING_AGENT_DIR/sessions).
  • Best-effort only: missing files and unsafe ids are ignored; Claude/Codex are unchanged.
  • store::rotate returns the previous session id so callers can clean up backend artifacts.

Why

Pi leaves session JSONL files on disk after Push rotates the conversation. Without cleanup, /new orphans large session files and grows ~/.pi/agent/sessions unbounded.

Test plan

  • cargo fmt --all --check
  • cargo clippy --locked --all-targets -- -D warnings
  • cargo build --locked
  • cargo test --locked
  • cargo test discards_matching_session_jsonl_only
  • cargo test clear_rotates_only_the_exact_channel_qualified_session
  • Manual: with agent=pi, send a chat turn, /new, confirm the previous ~/.pi/agent/sessions/**/*_<old-id>.jsonl is gone and the thread still works

Risks

  • Over-deletion if session id matching were too broad; deletion is scoped to *_<session-id>.jsonl and ignores unsafe ids.
  • Best-effort delete failures are ignored so rotate still succeeds.

Related issue

None

Rotate already drops the DB pointer; also delete the matching Pi JSONL under
~/.pi/agent/sessions so /clear|/new|/reset do not leave orphan session files.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant