[Bug]: Server fails to start on Windows - AttributeError: module 'os' has no attribute 'fchmod' (openviking_gateway/storage.py)
Environment
- OS: Windows 11 Pro 26100 (x64)
- Python: 3.12.11 (uv-managed, MSC v.1943)
- openviking: 0.5.4.1, installed with
uv tool install openviking(fresh install, no prior config) - Ollama running locally on
127.0.0.1:11434
Steps to reproduce
uv tool install openvikingopenviking-server
Actual behavior
The process exits immediately, before the HTTP server is ever bound:
Ollama is running at localhost:11434
2026-11-12 00:31:58,897 - openviking.server.auth.plugins.ldap - WARNING - LDAP library not available. LDAP authentication will not work. Install with: uv pip install python-ldap
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "%USERPROFILE%\.local\bin\openviking-server.exe\__main__.py", line 10, in <module>
File "%USERPROFILE%\AppData\Roaming\uv\tools\openviking\Lib\site-packages\openviking_cli\server_bootstrap.py", line 104, in main
_real_main()
File "...\site-packages\openviking\server\bootstrap.py", line 262, in main
_main(recovery)
File "...\site-packages\openviking\server\bootstrap.py", line 477, in _main
app = create_app(
File "...\site-packages\openviking\server\app.py", line 882, in create_app
app.state.gateway_app = create_embedded_gateway(
File "...\site-packages\openviking\server\gateway_host.py", line 73, in create_embedded_gateway
return create_app(
File "...\site-packages\openviking_gateway\app.py", line 138, in create_app
store, management, close = open_stores(config, encryptor)
File "...\site-packages\openviking_gateway\app.py", line 113, in open_stores
store = SQLiteKernelStore(config.directory / "kernel.sqlite3", encryptor)
File "...\site-packages\openviking_gateway\storage.py", line 288, in __init__
super().__init__(path, encryptor)
File "...\site-packages\openviking_gateway\storage.py", line 171, in __init__
os.fchmod(fd, 0o600)
^^^^^^^^^
AttributeError: module 'os' has no attribute 'fchmod'. Did you mean: 'chmod'?
Root cause
os.fchmod() is POSIX-only and does not exist on Windows. openviking_gateway/storage.py calls it unconditionally in Database.__init__ (line 171 on main as of 2026-11-12, still present):
fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
os.fchmod(fd, 0o600)
os.close(fd)
Because this happens inside create_app() -> create_embedded_gateway() -> open_stores(), the whole server dies at startup; nothing else is reached. Guarding just this one call makes openviking-server boot on Windows, so this is currently the single blocker on the startup path.
For completeness, the mode arguments in the surrounding block have no POSIX meaning on Windows either:
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)- the mode is ignored byCreateDirectoryWos.open(..., 0o600)- only the read-only attribute is honoured
So there is nothing equivalent to apply on win32, and skipping the call is behaviourally identical.
Suggested fix
The project already has this platform split elsewhere - openviking/config/config_file.py::_atomic_write uses os.chmod on win32 and os.fchmod otherwise (and skips the O_DIRECTORY fsync on win32), so the intent to support Windows is clearly there.
Minimal fix:
fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
# os.fchmod is POSIX-only; Windows has no POSIX permission bits to apply here.
if hasattr(os, "fchmod"):
os.fchmod(fd, 0o600)
os.close(fd)
Or mirroring config_file.py:
fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
try:
if sys.platform == "win32":
os.chmod(path, 0o600)
else:
os.fchmod(fd, 0o600)
finally:
os.close(fd)
Verification
Patched 0.5.4.1 locally with the hasattr guard, then ran openviking-server:
- listens on
127.0.0.1:1933 GET /health->{"status":"ok","healthy":true,"version":"0.5.4.1","auth_mode":"dev"}- MCP streamable-http session manager starts
kernel.sqlite3andmanagement.sqlite3are created in WAL mode
A Windows smoke test that only calls create_app() would catch regressions like this without needing a full server run.
I’d like to take this issue. I’ve prepared a focused fix for gateway SQLite initialization on Windows that preserves the existing file permission handling on POSIX.
Thanks for taking this issue and preparing a focused fix. I appreciate your quick response and the effort to preserve the existing POSIX permission handling while addressing the Windows compatibility issue. Thanks for following through with PR #7474!