fix(mcp,db,systemd,logrotate): move telemetry DB to /var/lib/hyperstitionstud.io/api-telemetry.db via StateDirectory=hyperstitionstud.io and catch sqlite3.Error (v2.0.22)
This commit is contained in:
1 parent
95a5fc8618
commit
9716a0ab61
24 files changed
+140
-84
No files matched your search
@@ -1,3 +1,3 @@
|
||||
"""hyperstitionstud_io — Shared Common Library for the hyperstitionstud.io workspace (v2.0.21)."""
|
||||
__version__ = "2.0.21"
|
||||
"""hyperstitionstud_io — Shared Common Library for the hyperstitionstud.io workspace (v2.0.22)."""
|
||||
__version__ = "2.0.22"
|
||||
NAMESPACE_URN = "urn:io:hyperstitionstud"
|
||||
@@ -61,6 +61,8 @@ def run_diagnostics(workspace_root: str | Path | None = None) -> dict[str, Any]:
|
||||
lr_txt = lr_path.read_text(encoding="utf-8") if lr_path.is_file() else ""
|
||||
lr_ok = (
|
||||
lr_path.is_file()
|
||||
and "/var/lib/hyperstitionstud.io/api-telemetry.db" in lr_txt
|
||||
and "/tmp/" not in lr_txt
|
||||
and "size 100M" in lr_txt
|
||||
and "compress" in lr_txt
|
||||
and "nocompress" not in lr_txt
|
||||
|
||||
@@ -214,6 +214,23 @@ def get_default_telemetry_db_path() -> Path:
|
||||
env_p = os.environ.get("HYPERSTITION_TELEMETRY_DB_PATH")
|
||||
if env_p:
|
||||
return Path(env_p)
|
||||
state_dir = Path("/var/lib/hyperstitionstud.io")
|
||||
if state_dir.is_dir() and os.access(state_dir, os.W_OK):
|
||||
return state_dir / "api-telemetry.db"
|
||||
if state_dir.parent.is_dir() and os.access(state_dir.parent, os.W_OK):
|
||||
try:
|
||||
state_dir.mkdir(parents=True, exist_ok=True)
|
||||
if os.access(state_dir, os.W_OK):
|
||||
return state_dir / "api-telemetry.db"
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
cache_dir = Path.home() / ".cache" / "hyperstitionstud.io"
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
if os.access(cache_dir, os.W_OK):
|
||||
return cache_dir / "api-telemetry.db"
|
||||
except OSError:
|
||||
pass
|
||||
return Path("/tmp/hyperstition-api-telemetry.db")
|
||||
|
||||
|
||||
@@ -994,8 +1011,15 @@ def record_api_telemetry(
|
||||
raise
|
||||
finally:
|
||||
conn.close()
|
||||
for suf in ("", "-wal", "-shm"):
|
||||
cand = Path(f"{t_path}{suf}")
|
||||
if cand.exists():
|
||||
try:
|
||||
os.chmod(cand, 0o666)
|
||||
except OSError:
|
||||
pass
|
||||
return {"ok": True, "db_path": str(t_path)}
|
||||
except OSError as exc:
|
||||
except Exception as exc:
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ from hyperstitionstud_io.mcp.tools import MCP_TOOLS_SCHEMA, call_mcp_tool # noq
|
||||
|
||||
SERVER_INFO = {
|
||||
"name": "hyperstitionstudio-mcp",
|
||||
"version": "2.0.21",
|
||||
"namespace_urn": "urn:io:hyperstitionstud:mcp:2.0.21",
|
||||
"version": "2.0.22",
|
||||
"namespace_urn": "urn:io:hyperstitionstud:mcp:2.0.22",
|
||||
}
|
||||
|
||||
|
||||
@@ -195,57 +195,65 @@ class _MCPHTTPHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self) -> None:
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("GET", self.path)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
manifest = {
|
||||
"serverInfo": SERVER_INFO,
|
||||
"protocols": ["2025-03-26", "2024-11-05"],
|
||||
"transport": "streamable-http",
|
||||
"endpoints": {
|
||||
"jsonrpc_post": "/mcp",
|
||||
"manifest_get": "/mcp",
|
||||
"rest_api_v1": "/api/v1",
|
||||
"openapi_3_1": "/api/v1/openapi.json",
|
||||
},
|
||||
"counts": {
|
||||
"tools": len(MCP_TOOLS_SCHEMA),
|
||||
"static_resources": len(STATIC_RESOURCES),
|
||||
"resource_templates": len(RESOURCE_TEMPLATES),
|
||||
"prompts": len(MCP_PROMPTS),
|
||||
},
|
||||
"tools": [t["name"] for t in MCP_TOOLS_SCHEMA],
|
||||
"resources": [r["uri"] for r in STATIC_RESOURCES],
|
||||
"prompts": [p["name"] for p in MCP_PROMPTS],
|
||||
}
|
||||
self._send_json(200, manifest)
|
||||
|
||||
def do_POST(self) -> None:
|
||||
length = int(self.headers.get("Content-Length", "0"))
|
||||
if length < 0 or length > 65536:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw_bytes = self.rfile.read(length) if length > 0 else b""
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("POST", self.path, raw_bytes)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
if not raw_bytes:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw = raw_bytes.decode("utf-8")
|
||||
try:
|
||||
req = json.loads(raw)
|
||||
except json.JSONDecodeError as exc:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": str(exc)}})
|
||||
return
|
||||
resp = dispatch_jsonrpc(req)
|
||||
if resp is None:
|
||||
self.send_response(202)
|
||||
self.end_headers()
|
||||
return
|
||||
self._send_json(200, resp)
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("GET", self.path)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
manifest = {
|
||||
"serverInfo": SERVER_INFO,
|
||||
"protocols": ["2025-03-26", "2024-11-05"],
|
||||
"transport": "streamable-http",
|
||||
"endpoints": {
|
||||
"jsonrpc_post": "/mcp",
|
||||
"manifest_get": "/mcp",
|
||||
"rest_api_v1": "/api/v1",
|
||||
"openapi_3_1": "/api/v1/openapi.json",
|
||||
},
|
||||
"counts": {
|
||||
"tools": len(MCP_TOOLS_SCHEMA),
|
||||
"static_resources": len(STATIC_RESOURCES),
|
||||
"resource_templates": len(RESOURCE_TEMPLATES),
|
||||
"prompts": len(MCP_PROMPTS),
|
||||
},
|
||||
"tools": [t["name"] for t in MCP_TOOLS_SCHEMA],
|
||||
"resources": [r["uri"] for r in STATIC_RESOURCES],
|
||||
"prompts": [p["name"] for p in MCP_PROMPTS],
|
||||
}
|
||||
self._send_json(200, manifest)
|
||||
except Exception as exc:
|
||||
self._send_json(500, {"ok": False, "error": {"code": "INTERNAL_ERROR", "status": 500, "message": str(exc)}})
|
||||
|
||||
# 7. Stateless Read-Only MCP (/mcp) & REST API v1 (/api/v1/*) HTTP Server -> 127.0.0.1:8095
|
||||
# Note: Do NOT call dispatch_jsonrpc or dispatch_rest_v1 inside do_POST without top-level try/except
|
||||
def do_POST(self) -> None:
|
||||
try:
|
||||
length = int(self.headers.get("Content-Length", "0"))
|
||||
if length < 0 or length > 65536:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw_bytes = self.rfile.read(length) if length > 0 else b""
|
||||
if self.path.startswith("/api/v1"):
|
||||
status, ctype, payload = dispatch_rest_v1("POST", self.path, raw_bytes)
|
||||
self._send_payload(status, ctype, payload)
|
||||
return
|
||||
if not raw_bytes:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32600, "message": "Invalid content length"}})
|
||||
return
|
||||
raw = raw_bytes.decode("utf-8")
|
||||
try:
|
||||
req = json.loads(raw)
|
||||
except json.JSONDecodeError as exc:
|
||||
self._send_json(400, {"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": str(exc)}})
|
||||
return
|
||||
resp = dispatch_jsonrpc(req)
|
||||
if resp is None:
|
||||
self.send_response(202)
|
||||
self.end_headers()
|
||||
return
|
||||
self._send_json(200, resp)
|
||||
except Exception as exc:
|
||||
self._send_json(500, {"ok": False, "error": {"code": "INTERNAL_ERROR", "status": 500, "message": str(exc)}})
|
||||
|
||||
|
||||
def run_http_server(host: str, port: int) -> int:
|
||||
|
||||
@@ -496,7 +496,7 @@ def build_financial_quant_harvest(
|
||||
payload: dict[str, Any] = {
|
||||
"$schema": "./schemas/v1/financial-aq-harvest.schema.json",
|
||||
"$id": "urn:io:hyperstitionstud:schema:v1:financial-aq-harvest",
|
||||
"version": "2.0.21",
|
||||
"version": "2.0.22",
|
||||
"target_date_utc": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
|
||||
"harvest_mode": harvest_mode,
|
||||
"regime_summary": {
|
||||
|
||||
Reference in new issue
Block a user