# One invisible character, two reasonable assumptions, one lost write

> A broken PDF font map produced a NUL byte. Every layer accepted it until the database rejected the write, while HTTP 200 made the failure look successful.

URL: https://alokranjan.me/blog/invisible-character-production-bug/
Author: Alok Ranjan
Date: 2026-10-04
Tags: production, reliability, json, pdf, distributed-systems

<img
  src="https://alokranjan.me/blog/invisible-character/cover.webp"
  alt="An invisible character moving through a healthy data pipeline before a database rejects it."
  width="1200"
  height="630"
  decoding="async"
  fetchpriority="high"
/>

The production failure started with a character nobody could see.

A document entered a knowledge-base pipeline. It looked normal, ingestion completed, and search returned relevant passages.

Later, a record failed to save.

The PDF contained a broken font map. Some ligature glyphs that should have become letters were extracted as U+0000, the NUL character. That value moved through extraction, chunking, embeddings, storage, retrieval, tool output, and JSON encoding.

Every stage accepted it.

The database did not.

That alone would have been an ordinary input-validation bug. A second bug made it worse: the application error arrived with HTTP 200. One part of the system checked the transport status, decided the save had worked, and reported success.

Two reasonable assumptions had lined up in exactly the wrong way.

## The value stayed valid until it did not

<figure>
<div class="diagram" role="region" aria-label="The NUL character's path through the system" tabindex="0">
<svg viewBox="0 0 640 300" role="img" aria-labelledby="fig-byte-path-title">
  <title id="fig-byte-path-title">A NUL character passes through extraction, indexing, retrieval and JSON before the database rejects the write</title>
  <defs>
    <marker id="byte-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
      <path d="M0 1 L9 5 L0 9" class="d-head"/>
    </marker>
  </defs>
  <g class="d-line">
    <rect x="12" y="62" width="104" height="52" rx="4"/>
    <rect x="140" y="62" width="104" height="52" rx="4"/>
    <rect x="268" y="62" width="104" height="52" rx="4"/>
    <rect x="396" y="62" width="104" height="52" rx="4"/>
    <rect x="524" y="62" width="104" height="52" rx="4"/>
    <rect x="206" y="202" width="104" height="52" rx="4"/>
    <rect x="362" y="202" width="104" height="52" rx="4"/>
  </g>
  <g class="d-arrow">
    <path d="M116 88 H136" marker-end="url(#byte-arrow)"/>
    <path d="M244 88 H264" marker-end="url(#byte-arrow)"/>
    <path d="M372 88 H392" marker-end="url(#byte-arrow)"/>
    <path d="M500 88 H520" marker-end="url(#byte-arrow)"/>
    <path d="M576 114 C576 165 506 228 470 228" marker-end="url(#byte-arrow)"/>
    <path d="M362 228 H314" marker-end="url(#byte-arrow)"/>
  </g>
  <g class="d-text">
    <text x="64" y="83" text-anchor="middle" class="d-cap">PDF</text>
    <text x="64" y="101" text-anchor="middle">extract</text>
    <text x="192" y="83" text-anchor="middle" class="d-cap">TEXT</text>
    <text x="192" y="101" text-anchor="middle">chunk</text>
    <text x="320" y="83" text-anchor="middle" class="d-cap">VECTOR</text>
    <text x="320" y="101" text-anchor="middle">store</text>
    <text x="448" y="83" text-anchor="middle" class="d-cap">SEARCH</text>
    <text x="448" y="101" text-anchor="middle">retrieve</text>
    <text x="576" y="83" text-anchor="middle" class="d-cap">TOOL</text>
    <text x="576" y="101" text-anchor="middle">return</text>
    <text x="414" y="223" text-anchor="middle" class="d-cap">JSON</text>
    <text x="414" y="241" text-anchor="middle">decode</text>
    <text x="258" y="223" text-anchor="middle" class="d-cap">DATABASE</text>
    <text x="258" y="241" text-anchor="middle">reject</text>
  </g>
  <g class="d-accent">
    <text x="320" y="31" text-anchor="middle">the value stays valid until the final boundary</text>
    <circle cx="258" cy="268" r="3.5" class="d-dot"/>
    <text x="276" y="272">transaction rolled back</text>
  </g>
</svg>
</div>

