{"record":{"id":"aa9b4a5690b88639","repo":"gitbutlerapp/gitbutler","slug":"the-updated-review-was-missing-from-the-response","errorCode":null,"errorMessage":"The updated review was missing from the response.","messagePattern":"The updated review was missing from the response\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/but-mcp-app/src/ReviewApp.tsx","lineNumber":404,"sourceCode":"\tconst connectedApp = app;\n\tconst currentView = view;\n\tconst canCallTools = connectedApp.getHostCapabilities()?.serverTools !== undefined;\n\n\tasync function markReady(review: ReviewCardData) {\n\t\tsetPendingReview(review.number);\n\t\tsetActionError(null);\n\t\ttry {\n\t\t\tconst result = await connectedApp.callServerTool({\n\t\t\t\tname: \"gitbutler_mark_review_ready\",\n\t\t\t\targuments: {\n\t\t\t\t\trepository: currentView.repository.path,\n\t\t\t\t\treviewNumber: review.number,\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (result.isError) throw new Error(textFromToolResult(result));\n\t\t\tconst updatedView = reviewViewFromToolResult(result);\n\t\t\tconst updatedReview = updatedView?.reviews[0];\n\t\t\tif (!updatedReview) throw new Error(\"The updated review was missing from the response.\");\n\t\t\tsetView((current) =>\n\t\t\t\tcurrent === null || updatedView === null ? current : mergeReviewViews(current, updatedView),\n\t\t\t);\n\t\t} catch (actionCause) {\n\t\t\tsetActionError(\n\t\t\t\tactionCause instanceof Error ? actionCause.message : \"Could not mark the review ready.\",\n\t\t\t);\n\t\t} finally {\n\t\t\tsetPendingReview(null);\n\t\t}\n\t}\n\n\tasync function openReview(review: ReviewCardData) {\n\t\tsetActionError(null);\n\t\ttry {\n\t\t\tawait connectedApp.openLink({ url: review.url });\n\t\t} catch (actionCause) {\n\t\t\tsetActionError(","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/packages/but-mcp-app/src/ReviewApp.tsx#L386-L422","documentation":"After a successful (non-error) mark_review_ready response, markReady parses the structured review view and expects at least one review in updatedView.reviews. If the structured content is absent or contains an empty reviews array, this invariant error is thrown, meaning the tool succeeded but returned an unusable payload.","triggerScenarios":"reviewViewFromToolResult returns a view whose reviews array is empty or null — e.g. the tool returned only unstructured text content, or the host returned an empty/legacy payload shape.","commonSituations":"Version mismatch between the app and the host's tool schema (tool updated to return a different shape); a stale review was deleted server-side so the refreshed view no longer contains it; the tool silently degraded to a text-only response.","solutions":["Log the raw result content to confirm what structured data the tool actually returned.","Re-fetch the review list to get the current view instead of relying on the mark-ready response.","Check that the host and the but-mcp-app agree on the tool response schema (version alignment).","Treat the local review state as unchanged and surface a retry prompt rather than crashing the action.","If persistent, report an internal-invariant bug with the raw payload."],"exampleFix":"// before\nconst updatedReview = updatedView?.reviews[0];\nif (!updatedReview) throw new Error(\"The updated review was missing from the response.\");\n// after\nconst updatedReview = updatedView?.reviews[0];\nif (!updatedReview) { await refreshReviews(); return; }","handlingStrategy":"validation","validationCode":"const parsed = reviewViewFromToolResult(result);\nif (parsed === null || !Array.isArray(parsed.reviews) || parsed.reviews.length === 0) {\n  throw new Error(\"Tool returned no reviews: \" + textFromToolResult(result).slice(0, 200));\n}","typeGuard":"function hasReview(view: unknown): view is { reviews: [Review, ...unknown[]] } {\n  return typeof view === \"object\" && view !== null &&\n    Array.isArray((view as any).reviews) && (view as any).reviews.length > 0;\n}","tryCatchPattern":"catch (actionCause) {\n  if (isMissingReviewInvariant(actionCause)) {\n    await refreshReviews(); // recover by refetching instead of failing\n  } else {\n    setActionError(actionCause instanceof Error ? actionCause.message : \"Could not mark the review ready.\");\n  }\n}","preventionTips":["Keep but-mcp-app and the host on matching versions so tool schemas agree.","Log raw tool results at debug level to diagnose shape drift quickly.","Never assume structuredContent exists on a successful tool result — parse and guard.","Add a regression test for empty/absent reviews payloads."],"tags":["mcp","schema","invariant"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}