Last active
January 23, 2026 16:21
-
-
Save aliou/3249be6c7d01683670c64f47f7164509 to your computer and use it in GitHub Desktop.
Pi extension test - stall compaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Stall Compaction Extension (for debugging) | |
| * | |
| * Provides /stall-compact command to force-trigger compaction, and stalls it for 10 seconds | |
| * to reproduce the Alt-Up "no queued messages to restore" bug. | |
| */ | |
| import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; | |
| const STALL_SECONDS = 15; | |
| export default function (pi: ExtensionAPI) { | |
| // Add /stall-compact command to force-trigger compaction with stall | |
| pi.registerCommand("stall-compact", { | |
| description: "Force-trigger compaction with stall (for debugging)", | |
| handler: async (_args, ctx) => { | |
| ctx.ui.notify("Forcing compaction...", "info"); | |
| // compact() triggers compaction without awaiting - the stall happens in session_before_compact | |
| ctx.compact(); | |
| }, | |
| }); | |
| // Stall compaction to give time to reproduce the bug | |
| pi.on("session_before_compact", async (event, ctx) => { | |
| const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; | |
| let frame = 0; | |
| ctx.ui.notify(`${spinnerFrames[0]} Stalling compaction - try queueing a message then Alt+Up...`, "info"); | |
| // Helper to sleep with abort support | |
| const sleep = (ms: number): Promise<boolean> => { | |
| return new Promise((resolve) => { | |
| const timeout = setTimeout(() => resolve(true), ms); | |
| event.signal.addEventListener("abort", () => { | |
| clearTimeout(timeout); | |
| resolve(false); | |
| }, { once: true }); | |
| }); | |
| }; | |
| // Stall with countdown | |
| for (let i = STALL_SECONDS; i > 0; i--) { | |
| // Update every 100ms for smooth spinner | |
| for (let j = 0; j < 10; j++) { | |
| frame = (frame + 1) % spinnerFrames.length; | |
| ctx.ui.notify(`${spinnerFrames[frame]} Compaction stalled: ${i}s remaining... (Ctrl+C to abort)`, "info"); | |
| const completed = await sleep(100); | |
| if (!completed) { | |
| ctx.ui.notify("Compaction aborted", "warning"); | |
| return; | |
| } | |
| } | |
| } | |
| ctx.ui.notify("Stall complete, compaction skipped", "success"); | |
| // Cancel compaction - no changes made | |
| return { cancel: true }; | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "stall-compaction-gist", | |
| "version": "1.0.0", | |
| "pi": { | |
| "extensions": ["./index.ts"] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment