opencode icon indicating copy to clipboard operation
opencode copied to clipboard

`client.session.summarize` hangs forever in Plugin

Open JosXa opened this issue 3 weeks ago • 1 comments

Question

I'm trying to give OpenCode the ability to compact "itself":

plugin/compact.ts:

import type { Plugin } from "@opencode-ai/plugin"
import { tool } from "@opencode-ai/plugin"

export const CompactPlugin: Plugin = async ({ client }) => {
  // 'client' here is the SDK client connected to THIS server instance
  
  return {
    tool: {
      compact: tool({
        description: "Compact the current session to reduce token usage. Use this after having EXPLICITLY been instructed to write a <plan>.md file.",
        args: {
          reason: tool.schema.string().optional().describe("Optional reason for compacting"),
        },
        async execute(args, context) {
          // client is captured from the plugin closure
          // It knows which server/port to talk to!
          try {
            const res = await client.session.summarize({
              path: { id: context.sessionID },
              body: {
                providerID: "zai-coding-plan",
                modelID: "glm-4.6",
              }
            });

            console.warn(`Session ${context.sessionID} compacted successfully. Result: ${JSON.stringify(res)}`);
            
            return args.reason 
              ? `Session compacted successfully. Reason: ${args.reason}`
              : "Session compacted successfully";
          } catch (error) {
            return `Failed to compact session: ${error}`;
          }
        },
      }),
    },
  };
};

It shows as summarizing in the UI:

Image

But hangs forever in this state (no matter which valid provider/model combination I try).

Any clues?

JosXa avatar Dec 12 '25 20:12 JosXa

This issue might be a duplicate of existing issues. Please check:

  • #3053: Stuck After Compaction With long calls to models.dev - Similar hanging behavior after compaction/summarize operations
  • #4073: Hanging During Agent Tasks - Reports hanging during task execution with some models
  • #5304: /compact fails in ACP - Related to compact functionality issues

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Dec 12 '25 20:12 github-actions[bot]