{"record":{"id":"0ccb48d2153306d8","repo":"deepseek-ai/deepseek-harness","slug":"attachment-write-failed","errorCode":"ATTACHMENT_WRITE_FAILED","errorMessage":"Image normalization did not produce a single-frame 8-bit sRGB image with matching metadata.","messagePattern":"Image normalization did not produce a single-frame 8-bit sRGB image with matching metadata\\.","errorType":"exception","errorClass":"AttachmentError","httpStatus":null,"severity":"error","filePath":"packages/attachment/attachment-local/src/normalization.ts","lineNumber":108,"sourceCode":"  }\n  return true\n}\n\n/** Assert that a normalized output is an 8-bit sRGB/sRGBA single-frame image with matching facts. */\nasync function verifyNormalizedImage(\n  image: NormalizedImage,\n  expectedAlpha: boolean | undefined,\n): Promise<NormalizedImage> {\n  const detected = await detectImage(image.data)\n  if (detected.mediaType !== image.mediaType\n    || detected.width !== image.width\n    || detected.height !== image.height\n    || detected.animated\n    || detected.carriesMetadata\n    || detected.depth !== 'uchar'\n    || detected.space !== 'srgb'\n    || !encodedAlphaIsCompatible(expectedAlpha, detected)) {\n    throw new AttachmentError(\n      'Image normalization did not produce a single-frame 8-bit sRGB image with matching metadata.',\n      'ATTACHMENT_WRITE_FAILED',\n    )\n  }\n  return image\n}\n\n/** Build one fixed-size, oriented, metadata-free sRGB pipeline from submitted bytes. */\nfunction preparedPipeline(data: Uint8Array, width: number, height: number): Sharp {\n  return sharp(data, { failOn: 'error', limitInputPixels: false })\n    .rotate()\n    .toColourspace('srgb')\n    .resize({ width, height, fit: 'inside', withoutEnlargement: true })\n}\n\n/** Dimensions after the long edge is capped without changing aspect ratio. */\nfunction initialDimensions(detected: DetectedImage, maxDimension: number): { width: number; height: number } {\n  const scale = Math.min(1, maxDimension / Math.max(detected.width, detected.height))","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/attachment/attachment-local/src/normalization.ts#L90-L126","documentation":"After normalizeImage encodes a normalized variant, verifyNormalizedImage re-detects that output and asserts the normalization contract: same media type and dimensions as encoded, single-frame, no retained EXIF/ICC/metadata, 8-bit 'uchar' depth, 'srgb' colour space, and alpha compatible with the source. A mismatch means sharp/libvips produced output violating the invariant — an encoder or storage fault routed as ATTACHMENT_WRITE_FAILED, not a caller-input problem.","triggerScenarios":"normalizeImage returning an encode whose re-detection diverges: an encoder release that embeds an ICC profile or orientation tag, WebP dimension rounding differing from the encode info, a colourspace reported other than srgb, multi-frame output, or alpha dropped outside the tolerated all-opaque WebP case.","commonSituations":"sharp/libvips version drift after a dependency update changes metadata emission; platform libvips builds differing across Linux, macOS, and CI; usually deterministic for the same input and stack, so retries of the same bytes fail identically.","solutions":["Re-encode the source externally to a clean, metadata-free 8-bit sRGB image and resubmit.","Align the sharp/libvips version with the one this harness pins and retry.","If reproducible on the pinned stack, report it upstream with the source image — this check exists to catch encoder regressions."],"exampleFix":"// before\nconst normalized = await normalizeImage(data, detected, policy)\n\n// after: pre-clean problem sources so the encode path starts from 8-bit sRGB\nconst clean = await sharp(data).rotate().toColourspace('srgb').png().toBuffer()\nconst normalized = await normalizeImage(clean, await detectImage(clean), policy)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isNormalizationFault = (e: unknown): boolean =>\n  e instanceof Error && 'code' in e && (e as { code?: string }).code === 'ATTACHMENT_WRITE_FAILED'","tryCatchPattern":"try {\n  const normalized = await normalizeImage(data, detected, policy)\n} catch (error) {\n  if (isNormalizationFault(error)) {\n    // encoder/storage fault: surface for re-upload or an upstream report; same-bytes retry is futile\n  }\n  throw error\n}","preventionTips":["Pin the sharp version this package was built against; treat libvips upgrades as breaking changes.","Pre-strip metadata and normalize bit depth and colour space at the ingestion edge for exotic sources.","Route ATTACHMENT_WRITE_FAILED to operators rather than end users — it is not caller-correctable."],"tags":["image","normalization","sharp","attachment","internal-invariant"],"backgroundTag":"image-normalization-failed","analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}