Files
archie/internal/app/archied/chat_identity.go
T
sam 708233a538 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.
2026-09-22 03:18:59 +10:00

47 lines
1.9 KiB
Go

package archied
import (
"github.com/samcharles93/archie-core/internal/domain/memory"
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
// userIdentityResolver returns the gateway.TurnRunnerConfig.UserIdentity
// function for one channel, per docs/prds/memory-engine-unification.md §3:
// resolution is supplied per channel by the composition, never inferred by
// the engine or guessed from a channel-neutral "channel:SenderID"
// concatenation.
//
// Telegram and email carry a native per-person sender id (a Telegram numeric
// user id, an SMTP from address). The dashboard ("web") has one bearer
// token, not users, and a webhook carries no per-caller identity at all: its
// route path is a source, not a person, and never enters SenderID
// (internal/channels/webhook/webhook.go -- it travels in the transport-only
// Inbound.BudgetKey instead). Treating a URL or a shared token as an
// identity would give it the same standing as a real user, which the read
// path's isolation guarantee depends on never happening. Both resolve
// nothing, so a turn on either channel gets global and agent scopes only
// (Subject.WritableScopes' fail-closed behaviour).
func userIdentityResolver(channel string) func(messaging.Message) (memory.IdentityID, bool) {
switch channel {
case "telegram", "email":
return senderIDIdentity
default:
return noUserIdentity
}
}
// senderIDIdentity resolves a channel's own SenderID as the user's identity.
// Empty means the channel carries no per-person identity for this message.
func senderIDIdentity(msg messaging.Message) (memory.IdentityID, bool) {
if msg.SenderID == "" {
return "", false
}
return memory.IdentityID(msg.SenderID), true
}
// noUserIdentity resolves nothing: the channel it is wired to (the
// dashboard, a webhook) carries no per-person identity at all.
func noUserIdentity(messaging.Message) (memory.IdentityID, bool) {
return "", false
}