seance icon indicating copy to clipboard operation
seance copied to clipboard

[bug] Pi hook extension removed after /new — séance cleans up session directory on session-end

Open elmarco opened this issue 2 months ago • 0 comments

What happened

When using /new inside a pi session to start a fresh conversation, the séance pi hook stops working. The hook extension file (~/.cache/seance-pi/$SURFACE_ID/seance-hook.js) is deleted, so pi can no longer load it for the new session.

Expected behavior

The hook file should persist for the lifetime of the pi process, not the pi session. /new resets the conversation but pi remains the same process and reloads its extensions — including --extension paths.

Actual behavior

/new triggers pi's session_shutdown event → the hook sends seance ctl pi-hook session-end → séance deletes ~/.cache/seance-pi/$SURFACE_ID/ → pi reloads extensions → the --extension file is gone → the hook is silently dropped.

Root cause

The séance session-end hook handler appears to clean up the per-surface cache directory. But session-end does not mean the pi process has exited — it can also mean an in-process session reset (/new). The wrapper script (~/.local/share/seance/bin/pi) already has its own cleanup after the pi process exits:

  # ── Session-end cleanup ─────────────────────────────────────────────────
  seance ctl pi-hook session-end <<< "{}" 2>/dev/null || true
  rm -rf "$SESSION_DIR"
  exit $rc

So the directory removal on the séance side is redundant and premature.

Suggested fix

Either:

  1. Don't delete the session directory on session-end — let the wrapper's post-exit cleanup handle it, or
  2. Distinguish session reset from process exit — e.g. add a session-reset hook that séance handles without cleanup, and only clean up on the final session-end sent by the wrapper after pi exits, or
  3. Move the hook file outside the cache directory — write it somewhere séance won't clean up (e.g. ~/.pi/agent/extensions/seance-hook.js), so it survives regardless.

Steps to reproduce

  1. Launch pi inside a séance terminal (so the séance wrapper injects the hook)
  2. Verify the hook is working (séance tracks the session)
  3. Run /new in pi
  4. Observe that ~/.cache/seance-pi/$SURFACE_ID/seance-hook.js no longer exists
  5. Séance no longer tracks the session

Séance version

7bb5f3736423bbf1dd7e8e0ae83e0a4eef313651

How did you install it?

Built from source

Distro and desktop

Fedora

Relevant logs


elmarco avatar Oct 05 '26 09:10 elmarco