{"record":{"id":"5e8192b9d643d306","repo":"vercel/ai","slug":"opencode-compaction-failed-formaterror-compacte","errorCode":null,"errorMessage":"OpenCode compaction failed: ${formatError(compacted.error)}","messagePattern":"OpenCode compaction failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/harness-opencode/src/bridge/index.ts","lineNumber":880,"sourceCode":"      } else if (sawBusy && status === 'idle') {\n        compactionSettled.resolve();\n        return true;\n      }\n      if (event.type === 'session.error') {\n        terminalError = formatError(event.properties?.error ?? event);\n        compactionSettled.resolve();\n        return true;\n      }\n    },\n  });\n  const compacted = await legacySessionSummarize({\n    client,\n    sessionId,\n    model,\n  });\n  if (compacted.error) {\n    eventsAbort.abort();\n    throw new Error(\n      `OpenCode compaction failed: ${formatError(compacted.error)}`,\n    );\n  }\n  await Promise.race([compactionSettled.promise, sleep(250)]);\n  eventsAbort.abort();\n  await eventLoop.catch(() => {});\n  if (terminalError) throw new Error(terminalError);\n  if (!sawCompaction) {\n    emit({\n      type: 'compaction',\n      trigger: 'manual',\n      summary: '',\n      harnessMetadata: {\n        opencode: { missingSummary: true },\n      },\n    });\n  }\n}","sourceCodeStart":862,"sourceCodeEnd":898,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-opencode/src/bridge/index.ts#L862-L898","documentation":"runCompaction calls the OpenCode summarize API (legacySessionSummarize) with the resolved model. If the API returns an error result, the bridge aborts the event subscription and throws this error containing the server's formatted error. The compaction request itself was rejected or failed server-side.","triggerScenarios":"Calling compaction when legacySessionSummarize resolves compacted.error — invalid model id for the summarize endpoint, session not in a compactable state, OpenCode server rejecting the request (auth, HTTP 4xx/5xx), or provider failure during summarization.","commonSituations":"Model id not available on the OpenCode server's provider config; summarizing a session with nothing to summarize; provider API key/quota errors during summarization; OpenCode version where the summarize endpoint changed.","solutions":["Read formatError output in the message for the server's reason and fix that (model id, auth, session state).","Confirm the model passed to compaction is configured and available on the OpenCode server.","Ensure the session has enough history to summarize and is not mid-turn.","Retry after transient provider failures."],"exampleFix":"// before: model not configured on server\nawait bridge.compact({ sessionId, model: 'nonexistent/model' });\n// after\nawait bridge.compact({ sessionId, model: 'anthropic/claude-sonnet-4' });","handlingStrategy":"try-catch","validationCode":"const providerModels = await fetch(`${base}/model`).then(r => r.json());\nif (!providerModels.includes(model)) throw new Error(`Model ${model} not available on OpenCode server`);","typeGuard":"function isCompactionError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('OpenCode compaction failed:');\n}","tryCatchPattern":"try {\n  await bridge.compact({ sessionId, model });\n} catch (e) {\n  if (isCompactionError(e)) {\n    console.error('Summarize error detail:', e.message.replace('OpenCode compaction failed: ', ''));\n    // fix model/auth per detail, then retry\n  } else throw e;\n}","preventionTips":["Verify the compaction model exists in the server's provider config.","Compact only when the session is idle, never mid-turn.","Ensure provider auth/quotas cover summarization requests.","Retry transient provider failures with backoff."],"tags":["compaction","opencode","http","api"],"backgroundTag":"opencode-compaction-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}