Skip to content

fix: deliver hands-free updates through the active API after reload - #84

Merged
nicobailon merged 1 commit into
mainfrom
fix/82-stale-pi-after-reload
Oct 13, 2026
Merged

nicobailon merged 1 commit into
mainfrom
fix/82-stale-pi-after-reload

Conversation

@nicobailon

Copy link
Copy Markdown
Owner

After /reload, hands-free and dispatch overlay sessions keep running, but their callbacks still held the pi from before the reload. Pi invalidates that object, so the first pi.events.emit / pi.sendMessage when the session updated or exited threw "This extension ctx is stale after session replacement or reload" and took pi down through its uncaughtException handler.

Those callbacks now go through coordinator.runWithExtensionApi, the same path the headless completion already uses: it delivers on the currently bound API, or queues until the reloaded extension binds. Covered sites: the hands-free update handler, the foreground semantic setup failure message, transferred-output delivery, and the dispatch completion / moved-to-background / semantic transition messages. Message shapes and non-reload shutdown are unchanged.

tests/reload-stale-api.test.ts starts a hands-free session, reloads (old API throws pi's stale error), binds a new API, and checks that exit updates and transferred output arrive on the new API. It fails on main with the stale-ctx error.

Fixes #82. Thanks to @masonc15 for the detailed report and repro.

Overlay sessions survive /reload, but their update, dispatch-completion, transfer and semantic-setup-failure callbacks used the pi captured before the reload. Pi invalidates that API, so the first emit/sendMessage threw and crashed pi. Route them through coordinator.runWithExtensionApi like the headless completion path.

Fixes #82
@nicobailon
nicobailon force-pushed the fix/82-stale-pi-after-reload branch from 8714796 to 2d91b46 Compare October 13, 2026 06:42
@nicobailon
nicobailon merged commit 3572073 into main Oct 13, 2026
2 checks passed
@nicobailon
nicobailon deleted the fix/82-stale-pi-after-reload branch October 13, 2026 06:44
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.

Hands-free update handler crashes pi after /reload

1 participant