160-tool MCP server for real-time global intelligence from free public APIs: markets, liquidity, prediction markets, SEC filings, conflict, military, aircraft-cohort early warning, migration and border flows, cyber, climate, news and more. Dated observation history, 29 research prompts, cited briefs, geofences, SSE dashboard. MIT, no paid API keys.
Python ai-toolsai-watchanthropicclaudecybersecuritydashboardgeofencinggeopoliticalgeospatialintelligencemarketsmcpmigrationmilitarymodel-context-protocolnuclearosintreal-timespace-weatherthreat-intelligence
History health: compare against the per-user cache fallback
Phoenix Agent (mac-studio)9ec3d306d2c4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e372cf1..68ff29b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -110,6 +110,13 @@Measured with 8 processes on one fresh file: 29 to 67 failed opens in 80to 160 before, none in 160 after.+### Fixed: collection health names the per-user cache fallback+- `intel_collection_health` says when its run log is the temp-directory+ fallback, but it compared against the old shared `world-intel-mcp`+ directory after the fallback moved to the per-user+ `world-intel-mcp-<uid>` directory, so a run log in the real fallback was+ never named as one. The cache and history now read one path helper.+### Fixed: the collector cycle summary separates data from errors- A source that answers with an upstream error (`{"error": ...}`) stillcounts as a completed fetch, but the cycle summary now lists it underdiff --git a/src/world_intel_mcp/cache.py b/src/world_intel_mcp/cache.pyindex ab8b99b..ca926c9 100644--- a/src/world_intel_mcp/cache.py+++ b/src/world_intel_mcp/cache.py@@ -32,6 +32,19 @@ def _default_db_path() -> Path:return Path.home() / ".cache" / "world-intel-mcp" / "cache.db"+def fallback_directory() -> Path:+ """This user's directory under the temp dir that the fallback uses.++ Only the path: nothing is created or checked. Readers that need to+ tell whether a database is the fallback (history health) compare+ against it.+ """+ getuid = getattr(os, "getuid", None)+ if getuid is None:+ return Path(tempfile.gettempdir()) / "world-intel-mcp"+ return Path(tempfile.gettempdir()) / f"world-intel-mcp-{getuid()}"++def _fallback_db_path() -> Path:"""The cache file in this user's own directory under the temp dir.@@ -41,15 +54,14 @@ def _fallback_db_path() -> Path:one else can enter and none of the database's file names in it is asymlink."""+ directory = fallback_directory()getuid = getattr(os, "getuid", None)if getuid is None:# No POSIX owner or mode bits to check (Windows, whose default temp# directory is per-user).- directory = Path(tempfile.gettempdir()) / "world-intel-mcp"directory.mkdir(exist_ok=True)return directory / "cache.db"uid = getuid()- directory = Path(tempfile.gettempdir()) / f"world-intel-mcp-{uid}"db = directory / "cache.db"try:directory.mkdir(mode=0o700)diff --git a/src/world_intel_mcp/history.py b/src/world_intel_mcp/history.pyindex fb7862f..b388085 100644--- a/src/world_intel_mcp/history.py+++ b/src/world_intel_mcp/history.py@@ -152,6 +152,7 @@ from datetime import date, datetime, timezonefrom pathlib import Pathfrom typing import Any, Callable, Iterable+from .cache import fallback_directoryfrom .sources.markets import _COMMODITY_SYMBOLS, _DEFAULT_INDEX_SYMBOLSlogger = logging.getLogger("world-intel-mcp.history")@@ -878,7 +879,7 @@ def _unrecorded_attempts(failures: list[dict], source: str, after: float | None)def _temp_fallback_db() -> Path:"""Where ``Cache`` falls back when its default path is unusable."""- return Path(tempfile.gettempdir()) / "world-intel-mcp" / "cache.db"+ return fallback_directory() / "cache.db"def _same_path(a: Path, b: Path) -> bool:diff --git a/src/world_intel_mcp/tests/test_history_fallback_path.py b/src/world_intel_mcp/tests/test_history_fallback_path.pynew file mode 100644index 0000000..a00e9b9--- /dev/null+++ b/src/world_intel_mcp/tests/test_history_fallback_path.py@@ -0,0 +1,57 @@+"""History health recognizes the cache's real temp-dir fallback.++Cache isolation moved the fallback into a per-user directory+(``world-intel-mcp-<uid>``); history health still compared against the+old shared ``world-intel-mcp`` path, so a run log living in the fallback+was never named as one. Both now read one path helper.++Gaps / not covered: Windows (no ``os.getuid``), where the fallback stays+``world-intel-mcp`` and only the shared helper keeps the two in step; the+uid is pinned here, not read from a second real account.+"""++import os+import tempfile++from world_intel_mcp.cache import Cache+from world_intel_mcp.history import HistoryStore++T0 = 1_792_000_000.0+FALLBACK_GAP = "this run log is the temp-directory fallback"+++def _gaps(db) -> list[str]:+ s = HistoryStore(db)+ try:+ return s.collection_health(["wildfires"], now=T0)["data_gaps"]+ finally:+ s.close()+++def test_health_names_the_per_user_fallback(tmp_path, monkeypatch) -> None:+ blocker = tmp_path / "not-a-dir"+ blocker.write_text("")+ monkeypatch.setenv("WORLD_INTEL_CACHE_DB", str(blocker / "cache.db"))+ temp_root = tmp_path / "tmp"+ temp_root.mkdir()+ monkeypatch.setattr(tempfile, "tempdir", str(temp_root))+ cache = Cache()+ try:+ assert cache.fell_back is True+ assert cache.db_path == temp_root / f"world-intel-mcp-{os.getuid()}" / "cache.db"+ gaps = _gaps(cache.db_path)+ finally:+ cache.close()+ assert any(gap.startswith(FALLBACK_GAP) for gap in gaps)+++def test_health_does_not_call_the_old_shared_path_a_fallback(tmp_path, monkeypatch) -> None:+ temp_root = tmp_path / "tmp"+ shared = temp_root / "world-intel-mcp"+ shared.mkdir(parents=True)+ monkeypatch.setattr(tempfile, "tempdir", str(temp_root))+ monkeypatch.setattr(os, "getuid", lambda: 4242, raising=False)+ assert not any(gap.startswith(FALLBACK_GAP) for gap in _gaps(shared / "cache.db"))+ own = temp_root / "world-intel-mcp-4242"+ own.mkdir()+ assert any(gap.startswith(FALLBACK_GAP) for gap in _gaps(own / "cache.db"))