openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(memory): panic on char boundary in memory tree ingest persist (regression)

Open graycyrus opened this issue 6 months ago • 0 comments

Bug Report

Description

Memory tree ingestion panics on multi-byte UTF-8 characters during the persist step. This is a regression — #1595 and #1654 were closed but the panic is still firing in production at high volume across multiple users.

Sentry issues:

  • OPENHUMAN-TAURI-G2 — panic: byte index 387 not char boundary inside \u{200c} (167 events)
  • OPENHUMAN-TAURI-GK — panic: byte index 936 not char boundary inside \u{2007} (63 events)
  • OPENHUMAN-TAURI-GR — panic: byte index 4581 not char boundary inside \u{200c} (47 events)
  • OPENHUMAN-TAURI-KQ — panic: byte index 615 not char boundary inside \u{2007} (41 events)

Combined impact: 318 events, fatal panics. Characters involved: \u{200c} (zero-width non-joiner, common in Persian/Arabic/Hindi text) and \u{2007} (figure space). The panic crashes the memory ingestion pipeline.

Error

panic: byte index 387 is not a char boundary; it is inside '\u{200c}' (bytes 385..388) of `---
  • Platform: Windows x86_64 (10.0.26200, 10.0.19045)
  • Version: [email protected]
  • Environment: production
  • Culprit: openhuman_core::openhuman::memory::tree::ingest::persist::async_fn$0

Root Cause Analysis

src/openhuman/memory/tree/ingest.rs:366-374 — markdown_body_preview() was fixed with ceil_char_boundary and has tests. But the panic culprit is persist::async_fn$0, not markdown_body_preview. There is another string-slicing operation in the persist codepath that was not covered by the previous fixes (#1595, #1654).

The markdown_body_preview function at line 366 correctly uses ceil_char_boundary. But somewhere in the downstream persist flow, the markdown or a derived string is sliced at a raw byte index without a char-boundary check — likely when truncating for database storage, building chunk boundaries, or extracting metadata snippets.

Cascade

Call site Behavior
Memory ingestion pipeline Fatal panic — unhandled, kills the async task
User's conversation memory New messages not ingested, memory stale
Background memory jobs Worker may crash-loop if retrying the same document

Proposed Fix

  1. Audit all &str[index..] / &str[..index] slicing in src/openhuman/memory/tree/ingest.rs and the persist module for raw byte indices
  2. Replace any direct slicing with str::floor_char_boundary / str::ceil_char_boundary (or the util wrappers)
  3. Add test cases with \u{200c} and \u{2007} at chunk/persist boundaries (not just body_preview)
  4. Consider a catch_unwind around the ingest persist path so a single bad document doesn't kill the worker

Labels

sentry-traced-bug, os:windows, bug, priority: critical, area: core

graycyrus avatar May 18 '26 09:05 graycyrus