feat: always-on remote node — MCP over HTTP, TLS/token, Docker, CI, sqlc #9

Merged
david merged 14 commits from feat/remote-node into main 2026-11-05 02:14:34 +00:00
Owner

Deploys knox as a headless, always-on replica so agents keep their memory when the laptop is off.

Closes #8. Supersedes #5 (its hardening commit is merged in here; close #5 after this lands).

What changed

MCP transport + SDK

  • Moves from mark3labs/mcp-go v0.17 (stdio only, five releases behind) to the official modelcontextprotocol/go-sdk v1.8. Tool inputs are typed structs, so schemas are generated instead of hand-built.
  • Adds knox mcp --http (Streamable HTTP). stdio remains the default.

Transport security without a public name

  • KNOX_AUTH_TOKEN guards gossip and MCP HTTP; KNOX_TLS_CERT/KEY serve TLS; knox tls init mints a self-signed cert whose SANs are whatever addresses clients dial. Verified: 401 without the token, 200 with, cert valid for the overlay IP.

Daemon hygiene

  • SIGTERM shuts down the gossip and metrics servers.
  • --version reports the VCS revision.
  • KNOX_LOCAL_SOURCES=none makes a node ingest nothing but still derive.
  • Default watch dirs skip paths that do not exist.

Deployment topology fixes (all found by actually running a replica)

  • KNOX_LISTEN_ADDR split from KNOX_PEER_ADDR: a container cannot bind the host's overlay IP, and previously the gossip server silently failed to start.
  • Reconcile now fires on push and on startup, not only on pull. Three separate bugs left entries empty on a push-only node.
  • Pushes batch by byte budget, not just row count — 500 content-heavy rows exceeded the 4 MiB body limit and the log stalled permanently at 3,000 observations.
  • Threads and snippets derive on replicas: gating them with the ingesters left the server holding 11.5k observations and 4.9k entries but 2 of 28 threads.

Packaging + CI

  • Multi-stage Dockerfile (static, non-root, /data volume).
  • Gitea workflow builds on the dhg.lol daemon through the runner socket, tags :latest + :<sha>, and restarts the stack when installed. BuildKit cache mounts keep module downloads warm.

sqlc pilot

  • Schema extracted to internal/db/schema.sql (embedded); read paths behind the MCP tools are generated.
  • The pilot found real drift: entries.created_at existed only as a runtime ALTER. It is now declared in the schema, and sqlcdb_pilot_test.go fails if generated code disagrees with db.Open.
  • FTS5 stays hand-written: sqlc ignores CREATE VIRTUAL TABLE, so MATCH/bm25 cannot be generated.

Verification

  • go vet ./..., go test ./..., gofmt clean
  • scripts/conformance.sh — official MCP suite, exit 0 against conformance-baseline.yml (documents the capabilities knox does not implement: resources, prompts, completions, fixture tools)
  • Live: both containers healthy on dhg.lol, ports bound only to the ZeroTier address, 11,553 observations / 4,943 entries replicated and reconciled

Deploy

Infrastructure lives in tf-net/apps/knox (separate repo); this branch is what is currently running in production.

Deploys knox as a headless, always-on replica so agents keep their memory when the laptop is off. Closes #8. **Supersedes #5** (its hardening commit is merged in here; close #5 after this lands). ## What changed **MCP transport + SDK** - Moves from `mark3labs/mcp-go` v0.17 (stdio only, five releases behind) to the official `modelcontextprotocol/go-sdk` v1.8. Tool inputs are typed structs, so schemas are generated instead of hand-built. - Adds `knox mcp --http` (Streamable HTTP). stdio remains the default. **Transport security without a public name** - `KNOX_AUTH_TOKEN` guards gossip and MCP HTTP; `KNOX_TLS_CERT/KEY` serve TLS; `knox tls init` mints a self-signed cert whose SANs are whatever addresses clients dial. Verified: 401 without the token, 200 with, cert valid for the overlay IP. **Daemon hygiene** - SIGTERM shuts down the gossip and metrics servers. - `--version` reports the VCS revision. - `KNOX_LOCAL_SOURCES=none` makes a node ingest nothing but still derive. - Default watch dirs skip paths that do not exist. **Deployment topology fixes** (all found by actually running a replica) - `KNOX_LISTEN_ADDR` split from `KNOX_PEER_ADDR`: a container cannot bind the host's overlay IP, and previously the gossip server silently failed to start. - Reconcile now fires on push and on startup, not only on pull. Three separate bugs left `entries` empty on a push-only node. - Pushes batch by byte budget, not just row count — 500 content-heavy rows exceeded the 4 MiB body limit and the log stalled permanently at 3,000 observations. - Threads and snippets derive on replicas: gating them with the ingesters left the server holding 11.5k observations and 4.9k entries but 2 of 28 threads. **Packaging + CI** - Multi-stage Dockerfile (static, non-root, `/data` volume). - Gitea workflow builds on the dhg.lol daemon through the runner socket, tags `:latest` + `:<sha>`, and restarts the stack when installed. BuildKit cache mounts keep module downloads warm. **sqlc pilot** - Schema extracted to `internal/db/schema.sql` (embedded); read paths behind the MCP tools are generated. - The pilot found real drift: `entries.created_at` existed only as a runtime `ALTER`. It is now declared in the schema, and `sqlcdb_pilot_test.go` fails if generated code disagrees with `db.Open`. - FTS5 stays hand-written: sqlc ignores `CREATE VIRTUAL TABLE`, so `MATCH`/`bm25` cannot be generated. ## Verification - `go vet ./...`, `go test ./...`, `gofmt` clean - `scripts/conformance.sh` — official MCP suite, exit 0 against `conformance-baseline.yml` (documents the capabilities knox does not implement: resources, prompts, completions, fixture tools) - Live: both containers healthy on dhg.lol, ports bound only to the ZeroTier address, 11,553 observations / 4,943 entries replicated and reconciled ## Deploy Infrastructure lives in `tf-net/apps/knox` (separate repo); this branch is what is currently running in production.
david added 14 commits 2026-11-05 02:13:46 +00:00
# Conflicts:
#	internal/db/db.go
MCP moves from mark3labs/mcp-go v0.17 (stdio only, 5 releases behind) to the
official modelcontextprotocol/go-sdk with typed tool inputs, and gains a
Streamable HTTP transport so a remote node can serve agents.

