## Project: Confer A2A protocol platform for AI Agents to communicate on behalf of their owners. ## Codex workflow - Project skills live in `.agents/skills/`: `deploy`, `create-migration`, `rag-debug`, `sync-env`, `reset-user-password`, plus `a2a-contract-reviewer`, `migration-reviewer`, and `rag-pipeline-reviewer`. Invoke with `$skill-name`. The three review skills are checklists usable directly; they do not require spawning agents. - `.claude/settings.json` and `.claude/hooks/` are Claude Code configuration. They do not provide automatic enforcement or post-edit checks in Codex. Follow the rules below explicitly. - Never hand-edit Drizzle SQL or its journal; change `schema.ts` and run `bun run db:generate`. Do not edit live `.env*` files with tools; templates are editable. Compare key names without exposing values via `$sync-env`. - Run tests through `bun run test`, never bare `bun test`. Use the isolated test stack for gateway integration tests. - After code edits, run Biome on the changed supported files and type-check the owning project: `bun run typecheck` for root packages, `bunx tsc --noEmit -p packages/client/tsconfig.json` for the client. Root typecheck excludes the client. Run relevant tests, review, then deploy affected services before committing per Deployment below. - The Claude-only ban on shell file viewers does not apply to Codex; use available file tools and `rg` as appropriate. - Project MCP configuration lives in `.codex/config.toml`; credentials are forwarded from the launching environment, never committed. See `docs/codex-migration.md` for activation and validation. ## Commands ```bash bun install # install all workspace deps bun run dev # start all packages in dev mode bun run build # build all packages bun run test # run tests across all packages bun run typecheck # tsc --noEmit bun run lint # biome check bun run lint:fix # biome check --write bun run db:generate # generate Drizzle migration from schema changes bun run db:migrate # run gateway DB migrations (apply generated files) bun run test:setup # start isolated test stack + build test schema (run once before `bun run test`) bun run test:stack:down # tear down the isolated test stack bun run eval:rag # retrieval evaluation; requires a real embedding key ``` ## Testing Unit tests are pure (no infra). Gateway route tests (`*.integration.test.ts`) drive the real Hono app against a real Postgres + Qdrant + MinIO test stack (`docker-compose.test.yml`, isolated on ports 5433/6335/9002); embedding/LLM/DID calls are mocked. Run `bun run test:setup` once, then `bun run test`. Client component tests (`packages/client/src/components/*.test.tsx`) render for real — `packages/client/bunfig.toml` preloads `src/test/setup-dom.ts` (happy-dom globals) and they drive components through `@testing-library/react`. Mock `../lib/api.js` (and `../lib/ws.js` for `ChatLayout`), matching the exact paths the stores call, longest prefix first — otherwise a store lands `undefined` in state and the component throws with no error boundary to catch it. ## Architecture Bun workspaces monorepo (`packages/*`): | Package | Purpose | |---------|---------| | `gateway` | Hono HTTP server — A2A endpoints, REST API, WebSocket, DB/middleware | | `client` | Tauri 2.0 + React 19 desktop app — UI components, stores, Vite dev on :1420 | | `identity` | DID:web, HTTP signatures (RFC 9421), crypto, AgentFacts | | `agent-runtime` | LLM orchestration engine, policy enforcement | | `shared` | Zod schemas, shared types, utility functions | | `mcp-a2a` | stdio MCP server — lets an AI coding agent consult peer Agents; ships as the `confer-a2a` plugin (`plugins/confer-a2a/`) | | `cli` | `npx confer-cli` — the documented way to self-host. Plain Node (no Bun API), published to npm by hand; see Release rules | | `gateway/lib/` | Infrastructure adapters + cross-cutting gates — MinIO storage, Qdrant vector search, embedding (OpenAI / GLM / Qwen), `tenant.ts`, `a2a-admission.ts` | | `gateway/orchestration/` | The LLM agent loop (`agent-orchestrator.ts`). Sits ABOVE `tools/`, which sits above `lib/` — keep that direction; `lib/` must never import `tools/` or `orchestration/` | | `gateway/a2a/` | Both A2A wire formats and everything under them. `inbound.ts` is the one admission flow (signature → peer → consent → policy → thread → store → answer) that BOTH bindings call | ## Docs Design context in `docs/` — files 01 (product) through 09 (deployment). Default to **MVP scope (v0.1)** per `docs/08-mvp-backlog.md`. ## Tech stack TypeScript everywhere. Bun + Hono (server), Tauri 2.0 + React 19 + Zustand (client). PostgreSQL 18, Qdrant, MinIO. Bun workspaces monorepo. DID:web + RFC 9421. MCP: `@modelcontextprotocol/sdk`. ## Conventions - Sentence case headings; 2-space indent; named exports; async/await; no untyped `any` - Zod for external inputs; ULID for IDs; `Result` for expected failures - One responsibility per file: `kebab-case.ts`, `PascalCase.tsx`, migrations `NNNN_desc.sql` - Zustand: always subscribe with a selector (`useXStore((s) => s.field)`), never `useXStore()`. `setState` replaces the state object, so a selector-less read re-renders on *every* write to that store — see the pitfall below ## Contracts (do not break) 1. A2A endpoints (`/a2a/v1/*`) require HTTP signature verification — never disable 2. DID documents must be valid W3C DID v1.0 — use the `did` library 3. AgentFacts must validate against NANDA schema 4. Migration files are immutable once merged 5. Project memory stays human-readable Markdown. Today that means `project_memory.facts_md` / `decisions_md`, written and read by the MCP tools `write_project_memory` / `read_project_memory` — it lives in the gateway's database, keyed per user × project × peer, **not** on the developer's disk. The `.claude/peers/*` layout in `docs/07-project-memory.md` is the form it is headed for and is unbuilt (v0.2 in the backlog); this contract covers it in advance, so don't write it as anything but Markdown when it lands 6. Embedding provider auto-selected by the `EMBEDDING_PROVIDER_PRIORITY` constant in `lib/embedding.ts` (openai → glm → qwen → ollama) — first provider with a user-configured key wins. Ollama is last on purpose: it is the local fallback, so configuring a local chat model never takes embeddings away from a hosted key the owner already had. Its "key" is really a base URL (same slot-reuse as the chat provider) and `nomic-embed-text` returns 768 dimensions, which `toVectorSize` zero-pads to `VECTOR_SIZE` — padding leaves cosine similarity untouched, and points already carry the provider that produced them 7. Every LLM vendor is one entry in `packages/shared/src/llm/catalog.ts` — base URL, completions path, models path, wire shape, default model. Three packages read it: the gateway (key-slot whitelist and the `/models` proxy), agent-runtime (`createProvider`, which has no per-vendor code left), and the client's settings UI. Adding a vendor is that one entry; a base URL written anywhere else is a bug. Two things were learned the hard way and are load-bearing. **Model IDs are never hardcoded** — the client used to ship a curated list per provider and it named models like `deepseek-v4-pro` and `claude-opus-4-7` that no vendor has ever served; the list now always comes from the vendor's own `/models`, and a provider whose current IDs we cannot state simply carries no `defaultModel`. And **an empty model list always carries its reason** (`no_key` / `unauthorized` / `unreachable` / `unsupported`): all four used to collapse into `{models: []}`, which the UI read as "this provider has no models" and silently papered over with the hardcoded list. A local runtime's stored "key" is its base URL, so the listing goes to the address the owner configured — the gateway dials it, which is why `docker-compose.prod.yml` maps `host.docker.internal` and why the settings UI suggests that name rather than `localhost` ## Forbidden - Plaintext passwords/API keys (Argon2id / AES-256-GCM) - Sending LLM API keys to client - Disabling signature verification - Inline SQL (use query builder) - Auto-accepting L3 permissions - Logging full A2A request bodies (PII) ## Code generation rules - Read `docs/` before significant new logic; read existing code for patterns - Use existing libraries for crypto/DID/HTTP signatures/MCP; LLM calls via `LLMProvider` - Adding/changing API, A2A, or MCP features → update corresponding `docs/` file - Outside MVP scope → check `docs/08-mvp-backlog.md`, ask before expanding ## Branching `dev` is the daily working branch (unprotected — push directly). `main` is the release branch, protected by a GitHub **ruleset** (not classic protection — the `/protection` API returns 404). Feature branches and PRs target `dev`; releases go `dev` → `main`, then tag from `main`. CI `check` is the only required status. CI runs `lint`, `typecheck`, `test` (spins up `docker-compose.test.yml` via `bun run test:setup`), `build`, and `audit` (`bun audit --audit-level=high`) in parallel; `check` is an aggregator job over those five, so it stays the single required context. **Never add a new gate to the ruleset** — add it to `check`'s `needs` instead, or PRs deadlock. For the same reason, prefer a step in an existing job over a new job. `lint` runs Biome over the repo, then **actionlint** over `.github/workflows/`, then **shellcheck** over `infra/*.sh` and `.github/scripts/*.sh` (both digest-pinned docker images), then a `Cargo.lock` freshness check over `packages/client/src-tauri`. None of the three is decoration: nothing else validates workflow syntax — a malformed `${{ }}` makes GitHub reject the file outright, zero jobs and an error naming no line, and a YAML parser can't see it because the file is still valid YAML — nothing else reads shell, which is what deploy, rollback and release-note generation are written in — and no other job touches Rust, so a `Cargo.toml` edit merged without a regenerated lockfile would surface only during a tagged release. All three ride in this job rather than jobs of their own, per the rule above. `audit` blocks, so a new high advisory turns the branch red. Fix it by upgrading — no advisory is exempted today. Only when no reachable fix exists may you add `--ignore=`, and the workflow comment must record why the vulnerable code path can't be hit. A separate `audit.yml` re-runs the same command on a daily schedule, so an advisory published during a quiet week surfaces on its own instead of reddening the next unrelated commit; scheduled runs come from the default branch, so it watches `main` while `dev` stays covered by CI on every push. The Rust crate is audited beside it by `cargo audit` — a prebuilt binary from `taiki-e/install-action`, so no Rust toolchain is involved — in both `ci.yml` and `audit.yml`, so the two can't drift. It gates on vulnerabilities only: the 17 warnings it prints today are unmaintained gtk3/unic bindings that tauri pulls in, with nothing to upgrade to. Bun's version is pinned in **two** places that must stay in step: `.github/actions/setup/action.yml` for CI, and `release.yml`'s top-level `env.BUN_VERSION` — the release jobs can't use that action because they also run on Windows, where its cache path doesn't apply. Every third-party action is SHA-pinned with the tag in a trailing comment. The Tauri crate carries its own **`Cargo.lock`**, committed alongside `bun.lock`. It went untracked until 2026-08-24, so every release build re-resolved 469 crates from scratch: a tag was not reproducible, and an upstream patch release could have landed in a shipped binary with no diff to show for it. Regenerate it with `cargo generate-lockfile` inside `packages/client/src-tauri` whenever `Cargo.toml` changes, and commit it in the same change — cargo honours the lockfile by default, so no build flag is needed, but `lint` fails once the two have drifted. The *compiler* is still floating (`dtolnay/rust-toolchain` defaults to `stable`): the lock pins dependencies, not the toolchain. Transitive advisories are usually a lockfile pinned below what the parent's own range already permits — but neither bun command you'd reach for first will lift one. A plain `bun install` honours the existing pin, and `bun update ` is **not** a re-resolve: for anything that isn't already a direct dependency it behaves like `bun add`, writing a fresh root `dependencies` entry at the latest major while leaving the transitive pin untouched (this happened with `nanoid`, which it "updated" to 6.0.1 in `dependencies` while `postcss` kept resolving 3.3.17). Go straight to a root `package.json` `overrides` entry, pinned to the major line the parent still accepts — `nanoid` stays on 3.x because `postcss` requires it and 4+ is ESM-only. Never hand-edit the lockfile; to undo a bad attempt, `git restore package.json bun.lock`. One moderate is genuinely upstream-blocked and stays: `drizzle-kit` still ships the deprecated `@esbuild-kit/esm-loader`, which hard-pins `esbuild ~0.18.20` (GHSA-67mh-4wv8-2f99, a dev-server issue drizzle-kit never triggers). It sits below the `high` gate, so it needs no `--ignore`. Keeping any of this current is Dependabot's job rather than a person's: `.github/dependabot.yml` covers **bun** (not `npm` — that ecosystem cannot read `bun.lock`), **cargo**, **github-actions**, **docker-compose** and **docker**, grouped so a week arrives as a few PRs instead of twenty, all aimed at `dev`. The catch that made every line of it useless for its first seventeen days is worth internalising: **Dependabot reads that config, and GitHub schedules `audit.yml`, from the default branch only.** Both had been added on `dev`; `main` had not moved since 2026-08-02; so the config was never seen and the nightly audit never ran, while `bun outdated` and a green CI both reported that nothing was wrong. Any time `main` falls behind `dev`, every scheduled and background job in this repo stops silently — no warning exists for it. Two surfaces stay out of Dependabot's reach and need a human: the pins inside `.github/actions/setup/action.yml` (composite actions are a known dependabot-core gap, issues #6704 and #7495) and the `oven/bun:1` / `oven/bun:1-alpine` tags, which float on purpose. A Dependabot PR bumping a **container image is not covered by its own green checks**, and the three that arrived on the first day made the point three different ways. CI runs `bun run build`, never `docker build`, and the test stack starts every service on an empty volume — so the checkmarks say nothing about whether the container starts or whether it can read the data already on disk. Verify by building the image and running it against a throwaway copy of the real thing: `alpine` 3.22→3.24 passed that (3.24 ships nginx 1.30.4 with a matching `nginx-mod-http-brotli`, and `brotli_static` still serves) and was merged; `postgres` 16→18 refuses to start on a PG16 data directory *and* moved its mount point to `/var/lib/postgresql`; `qdrant` v1.12→v1.19 panics on the older `segment.json`. Postgres majors are ignored in `.github/dependabot.yml` — a major is a `pg_upgrade` behind a maintenance window, never a merge — and `qdrant/qdrant` is excluded from the image group, because its breakage is *minor*-versioned and the majors-get-their-own-PR rule cannot see it. Both were then taken on 2026-08-29 as their own piece of work rather than a merge, and the stack now runs **postgres 18 / qdrant 1.19**: postgres moved by `pg_dumpall` and a restore onto a fresh volume mounted at `/var/lib/postgresql`, qdrant by scrolling every point out **with its vector** and upserting it back, which re-embeds nothing. `docs/09-deployment.md` carries the procedure; `npx confer-cli` probes for a 16 data directory before it starts anything, because the alternative is a container restarting in the background and the failure arriving three minutes later as a health-check timeout showing the gateway's logs and not postgres's. The ignore rules stay as they are — the next postgres major and the next qdrant minor will break in exactly the same way. The reassuring half of what was learned is that neither failure is silent: the postgres entrypoint recognises the old layout at *both* mount points and refuses to start rather than initialising an empty database beside it, which is the difference between a stopped instance and a lost one. ## Release rules Every release: merge to `main` first, then `git tag v* && git push origin v*` from main. Workflow rejects tags not reachable from `origin/main`. Run `.github/scripts/gen-release-notes.sh `, review draft, **translate ZH/JA sections** before publishing. Workflow auto-updates GitHub About + labels on finalize. Never publish untranslated placeholder text. `release.yml` is the one workflow CI cannot exercise — only a tag triggers it — so it has a rehearsal mode: dispatch it with an existing tag and `dry_run: true`, and it builds all four desktop targets and the Android APK, generates the notes, and publishes nothing (tauri-action treats an omitted `tagName`/`releaseName` as build-only). Run it after touching that file or any action it pins. One trap when editing those guards: GitHub's `a && b || c` yields `c` whenever `b` is falsy, and `''` is falsy — so the guard must read `!inputs.dry_run && value || ''` and never `inputs.dry_run && '' || value`, which would quietly hand back the real tag and cut a release in the middle of the rehearsal. `packages/cli` — the `confer-cli` npm package the README now leads with — is published **by hand**. No workflow does it, no tag triggers it. Since 0.6.2 its version tracks the app's: every app release republishes it under the same number (it was independent through 0.4.2, and 0.5.x was skipped on npm). Two things follow. `prepack` copies the repo's `docker-compose.ghcr.yml` into the tarball, so edits to that file reach `npx confer-cli` users only when someone republishes the CLI; changing it and shipping nothing is a silent divergence between the repo and what people actually run. And verify a publish by running the published artifact, never by `npm publish`'s exit code: 0.3.1 shipped with a broken entry guard — `argv[1]` is the `node_modules/.bin/confer` symlink while `import.meta.url` is already resolved, so `main()` never ran and `npx confer-cli` did nothing at all while exiting 0. `packages/cli/src/index.test.ts` now builds the bundle, symlinks it the way npm does and runs it under plain `node`, which is the only way that guard can be exercised at all. Publishing it is two authentications, and neither works the obvious way from an agent's shell (learned publishing 0.4.1, 2026-09-12). The `~/.npmrc` session token goes stale (`npm whoami` → 401); renew it with `npm login --auth-type=web --browser=false` run in the background, which prints a `npmjs.com/login?next=/login/cli/…` URL for the owner to open and polls until they have signed in. `npm publish` then needs the account's 2FA — a security key — and from a non-TTY shell it fails `EOTP` with the approval URL redacted to `***`, in the debug log too; run it under a pty, `script -q /dev/null npm publish --browser=false`, and it prints `npmjs.com/auth/cli/…` unredacted and waits for the key to be touched. Ignore `npm warn publish "bin[confer]" script name dist/confer.mjs was invalid and removed`: `@npmcli/package-json` prints that whenever it strips the leading `./` and then keeps the entry — `npm view confer-cli bin` shows it on every published version. Whether that bin *runs* is the separate question the 0.3.1 lesson is about, which is why the check that counts is `npm install confer-cli@` in a scratch directory followed by `node ./node_modules/.bin/confer --help`. ## Deployment After completing any code change (post-review, pre-commit), redeploy the affected service so the effect is immediately visible at http://localhost/. Determine which packages changed and run only the necessary steps: | Changed package | Deploy command | |----------------|----------------| | `packages/client` only | `./infra/deploy.sh client` | | `packages/gateway` only | `./infra/deploy.sh gateway` | | both / unsure | `./infra/deploy.sh` | Run from the repo root. Deployment happens **before** commit & push (not after). `deploy.sh` runs `bun run build`, rebuilds those images and restarts them, but first re-tags the image each service is about to replace as `:previous` — `docker compose build` overwrites `:latest` in place, so the outgoing image otherwise loses its name and the next prune reclaims it, which is how this stack spent its whole life with no way back from a bad deploy. `./infra/rollback.sh [service...]` undoes one by pointing `:latest` back at `:previous` and recreating the containers. It reverts **code only**: migrations are forward-only, so rolling an image back does not undo a migration that deploy applied. Both scripts read image names out of `docker-compose.prod.yml`, where they are declared explicitly rather than derived from compose's `-` rule. `deploy.sh` builds without `--pull`, and both Dockerfiles sit on a floating Bun tag — `oven/bun:1-alpine` for the gateway, `oven/bun:1` for the client's build stage — so a cached base image keeps whatever Bun it was pulled with. **Raising the Bun version therefore needs `docker pull` on both first**, or the containers ship the old runtime against a lockfile the new one generated — silently, because `bun install --frozen-lockfile` still succeeds across a minor. Verify with `docker compose -f docker-compose.prod.yml exec gateway bun --version`, not by reading the Dockerfile. That cached base is also what hides a **new** Bun breaking the Dockerfile, which is worse than shipping an old one and is not hypothetical: Bun 1.4 stopped hoisting workspace dependencies to the root `node_modules` and now installs each package's own as symlinks into a root `.bun` store, so the release stage's `COPY --from=install /app/node_modules` stopped carrying the dependencies at all and neither gateway nor migrate could resolve `drizzle-orm`. Every local image had been built against a cached pre-1.4 base, and CI runs `bun run build` and never `docker build`, so the repo looked green for the thirteen days the README's quick start was failing for anyone who cloned it. After pulling a new base, **build the images and start them** — `docker compose build && up`, then check the containers are actually `running` and a migration actually applies. A version string proves the runtime changed, not that the image works. The build context is the other half of that story, and `.dockerignore` patterns are anchored at the context root: `node_modules/` excluded only the top-level directory, so every `packages/*/node_modules` — bun's per-workspace symlink farm — rode into the image, and `COPY packages/client` overwrote the links `bun install` had just created with the host's. Those point into the `.bun` store by a name that carries a hash bun computes per version (`react-i18next@17.0.13+ea9c…` from the host's 1.4.2, `+2102…` under the image's 1.4.0), so the moment the host's Bun moved past the base image's, the links dangled and `tsc` reported forty `Cannot find module` errors for packages that were installed. It had been latent since the file was written and CI could never see it — a runner's checkout has no `node_modules` to copy. `**/node_modules/` and `**/dist/` are the fix (2026-09-12); a host-only artefact such as `.vite-temp` showing up inside the image is the tell. Migration files ride inside the `migrate` service, which runs out of the **gateway's own image** — one tag, two commands — on both the prod and the ghcr path. Until 2026-09-20 the prod file built it as a second tag, `confer-migrate:latest`, and that split is the whole reason this needed remembering: `deploy.sh` built `gateway client`, the migrate image went stale, and it then applied last month's migration set while still printing `Migrations complete`, leaving the new tables uncreated (the copy on the machine where this was found was 19 days behind the gateway's, and had not bitten only because the last migration happened to predate it). Sharing the tag makes that impossible rather than merely documented. The `build` stanza stays on **both** services, though — dropping it from `migrate` turns `docker compose build migrate` into a silent no-op (`No services to build`) and sends a bare `up -d migrate` off to a registry for an image that only ever exists locally. *Running* it was never the missing half: `gateway` declares `depends_on: migrate: service_completed_successfully`, so any `up` that brings the gateway up starts it and waits for exit 0 first. Verify a migration landed by querying the actual tables/columns (and the drizzle journal count), not by trusting the `Migrations complete` log line — and remember `docker ps` hides it, since a job container that exited 0 only shows under `ps -a`. ## Environment Local infra via Docker: `docker compose up -d` starts PostgreSQL (5432), MinIO (9000/9001), Qdrant (6333). Copy `.env.example` to `.env` before first run. Gateway dev server on :3000, client Vite on :1420 (proxies `/api` to gateway). ## Pitfalls - MCP SDK tool schema validator is strict — test with real Codex connection - `Bun.serve` WebSocket API ≠ Node `ws` - HTTP signatures: adding headers invalidates unless in signing set - DID document caching: respect TTL/ETag or auth breaks - Drizzle migrations: ALWAYS use `bun run db:generate`, never write SQL manually — the journal won't track it and schema gets out of sync requiring manual `ALTER TABLE` in prod (this bit us once: migrations 0002-0004 were hand-written and untracked; the journal was repaired by regenerating a tracked, idempotent `0002` from `schema.ts`) - Qdrant point IDs must be UUID or uint64 — ULIDs are rejected with 400; convert via SHA-256 hash (`toUUID` in `lib/qdrant.ts`) - Docker inter-container networking: use service names (`qdrant:6333`, `minio:9000`), not `localhost` — localhost resolves to the container itself - `peer_agents` rows are globally unique by DID — one peer connected to several users shares a single row and a single `peer_id`. Any query scoped only by `peer_id` is **not** tenant-isolated; always add the owner constraint (`conversations.created_by` / `*.user_id`). This produced a real cross-tenant A2A thread injection, fixed in `1a4308b`. **The gates now live in `gateway/lib/tenant.ts`** (`isContact` / `assertIsContact` / `assertIsConversationParticipant` / `assertOwnsConversation`) — use them instead of re-writing the query inline, which is how the bug happened four separate times. Each takes an optional `db` handle: that is the injection seam, and it exists precisely because `mock.module`-ing `getDb` poisons the whole process (see below) - **A2A federation needs HTTPS, not as hardening but as the mechanism.** `did:web` resolution is https-only (`parseDidWeb` always builds `https://`), so an instance on `localhost` or a bare IP publishes identities no peer can resolve — inbound A2A dies at `did_resolution_failed` before the signature is examined. `docker-compose.tls.yml` is the overlay that fixes it (Caddy, automatic certificates, `PUBLIC_HOST` = bare domain); `npx confer-cli --domain ` and `CONFER_DOMAIN=` in `oracle-bootstrap.sh` are the same thing from the two self-host paths. The overlay uses `ports: !override []` on `client` because compose MERGES sequences — a bare `ports: []` would leave the base mapping and collide with Caddy on 80. The `caddy` image declares no ENTRYPOINT, so `command` must start with `caddy` - **Bun closes an idle connection after 10 seconds by default**, and both long-lived responses here are silent for longer: an SSE turn writes nothing until the model's first token, and the consult long-poll waits up to 55s by design. `index.ts` sets `idleTimeout: 255` (Bun's maximum). The symptom is misleading enough to be worth naming — the gateway's own log prints a clean `200`, nginx returns a bare 502, and each looks like the other's fault; isolate by issuing the same request from **inside** the gateway container. nginx's `/api/` block also needs `proxy_buffering off` + a raised `proxy_read_timeout` + HTTP/1.1, or tokens arrive in one lump and anything past 60s is cut anyway - **`GET /api/v1/stream/:conv/:msg` calls the model and writes a row.** Requesting it twice for one message bought two completions and appended two answers (reproduced live, 25s apart) — a reload, a flaky connection or a second tab was enough. It now takes a process-local claim on the message id **before** reading for an existing reply: the obvious order loses to a turn that finishes and releases in between. Claims carry a TTL because no LLM call has a timeout — a hung provider would otherwise wedge that message forever, with no reply row to replay and every retry declined - **One A2A peer reaches you under two DIDs**, and which one you hold depends on how the contact was added. `from` and `/.well-known/agents.json` carry the AGENT did (`:agent`); the only DID that *resolves*, and the one the UI shows behind a copy button, is the owner's. So `to` accepts either (`findTargetAgent`), and peer lookup accepts `from` **or the verified signer DID** (`ensurePeerAgent`) — matching one alone made a contact added from a pasted DID 404, and turned the peer's own reply into a connection request from a stranger. Relatedly, a reply must echo the **asker's** `thread_id`: thread ids are per-side, `resolveOrCreateThread` correctly refuses a thread the caller doesn't own, and replying with ours filed the answer under a new conversation while the asker polled theirs — every consult sat at `pending` next to a good answer on both machines. `messages.thread_root` is `char(26)` for our own ULIDs: store the local conversation id, never the peer's raw value, which any peer could overflow into a 500. The receiving side needs the mirror of that rule: a thread id you don't recognise is not "no thread", it is *their* numbering, so derive the local conversation id from it (`derivedId('a2a-thread', ownerId, peerId, theirThreadId)`) instead of minting a new one. Treating it as absent opened a fresh conversation per inbound message — no history, and the owner's list full of one-line threads. Deriving also removes the create-race and needs no column; only the LAST part of a derived id may be variable-width or attacker-supplied, since `:` is not escaped - **A column with no way to set it is a dead feature, not a default.** `agents.is_public` had a schema column, an API field and two read paths, and nothing in the product ever wrote it — so `/.well-known/agents.json` was empty on every instance and search by name matched nobody, which made adding a contact impossible and A2A, consult and errands unreachable behind it. When auditing, ask of every gate: *what writes this?* - **An agent with nothing configured is a misconfiguration, not an auth failure.** Both turn paths defaulted the provider name to a hardcoded `'anthropic'`, so an agent whose owner never opened the settings tab dialled a vendor they have no key for and came back `401` — naming a company the owner may never have heard of. `lib/agent-model.ts` (`resolveAgentModel`) is now the single answer to "what does this agent run on", returning a machine code (`no_model_configured` / `unknown_provider` / `no_key_for_provider`) that the client words. A `keyIsBaseUrl` provider is exempt from the key check: a local runtime's empty slot means the catalogue's default address, not a missing credential - **On A2A, a failure that only logs is indistinguishable from one still in progress.** An answering side that logged and returned left the asker's `/consult/{id}/reply` long-poll running to its deadline and reporting `pending` — forever, on every retry. Every path that cannot produce an answer now sends the asker a `type: 'notification'` carrying the reason in `context.error` (`notification` because only a `question` provokes a reply, so it cannot loop). English prose rides in `content` as the fallback: the peer is another instance and does not share our locale, which is why the code, not the sentence, is the contract - **Two A2A bindings, one set of gates.** `/a2a/v1` serves the Linux Foundation HTTP+JSON binding (`routes/a2a-rest.ts` — the spec's own paths, `POST /message:send`, `GET /tasks/{id}`, …) beside Confer's native dialect (`routes/a2a.ts`). Only the wire format differs: signature verification, the consent gate, the policy decision and thread resolution all live in `a2a/inbound.ts` and both callers go through it. Writing that flow once per binding is exactly how the cross-tenant thread-injection bug got authored four separate times. The Agent Card advertises **only** the standard binding, because §5.1 requires every binding an agent declares to be functionally equivalent and the dialect has no task lifecycle — the dialect is discovered through `/.well-known/agents.json` instead. A task is not a new table: it IS the inbound message row, its `contextId` is the conversation, and its state is derived (reply → `COMPLETED`, `system_notice` reply → `FAILED`, pending `ask` permission → `AUTH_REQUIRED`, denied → `REJECTED`). Two outcomes have no task to return at all — an unconnected peer and a policy denial — and both answer `403` rather than minting a task id that would 404 on the next call. Also: Hono cannot express `/tasks/{id}:cancel`; `:id{[^:]+}:cancel` compiles and matches nothing, so those arrive as `POST /tasks/:target` and are split on the last colon. - **A signature that stops at `?` leaves the query string rewritable.** RFC 9421's `@path` excludes the query, so until the REST binding arrived — where `GET /tasks` filters and pages entirely through query parameters — nothing covered them. `signRequest` now adds `@query` whenever the URL has one and the verifier *requires* it in that case (mirroring the content-digest rule, so peers signing the query-less endpoints stay interoperable). The same change fixed a functional bug hiding behind it: `created` has second granularity, so two identical requests in one second signed to identical bytes and the receiver's replay cache rejected the second as an attack — any client polling a task, or retrying anything, got a 401 saying its credentials were bad. A per-request `nonce` parameter fixes that without weakening replay detection, since a true replay is still the same bytes. - **A turn that only logs its failure is indistinguishable from one still running — on three surfaces at once.** When `runAgentTurn` cannot run (no model, unknown provider, no key, provider threw), the reason is now written into the conversation as a `content_type: 'system_notice'` message with the code in `content_json`, not just sent to the peer. Without the row: the owner sees their peer's question followed by nothing forever, the REST task sits at `WORKING` instead of `FAILED`, and `/a2a/v1/stream/{id}` answers `pending` for good. The client words the sentence from the code (`lib/agent-failure-text.ts`, shared with the chat stream's error path) — the gateway has no locale context, so its English `content` is only a fallback for readers that are not our UI. - **`LLMStreamEvent.usage` was declared and never once set.** Both providers yielded a bare `{type:'done'}`, so every streamed turn — which is all of them, on both the chat and A2A paths — threw its token count away and an owner could not answer "what is this spending?" from anything the instance recorded. Anthropic splits usage across two frames (input on `message_start`, output on `message_delta`); OpenAI-compatible vendors put it on a final chunk whose `choices` array is empty or absent, so indexing into it unguarded throws *after* the answer has already streamed. `stream_options: {include_usage: true}` is deliberately never sent: one code path serves all eighteen catalogue entries and an unknown body field is a 400 at some of them — which ones is exactly the sort of per-vendor claim this codebase has been wrong about before. A vendor that volunteers nothing is recorded as `unreported`, never as zero. `lib/telemetry.ts` emits one line per turn carrying cost *and* grounding together, named with the OpenTelemetry GenAI attributes (`gen_ai.*`, `error.type`) so a collector is later a config change rather than a rewrite. No OTel SDK is wired up — nothing in this stack runs a collector, and exporting into the void is the Redis/NATS mistake again. The cost half is also kept per turn in `llm_usage` (`storeTurnUsage`, detached via `runDetached`), which is what `GET /api/v1/usage` and the settings Usage tab read: tokens only, never a price — per-model prices would be a vendor claim written down locally, the model-ID mistake again — and an unreported vendor stays `null`, never `0`. Only agent turns land there; memory extraction, embedding and rerank calls do not. - **The prompt is ordered for the cache: stable first, per-turn last.** Anthropic caches only up to a block marked `cache_control`, OpenAI-shape vendors cache a matching prefix on their own, and both are prefix matches in the order tools → system → messages — one changed byte and everything after it misses. So `runAgentTurn` sends: the system prompt (the agent's instructions, identical every turn), then the stored history, then the question with this turn's recalled memories in front of it, inside `` tags. Because that block now sits in the owner's own message, `formatMemoryLine` flattens each memory to one line and strips the tags from it — an `a2a` memory is distilled from text a peer wrote, and a newline or closing tag in it would otherwise let what follows pass for the owner speaking. Memories used to live in the system prompt, where each turn's different recall invalidated the whole conversation behind it; the history row keeps the *bare* question, which is what makes the next turn's prefix match. The last history message carries `cache_breakpoint: true` — a provider-neutral hint, dropped by `OpenAICompatibleProvider` — because it is where the next turn stops matching this one, and `AnthropicProvider` marks it, the system block, and (in `stream`) the conversation's last block: three of Anthropic's four breakpoints; if several messages are flagged, only the last counts, so a future caller cannot tip a request over the limit into a 400. Put anything turn-dependent into the system prompt or the history and the cache quietly stops working — nothing fails, turns just get slower and dearer. `stream-memory.integration.test.ts` checks the property on the wire (turn 2's request starts with turn 1's, byte for byte); the telemetry line is the production witness: `gen_ai.usage.cache_read.input_tokens` (hits) and `cache_creation.input_tokens` (writes, billed at 1.25× by Anthropic, so a write nothing reads is a cost). Anthropic's `input_tokens` excludes both, which is why `prompt_tokens` adds them back. The history window is sized for the same reason (`turnHistory` in `lib/conversation-history.ts`): at most 20 messages, but past that its start moves in whole steps of 10 rather than one message per turn — the plain newest-20 rule gave a long conversation a new opening every turn, so none of its history was ever reused. A long conversation therefore shows the model between 11 and 20 messages. Paging (`GET /conversations/:id/messages`) keeps `historyBefore` and its plain limit. The same change runs a round's tool calls concurrently (at most 4, in `boundedMap`) and reports them in call order; citations are collected per call for the same reason - **An inbound A2A turn must not be as capable as an owner's own turn.** `runAgentTurn` is shared by the web chat and the A2A answer path, and `resolveAgentCapabilities` used to hand both the same tools — so a connected peer's question searched every knowledge base the owner had and pulled their long-term memory into the prompt, with the answer going straight back over the wire. Nothing there was a tenant bug (the user id is the owner's throughout); the point is that **the peer's question and the owner's instructions reach the model as the same kind of text**, so "the agent will decline to reveal that" is not a boundary — only the set of documents the search can physically reach is. `resolveAgentCapabilities` therefore takes a required `audience` (`'owner' | 'peer'`, required rather than defaulted because the permissive value is what a forgotten argument lands on) and a peer turn gets `kbScope` = only the bases marked `shared_with_peers`, plus `recallMemory: false`. `runAgentTurn` takes the same required `audience`, because the tool set depends on it as well: `search_memory` and `list_contacts` read owner-only data and are never offered on a peer turn. Three traps if you touch this. `kb_ids` **is** in the `search_knowledge_base` schema now, so the model can aim after calling `list_knowledge_bases` — but that was never what enforced the scope: the model could always put it in the arguments and `executeToolCall` passes them through, which is why `narrowKbIds` intersects and never widens. `searchChunks` reads an **absent** kb_ids list as *search everything*, so an empty scope must resolve to a sentinel that matches nothing, never to `undefined`. And **not offering a tool is not access control** — a model can emit a call for a name it was never handed, so each owner-only branch in `executeToolCall` re-checks the audience at the point the call would actually run, not merely at the point the tool list is built - **Long-term memory is a write surface a peer can reach.** `extractAndStore` distils durable facts from *every* turn, and the A2A answer path calls it with the owner's `user_id` — so a connected peer's questions become rows in the owner's memory and come back, unattributed, inside the owner's own private chats, where "对方想了解我们的 Q3 数据" reads as something the owner wants. Memories therefore carry a `source` (`manual` / `auto` / `a2a`) on **both** stores: the Postgres row is what the owner reviews in the UI, and the Qdrant payload is what recall reads — recall never touches the row, so an origin written only to Postgres is invisible where it matters. Two consequences when touching this: every `upsertMemory` caller must state a source (the PATCH route carries the existing row's across, or an edit would silently relabel an `a2a` memory `manual`), and points written before this exist carry none, so an unknown origin has to read as unknown rather than be defaulted into the union - **Recall returning nothing has three causes that look identical.** Nothing stored, nothing above `RECALL_MIN_SCORE`, and rows that were never indexed all surfaced as an empty prompt fragment — and the third ran undetected for months (`a32e840`: UI-written memories only ever hit Postgres). `recallMemories` now returns its hits beside the fragment and `logTurnGrounding` prints one line per turn (`recall=3@0.62 kb=unsearched tools=1`), which is also the only signal that a model ignored the KB instruction: the prompt *mandates* searching before answering, and a model that skips it produces a fluent ungrounded answer that reads exactly like a grounded one. Counts and scores only — memory text and message content are PII - **A workspace install puts every workspace's dependencies in every image.** `bun install` in this monorepo resolves all six packages, so the gateway image shipped biome, the TypeScript compiler, rolldown, the Tauri CLI, lightningcss and happy-dom — a server carrying the desktop app's build chain, 1.2 GB where 363 MB does the job. `--production --filter '@confer/gateway' …` (naming the workspace *and* the three it depends on) is the fix; every workspace's `package.json` still has to be COPYed for `--frozen-lockfile` to validate. Two things that survive `--production` and surprise you: an **optional peer** dependency (i18next optionally peers on `typescript`, which is how 30 MB of compiler reached a server image) and a package pulled at two versions — `@napi-rs/canvas` arrived as four 25 MB Skia binaries, two versions × two libcs, because bun matches optional deps on os+cpu and has no libc axis. A root `overrides` entry dedupes the versions; the wrong libc has to be `rm -rf`'d, which is safe here only because the base image is fixed and a missing binary throws at the first PDF. And canvas is **not** removable despite reading as optional: pdfjs loads it to polyfill `DOMMatrix`, so without it even text extraction dies at import - **`docker images` lies about a foreign-architecture image.** The amd64 gateway reports 85 MB and contains 178 MB of `node_modules` on top of a 263 MB base. Measure a cross-built image with `du` inside it, not from the host - **Qdrant applies a write asynchronously unless you ask it not to.** Upserts carried `?wait=true` and deletes did not, so a deleted memory or document stayed searchable after its API call returned 200 — and the suite failed on any second local run, because the collection was then big enough for the write to lag. Symptom to recognise: a delete test that passes on an empty store and fails on a used one - **A gateway resolves its own DIDs from its own database** (`lib/did-resolution.ts`), never over the network. Fetching them back failed on every `PUBLIC_HOST=localhost` install (https vs. the http nginx serves) and is fragile behind NAT; answering locally is also stricter, since nobody controlling DNS can substitute a key for one of our own accounts. It mirrors exactly the two documents we publish — `/.well-known/did.json` and `/agents//did.json` — and reports anything else under our authority as not found rather than fetching our own 404. Use `resolveDidDocument`, not `resolveDID`, anywhere the DID might be ours - **Outbound A2A signs with the OWNER's key** (`owner_type: 'user'`, keyed by user id) because that is the only key registration mints and the only one `/agents//did.json` publishes. It queried `owner_type: 'agent'` until 2026-08-29 — a row nothing has ever written — so every consult and every A2A reply failed with `no_signing_key`. The one test covering it hand-seeded that row, which is the general lesson: **a fixture that invents a shape production cannot produce tests nothing.** Drive identity-adjacent tests through the real registration route - The gateway is **single-instance by design**. WS connections (`ws/handler.ts`), A2A replay nonces (`lib/nonce-cache.ts`) and rate-limit counters (`middleware/rate-limit.ts`) are all process-local `Map`s. A second replica silently breaks A2A replay protection — the replay hits the other replica's empty nonce table and is accepted. Redis/NATS were removed from compose and `env.ts` on 2026-08-07 because nothing ever dialed them; don't re-add them as decoration. Scaling out means moving those three first, nonce foremost - User-facing text belongs on the **client**, behind i18n. The gateway has no locale context, so anything it words itself reaches en/ja users in Chinese. `permission.request` therefore ships structured facts only (`@confer/shared`'s `permissionRequestEventSchema`) and `client/src/lib/permission-text.ts` renders the sentence. Strings sent to an **LLM** (tool descriptions, system prompts in `orchestration/` and `tools/`) are a different thing and stay where they are - LLM / embedding / Tavily keys live encrypted in `users.llm_keys_json` (AES-256-GCM via `ENCRYPTION_KEY`), set per-user via the settings UI — **not** in `.env`. The `TAVILY_API_KEY` env var is only a fallback; `web_search` is offered only when a key resolves - **`mockFetch` cannot see DNS, and the SSRF guard resolves before it fetches.** `@confer/identity`'s `assertPublicHostname` runs a real `node:dns` lookup on every DID host with a 5s deadline — the same 5s bun gives a test — so every signed request in the gateway suite queried the OS resolver for `peer.example`, and a CI runner whose resolver sat on that NXDOMAIN produced a timed-out test reporting `401 did_resolution_failed` (#75: once in 25 runs, never locally, and the 401 pointed at signatures). `src/test/setup.ts` stubs `node:dns/promises` for the whole gateway process — every name answers from TEST-NET-3, `localhost` stays loopback so the contact lookup's guard still refuses it — and `test/dns-stub.test.ts` pins that the stub reaches the guard across the package boundary. The identity package solved its own instance with IP-literal fixtures (`did:web:203.0.113.10`); the gateway has too many hostname fixtures for that. The same change closed two more untracked-write gaps of the `4161dae` class: the inbound A2A turn (`a2a/inbound.ts`) and the WebSocket handler's presence/subscription/read-ack work now go through `runDetached`, so `settleDetached()` joins them before a truncate - Run tests as `bun run test`, never `bun test` — the bare form bypasses the `bunfig.toml` preload (test env + per-test truncation) and points at the shared **dev** DB - Any client file importing `@confer/shared` needs the alias in `packages/client/tsconfig.json` `paths` — the root tsconfig `exclude`s `packages/client`, and CI type-checks it separately (`npx tsc --noEmit` + `vite build` inside that dir). Local `node_modules` symlinks hide the breakage; only CI catches it - In gateway, don't `mock.module` anything touching `getDb`/`getEnv` in unit tests — it pollutes the process globally and takes the real-stack integration tests down with it (this once caused 102 false failures). Test infra-touching code via integration tests instead - Zod must resolve to **one** copy. `@modelcontextprotocol/sdk` accepts `^3.25 || ^4.0`, and bun will happily nest its own v3 alongside our v4 — the SDK's `AnySchema` then comes from a different `zod/v4/core` declaration and every `server.tool()` call fails to typecheck (51 errors, none of them in our code). The root `overrides.zod` entry fixes it, but only after `bun install --force`: a plain install leaves the stale nested resolution in the lockfile - Zod 4 changed `.default()` to take the schema's **output** type. Anywhere the fallback is a raw input that must still run through parsing — `z.object({...}).default({})` relying on inner defaults, or `.transform(...).default('false')` — use `.prefault()` instead, which is the v3 behaviour. Also `z.record(v)` now requires the key type: `z.record(z.string(), v)` - Zod 4 rewrote validation error text (`"Required"` → `"Invalid input: expected string, received undefined"`). That text ships to clients in `error.details`, so treat it as an API-visible string, not an internal detail - TypeScript 7 no longer auto-collects `@types` from parent `node_modules`, and it errors on side-effect imports of non-TS files (TS2882). `packages/client/tsconfig.json` therefore declares `"types": ["bun", "vite/client"]` explicitly — dropping it breaks `bun:test` imports and `import './index.css'` even though the local symlinked install looks fine - Every package must declare what it imports. `gateway` and `client` both `import ... from 'zod'` while declaring nothing, resolving it through the root devDependency — deleting that root entry broke CI's typecheck, build and test while local stayed green, because the stale hoisted `node_modules/zod` symlink was still lying around. Auditing dependencies is **two** questions, not one: declared-but-unused *and* used-but-undeclared. And any dependency removal must be re-verified after `rm -rf node_modules packages/*/node_modules && bun install` — a plain reinstall does not prune stale symlinks, so local resolution keeps working long after the declaration is gone - Tailwind is v4: there is **no `tailwind.config.js`**. Theme lives in `@theme { --color-*: … }` inside `src/index.css`, custom classes use `@utility`, and PostCSS loads `@tailwindcss/postcss` (autoprefixer is built in and was removed). Biome needs `css.parser.tailwindDirectives` on or it fails to parse that file - The client image is **Alpine's nginx**, not `nginx:alpine`. Brotli is a dynamic module and only Alpine's repo ships one built against a matching nginx; nginx.org's module set (which the official image uses) has none. Two consequences: the server block lives in `/etc/nginx/http.d/`, not `conf.d/`, and reverting the base image makes `brotli_static` an **unknown directive**, which is fatal — the container will not start at all. `infra/client.Dockerfile` precompresses every js/css/html/svg/json/txt in `dist` with brotli -11 and gzip -9 at build time; `brotli_static`/`gzip_static` serve those and fall back to the plain file on their own, so the two can never disagree about `Content-Encoding` - Locale resources are dynamically imported per language (`src/i18n/index.ts`), and i18next no longer initialises on import — `main.tsx` awaits `initI18n()` and tests get it from `src/test/setup-dom.ts`. Switch languages via the exported `changeLanguage`, never `i18n.changeLanguage`, which would announce the switch before the bundle exists. Two non-obvious constraints: the `import()` specifiers must be written out literally (a computed one makes Rollup bundle all three back in), and `main.tsx` must use `.then()` rather than a **top-level await** — awaiting makes the entry an async module, and Rollup responds by hoisting shared modules into separate chunks, which fragmented the login path into five files and cost more in lost compression context than the split saved - `zod/mini` is **not** a bundle win here, measured: converting the client's schemas made the chunk 1.7 KB *bigger*. The 69 KB that zod contributes is almost entirely `zod/v4/core`, which mini needs too — only dropping zod outright would recover it, at the cost of hand-rolled validation of untrusted socket frames - **MinIO's images are gone from both registries, and the stack runs SILO instead.** `minio/minio` on Docker Hub began answering "repository does not exist" on 2026-09-12, and the move to `quay.io/minio/minio` bought thirteen days: by 2026-09-25 Quay answered `401` to anonymous pulls of `minio/minio` and `minio/mc` alike, while `coreos/etcd` beside them still answered 200, and the upstream repository is archived. Each time CI's test stack, the quick start and every `npx confer-cli` install died together, and a machine with the image cached saw nothing wrong. All four compose files now pull `pgsty/silo` (PGSTY's maintained fork, formerly `pgsty/minio`, public source at `github.com/pgsty/silo`), pinned to a release tag. It keeps the `minio` service name, the `MINIO_ROOT_*` variables, the `server /data` command (its entrypoint maps `minio`/`server` onto `silo`) and the on-disk format. That last claim was checked against a copy of the real volume, not taken from the release notes: every object mirrored out of SILO diffed identical to the live MinIO's, and a write round-tripped. Its release notes also say upstream MinIO/MC compatibility is best effort, so give a SILO bump the same test as any other image upgrade before merging it. `confer-cli` copies the compose file into its tarball at pack time, so a registry change reaches `npx` users only when the CLI is republished by hand