OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

bug(vikingbot): OpenAPI session id contains ':' breaking pathlocks on Windows (os error 267, lock component unhealthy)

Open lmksks opened this issue 3 months ago • 1 comments

Summary

On Windows, when a vikingbot session interacts with OpenViking (started with --with-bot), the lock component reports unhealthy and all writes fail with:

Storage backend unavailable: internal error: lock error: lock i/o error:
failed to create lock dir: lock i/o error: failed to create lock dir
'/local/default/user/chenfei/sessions/cli__default__4ab668637bdb513f9384c8a8:7425fd71-...':
plugin error: failed to create directory: 目录名称无效。 (os error 267)

The observer (/api/v1/observer/lock) returns is_healthy=false, has_errors=true with status Not initialized. Every lock-requiring write (session commit, memory write, resource delete) fails with UNAVAILABLE until the server is restarted.

Root cause

vikingbot generates session identifiers containing ::

  1. vikingbot/channels/openapi.py _scoped_session_id(): base = f"{principal_scope}:{session_id}"
  2. vikingbot/config/schema.py SessionKey.safe_name(): f"{self.type}__{self.channel_id}__{self.chat_id}" (chat_id contains the colon)

This string is passed to OpenViking as the session_id and becomes a session directory (sessions/<id>/). RAGFS stores its lock token next to the locked path (sessions/<id>/.path.ovlock), and ensure_lock_dir() walks up creating missing ancestors. On Windows, : is an illegal filename character, so mkdir fails with ERROR_INVALID_NAME (os error 267), lock creation fails, and all writes go UNAVAILABLE.

Windows-specific: on Linux/macOS : is a legal filename char, so this never triggers there. Only affects Windows deployments with --with-bot.

Repro

  1. Windows host, openviking-server --with-bot (vikingbot gateway on 18790)
  2. POST /bot/v1/chat with any message (session_id is generated by vikingbot, e.g. cli__default__<scope>:<uuid>)
  3. The bot's session commit to OpenViking fails; check vikingbot.log for os error 267

Suggested fix (one line, vikingbot schema.py)

Sanitize the final storage identifier in SessionKey.safe_name() (or the scope/session join):

def safe_name(self):
    return f"{self.type}__{self.channel_id}__{self.chat_id}".replace(":", "_")

_session_generation_path() already hashes base (sha256) before using it as a filename, so the internal base with colons never touches the filesystem there. from_safe_name() splits on __ and is unaffected by the replacement.

Consider also normalizing user-controlled session ids at the OpenViking server boundary, since any integration that passes ids with : into session directory names hits the same issue on Windows.

Environment

  • openviking 0.4.13, Windows 10, --with-bot
  • vikingbot distributed with openviking (site-packages/vikingbot)

lmksks avatar Aug 15 '26 02:08 lmksks

I'd like to work on this. I confirmed the OpenAPI scoped ID flows through SessionKey.safe_name() into both local filesystem paths and the OpenViking session ID. I'll keep existing safe names unchanged, make unsafe components filesystem-safe with a reversible encoding (avoiding collisions such as a:b vs a_b), and add regression tests for round-tripping and Windows-invalid characters.

Mchenr avatar Aug 15 '26 02:08 Mchenr