Skip to content

client.session.summarize hangs forever in Plugin #5449

@JosXa

Description

@JosXa

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions