A hidden 50-byte limit on SQLite’s LIKE patterns caused Cloudflare Workers to crash when the Agentic Inbox project tried to search long email subjects, and trimming search strings to 48 characters stopped the failures.

What broke the edge runtime

Agentic Inbox runs each mailbox inside a Cloudflare Durable Object, using an embedded SQLite database for storage. The AI-driven agent builds a search pattern as %search_term%. SQLite enforces a hard 50-byte ceiling on the total length of a LIKE pattern. When a user entered a subject longer than 48 characters, the surrounding % signs pushed the pattern past that ceiling. SQLite threw an unhandled runtime error, which the constrained Worker environment treated as fatal. The whole script terminated, leaving the inbox unusable and the AI agent broken.

How the bug was discovered

Sentry logged uncaught exceptions from the Workers. When the crash appeared, Sentry recorded the exact line where SQLite raised an error. Its “Seer AI” feature parsed the stack trace, highlighted the LIKE pattern construction, and suggested the pattern length as the culprit. A quick look at SQLite’s compile-time documentation confirmed the 50-byte restriction, and the team used Gemini to verify the limit and calculate a safe maximum length for user input.

The surgical fix

The resolution required three tiny changes, all inside the existing search routine:

  • Impose a hard cap of 48 characters on any incoming search term.
  • Slice the input string to that length before concatenating the % wildcards.
  • Leave the rest of the query unchanged, preserving search accuracy without adding new libraries.

Because the adjustment happens before the query reaches SQLite, the final pattern never exceeds the 50-byte threshold, and the Worker no longer crashes. No extra dependencies were added, so the codebase stays lightweight.

Why it matters

Edge-hosted databases are attractive for low-latency use cases, but they inherit the same constraints as on-premises versions. An obscure compile-time limit can become a production-blocking bug when a runtime treats any uncaught exception as fatal. Here, the crash stopped an AI-powered email assistant from working for any user who typed a long subject line—a direct hit to user experience and the reliability promise of serverless platforms.

What could have been done differently

The fix is straightforward, but it highlights a missed validation step. Input sanitization that checks pattern length before building the SQL string would have caught the issue during development rather than in production.

What to watch for next

Developers deploying SQLite on edge runtimes should audit all query constructions that involve pattern matching, especially those that add wildcards or escape characters. Sentry captured the exact line where SQLite failed. As edge computing gains traction, hidden platform limits will surface more often, and a habit of validating inputs against documented constraints will pay off.

Takeaway: A 50-byte ceiling on SQLite LIKE patterns can crash Cloudflare Workers, but trimming search terms to 48 characters eliminates the fault without any extra baggage—proof that a tiny validation step can keep edge services stable.