Skip to content

fix(hosted-worker): KV usage and ceiling count UTF-8 characters, not bytes #11349

Closed

Description

@dezren39

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_cap report actual bytes.
  • Existing ASCII accounting, overwrites, and delete/recovery behavior remain correct.

Activity

  1. developing-today commented on Nov 17, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 17, 2026
  3. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    Current-main triage (2026-11-17): still present at origin/main a03c40960a6b938bf36258687f1305237da717e6. user-do.ts:152 uses SUM(LENGTH(value)) for reported KV bytes; SQLite TEXT LENGTH counts Unicode code points. The prior-value query at :334-336 uses the same character count, while the write delta at :347 is TextEncoder byteLength. 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, status queued. I’m syncing the issue labels to that live fix task.

  4. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    status/triagedTriaged and routed (see agent note)
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 17, 2026
  5. added a commit that references this issue on Nov 17, 2026
  6. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    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.

  7. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor
    kind: done
    lane: oc-code-01 (openchamber scheduled lane)
    task: 20805
    outcome: already_done
    evidence: PR #11426 merged 2026-11-17T22:22:34Z (merge 97a89b4c5603251f0d007beab31bf95885acad15); issue closed. Revalidated on fresh GitHub state at 2026-11-18T12:02Z; no further work.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus/triagedTriaged and routed (see agent note)status:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions