different-ai/openwork · error
MCP_APP_DOCUMENT_RUNTIME_ERROR
MCP_APP_DOCUMENT_RUNTIME_ERROR
Error message
stage + ": " + safeMessage(value)
What it means
This error originates inside the generated Artifact application document sandbox: the report helper posts a ui/notifications/sandbox-diagnostic message with code MCP_APP_DOCUMENT_RUNTIME_ERROR to the parent window whenever the generated app throws at runtime. The message text is built as stage + ': ' + safeMessage(value), where stage identifies where it fired (e.g. 'document-error' from the window error listener). It means the generated interactive view's document-level JavaScript failed while executing.
Source
Thrown at ee/apps/den-api/src/generated-artifact-view-builder.ts:187
loader: "js",
resolveDir: process.cwd(),
}))
},
}
}
const GENERATED_ARTIFACT_RUNTIME_REPORTER = `
(() => {
const safeMessage = (value) => {
if (value instanceof Error) return value.message.slice(0, 1000);
if (typeof value === "string") return value.slice(0, 1000);
return "The generated Artifact application failed at runtime.";
};
const report = (stage, value) => {
window.parent.postMessage({
method: "ui/notifications/sandbox-diagnostic",
params: {
code: "MCP_APP_DOCUMENT_RUNTIME_ERROR",
message: stage + ": " + safeMessage(value),
},
}, "*");
};
window.__openworkReportArtifactRuntimeError = report;
window.addEventListener("error", (event) => report("document-error", event.error || event.message));
window.addEventListener("unhandledrejection", (event) => report("unhandled-rejection", event.reason));
})();
`.trim().replace(/<\/script/giu, "<\\/script")
async function buildClientBundle(reactSource: string): Promise<string> {
const entry = `
import React from "react";
import { createRoot } from "react-dom/client";
import { App, PostMessageTransport } from "@modelcontextprotocol/ext-apps";
const ArtifactView = React.lazy(() => import("artifact:view"));
const mount = document.getElementById("openwork-artifact-view-root");
const reportRuntimeError = (stage, error) => {View on GitHub (pinned to 2b7df46e8a)
Solutions
- Read the stage prefix and message in the sandbox-diagnostic notification to locate where the document threw.
- Fix the generated artifact code at the reported stage (guard null/undefined values, wrap async work in try/catch).
- Regenerate the artifact and confirm the document loads without a document-error report.
- If generated by a model, harden the generation prompt/template against the specific runtime failure.
Example fix
// before: unguarded access in generated doc render(data.items[0].title) // after: defensive access const title = data?.items?.[0]?.title ?? ''; render(title)
Defensive patterns
Strategy: try-catch
Validate before calling
window.addEventListener('error', (event) => report('document-error', event.error || event.message));
window.addEventListener('unhandledrejection', (event) => report('unhandled-rejection', event.reason)); Type guard
function hasMessage(v: unknown): v is { message: string } {
return typeof v === 'object' && v !== null && typeof (v as { message?: unknown }).message === 'string';
} Try / catch
try { render(data); } catch (err) {
window.__openworkReportArtifactRuntimeError?.('render', err);
showFallbackView();
} Prevention
- Wrap all async generated code in try/catch and report failures with a stage label
- Guard optional data access (?. and defaults) in generated artifact code
- Test generated artifacts with empty/partial data before shipping
- Listen for both error and unhandledrejection in sandbox documents
When it happens
Trigger: An uncaught exception in the generated artifact document (window 'error' event), or code explicitly calling window.__openworkReportArtifactRuntimeError(stage, value): runtime errors in generated render code, undefined references, failed fetches inside the sandbox, errors during initial document evaluation.
Common situations: Generated app code referencing data that turned out null/undefined; schema drift between the artifact generator output and runtime APIs; unhandled promise rejections in the sandbox; syntax-valid but logically broken generated code hitting an edge case with real data.
Related errors
- Number.${name} is not available in CodeMode.
- path_escape
- The right-hand side of 'instanceof' must be a constructor Co
- String method '${name}' is not available in CodeMode.
- Array.from(...) does not support a map function in CodeMode;
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/cf2177a00353f955.
Report an issue: GitHub.