{"record":{"id":"120a3fbed6647946","repo":"different-ai/openwork","slug":"invalid-utf8","errorCode":"invalid_utf8","errorMessage":"invalid_utf8","messagePattern":"invalid_utf8","errorType":"error_code","errorClass":"SafeProbeFailure","httpStatus":null,"severity":"warning","filePath":"apps/server/src/agent-context-cloud-probe.ts","lineNumber":483,"sourceCode":"    if (error instanceof SafeProbeFailure) throw error;\n    // Invoke cancellation even after the deadline has fired. Do not await it:\n    // a hostile stream can ignore both AbortSignal and cancellation.\n    void reader.cancel().catch(() => undefined);\n    if (error instanceof ProbeTimeout || deadline.timedOut()) throw new ProbeTimeout();\n    // Mid-body transport failures keep their original cause so the outer\n    // classifier can attribute them to the network layer, not the protocol.\n    throw error;\n  }\n  const bytes = new Uint8Array(size);\n  let offset = 0;\n  for (const chunk of chunks) {\n    bytes.set(chunk, offset);\n    offset += chunk.byteLength;\n  }\n  try {\n    return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n  } catch {\n    throw new SafeProbeFailure(\"invalid_utf8\");\n  }\n}\n\nfunction parseJson(text: string): unknown {\n  try {\n    return JSON.parse(text);\n  } catch {\n    throw new SafeProbeFailure(\"invalid_json\");\n  }\n}\n\nfunction parseSse(text: string): unknown {\n  const messages: unknown[] = [];\n  let event = \"\";\n  let data: string[] = [];\n  const dispatch = () => {\n    if (data.length === 0) {\n      event = \"\";","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/server/src/agent-context-cloud-probe.ts#L465-L501","documentation":"After accumulating the bounded bytes, readBoundedBody decodes them with a fatal UTF-8 TextDecoder. If the bytes are not valid UTF-8 (e.g., gzip/binary payload), decoding throws and SafeProbeFailure('invalid_utf8') is raised. The probe only understands textual (JSON/SSE) responses.","triggerScenarios":"Probing an endpoint that returns compressed (gzip/br not auto-decompressed), encrypted, or otherwise binary bytes instead of UTF-8 text.","commonSituations":"Probe URL points at a binary download or the response arrives with content-encoding the fetch layer did not decode; server returns protobuf/msgpack instead of JSON.","solutions":["Probe a textual JSON endpoint, not a binary/compressed one.","Ensure the request sets Accept headers the server honors (application/json, identity encoding).","Decompress manually if the transport cannot (e.g., DecompressionStream) before decoding."],"exampleFix":"// before\ntry {\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n} catch {\n  throw new SafeProbeFailure(\"invalid_utf8\");\n}\n// after — tolerate compressed bodies\ntry {\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n} catch {\n  const decompressed = await new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream(\"gzip\"))).bytes();\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(decompressed);\n}","handlingStrategy":"validation","validationCode":"const contentType = response.headers.get(\"content-type\") ?? \"\";\nif (!contentType.startsWith(\"text/\") && !contentType.includes(\"json\")) {\n  throw new SafeProbeFailure(\"unexpected_content_type\");\n}","typeGuard":"function isInvalidUtf8(e: unknown): e is SafeProbeFailure {\n  return e instanceof SafeProbeFailure && e.code === \"invalid_utf8\";\n}","tryCatchPattern":"try {\n  const text = await readBoundedBody(response, deadline, budget);\n} catch (error) {\n  if (error instanceof SafeProbeFailure && error.code === \"invalid_utf8\") {\n    return { ok: false, reason: \"binary_response\" };\n  }\n  throw error;\n}","preventionTips":["Send Accept: application/json and Accept-Encoding: identity on probe requests.","Check content-type before decoding.","Handle compression explicitly (DecompressionStream) when needed.","Only probe textual endpoints."],"tags":["encoding","utf8","probe"],"backgroundTag":"invalid-utf8","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}