From fc1d71162bd7c869b8f55761ab36b146e654d064 Mon Sep 17 00:00:00 2001 From: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:56:07 +0530 Subject: [PATCH] fix(a2a): add cross-platform atomic write safety & handle Windows chmod permission errors --- a2a_context.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/a2a_context.py b/a2a_context.py index 1e8d7d3..209593c 100644 --- a/a2a_context.py +++ b/a2a_context.py @@ -6,6 +6,7 @@ import json import os import threading +from contextlib import suppress from pathlib import Path from typing import Any, Dict, Optional @@ -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: