From 9716a0ab61a427c2041d4ff89c719aecc316bd23 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 30 Nov 2026 07:49:43 +0000 Subject: [PATCH] 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) --- deploy/hyperstition-mcp.service | 4 +- deploy/logrotate.d/hyperstition-sqlite-meta | 9 +- deploy/sync-vps-repos.sh | 3 + package.json | 2 +- packages-js/ciphers-aq/package.json | 2 +- pyproject.toml | 2 +- scripts/build_gallery_manifest.py | 4 +- site/donate/index.html | 4 +- site/gallery/index.html | 2 +- site/index.html | 4 +- site/learn/index.html | 2 +- site/learn/learn-app.js | 2 +- site/quant/index.html | 4 +- site/quant/quant-app.js | 2 +- site/quant/quant-timeseries-data.js | 2 +- site/quant/quant-timeseries.json | 8 +- site/quant/quant-tutorials.js | 4 +- src/hyperstitionstud_io/__init__.py | 4 +- src/hyperstitionstud_io/ci/doctor.py | 2 + src/hyperstitionstud_io/db/sqlite_meta.py | 26 ++++- src/hyperstitionstud_io/mcp/server.py | 112 +++++++++++--------- src/hyperstitionstud_io/quant/collector.py | 2 +- tests/test_core_suite.py | 16 +++ workspace.example.toml | 2 +- 24 files changed, 140 insertions(+), 84 deletions(-) diff --git a/deploy/hyperstition-mcp.service b/deploy/hyperstition-mcp.service index 5ede551..ac1d16d 100644 --- a/deploy/hyperstition-mcp.service +++ b/deploy/hyperstition-mcp.service @@ -7,9 +7,10 @@ Before=caddy.service [Service] Type=simple WorkingDirectory=/srv/hyperstitionstud.io/repos +StateDirectory=hyperstitionstud.io Environment="HYPERSTITIONSTUDIO_CONFIG=/srv/hyperstitionstud.io/repos/workspace.toml" Environment="PYTHONPATH=/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/src" -Environment="HYPERSTITION_TELEMETRY_DB_PATH=/tmp/hyperstition-api-telemetry.db" +Environment="HYPERSTITION_TELEMETRY_DB_PATH=/var/lib/hyperstitionstud.io/api-telemetry.db" Environment="HYPERSTITION_SQLITE_MAX_MB=100" ExecStart=/srv/hyperstitionstud.io/repos/.venv/bin/python3 /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/server.py --transport http --host 127.0.0.1 --port 8095 Restart=always @@ -17,6 +18,7 @@ RestartSec=2 NoNewPrivileges=true ProtectSystem=strict ReadOnlyPaths=/srv/hyperstitionstud.io/repos +ReadWritePaths=/var/lib/hyperstitionstud.io [Install] WantedBy=multi-user.target diff --git a/deploy/logrotate.d/hyperstition-sqlite-meta b/deploy/logrotate.d/hyperstition-sqlite-meta index b329634..b3291be 100644 --- a/deploy/logrotate.d/hyperstition-sqlite-meta +++ b/deploy/logrotate.d/hyperstition-sqlite-meta @@ -6,10 +6,11 @@ # writers hold locks corrupts the SQLite B-tree page header and WAL frame index. # Instead, `prerotate` invokes `hyperstitionstud_io.db.sqlite_meta --truncate-quiescent --compress-archive`, which: # 1. Sets `PRAGMA busy_timeout = 30000` (waits up to 30s for in-flight requests to finish), -# 2. Acquires `BEGIN EXCLUSIVE` to guarantee 100% SQLite reader/writer quiescence, +# 2. Flushes committed WAL frames via `PRAGMA wal_checkpoint(TRUNCATE)`, # 3. Writes a consistent point-in-time SQLite snapshot and compresses it with `gzip -9` # to `.1.gz` (rotating `.1.gz` .. `.12.gz` rather than removing history), -# 4. Purges the live telemetry tables and commits cleanly, +# 4. Acquires `BEGIN EXCLUSIVE` to guarantee 100% SQLite reader/writer quiescence, +# purges the live telemetry tables, and commits cleanly, # 5. Executes `PRAGMA wal_checkpoint(TRUNCATE)` + `VACUUM` + `PRAGMA optimize` on the live DB, and # 6. Verifies `PRAGMA integrity_check == 'ok'` on the live DB. # @@ -17,7 +18,7 @@ # - Default logrotate trigger: `size 100M` (100 MB) # - Runtime override: export `HYPERSTITION_SQLITE_MAX_MB` (default `100`) or `HYPERSTITION_SQLITE_MAX_BYTES`. -/tmp/hyperstition-api-telemetry.db /var/lib/hyperstitionstud.io/api-telemetry.db { +/var/lib/hyperstitionstud.io/api-telemetry.db { size 100M rotate 12 compress @@ -27,7 +28,7 @@ nocreate sharedscripts prerotate - TARGET_DB="${1:-${HYPERSTITION_TELEMETRY_DB_PATH:-/tmp/hyperstition-api-telemetry.db}}" + TARGET_DB="${1:-${HYPERSTITION_TELEMETRY_DB_PATH:-/var/lib/hyperstitionstud.io/api-telemetry.db}}" MAX_MB="${HYPERSTITION_SQLITE_MAX_MB:-100}" MAX_BYTES="${HYPERSTITION_SQLITE_MAX_BYTES:-$((MAX_MB * 1024 * 1024))}" ROTATE_KEEP="${HYPERSTITION_SQLITE_ROTATE_KEEP:-12}" diff --git a/deploy/sync-vps-repos.sh b/deploy/sync-vps-repos.sh index 0e034c8..f1fbc8f 100755 --- a/deploy/sync-vps-repos.sh +++ b/deploy/sync-vps-repos.sh @@ -186,6 +186,9 @@ fi # Step 5: Idempotent systemd unit, logrotate.d & /etc/caddy/Caddyfile synchronization (enabled by default; skip with --no-caddy) if [[ "${DO_CADDY}" -eq 1 ]]; then DEPLOY_DIR="${REPOS_ROOT}/hyperstitionstudio-core/deploy" + if [[ -w "/var/lib" ]] || [[ -n "${SUDO}" ]]; then + run_checked "mkdir /var/lib/hyperstitionstud.io" ${SUDO} mkdir -p "/var/lib/hyperstitionstud.io" + fi SRC_LOGROTATE="${DEPLOY_DIR}/logrotate.d/hyperstition-sqlite-meta" DST_LOGROTATE="/etc/logrotate.d/hyperstition-sqlite-meta" if [[ -f "${SRC_LOGROTATE}" ]] && [[ -d "/etc/logrotate.d" ]] && { [[ -w "/etc/logrotate.d" ]] || [[ -n "${SUDO}" ]]; }; then diff --git a/package.json b/package.json index b23c75f..07df75e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hyperstitionstud.io/workspace-core", - "version": "2.0.21", + "version": "2.0.22", "private": true, "description": "Offline-first ESM & browser global (@hyperstitionstud.io/* / window.HyperstitionStudio.*) packages for Base-36 AQ ciphers and interactive knowledge graph workbenches.", "license": "MIT", diff --git a/packages-js/ciphers-aq/package.json b/packages-js/ciphers-aq/package.json index c91b9b2..50f96c0 100644 --- a/packages-js/ciphers-aq/package.json +++ b/packages-js/ciphers-aq/package.json @@ -1,6 +1,6 @@ { "name": "@hyperstitionstud.io/ciphers-aq", - "version": "2.0.21", + "version": "2.0.22", "type": "module", "main": "index.js", "license": "MIT" diff --git a/pyproject.toml b/pyproject.toml index 0b5601b..44e0ff4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "hyperstitionstudio-core" -version = "2.0.21" +version = "2.0.22" description = "Shared PEP 420 common library (hyperstitionstud_io.*) for Base-36 AQ ciphers, offline CMUdict Ingglish phonetics, ReportLab/Pillow publishing, SHA-256 glossary isolation guards, local-config citation verification, and multi-format knowledge graphs." readme = "README.md" requires-python = ">=3.10" diff --git a/scripts/build_gallery_manifest.py b/scripts/build_gallery_manifest.py index 665d251..5b14c11 100755 --- a/scripts/build_gallery_manifest.py +++ b/scripts/build_gallery_manifest.py @@ -144,8 +144,8 @@ def main() -> int: }) manifest = { - "version": "2.0.21", - "namespace_urn": "urn:io:hyperstitionstud:gallery:2.0.21", + "version": "2.0.22", + "namespace_urn": "urn:io:hyperstitionstud:gallery:2.0.22", "total_items": len(items), "items": items, } diff --git a/site/donate/index.html b/site/donate/index.html index 09f3112..e104d3e 100644 --- a/site/donate/index.html +++ b/site/donate/index.html @@ -342,7 +342,7 @@

hyperstitionstud.io/donate — Signal Patronage & Open-Instrument Notes

-

Open-Readout Phonemic, Graph & Closing-Bell Telemetry Workbench • Namespace Authority: urn:io:hyperstitionstud:donate:v2.0.21

+

Open-Readout Phonemic, Graph & Closing-Bell Telemetry Workbench • Namespace Authority: urn:io:hyperstitionstud:donate:v2.0.22