fix(core): report in-memory file sizes in UTF-8 bytes

EL
6d ago
+68-5

PR Checklist

  • The commit message follows the contribution guidelines.

Bugs / Features

  • Related issue(s) linked — no existing issue found; discovered through the public WorkspaceFilesystem API.
  • Tests for the changes have been added.
  • Docs added / updated — no new API; restores the existing byte-size behavior displayed by filesystem tools and provided by the disk backend.
  • Changeset added for @voltagent/core.

What is the current behavior?

After await fs.write("/content.txt", "你好") on the default in-memory workspace filesystem, stat, lsInfo, and globInfo report size 2. The same public calls using NodeFilesystemBackend report 6. The memory backend uses JavaScript string length (UTF-16 code units), while filesystem output labels the value as bytes. Byte-limit consumers also receive the smaller value.

What is the new behavior?

Compute UTF-8 byte lengths through one shared helper at the three metadata sites. The example reports 6 across both backends. Use Buffer.byteLength when available to avoid allocating a full encoded byte array just to obtain its size; retain a TextEncoder fallback for runtimes without Buffer.

The regression runs real public write/readRaw/stat/lsInfo/globInfo operations against both memory and temporary on-disk files. Chinese, emoji with a newline and combining marks cover multibyte inputs; ASCII and empty files are controls. Before: 9 fail, 8 pass including two existing tests. After: all 18 pass, including an additional compatibility control with Buffer unavailable. The filesystem/search/skills test group passes 39 tests. No model, network service, or replacement implementation is used in these regressions.

Notes for reviewers

  • pnpm --filter @voltagent/core build: passed CJS, ESM and declaration builds (Node 24.13.0, pnpm 8.10.5, macOS).
  • Standalone probe against the actual built package: all five inputs report the expected byte sizes through all three interfaces and read back unchanged.
  • Biome on both changed TS files, Prettier on the changeset and git diff --check: passed.
  • pnpm --filter @voltagent/core run test --run --maxWorkers=1 --minWorkers=1: 1,416 passed, 2 skipped, 1 todo; 110 test files passed, no type errors.
  • Focused all-state searches, all 108 open PRs and their complete file lists were checked. The same-file mkdir fix in #1452 changes directory bookkeeping, not size calculation.
  • Investigation, implementation, agent self-review and validation used OpenAI Codex.

Summary by cubic

Fixes the in-memory workspace filesystem to report file sizes in UTF-8 bytes, matching the disk backend for non-ASCII content.

  • Previously stat, lsInfo, and globInfo reported sizes in UTF-16 code units (e.g., "你好" showed 2 instead of 6).
  • Size computation now uses Buffer.byteLength when available, falling back to TextEncoder to stay portable outside Node.
  • Adds regression tests covering Chinese, emoji, combining marks, ASCII, and empty files across both backends.

Summary by CodeRabbit

  • Bug Fixes
    • In-memory workspace file sizes now report UTF-8 byte counts, matching disk-backed filesystems. File details, directory listings, and glob results show consistent sizes for non-ASCII content, including emoji and accented characters, as well as empty files and files containing newlines. This makes reported sizes consistent regardless of which workspace filesystem is in use.