fix(webhook): keep a route path out of the sender identity

A webhook set SenderID to its configured route path. The turn path reads that
field through a per-channel resolver which refuses webhook, but the session
curator derives its participant from the raw field with no channel filter, so a
webhook session with exactly one distinct sender and one extracted fact wrote
agent-user memory addressed to User: "/hooks/...". Nothing reads it, and every
pass added more, because the facts are identical strings with no dedup.
docs/prds/memory-engine-unification.md criterion 7 requires that a route path
never become a user identity.

Clear it at the producer rather than teaching every consumer which channels are
lying: a route path is a source, not a person, so it no longer enters SenderID.
It still keys the inbound rate limit, where it is the documented per-source
budget for webhooks (config.RateLimitConfig), so it travels in the new
transport-only Inbound.BudgetKey -- carried on the wire beside Page, never
persisted, and never read as an identity.

pb.Message gains budget_key (field 9) for the same reason page (field 7) exists:
transport context that rides with an inbound message and is deliberately absent
from storedProto's rendering of a canonical record.

The curator needs no change. An empty SenderID already fails closed as an
unidentified user message, which is the path a dashboard session takes, and
sessionParticipant's existing skip covers it; the test name now says so.
This commit is contained in:
sam committed 2026-09-22 03:18:59 +10:00
1 parent 5f8c27a0a4
commit 708233a538
16 files changed
+220 -74

No files matched your search

+12 -9
View File
@@ -36,11 +36,13 @@ Three further defects fall out of the same split:
string`, and the curator fills it with a **session id** (`sessioncurator.go`)
— which is none of the four scopes `docs/architecture/agent-system.md`
requires, and stops meaning anything when the session ends.
3. **The chat turn has no user identity on half the channels.** `SenderID` is
populated by Telegram and email (a person) and by webhook (a **route path**,
`webhook.go`), and not at all by the dashboard, whose gateway wire message
carries no sender field. It is also never persisted: `sender_id` appears
nowhere in `session_store_sqlite.go`.
3. **The chat turn has no user identity on half the channels.** Telegram and
email populate `SenderID` with a person; the dashboard populates it with
nothing, and a webhook populates it with nothing either — a route path names
a source, not a person, so `webhook.go` leaves `SenderID` empty and carries
the route in `Inbound.BudgetKey` for rate limiting. `sender_id` is persisted
(`session_store_sqlite.go`), so whatever a channel puts there reaches the
consumers that read it.
`agent-system.md` says the write-scope selection and cross-scope sharing
rules "require a focused memory design decision". This is that decision.
@@ -149,10 +151,11 @@ UserIdentity func(msg messaging.Message) (IdentityID, bool)
```
This must be injectable rather than a blanket `channel + ":" + SenderID`
concatenation, because a **webhook's `SenderID` is a route path**
(`webhook.go`), not a person; treating it as one would give a URL an
identity. Telegram and email supply their sender id; the dashboard and webhook
resolve nothing.
concatenation, because a channel's sender id is not necessarily a person: a
webhook's route path names a source, and treating it as an identity would give
a URL one -- which is why `webhook.go` leaves `SenderID` empty and carries the
route in `Inbound.BudgetKey` instead. Telegram and email supply their sender
id; the dashboard and webhook resolve nothing.
**Fail closed.** When `UserID` is empty the turn proceeds with global and agent
scopes only, and a write targeting `user` or `agent-user` fails with a clear