Skip to content
Closed
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
5 changes: 4 additions & 1 deletion agent/copilot_acp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@ def _handle_server_message(
block_error = get_read_block_error(str(path))
if block_error:
raise PermissionError(block_error)
content = path.read_text() if path.exists() else ""
try:
content = path.read_text()
except FileNotFoundError:
content = ""
line = params.get("line")
limit = params.get("limit")
if isinstance(line, int) and line > 1:
Expand Down
5 changes: 4 additions & 1 deletion agent/shell_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ def _locked_update_approvals() -> Iterator[Dict[str, Any]]:
yield data
save_allowlist(data)
finally:
fcntl.flock(lock_fh.fileno(), fcntl.LOCK_UN)
try:
fcntl.flock(lock_fh.fileno(), fcntl.LOCK_UN)
except (OSError, IOError):
pass


def _prompt_and_record(
Expand Down
5 changes: 4 additions & 1 deletion cron/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,10 @@ def _process_job(job: dict) -> bool:
return sum(_results)
finally:
if fcntl:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
try:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
except (OSError, IOError):
pass
elif msvcrt:
try:
msvcrt.locking(lock_fd.fileno(), msvcrt.LK_UNLCK, 1)
Expand Down
21 changes: 17 additions & 4 deletions gateway/sticker_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""

import json
import os
import tempfile
import time
from typing import Optional

Expand All @@ -35,12 +37,23 @@ def _load_cache() -> dict:


def _save_cache(cache: dict) -> None:
"""Save the sticker cache to disk."""
"""Save the sticker cache to disk atomically."""
CACHE_PATH.parent.mkdir(parents=True, exist_ok=True)
CACHE_PATH.write_text(
json.dumps(cache, indent=2, ensure_ascii=False),
encoding="utf-8",
fd, tmp_path = tempfile.mkstemp(
dir=str(CACHE_PATH.parent), suffix=".tmp"
)
try:
with os.fdopen(fd, "w", encoding="utf-8") as f:
json.dump(cache, f, indent=2, ensure_ascii=False)
f.flush()
os.fsync(f.fileno())
os.replace(tmp_path, str(CACHE_PATH))
except BaseException:
try:
os.unlink(tmp_path)
except OSError:
pass
raise


def get_cached_description(file_unique_id: str) -> Optional[dict]:
Expand Down
5 changes: 4 additions & 1 deletion hermes_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,10 @@ def _file_lock(
finally:
holder.depth = 0
if fcntl:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
try:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
except (OSError, IOError):
pass
elif msvcrt:
try:
lock_file.seek(0)
Expand Down
5 changes: 4 additions & 1 deletion tools/environments/file_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ def _sync_back_locked(self, lock_path: Path) -> None:
fcntl.flock(lock_fd, fcntl.LOCK_EX)
self._sync_back_impl()
finally:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
try:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
except (OSError, IOError):
pass
lock_fd.close()

def _sync_back_impl(self) -> None:
Expand Down
5 changes: 4 additions & 1 deletion tools/memory_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def _file_lock(path: Path):
yield
finally:
if fcntl:
fcntl.flock(fd, fcntl.LOCK_UN)
try:
fcntl.flock(fd, fcntl.LOCK_UN)
except (OSError, IOError):
pass
elif msvcrt:
try:
fd.seek(0)
Expand Down
5 changes: 4 additions & 1 deletion tools/skill_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def _usage_file_lock():
yield
finally:
if fcntl:
fcntl.flock(fd, fcntl.LOCK_UN)
try:
fcntl.flock(fd, fcntl.LOCK_UN)
except (OSError, IOError):
pass
elif msvcrt:
try:
fd.seek(0)
Expand Down
6 changes: 3 additions & 3 deletions trajectory_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class CompressionConfig:
def from_yaml(cls, yaml_path: str) -> "CompressionConfig":
"""Load configuration from YAML file."""
with open(yaml_path, 'r', encoding="utf-8") as f:
data = yaml.safe_load(f)
data = yaml.safe_load(f) or {}

config = cls()

# Tokenizer
if 'tokenizer' in data:
config.tokenizer_name = data['tokenizer'].get('name', config.tokenizer_name)
Expand Down
Loading