Skip to content

Self-hosted AI workspace.

Python

fix: TOCTOU race in personal file delete + IndexError on whitespace cmd (#2228)

Wes Huber3146b2e62fc5
diff --git a/routes/personal_routes.py b/routes/personal_routes.py
index 77526c1d1..e47fbbd7c 100644
--- a/routes/personal_routes.py
+++ b/routes/personal_routes.py
@@ -286,9 +286,12 @@ def setup_personal_routes(personal_docs_manager, rag_manager, rag_available):
except ValueError:
# commonpath raises on mixed drives / non-comparable paths
in_uploads = False
- if in_uploads and abs_target != base_abs and os.path.exists(abs_target):
- os.remove(abs_target)
- deleted_from_disk = True
+ if in_uploads and abs_target != base_abs:
+ try:
+ os.remove(abs_target)
+ deleted_from_disk = True
+ except FileNotFoundError:
+ pass # already gone — race with another request or cleanup
# Exclude the file from the listing (persists across restarts)
personal_docs_manager.exclude_file(filepath)
diff --git a/src/tool_implementations.py b/src/tool_implementations.py
index 316588b0b..90d9dae05 100644
--- a/src/tool_implementations.py
+++ b/src/tool_implementations.py
@@ -2662,7 +2662,7 @@ async def _cookbook_register_task(session_id: str, model: str, host: str,
placeholder = (
f"Launched via agent — waiting for tmux output…\n"
f" session: {session_id}\n"
- f" target: {target}{cmd.split()[0] if cmd else ''}\n"
+ f" target: {target}{(cmd.split() or [''])[0] if cmd else ''}\n"
f" cmd: {cmd[:200]}{'…' if len(cmd) > 200 else ''}"
)
tasks.append({