Transport security works without a public DNS name: KNOX_AUTH_TOKEN guards
every endpoint, KNOX_TLS_CERT/KEY serve TLS from a self-signed cert, and
`knox tls init` mints one whose SANs are whatever addresses clients dial.

Daemon hygiene for an always-on host: SIGTERM shutdown of the gossip and
metrics servers, --version reporting the VCS revision, KNOX_LOCAL_SOURCES=none
for a replicate-only node (no ingest tickers, no Obsidian vault adoption), and
default watch dirs that skip paths which do not exist.

Packaging: multi-stage Dockerfile (static, non-root, /data volume).

sqlc pilot: schema moved to internal/db/schema.sql (embedded) and the read
paths behind the MCP tools are now generated. The pilot found real drift —
entries.created_at existed only as a runtime ALTER — so the column is declared
in schema.sql and a parity test fails if generated code disagrees with db.Open.

Conformance: scripts/conformance.sh runs the official suite against a throwaway
node; conformance-baseline.yml records the capabilities knox deliberately does
not implement (resources, prompts, completions, fixture tools).

Refs #8
Builds on dhg.lol's daemon (the runner whitelists /var/run/docker.sock and
/apps), tags :latest plus the commit SHA, and restarts the compose stack only
when apps/knox is already installed. No registry credentials: the registry
requires htpasswd auth and self-built apps are consumed with pull_policy never.
KNOX_PEER_ADDR doubled as the bind address, so a container tried to bind the
host's overlay IP and the gossip server never started. KNOX_LISTEN_ADDR now
controls the bind (defaulting to KNOX_PEER_ADDR for compatibility) and the
advertised address stays what peers dial.
A push-only node — a replica with no peers of its own, which is exactly the
dhg.lol deployment — received observations but never rebuilt entries, so search
returned nothing while the log filled up. The batch handler now signals the
sweep, and reconcile runs when either direction changed the log.
The sweep returned early on an empty peer list, which is precisely the
replica case: dhg.lol configures no peers, receives pushes, and never rebuilt
entries. Check for pending pushes before bailing out.
A 500-row batch of content-heavy observations exceeded the receiver's 4 MiB
body limit and returned 400, so the sender retried the same batch on every
sweep and the log stalled. Pushes now trim to a 2 MiB budget (rows are ordered
by HCL, so the tail simply arrives next time) and the receiver accepts up to
8 MiB.
The Dockerfile uses BuildKit cache mounts so module downloads and compiled
packages survive a go.sum bump, and the test job restores the runner-local
cache server that act_runner already exposes.
A replica that restarts with a populated observation log and an empty entries
cache had no trigger to reconcile: pushes and pulls only fire on *new* rows,
and the node is already in sync. It now rebuilds once at startup.
KNOX_LOCAL_SOURCES=none disabled the auto-threader and snippet extractor along
with the ingesters. Both derive from rows already in the log, so a replica has
everything they need: the dhg.lol node held 11.5k observations and 4.9k entries
but only 2 of the origin's 28 threads, quietly degrading half the MCP surface.

Ingestion stays gated; derivation always runs.
david force-pushed feat/remote-node from 927e61fa45 to 24d28c4cc5 2026-11-05 02:13:46 +00:00 Compare
david merged commit e3bbeabb6b into main 2026-11-05 02:14:34 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#9