tact icon indicating copy to clipboard operation
tact copied to clipboard

Example/feedback: a tested remote memory implementation for Tact via P2P transport

Open birdmanmandbir opened this issue 3 months ago • 0 comments

I built and tested kepos-tact-memory, a self-hosted SQLite implementation of Tact's remote-memory protocol published through Kepos P2P HTTP transport. It works with an unmodified Tact client.

What is implemented

  • All v1 endpoints: session, scan, read, list, put, delete, sync, and export.
  • The same wire types, production bounds, BM25 retrieval, optimistic concurrency, namespace/role enforcement, and protocol error codes as the reference server.
  • Authenticated Kepos device public keys mapped to a Tact namespace and reader/writer role; several devices can share one namespace.
  • Optional bearer authentication for same-host clients, enforced as loopback-only.
  • Unit tests for authentication and SQLite semantics, plus HTTP contract tests using the headers injected by the Kepos publisher. cargo test and strict clippy both pass.

Compared with the Cloudflare/D1 example

Cloudflare example kepos-tact-memory
Runtime/storage Managed Worker + D1 Operator-owned process + SQLite
Reachability Public HTTPS deployment Private P2P publication; no public listener or inbound port required
Network authentication Bearer credential at MemoryServer Noise-authenticated Kepos device public key; loopback clients may still use bearer
Tact client Unmodified Unmodified

The Cloudflare example is the natural managed deployment. This implementation explores the complementary case where the operator wants to own the host and data while reaching it privately from multiple devices.

How Kepos authentication works

  1. The subscriber connects to the publisher over an end-to-end encrypted Noise stream, which authenticates the subscriber device public key.
  2. The publisher checks that key against its global and per-service allowlists before opening the service channel.
  3. For a service configured as kind = "http", the publisher-side HTTP/1.1 adapter removes every caller-supplied Authorization field and injects exactly Authorization: Kepos <subscriber-public-key> on each request.
  4. kepos-tact-memory treats that public key as an authenticated device credential—not a bearer secret—and maps it to a Tact namespace and role. The assertion is trusted only on the target's private publisher ingress; the memory server stays bound to loopback.

Upstream integration feedback

The Tact client does not need any changes for this deployment. It continues to send its bearer token:

  • for same-host loopback access, kepos-tact-memory validates it normally;
  • over Kepos, the publisher removes it and injects the authenticated Kepos device public key.

The one integration seam I could not reuse is the server authentication layer. MemoryServer<S> currently combines bearer authentication with protocol routing, validation, role enforcement, tracing, timeouts, and error mapping.

To accept a transport-authenticated Kepos device public key, kepos-tact-memory therefore mirrors the server router and substitutes its own principal resolution. This works and is covered by protocol tests, but it means an external authentication adapter must track upstream changes across the whole server layer.

Would you be open to making principal resolution/authentication pluggable while retaining the existing bearer credential constructor as the default? The resolver would need access to request headers and the peer address because bearer authentication is intentionally restricted to loopback here.

Separately, would this deployment be useful as an additional upstream example alongside the Cloudflare/D1 implementation?

birdmanmandbir avatar Aug 26 '26 09:08 birdmanmandbir