Skip to content

fix: reset module state on session_start to fix /new (daemon reconnect + fresh name) - #20

Merged
elecnix merged 1 commit into
mainfrom
fix/new-daemon-reconnect
Jul 6, 2026
Merged

fix: reset module state on session_start to fix /new (daemon reconnect + fresh name)#20
elecnix merged 1 commit into
mainfrom
fix/new-daemon-reconnect

Conversation

@elecnix

@elecnix elecnix commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Problem

Typing /new in a pi session causes two issues:

  1. The agent-identity status gets permanently stuck at 🟡 <name> (connecting to daemon...)
  2. The new session reuses the old agent name instead of generating a fresh one

Root cause

Both stem from module-level variables that persist when /new reuses the same pi process and extension module:

  1. shuttingDown — set to true during session_shutdown but never reset. connectToDaemon() returns immediately at its guard clause.
  2. agentName — retains the previous session's name. After the restore loop finds nothing in the new (empty) session file, if (!agentName) is false, so generateName() is never called.

Fix

Reset both at the top of session_start:

shuttingDown = false;
agentName = "";

Tested

  • ✅ All 10 existing tests pass
  • ✅ Manual tmux test: after /new, status transitions 🟡 connecting🟢 connected
  • ✅ Manual tmux test: after /new, agent name changes (e.g. shadow-raven-24silver-quail-9)
  • ✅ Daemon log confirms clean reconnect: old connection ghosted → immediately replaced by new registration

— gentle-newt-20

The shuttingDown flag was set to true during session_shutdown but never
reset to false. When /new starts a new session (same pi process, same
extension module), connectToDaemon() immediately returns because
shuttingDown is still true, leaving the agent status permanently at
'connecting to daemon...'.

Fix: reset shuttingDown = false at the top of session_start handler.
Co-authored-by: gentle-newt-20 <gentle-newt-20@pi-agent.local>
@elecnix
elecnix marked this pull request as ready for review July 6, 2026 23:25
@elecnix
elecnix merged commit 38fce88 into main Jul 6, 2026
1 check passed
@elecnix
elecnix deleted the fix/new-daemon-reconnect branch July 6, 2026 23:26
@elecnix elecnix changed the title fix: reset shuttingDown flag on session_start to fix /new hang fix: reset module state on session_start to fix /new (daemon reconnect + fresh name) Jul 6, 2026
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