Skip to content
Open
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
12 changes: 6 additions & 6 deletions agentkit/utils/global_config_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Any, Optional, Tuple


_cache: Tuple[Optional[float], dict] = (None, {})
_cache: Tuple[Optional[Path], Optional[float], dict] = (None, None, {})


def get_default_global_config_path() -> Path:
Expand All @@ -38,13 +38,13 @@ def read_global_config_dict(
mtime = path.stat().st_mtime
except FileNotFoundError:
if force_reload:
_cache = (None, {})
_cache = (None, None, {})
return {}
except Exception:
return {}

cached_mtime, cached_data = _cache
if not force_reload and cached_mtime == mtime:
cached_path, cached_mtime, cached_data = _cache
if not force_reload and cached_path == path and cached_mtime == mtime:
return cached_data

try:
Expand All @@ -53,7 +53,7 @@ def read_global_config_dict(
with open(path, "r", encoding="utf-8") as f:
data = yaml.safe_load(f) or {}
parsed = data if isinstance(data, dict) else {}
_cache = (mtime, parsed)
_cache = (path, mtime, parsed)
return parsed
except Exception:
return {}
Expand Down Expand Up @@ -86,7 +86,7 @@ def write_global_config_dict(

try:
mtime = path.stat().st_mtime
_cache = (mtime, data)
_cache = (path, mtime, data)
except Exception:
pass

Expand Down
16 changes: 16 additions & 0 deletions tests/platform/test_global_config_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import pytest
from agentkit.toolkit.config.global_config import GlobalConfig
from agentkit.utils.global_config_io import read_global_config_dict


def test_global_config_cache_is_scoped_to_path(tmp_path):
first = tmp_path / "first.yaml"
second = tmp_path / "second.yaml"
first.write_text("region: cn-beijing\n", encoding="utf-8")
second.write_text("region: ap-southeast-1\n", encoding="utf-8")
shared_mtime_ns = 1_700_000_000_000_000_000
os.utime(first, ns=(shared_mtime_ns, shared_mtime_ns))
os.utime(second, ns=(shared_mtime_ns, shared_mtime_ns))

assert read_global_config_dict(first, force_reload=True)["region"] == "cn-beijing"
assert read_global_config_dict(second)["region"] == "ap-southeast-1"


class TestGlobalConfigCompatibility:
Expand Down