OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: content write normalizes whitespace path segments to _ but read does not — edit on an existing memory forks a new file

Open DamonDay opened this issue 1 month ago • 2 comments

Issue Origin

Observed or reproduced in a real environment

Bug Description

[Bug] content write normalizes whitespace path segments to _ but read does not — edit on an existing memory forks a new file

Version: v0.5.2 (openviking[bot]==0.5.2, plugin @openviking/opencode-plugin 0.5.19)

The same applies to write mode=replace on any pre-existing whitespace path.

Scale (our deployment, read-only count)

~11% of memory .md files (4,697 / 42,505) sit under a path segment containing a space.

Related

#5178 (a09a9d20a) lowercases preferences / cases / experiences / trajectories filenames ({{ user|lower }}/...), so one user's preferences now also split between Jane Doe/ (pre-0.5) and jane doe/ (new topics). Combined with this bug a single user can end up with Jane Doe/, jane doe/ and Jane_Doe/.

Steps to Reproduce

Reproduce

Any memory file whose path has a space-containing segment; call the MCP edit tool on it with a valid old_string, then read the original URI and ls the parent.

Expected Behavior

Expected

Read and write resolve the same canonical URI. Options: apply the same normalization on read (with the existing %20 fallback extended to the space→_ form), or skip whitespace normalization for paths that already exist / for memories/ targets, and make memory templates produce canonical segments up front.

Actual Behavior

What happens

Since #5328 (d8f675445), ContentWriteService.write runs the target URI through normalize_storage_target_uri, which applies VikingURI.sanitize_segment to every path segment that contains whitespace (space → _). fs.read / read_visible does not.

Memory directories created by extraction (e.g. preferences {{ user }}/{{ topic }}.md) routinely contain spaces, because user is a display name such as Jane Doe. So on an existing memory:

  1. read viking://user/<u>/memories/preferences/Jane Doe/topic.md → returns the file.
  2. edit (MCP tool) on the same URI → reads the old file, then fs.write(..., mode="replace") writes to .../preferences/Jane_Doe/topic.md — a new file. Response: Edited .../Jane_Doe/topic.md.
  3. Subsequent read of the original URI still returns the old content. The new file carries MEMORY_FIELDS {"version": 1} only (user/topic lost), so extraction merge does not recognize it.

Minimal Reproducible Example


Error Logs


OpenViking Version

Version: v0.5.2 (openviking[bot]==0.5.2, plugin @openviking/opencode-plugin 0.5.19)

Python Version

3.10.12

Operating System

Linux

Model Backend

None

Additional Context

No response

DamonDay avatar Nov 01 '26 09:11 DamonDay

Hi, I'd like to take this one. Reproduced the fork locally against v0.5.2 behavior.

Plan: in ContentWriteCoordinator._write (openviking/storage/content_write.py), keep the literal URI when the unsanitized target already exists — i.e. validate with validate_safe_viking_uri_path, apply normalize_storage_target_uri, but if the two differ and the literal path is an existing file, target the literal path so mode=replace edits in place instead of forking a ...\_... sibling. New writes (target absent) still get canonical whitespace-free segments, so #5328's storage-hygiene goal is preserved for fresh content.

Will follow up with a PR including offline tests covering: replace-in-place on an existing space path, fresh writes still sanitize, and the read-back coherence after an edit.

lester076 avatar Nov 01 '26 12:11 lester076

Thanks for reporting this and for the additional deployment details. The read/edit mismatch is real: reading a file under Jane Doe/ uses that path, while the write step can target Jane_Doe/, leaving the original unchanged.

This is the same behavior already tracked in #6521, including files produced by memory extraction. Closing this issue as a duplicate so the problem has one tracking issue. PR #6881 remains open; this closure does not mean the bug is fixed.

qin-ctx avatar Nov 02 '26 07:11 qin-ctx