Skip to content

feat(serve): remote-mode HTTP server — ADR-0009 Phase 1, first slice - #14

Merged
luiscota99 merged 2 commits into
mainfrom
feat/serve-phase1
Oct 15, 2026
Merged

luiscota99 merged 2 commits into
mainfrom
feat/serve-phase1

Conversation

@luiscota99

Copy link
Copy Markdown
Owner

Summary

First server-side slice of ADR-0009 Phase 1 (#12): engram serve, a JSON-over-HTTP API that hosts the existing modules unchanged against this host's SQLite. No new business logic; each endpoint is a thin mapping over a function the local CLI/MCP already calls.

Endpoint Maps to
GET /v1/health schema version, vec dimension, instance id, server version
POST /v1/search search()
POST /v1/recall build_recall_context (writes the recall_inject ledger row)
POST /v1/guard _probe_guard_warnings (writes the guard_inject ledger row)
POST /v1/add handle_memory_add (dedup gate, FTS, trigger index, embedding queue as today)
POST /v1/route handle_memory_route
POST /v1/extract handle_memory_auto_extract
GET /v1/inbox inbox.list_items, read-only

Security (ADR-0009 §6). Binds 127.0.0.1 only; anything else is refused unless --allow-nonlocal. Designed to sit behind tailscale serve, which injects Tailscale-App-Capabilities; authorization keys on that grant (read / write / add / *; cap name ENGRAM_SERVE_CAP_NAME, default engram.dev/cap/engram). Tailscale-User-Login is attribution only. --auth none trusts every caller, for tests.

Measured, not vibes. Every call writes a remote_call ledger row (endpoint, status, outcome, server_ms, caller, and host/profile/session when the client sends them) through search_audit.append_remote_call_audit.

Not in this slice (stays on #12)

/v1/checkpoint and /v1/resume (wait for the v29 identity migration), project affinity by project_key (recall/search pass project_path=None for now), the systemd unit, engram roi reporting of the new rows, and the client side (ENGRAM_REMOTE_URL).

Verification

  • tests/test_serve.py: 15 tests on a scratch DB — endpoint round-trips, 404/405/400 paths, the caps auth matrix (401 missing header, 403 wrong grant, add-only vs write vs *), bind policy, ledger rows
  • Full suite: 1459 passed
  • ruff clean; pyright 0 errors (src/serve.py, src/search_audit.py added to the include list); Cloak 0 errors
  • CLI smoke test: engram serve --auth none --port 17437 answered /v1/health and /v1/search, returned 405 on a wrong method, and refused --host 0.0.0.0
  • docs/COMMANDS.md regenerated; CHANGELOG entry added

🤖 Generated with Claude Code

`engram serve` hosts the existing modules unchanged behind a small
JSON-over-HTTP API on 127.0.0.1: GET /v1/health, POST /v1/search|recall|
guard|add|route|extract, GET /v1/inbox (read-only). Each endpoint is a thin
mapping over what the local CLI/MCP already calls — no new business logic,
single write path preserved.

Security per ADR-0009 §6: loopback bind only (non-loopback refused unless
--allow-nonlocal); meant to sit behind `tailscale serve`, which injects
Tailscale-App-Capabilities. Authorization keys on that grant (read/write/
add/*, cap name ENGRAM_SERVE_CAP_NAME, default engram.dev/cap/engram);
Tailscale-User-Login is attribution only; --auth none for tests. 401 when
the header is missing, 403 when the grant lacks the endpoint's action.

Measured, not vibes: every call writes a `remote_call` ledger row
(endpoint, status, outcome ok|denied|client_error|error, server_ms,
caller, host/profile/session_id when sent) via
search_audit.append_remote_call_audit, so `engram roi` can report remote
latency and denied/unreachable rates. The guard endpoint also writes the
same guard_inject row the local hook writes (echo detection joins on it).

Not in this slice (tracked in #12): /v1/checkpoint and /v1/resume (wait
for the v29 identity migration), project affinity by project_key, the
systemd unit, roi reporting of the new rows, and the client side
(ENGRAM_REMOTE_URL).

Tests: tests/test_serve.py (15) — endpoints round-trip on a scratch DB,
404/405/400/413 paths, caps auth matrix, bind policy, ledger rows.
Verification: ruff clean, pyright 0 errors (src/serve.py and
src/search_audit.py added to the include list), Cloak 0 errors, full
suite 1459 passed. docs/COMMANDS.md regenerated via scripts.gen_docs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CI (3.11) caught a race in test_every_call_writes_a_remote_call_ledger_row:
the row was appended in a finally block after the reply had been sent, so a
caller reading the ledger right after the response could miss the call.
The ledger now lands before the response is written; status/outcome are
known by then and the append is a local file write.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@luiscota99
luiscota99 merged commit ea824cc into main Oct 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant