Skip to content

fix: prevent crash on /new with running background processes#36

Merged
aliou merged 2 commits into
mainfrom
fix/stale-ctx-crash
May 7, 2026
Merged

fix: prevent crash on /new with running background processes#36
aliou merged 2 commits into
mainfrom
fix/stale-ctx-crash

Conversation

@aliou
Copy link
Copy Markdown
Owner

@aliou aliou commented May 7, 2026

Bandaid fix for #35.

Problem

Running /new while background processes are active crashes pi:

Error: This extension ctx state is stale after session replacement or reload.
    at Object.sendMessage (loader.js:20:41)
    at EventEmitter.<anonymous> (process-end.ts:57:8)

session_shutdown kills all processes, their exit handlers fire pi.sendMessage() on the now-stale pi proxy, which throws.

Fix

safeSendMessage() wraps pi.sendMessage() — catches stale-context errors instead of crashing. Processes are still killed on session shutdown as before. The fix just prevents the crash during teardown.

Tradeoff

Process events that fire after the pi proxy is invalidated are silently dropped. This is acceptable for a bandaid — a full reattach solution will come with the extension rewrite.

aliou added 2 commits May 2, 2026 22:41
Updated peer and dev Pi package versions from 0.69.0 to 0.72.1. No code migrations required; existing extension APIs remain compatible.
Bandaid fix for #35.

The crash happens because session_shutdown kills all processes, their
exit handlers fire pi.sendMessage() on the now-stale pi proxy, which
throws. Wrap pi.sendMessage in safeSendMessage that catches stale-context
errors so the extension doesn't crash during teardown.

Processes are still killed on session shutdown — the fix just prevents
the stale-proxy crash during that teardown.
@aliou aliou force-pushed the fix/stale-ctx-crash branch from 46fa219 to ab83249 Compare May 7, 2026 16:12
@aliou aliou merged commit b0f3ef6 into main May 7, 2026
1 check passed
@aliou aliou deleted the fix/stale-ctx-crash branch May 7, 2026 16:49
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