client.session.summarize hangs forever in Plugin #3505

Open
opened 2026-02-16 17:40:24 -05:00 by yindo · 1 comment
Owner

Originally created by @JosXa on GitHub (Dec 12, 2025).

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?

Originally created by @JosXa on GitHub (Dec 12, 2025). ### Question I'm trying to give OpenCode the ability to compact "itself": _plugin/compact.ts_: ```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: <img width="1091" height="710" alt="Image" src="https://github.com/user-attachments/assets/68ffdae9-45bd-4a3a-9451-c2939b41fcff" /> But hangs forever in this state (no matter which valid provider/model combination I try). Any clues?
Author
Owner

@github-actions[bot] commented on GitHub (Dec 12, 2025):

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] commented on GitHub (Dec 12, 2025): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3505