Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Server/src/services/tools/manage_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from transport.unity_transport import send_with_unity_instance
import transport.legacy.unity_connection

# Strong references to fire-and-forget tasks to prevent GC before completion
_background_tasks: set = set()


def _split_uri(uri: str) -> tuple[str, str]:
"""Split an incoming URI or path into (name, directory) suitable for Unity.
Expand Down Expand Up @@ -326,6 +329,7 @@ def _le(a: tuple[int, int], b: tuple[int, int]) -> bool:
unity_instance,
"manage_script",
params,
retry_on_reload=False,
)
if isinstance(resp, dict):
data = resp.setdefault("data", {})
Expand All @@ -335,8 +339,7 @@ def _le(a: tuple[int, int], b: tuple[int, int]) -> bool:
if resp.get("success") and (options or {}).get("force_sentinel_reload"):
# Optional: flip sentinel via menu if explicitly requested
try:
import threading
import time
import asyncio
import json
import glob
import os
Expand All @@ -354,7 +357,7 @@ def _latest_status() -> dict | None:

async def _flip_async():
try:
time.sleep(0.1)
await asyncio.sleep(0.1)
st = _latest_status()
if st and st.get("reloading"):
return
Expand All @@ -367,7 +370,9 @@ async def _flip_async():
)
except Exception:
pass
threading.Thread(target=_flip_async, daemon=True).start()
task = asyncio.create_task(_flip_async())
_background_tasks.add(task)
task.add_done_callback(_background_tasks.discard)
except Exception:
pass
return resp
Expand Down Expand Up @@ -423,6 +428,7 @@ async def create_script(
unity_instance,
"manage_script",
params,
retry_on_reload=False,
)
return resp if isinstance(resp, dict) else {"success": False, "message": str(resp)}

Expand Down Expand Up @@ -452,6 +458,7 @@ async def delete_script(
unity_instance,
"manage_script",
params,
retry_on_reload=False,
)
return resp if isinstance(resp, dict) else {"success": False, "message": str(resp)}

Expand Down Expand Up @@ -551,6 +558,7 @@ async def manage_script(
unity_instance,
"manage_script",
params,
retry_on_reload=(action == "read"),
)

if isinstance(response, dict):
Expand Down
5 changes: 5 additions & 0 deletions Server/src/services/tools/script_apply_edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ def error_with_hint(message: str, expected: dict[str, Any], suggestion: dict[str
unity_instance,
"manage_script",
params_struct,
retry_on_reload=False,
)
if isinstance(resp_struct, dict) and resp_struct.get("success"):
pass # Optional sentinel reload removed (deprecated)
Expand Down Expand Up @@ -1110,6 +1111,7 @@ def _expand_dollars(rep: str, _m=m) -> str:
unity_instance,
"manage_script",
params_text,
retry_on_reload=False,
)
if not (isinstance(resp_text, dict) and resp_text.get("success")):
return _with_norm(resp_text if isinstance(resp_text, dict) else {"success": False, "message": str(resp_text)}, normalized_for_echo, routing="mixed/text-first")
Expand All @@ -1135,6 +1137,7 @@ def _expand_dollars(rep: str, _m=m) -> str:
unity_instance,
"manage_script",
params_struct,
retry_on_reload=False,
)
if isinstance(resp_struct, dict) and resp_struct.get("success"):
pass # Optional sentinel reload removed (deprecated)
Expand Down Expand Up @@ -1267,6 +1270,7 @@ def _expand_dollars(rep: str, _m=m) -> str:
unity_instance,
"manage_script",
params,
retry_on_reload=False,
)
if isinstance(resp, dict) and resp.get("success"):
pass # Optional sentinel reload removed (deprecated)
Expand Down Expand Up @@ -1356,6 +1360,7 @@ def _expand_dollars(rep: str, _m=m) -> str:
unity_instance,
"manage_script",
params,
retry_on_reload=False,
)
if isinstance(write_resp, dict) and write_resp.get("success"):
pass # Optional sentinel reload removed (deprecated)
Expand Down