different-ai/openwork · error

serializeSDKError(result.error)

Error message

serializeSDKError(result.error)

What it means

In performQueuedDraftSend, when a queued draft is a slash-command draft, the app calls opencodeClient.session.command and checks the SDK result. If the OpenCode SDK returns an `error` field on an otherwise-resolved response, the code wraps it via serializeSDKError and throws. This means the server accepted the HTTP request but rejected the command execution (bad session, unknown command, invalid arguments, or server-side failure).

Source

Thrown at apps/app/src/react-app/domains/session/sync/global-queue-drainer.ts:117

  const sendVariant = sessionModelSelection ? sessionModelSelection.variant : context.variant;
  const opencodeClient = createClient(
    context.opencodeBaseUrl,
    context.workspaceRoot || undefined,
    { token: context.openworkToken, mode: "openwork" },
  );

  if (draft.mode === "shell") {
    await shellInSession(opencodeClient, sessionId, text);
    return;
  }

  if (draft.command) {
    const result = await opencodeClient.session.command({
      sessionID: sessionId,
      command: draft.command.name,
      arguments: draft.command.arguments,
    });
    if (result.error) throw new Error(serializeSDKError(result.error));
    return;
  }

  const parts = await draftToParts(draft, context.workspaceRoot, sessionId, {
    client: context.client,
    workspaceId: context.workspaceId,
  });
  const envSystemContext = await buildOpenworkEnvSystemContext(context.client, {
    cacheKey: sessionId,
    runtimeKey: context.environmentRuntimeKey,
  });
  const result = await opencodeClient.session.promptAsync({
    sessionID: sessionId,
    parts,
    model: sendModel ?? undefined,
    agent: context.agent ?? undefined,
    ...(sendVariant ? { variant: sendVariant } : {}),
    ...(envSystemContext ? { system: envSystemContext } : {}),

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Inspect the serialized error text to see the SDK's error code/message and fix the underlying cause (e.g. recreate the session or correct the command).
  2. Verify the sessionID is still valid: fetch the session via the client before draining or drop drafts whose session is gone.
  3. Validate command name and arguments against the server's command registry before enqueueing.
  4. Confirm the openwork/opencode server is running and reachable; retry the drain after connectivity is restored.

Example fix

// before
if (result.error) throw new Error(serializeSDKError(result.error));
// after
if (result.error) {
  const msg = serializeSDKError(result.error);
  if (isSessionNotFound(result.error)) {
    await discardDraft(draft.id); // stale draft, don't crash the drain
    return;
  }
  throw new Error(`Command "${draft.command.name}" failed: ${msg}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const session = await opencodeClient.session.get({ sessionID: sessionId });
if (!session.data) throw new Error(`Session ${sessionId} no longer exists; discard queued draft`);

Type guard

function hasCommand(draft: Draft): draft is Draft & { command: { name: string; arguments: Record<string, string> } } {
  return typeof draft.command?.name === "string" && draft.command.name.length > 0;
}

Try / catch

try {
  await performQueuedDraftSend(draft, context);
} catch (err) {
  if (String(err.message).includes("session")) await discardDraft(draft.id);
  else await requeueWithBackoff(draft, err);
}

Prevention

When it happens

Trigger: Draining the global draft queue while the target session no longer exists, the command name/arguments are stale or invalid, or the openwork/opencode server returns a structured error payload for session.command.

Common situations: Queued drafts persisted before a session was deleted or after a server restart; typo'd or renamed custom commands; command arguments failing server-side validation; server temporarily unhealthy while the queue drains in the background.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/f73eff68e15e72a1. Report an issue: GitHub.