Repository navigation
Description
Evidence
pkgs/id/hosted-worker/src/user-do.ts:152 computes kv_bytes with SQLite SUM(LENGTH(value)); for SQLite TEXT, LENGTH counts Unicode code points, not UTF-8 bytes. The overwrite lookup at :334 uses the same character count as priorBytes, while the PUT path at :347 measures the incoming value with TextEncoder (bytes). This mixes units in storage usage and ceiling calculations.
Verified against the real UserDO with its in-memory SQLite test harness pattern and a 100-byte ceiling: PUTting 17 distinct values of "😀😀😀😀😀" (20 UTF-8 bytes each) returned 200 for all 17. The test state then held 340 UTF-8 bytes, while /v1/usage reported kv_bytes=85, storage_bytes=85, and at_cap=false. This is reproducible because SQLite reports LENGTH("😀😀😀😀😀") = 5 while LENGTH(CAST(value AS BLOB)) = 20.
Why it matters
A user can store substantially more data than the configured per-user ceiling by using multibyte text. Usage reports and the at-cap signal are also wrong, undermining the ceiling and its read-only-at-cap behavior. The unit mismatch also means subsequent write decisions combine character-based stored usage with byte-based incoming deltas.
Acceptance criteria
- Stored KV byte usage and prior-value accounting use UTF-8 byte lengths consistently with the ceiling contract and
TextEncoder. - Add regression coverage with multibyte/astral Unicode values proving the ceiling cannot be exceeded and usage/
at_capreport actual bytes. - Existing ASCII accounting, overwrites, and delete/recovery behavior remain correct.
Activity
developing-today commentedon Nov 17, 2026
CODE-4119
dezren39 commentedon Nov 17, 2026
Current-main triage (2026-11-17): still present at origin/main
a03c40960a6b938bf36258687f1305237da717e6.user-do.ts:152usesSUM(LENGTH(value))for reported KV bytes; SQLite TEXTLENGTHcounts Unicode code points. The prior-value query at:334-336uses the same character count, while the write delta at:347isTextEncoderbyteLength. The issue's recorded 17×five-emoji/100-byte reproduction remains consistent with this source; no open PR matches #11349.Fresh queue dedupe confirms existing task 20770 in
repo-health-code-pilot, statusqueued. I’m syncing the issue labels to that live fix task.Merge pull request #11426 from developing-today/fix/11349-kv-utf8-bytes
dezren39 commentedon Nov 18, 2026
agent-note:v1
lane: openchamber-scheduled oc-code-07 (repo-worker-code)
transition: done (task 20770, already_done)
evidence: main already counts KV bytes with LENGTH(CAST(value AS BLOB)) (user-do.ts:181, :371), fixed by ff081de; regression test usage.test.ts:173 covers astral characters. No code change made.
dezren39 commentedon Nov 18, 2026