@juicesharp/rpiv-btw 1.17.1 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/btw.ts +21 -2
  2. package/package.json +1 -1
package/btw.ts CHANGED
@@ -287,8 +287,27 @@ export function registerMessageEndSnapshot(pi: ExtensionAPI): void {
287
287
  }
288
288
 
289
289
  export function registerInvalidationHooks(pi: ExtensionAPI): void {
290
- pi.on("session_compact", async (_e, ctx) => invalidateSnapshot(ctx));
291
- pi.on("session_tree", async (_e, ctx) => invalidateSnapshot(ctx));
290
+ pi.on("session_compact", async (_e, ctx) => safeInvalidateSnapshot(ctx));
291
+ pi.on("session_tree", async (_e, ctx) => safeInvalidateSnapshot(ctx));
292
+ }
293
+
294
+ // Auto-compaction races session disposal: pi-core invalidates the extension
295
+ // runner while still emitting session_compact, so `ctx` may be a dead proxy
296
+ // whose getters throw the stale error. The compacting session is being
297
+ // discarded — there is no snapshot worth invalidating — so swallow only the
298
+ // stale error. Any other error is a real bug and must propagate.
299
+ function safeInvalidateSnapshot(ctx: ExtensionContext): void {
300
+ try {
301
+ invalidateSnapshot(ctx);
302
+ } catch (e) {
303
+ if (!isStaleCtxError(e)) throw e;
304
+ }
305
+ }
306
+
307
+ // pi-core's ExtensionRunner throws this exact phrase from an invalidated ctx
308
+ // proxy after session replacement/reload. Match the stable substring.
309
+ function isStaleCtxError(e: unknown): boolean {
310
+ return /stale after session replacement/.test(String(e));
292
311
  }
293
312
 
294
313
  export function registerBtwCommand(pi: ExtensionAPI): void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-btw",
3
- "version": "1.17.1",
3
+ "version": "1.18.0",
4
4
  "description": "Pi extension. The /btw slash command, for putting a one-off side question to the same primary model without polluting the main conversation.",
5
5
  "keywords": [
6
6
  "pi-package",