<figcaption>every arrow preserved the bad value correctly</figcaption>
</figure>

PDFs often store glyphs plus a map that tells extractors which character each glyph represents. A damaged map can return NUL where letters should be.

The value can then cross a JSON boundary as the visible escape sequence `\u0000`. After another decode, it becomes a real NUL again. The JSON remains valid, but the database refuses the resulting value and rolls back the transaction.

Syntactically valid is not the same as safe for the next system.

## HTTP 200 answered the wrong question

The HTTP request had succeeded. The server received it and returned a valid response. The application operation had failed.

Those are different outcomes.

<figure>
<div class="diagram" role="region" aria-label="Transport status and application confirmation lead to different outcomes" tabindex="0">
<svg viewBox="0 0 640 258" role="img" aria-labelledby="fig-ack-title">
  <title id="fig-ack-title">Transport success and application confirmation lead to different acknowledgement decisions</title>
  <defs>
    <marker id="ack-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
      <path d="M0 1 L9 5 L0 9" class="d-head"/>
    </marker>
  </defs>
  <g class="d-line">
    <rect x="18" y="92" width="132" height="52" rx="4"/>
    <rect x="206" y="92" width="132" height="52" rx="4"/>
    <rect x="470" y="24" width="152" height="52" rx="4"/>
    <rect x="470" y="180" width="152" height="52" rx="4"/>
  </g>
  <g class="d-arrow">
    <path d="M150 118 H202" marker-end="url(#ack-arrow)"/>
    <path d="M338 108 C394 108 407 50 466 50" marker-end="url(#ack-arrow)"/>
    <path d="M338 128 C394 128 407 206 466 206" marker-end="url(#ack-arrow)"/>
  </g>
  <g class="d-text">
    <text x="84" y="113" text-anchor="middle" class="d-cap">HTTP</text>
    <text x="84" y="132" text-anchor="middle">200 received</text>
    <text x="272" y="113" text-anchor="middle" class="d-cap">OUTCOME</text>
    <text x="272" y="132" text-anchor="middle">inspect result</text>
    <text x="546" y="45" text-anchor="middle" class="d-cap">CONFIRMED</text>
    <text x="546" y="64" text-anchor="middle">finish</text>
    <text x="546" y="201" text-anchor="middle" class="d-cap">FAILED</text>
    <text x="546" y="220" text-anchor="middle">retain and surface</text>
  </g>
  <g class="d-small">
    <text x="404" y="42" text-anchor="middle">confirmed outcome</text>
    <text x="404" y="228" text-anchor="middle">error or unknown</text>
  </g>
  <g class="d-accent">
    <text x="320" y="20" text-anchor="middle">acknowledge the outcome, not the envelope</text>
  </g>
</svg>
</div>

<figcaption>HTTP 200 only proves that the response arrived</figcaption>
</figure>

A save should count as complete only when the application confirms it. An error, an empty result, or an unfamiliar response is not confirmation.

That same decision should govern cleanup. Keep the original work until the system of record confirms the intended state. In this incident, that rule left a recoverable copy after the failed write.

## Retries need somewhere to end

Retries help with failures that change over time, such as a short outage or a busy database. They cannot repair a deterministic bad character. The same input fails in the same place each time.

If a job retries five times and then disappears, the system has only delayed the loss.

A reliable retry path needs a durable terminal state, an alert, and an idempotent way to replay the work. It also needs to distinguish permanent input errors from transient infrastructure errors.

## Fix the class of failure

Removing NUL from one bad value would fix one write. It would not fix the system.

The useful repair works at several boundaries:

- Detect the damaged PDF text layer and use OCR to recover the intended letters.
- Strip NUL after chunking so no document format can place it in the index.
- Sanitize again before persistence as a final safety boundary.
- Treat only an explicit application confirmation as success.
- Make exhausted work visible and recoverable.

Each safeguard has one job. OCR protects meaning. Sanitization protects storage. Confirmation protects acknowledgement. Durable failure handling protects the work itself.

The deeper lesson is not that one database dislikes one character. It is that every boundary has its own definition of valid, and every layer has its own definition of success.

Production systems rarely fail because one component explodes. The difficult failures are quieter. Every component follows its local contract, while the contracts between them leave a small gap.

In this case, the gap was one invisible character wide.
