Skip to content

zettelkasten.synapse.query

zettelkasten.synapse.query

Out-of-process synapse READ query (subprocess / CLI entrypoint).

search and frame fuse the memory tree with intersecting (possibly FEDERATED) ZK projects. On a cold process the first query rebuilds the embedding indexes for every in-scope graph — including peer .kgl caches loaded via kglite, whose native, process-global state has been observed to SIGSEGV. A segfault in the stdio MCP server takes the WHOLE server down ("Not connected"); a slow cold rebuild blows past the MCP client timeout and drops the connection.

Running the query in a FRESH subprocess fixes both: a native crash kills only the child (the parent maps exit 139 to a clean error), and a long rebuild is bounded by our own timeout rather than the client's. Crucially this module also enables :mod:faulthandler, so a SIGSEGV dumps the Python traceback (which in-scope source / native call it died in) to stderr — which the parent captures — turning an opaque "exit 139" into a located fault.

Usage::

python -m zettelkasten.synapse.query --payload-json '{"action": "search", ...}'

--payload-json is a JSON object with keys: action (search|frame), query / question, projects (null = configured intersection, [] = memory only, or a token list), top_k, expand, and the frame tuning keys (facets/max_facets/per_facet_k/thin_min_results/ thin_min_similarity). Prints one SYNAPSE_QUERY_RESULT <json> line to stdout (logs + any fault trace go to stderr).