Skip to content
Open
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
17 changes: 13 additions & 4 deletions a2a_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import threading
from contextlib import suppress
from pathlib import Path
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -36,10 +37,18 @@ def _queue_path(session_id: str) -> Path:

def _atomic_write(path: Path, value: Any) -> None:
tmp = path.with_suffix(f"{path.suffix}.tmp")
tmp.write_text(json.dumps(value, sort_keys=True) + "\n")
tmp.chmod(0o600)
os.replace(tmp, path)
path.chmod(0o600)
try:
tmp.write_text(json.dumps(value, sort_keys=True) + "\n", encoding="utf-8")
with suppress(OSError):
tmp.chmod(0o600)
os.replace(tmp, path)
with suppress(OSError):
path.chmod(0o600)
finally:
with suppress(OSError):
if tmp.exists():
tmp.unlink()



def write_a2a_turn_context(session_id: str, context: Dict[str, Any]) -> None:
Expand Down
Loading