Skip to content

Unhandled Non-Atomic File Operations & Permission Crashes in A2A Context State Persistence (a2a_context.py) #84

Description

@Adityakk9031

Location:

a2a_context.py:37-43

Code snippet:

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)

Root Cause & Mechanism:

On Windows systems (or POSIX filesystems with strict ACL permissions), invoking path.chmod(0o600) or tmp.chmod(0o600) raises an OSError / PermissionError or is ignored with unexpected ACL side effects.

More critically, if _atomic_write fails mid-execution (e.g. after writing tmp but before os.replace), tmp remains left behind. On subsequent calls, os.replace(tmp, path) on Windows will throw PermissionError: [WinError 5] Access is denied or FileExistsError if path is locked or opened by another thread or process reading context asynchronously via read_a2a_turn_context().

Impact:

  • Inbound Agent-to-Agent (A2A) turns throw unhandled file system exceptions.
  • The thread context queue files lock up, causing loss of multi-agent turn state and crashing the gateway runner.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions