Repository navigation
fix(slack-bridge): make /reload load new Pinet code and keep the running mode - #1101
Conversation
…ing mode /reload after `pi update` kept running most of the old Pinet code and left Pinet off, so a broker had to be restarted by hand and still ran stale code until Pi itself restarted. Pi loads extensions with jiti, which imports Pinet's built ES modules with Node's native import whenever it can. Node evaluates each native module once per URL for the life of the process, so only the few files jiti compiles itself (those importing Pi host packages) were fresh after /reload; everything else, including the broker Slack adapter and the workspace packages, stayed old. - module-reload.ts registers one Node resolve hook on the first load. Each later load of the entry gives every Pinet module (not third-party dependencies) a new URL, so Node evaluates the code on disk again. - session_shutdown with reason reload records the running Pinet mode process-wide, and session_start with reason reload restarts it instead of the startup default.
…oad nested @PiNet packages - Reload stops Pinet without releasing its identity, like the in-place broker reload, so the agent keeps its threads, inbox and supervised workers and rejoins as itself. - The mode carried across reload includes off, so a session that left the broker stays off. A startup still in progress carries nothing. - npm may nest @PiNet packages under another package's node_modules; the hook now reloads every @PiNet package and only skips third-party ones.
|
Independent review (oracle, gpt-6.1-sol high): no critical findings; three warnings, all fixed in 827b679:
Not changed: the reload hand-off is one process-wide slot, not keyed per session. Interactive Pi runs one session per process; noted as a limit. slack-bridge: 1745 passed; lint, typecheck, agent-standards pass. |
|
Follow-up review (oracle): no critical findings; the three fixes verified (joined workers still clear tokens and reread the join file on reload). Two remaining continuity gaps are existing broker-start behaviour, shared with the in-place broker reload (
With this PR, Pi |
Problem
After
pi update,/reloadin a broker session:/pinet start), andCause
moduleCache: false), but jiti imports.jsfiles in a"type": "module"package with Node's native import first. It only compiles a file itself when native import fails, which for Pinet happens to the few files that import Pi host packages (index.js,pinet-tools.js,tool-registration-runtime.js). Node evaluates a native module once per URL for the life of the process, so after/reloadeverything else — the broker Slack adapter, broker-core, pinet-core, transport-core — stayed old. Confirmed withJITI_DEBUG=1and a minimal probe extension:/reloadkeptv1code after the files changed tov2.session_shutdownstopped the runtime andsession_startchose the mode from settings, so a broker started with/pinet startcame back off.Loading the TypeScript source instead would avoid native imports but undo the startup speed-up from #984.
Fix
module-reload.tsregisters onemodule.registerHooksresolve hook on the first load. Each later load of the entry gives every Pinet module a new URL (?pinet-load=N), so Node evaluates the code on disk again. Third-party dependencies undernode_modulesand the hook module itself keep their single instance. Requiresmodule.registerHooks(Node 22.15+; Pi requires 22.19+); Bun-compiled Pi binaries without it keep today's behaviour.session_shutdownwithreason: "reload"records the running mode on a process-wide symbol;session_startwithreason: "reload"restarts that mode instead of the startup default.Each reload keeps the previous module copies in memory; reloads are rare, so this is accepted.
Tests
module-reload.test.ts: a child Node process loads a mirrored install three times like jiti, editing a module between loads. Asserts fresh code each load, one hook-module evaluation, one third-party evaluation, and no double load on the first pass. Fails against: no hook, hook module reloaded, third-party reloaded, never bumping, tagging the first load.token-free-follower.test.ts: against a real broker socket, a session that followed with/pinet followrejoins aftersession_shutdown/session_startwithreason: "reload"even though settings would leave it off. Fails without the carry-over.Real Pi check
Built this branch and ran
pi --no-session --no-extensions -e slack-bridge/dist/index.js,/pinet followto the live broker, then edited the built broker Slack adapter between two real/reloads. A temporary line in that file logged its module URL:After each reload the session rejoined the broker on its own as the same agent. The live broker's own reload follows after merge.