Files
encyclopedia-knowledge-graph/docs/PLAN-SQLITE-META-REST-ENDPOINTS-ETAG-AND-VPS-SYNC.md
T

7.4 KiB
Raw Permalink Blame History

Plan: Expose SQLite /api/v1/meta/* REST Endpoints, HTTP ETag (304 Not Modified), hs_query_sqlite_catalog MCP Tool & sync-vps-repos.sh Hydration (v2.0.18)

  • Document ID: PLAN-SQLITE-META-REST-ENDPOINTS-ETAG-AND-VPS-SYNC (v2.0.18)
  • Roadmap Status: LONG-TERM INACTIVE PLAN (Deferred) — Extracted from PLAN-SQLITE-REST-API-METADATA-DB and preserved as a long-term architectural specification alongside PLAN-LLM-TOKEN-ECONOMIZER-AND-VARIANCE-ROUTING, PLAN-MEMETIC-GALLERY-SUBPAGE, and Episodes 06–09 of The Encyclopedia Expeditions; not scheduled for active implementation unless explicitly activated.
  • Prerequisite Module: hyperstitionstud_io.db.sqlite_meta (hs-db-build CLI, hyperstition-catalog.db, and api-telemetry.db automatically populated by dispatch_rest_v1() and dispatch_jsonrpc(), defined in the active plan /workspace/encyclopedia-knowledge-graph/docs/PLAN-SQLITE-REST-API-METADATA-DB.{md,pdf}).
  • Target Modules (When Activated):
    • /workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/rest.py & server.py
    • /workspace/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/tools.py
    • /workspace/hyperstitionstudio-core/deploy/hyperstition-mcp.service
    • /workspace/hyperstitionstudio-core/deploy/sync-vps-repos.sh & deploy/test-first-deployment.sh

1. Scope of Deferred Integration

Once the standalone hyperstitionstud_io.db.sqlite_meta engine (hyperstition-catalog.db + api-telemetry.db) is built, this long-term plan specifies how to expose it over the public /api/v1/meta/* HTTP REST surface and /mcp JSON-RPC server and wire automatic RAM-tmpfs database hydration into the VPS deployment pipeline:

  1. Five /api/v1/meta/* HTTP REST Endpoints: Expose /api/v1/meta/{manifests,search,coordinate/{aq_int},timeseries/query,telemetry} on hyperstitionstud_io.mcp.rest and server.py.
  2. HTTP ETag / If-None-Match (304 Not Modified) Conditional Caching Middleware: Serve deterministic ETag headers backed by registry_manifests.dag_json_cidv1 (or SHA-256) and short-circuit matching If-None-Match requests with HTTP 304 Not Modified in < 0.1 ms.
  3. MCP Tool hs_query_sqlite_catalog: Register hs_query_sqlite_catalog in MCP_TOOLS_SCHEMA (src/hyperstitionstud_io/mcp/tools.py) and expose it at /mcp (tools/call) and /api/v1/tools/hs_query_sqlite_catalog.
  4. VPS tmpfs Hydration in deploy/sync-vps-repos.sh & Systemd Sandboxing: Run hs-db-build ("${PYTHON_BIN}" -m hyperstitionstud_io.db.sqlite_meta --build) inside deploy/sync-vps-repos.sh so /var/www/hyperstitionstud.io/repos/hyperstition-catalog.db refreshes in the 512 MB RAM tmpfs mount on every pull while keeping ProtectSystem=strict and ReadOnlyIsolationGuard intact.

2. /api/v1/meta/* REST Endpoints & hs_query_sqlite_catalog MCP Tool Specification

2.1 REST Endpoints (src/hyperstitionstud_io/mcp/rest.py)

HTTP Method & Path Query Parameters What It Queries in SQLite (< 1 ms)
GET /api/v1/meta/manifests ?registry=glossary-registry (optional) Calls query_registry_manifests() on registry_manifests for all compiled schemas/registries, their record counts, raw_sha256, dag_json_cidv1, and ETag headers.
GET /api/v1/meta/search ?q=envideea+137&type=all|glossary|equation|node&limit=25 Calls query_fts_catalog() to execute a ranked FTS5 BM25 full-text search across fts_catalog (searching glossary terms, 1,850+ equations, 388 graph nodes, and 24 tickers in < 0.6 ms).
GET /api/v1/meta/coordinate/{aq_int} aq_int in 1..999 (e.g. /api/v1/meta/coordinate/137 or /api/v1/meta/coordinate/125) Calls query_coordinate_join(aq_int) for a Unified Cross-Corpus Coordinate Join: in a single indexed SQL query, returns every glossary term, bilingual specimen, Knowledge Graph node/edge, 333/666/777 archive equation, and /quant/ closing-bell bar that locks onto integer coordinate {aq_int}.
GET /api/v1/meta/timeseries/query ?symbol=NVDA&start=2026-11-10&end=2026-11-30&min_points=1.5 Calls query_timeseries_bars() to execute indexed range queries over quant_timeseries_bars (WHERE symbol = ? AND date_utc BETWEEN ? AND ? AND contingent_points >= ?).
GET /api/v1/meta/telemetry None Calls get_api_telemetry_summary() on api-telemetry.db, returning live server uptime, total calls, cache hit rate (304), mean/max latency (\mu\text{s}) per endpoint, and 100% isolation verification counts.

2.2 MCP Tool hs_query_sqlite_catalog (src/hyperstitionstud_io/mcp/tools.py)

  • Tool Name: hs_query_sqlite_catalog
  • Input Schema (inputSchema):
    • mode: "manifests" | "search" | "coordinate" | "timeseries" | "telemetry" (default "search")
    • query: str (FTS5 BM25 search query when mode == "search")
    • doc_type: "all" | "glossary" | "equation" | "node" | "dossier" | "instrument" (default "all")
    • aq_int: int (1..999, required when mode == "coordinate")
    • symbol: str (optional ticker filter when mode == "timeseries")
    • start_date, end_date: str (YYYY-MM-DD bounds when mode == "timeseries")
    • min_points: float (default 0.0)
    • limit: int (1..100, default 25)
  • Execution Guarantees: Runs strictly inside ReadOnlyIsolationGuard against file:/.../hyperstition-catalog.db?mode=ro (PRAGMA query_only = ON;).

3. HTTP ETag / If-None-Match (304 Not Modified) & VPS Systemd Sandboxing

  1. HTTP ETag & If-None-Match (304 Not Modified) Middleware in _MCPHTTPHandler (mcp/server.py):
    • Every GET /api/v1/* response computes or looks up its deterministic ETag ("<dag_json_cidv1>" from registry_manifests or SHA-256 payload digest).
    • If the client sends If-None-Match: "<etag>" (or a comma-separated list containing "<etag>"), _MCPHTTPHandler records a status_304 hit in api-telemetry.db and returns HTTP 304 Not Modified with an empty body immediately (~95% bandwidth reduction on repeat polls).
  2. Read-Only Catalog DB Hydration in deploy/sync-vps-repos.sh:
    • During Step 2 of deploy/sync-vps-repos.sh, invoke "${PYTHON_BIN}" -m hyperstitionstud_io.db.sqlite_meta --build --db "${LIVE_REPOS}/hyperstition-catalog.db" so the 512 MB RAM-backed tmpfs mount always holds an up-to-date catalog DB after every repository pull.
  3. Preserving ProtectSystem=strict & ReadOnlyIsolationGuard in deploy/hyperstition-mcp.service:
    • Configure RuntimeDirectory=hyperstition-mcp (or PrivateTmp=true writing to /tmp/hyperstition-api-telemetry.db) so hyperstition-mcp.service writes api-telemetry.db only to an ephemeral tmpfs path while /srv/hyperstitionstud.io/repos and /var/www/hyperstitionstud.io/repos remain 100% read-only.

4. Activation & Verification Checklist (When Promoted from Inactive Backlog)

  1. Wire /api/v1/meta/{manifests,search,coordinate/{aq_int},timeseries/query,telemetry} and ETag / If-None-Match (304 Not Modified) into src/hyperstitionstud_io/mcp/rest.py and server.py.
  2. Add hs_query_sqlite_catalog to MCP_TOOLS_SCHEMA in src/hyperstitionstud_io/mcp/tools.py.
  3. Wire hs-db-build into deploy/sync-vps-repos.sh and add HTTP checks for /api/v1/meta/manifests, /api/v1/meta/search?q=envideea, /api/v1/meta/coordinate/137, If-None-Match -> 304 Not Modified, and /api/v1/meta/telemetry to tests/test_core_suite.py and deploy/test-first-deployment.sh.