Skip to content

fix: bind the extension API at session_start, not in the factory - #86

Merged
nicobailon merged 1 commit into
mainfrom
fix/85-bind-api-on-session-start
Oct 13, 2026
Merged

nicobailon merged 1 commit into
mainfrom
fix/85-bind-api-on-session-start

Conversation

@nicobailon

Copy link
Copy Markdown
Owner

During /reload, pi runs extension factories while the new runtime's action methods are still a loader stub that throws "Extension runtime not initialized". The real runtime exists only right before session_start. Our factory bound the coordinator's API first thing, so for sessions that survive a reload:

  • messages queued after session_shutdown were flushed inside the factory, sendMessage threw, and pi reported the extension as failed to load;
  • messages arriving after the factory but before session_start ran on the stub and threw from a PTY callback, crashing pi the same way as Hands-free update handler crashes pi after /reload #82.

The API is now bound only in session_start, so those messages wait and are delivered once to the reloaded session. Tools, commands, and shortcuts cannot run before session_start, and headless semantic supervision stays paused through the loading window, as it already was after shutdown.

/spawn --worktree also skips its "Worktree left in place" notice when the overlay outlived a reload, since that command ctx is stale.

tests/reload-stale-api.test.ts sends one update before the new factory runs and one after it but before session_start; neither may throw, nothing is sent early, and both arrive in order afterwards. It fails on main with the "not initialized" error. Two test harnesses that never fired session_start now do, matching pi.

Fixes #85.

During /reload pi runs extension factories before the new runtime exists,
so action methods like sendMessage throw until session_start. Binding in
the factory flushed queued session messages into that stub (failing the
extension load) and delivered later ones to it (crashing pi from PTY
callbacks). Delivery now binds only at session_start.

/spawn --worktree also skips its closing notice when a reload replaced
the command context while the overlay was open.

Fixes #85
@nicobailon
nicobailon merged commit dacfd39 into main Oct 13, 2026
2 checks passed
@nicobailon
nicobailon deleted the fix/85-bind-api-on-session-start branch October 13, 2026 06:57
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.

Messages from sessions that survive /reload can hit the extension loader stub

1 participant