Skip to content

Two compatibility bugs: serve_file path corruption + effective_ids crash #154

Description

@twilso24

Summary

Two Windows compatibility bugs introduced in open-terminal that prevent the server from functioning on Windows.


Bug 1: /files/serve/ returns 404 for valid files (path corruption)

Location: main.py, serve_file() function (line ~651-653)

Problem: The /files/serve/{path:path} route always prepends a / to the path before passing to view_file():
python
async def serve_file(path: str, fs: UserFS = Depends(get_file_system)):
return await view_file(path=f"/{path}", fs=fs)```

On Windows, file paths use drive letters like C:/Users/.... After prepending /, the path becomes /C:/Users/..., which is not a valid Windows path. This causes os.path.isfile() to return False, resulting in:

{"detail": "File not found"}

Request that triggers it:

GET /files/serve/C%3A/Users/USER/Desktop/Proj/index.html HTTP/1.1

Fix: Detect Windows drive letters and skip the / prepend:

if not (path.startswith("/") or (len(path) >= 2 and path[1] == ":")):
path = f"/{path}"
return await view_file(path=path, fs=fs)

###Bug 2: _is_writable_sync() crashes with NotImplementedError

Location: utils/fs.py, _is_writable_sync() method (line ~194)

Problem: Uses os.access(path, os.W_OK, effective_ids=True) which is only available on Unix:

return os.access(path, os.W_OK, effective_ids=True)

On Windows, this raises:

NotImplementedError: access: effective_ids unavailable on this platform
This crashes any endpoint that calls listdir(), glob_search(), or other directory listing operations, returning HTTP 500.

Fix: Catch NotImplementedError in addition to TypeError:

except (TypeError, NotImplementedError):
return os.access(path, os.W_OK)

Environment
OS: Windows 11
Python: 3.13 (base conda) and 3.11 (open-terminal env)

Workaround
Manual patches applied to both main.py and utils/fs.py resolve both issues. A proper fix in upstream would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions