diff --git a/internal/app/archiegateway/chat_identity.go b/internal/app/archiegateway/chat_identity.go index 5ee4a890f..6008dbac5 100644 --- a/internal/app/archiegateway/chat_identity.go +++ b/internal/app/archiegateway/chat_identity.go @@ -9,9 +9,7 @@ import ( // // 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 -// (it travels in the transport-only Inbound.BudgetKey instead). Treating a URL or a shared token as an identity +// not users. Treating 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. // diff --git a/internal/contracts/gateway/v1/chat.pb.go b/internal/contracts/gateway/v1/chat.pb.go index ed996007c..03ee8069a 100644 --- a/internal/contracts/gateway/v1/chat.pb.go +++ b/internal/contracts/gateway/v1/chat.pb.go @@ -148,15 +148,8 @@ type Message struct { Text string `protobuf:"bytes,6,opt,name=text,proto3" json:"text,omitempty"` Page string `protobuf:"bytes,7,opt,name=page,proto3" json:"page,omitempty"` At *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=at,proto3" json:"at,omitempty"` - // budget_key is the source an inbound message is charged against by the - // Gateway's inbound rate limiter, for a channel that has no per-person - // sender id but does have a stable, operator-controlled source of its own - // -- a webhook's configured route path. Transport-only: a channel frontend - // sets it on inbound and it is never persisted, exactly like page. Empty - // means the message is not rate limited. - BudgetKey string `protobuf:"bytes,9,opt,name=budget_key,json=budgetKey,proto3" json:"budget_key,omitempty"` // platform is the channel that carried this message ("telegram", "email", - // "webhook", "web"), as the frontend that owns that channel knows it. It is + // "web"), as the frontend that owns that channel knows it. It is // how the Gateway learns which channel it is serving: one Router serves every // channel, so its own name is "web" even for a Telegram turn, which made // Source.Platform -- the first component of the session natural key -- a @@ -260,13 +253,6 @@ func (x *Message) GetAt() *timestamppb.Timestamp { return nil } -func (x *Message) GetBudgetKey() string { - if x != nil { - return x.BudgetKey - } - return "" -} - func (x *Message) GetPlatform() string { if x != nil { return x.Platform @@ -3388,7 +3374,7 @@ const file_gateway_v1_chat_proto_rawDesc = "" + "\n" + "created_at\x18\t \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x12@\n" + "\x0elast_active_at\x18\n" + - " \x01(\v2\x1a.google.protobuf.TimestampR\flastActiveAt\"\xea\x02\n" + + " \x01(\v2\x1a.google.protobuf.TimestampR\flastActiveAt\"\xdd\x02\n" + "\aMessage\x12\x1d\n" + "\n" + "message_id\x18\x01 \x01(\tR\tmessageId\x12\x1b\n" + @@ -3399,13 +3385,13 @@ const file_gateway_v1_chat_proto_rawDesc = "" + "\x04from\x18\x05 \x01(\tR\x04from\x12\x12\n" + "\x04text\x18\x06 \x01(\tR\x04text\x12\x12\n" + "\x04page\x18\a \x01(\tR\x04page\x12*\n" + - "\x02at\x18\b \x01(\v2\x1a.google.protobuf.TimestampR\x02at\x12\x1d\n" + - "\n" + - "budget_key\x18\t \x01(\tR\tbudgetKey\x12\x1a\n" + + "\x02at\x18\b \x01(\v2\x1a.google.protobuf.TimestampR\x02at\x12\x1a\n" + "\bplatform\x18\n" + " \x01(\tR\bplatform\x12'\n" + "\x05media\x18\v \x03(\v2\x11.gateway.v1.MediaR\x05media\x12\x1b\n" + - "\tsender_id\x18\f \x01(\tR\bsenderId\"|\n" + + "\tsender_id\x18\f \x01(\tR\bsenderIdJ\x04\b\t\x10\n" + + "R\n" + + "budget_key\"|\n" + "\bToolCall\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\x12\x1e\n" + diff --git a/internal/domain/messaging/inbound.go b/internal/domain/messaging/inbound.go index 7c4de8ff2..0863a3132 100644 --- a/internal/domain/messaging/inbound.go +++ b/internal/domain/messaging/inbound.go @@ -14,9 +14,6 @@ type Inbound struct { // this message. Transport-only: it reaches the system prompt and // is never persisted. Empty for non-web channels. Page string - // BudgetKey is the rate-limit key for a channel with no per-person sender, - // such as a webhook route. Not persisted. Empty means not limited. - BudgetKey string // Platform is the channel that carried the message. Not persisted. Empty // falls back to the gateway's name. Platform string diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 1f191a399..0856af6b0 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -176,7 +176,7 @@ type Router struct { // important enough to fail the turn over. Log *slog.Logger // Limiter enforces a per-(gateway, source) inbound budget, keyed by - // inboundBudgetKey. Nil disables it. + // sender. Nil disables it. Limiter *ratelimit.Limiter // Dedup declines a redelivered platform message inside its TTL. Nil disables // it. @@ -229,25 +229,16 @@ func (r *Router) SessionTracker() *sessionTracker { // budget, in place of normal dispatch. const rateLimitReply = "You're sending messages too quickly. Please wait a moment and try again." -// checkRateLimit reports whether in is over its source's inbound budget. -// A nil Limiter (rate limiting not configured) or no key to charge the -// message against (see inboundBudgetKey) always allows. +// checkRateLimit reports whether in is over its sender's inbound budget. +// A nil Limiter (rate limiting not configured) or no sender always allows. func (r *Router) checkRateLimit(in Inbound) (blocked bool) { - key := inboundBudgetKey(in) + key := in.Message.SenderID if r.Limiter == nil || key == "" { return false } return !r.Limiter.Allow(r.gatewayName, key) } -// inboundBudgetKey returns the channel's BudgetKey when set, else SenderID. -func inboundBudgetKey(in Inbound) string { - if in.BudgetKey != "" { - return in.BudgetKey - } - return in.Message.SenderID -} - // Route dispatches msg and returns the reply. Gateway-local commands // are handled directly; everything else goes to the LLM responder. func (r *Router) Route(ctx context.Context, in Inbound) (string, error) { diff --git a/internal/infrastructure/gatewayrpc/values.go b/internal/infrastructure/gatewayrpc/values.go index 48ad38e8d..e4dd89b8b 100644 --- a/internal/infrastructure/gatewayrpc/values.go +++ b/internal/infrastructure/gatewayrpc/values.go @@ -59,12 +59,11 @@ func storedValue(v *pb.Message) messaging.Message { } // inboundProto renders a channel message and its transport context in wire -// shape. Page, BudgetKey and Platform ride along; the record's role does not, for +// shape. Page and Platform ride along; the record's role does not, for // the reason storedProto gives. func inboundProto(v messaging.Inbound) *pb.Message { m := storedProto(v.Message) m.Page = v.Page - m.BudgetKey = v.BudgetKey m.Platform = v.Platform m.Media = inboundAttachmentProtoList(v.Media) return m @@ -82,7 +81,7 @@ func inboundValue(v *pb.Message) messaging.Inbound { msg.Role = messaging.RoleUser // The record keeps the metadata the store persists; the transport media // carries the bytes the turn model reads, which the record must not hold. - return messaging.Inbound{Message: msg, Page: v.Page, BudgetKey: v.BudgetKey, Platform: v.Platform, Media: inboundAttachmentValueList(v.GetMedia())} + return messaging.Inbound{Message: msg, Page: v.Page, Platform: v.Platform, Media: inboundAttachmentValueList(v.GetMedia())} } func toolProto(v messaging.ToolCallEvent) *pb.ToolCall { diff --git a/internal/infrastructure/gatewayrpc/wire_test.go b/internal/infrastructure/gatewayrpc/wire_test.go index e9fca06dd..47ee40432 100644 --- a/internal/infrastructure/gatewayrpc/wire_test.go +++ b/internal/infrastructure/gatewayrpc/wire_test.go @@ -9,9 +9,9 @@ import ( // TestChatWireKeepsGatewayInputs pins the fields the Gateway decides on // across the messaging-to-gateway hop. func TestChatWireKeepsGatewayInputs(t *testing.T) { - in := messaging.Inbound{Message: messaging.Message{SenderID: "42"}, BudgetKey: "/hooks/a", Platform: "telegram"} + in := messaging.Inbound{Message: messaging.Message{SenderID: "42"}, Platform: "telegram"} got := inboundValue(inboundProto(in)) - if got.Message.SenderID != "42" || got.BudgetKey != "/hooks/a" || got.Platform != "telegram" { + if got.Message.SenderID != "42" || got.Platform != "telegram" { t.Fatalf("inbound round trip lost a field: %+v", got) } } diff --git a/internal/webui/api_config.go b/internal/webui/api_config.go index afee73940..d45c70ea0 100644 --- a/internal/webui/api_config.go +++ b/internal/webui/api_config.go @@ -77,8 +77,6 @@ func channelViewFromStatus(status status.Status) ChannelView { switch status.ID { case "telegram": view.Description = "Talk to Archie and approve its work from your phone." - case "webhook": - view.Description = "Lets another service push messages to Archie over HTTP." case "email": view.Description = "Email Archie a task and receive replies through its inbound SMTP listener." } diff --git a/proto/buf.yaml b/proto/buf.yaml index 7a9a9506f..fdbbe93ad 100644 --- a/proto/buf.yaml +++ b/proto/buf.yaml @@ -27,6 +27,9 @@ breaking: # Control-plane requests stopped naming their org or raw audit records: the # State Store derives the org from the caller, so those fields are removed # (numbers and names reserved). + # + # Message.budget_key went with the webhook chat channel (number and name + # reserved). An older channel extension that still sets it is ignored. ignore_only: FIELD_SAME_TYPE: - state/v1/state.proto @@ -37,3 +40,4 @@ breaking: FIELD_NO_DELETE: - state/v1/state.proto - controlplane/v1/controlplane.proto + - gateway/v1/chat.proto diff --git a/proto/gateway/v1/chat.proto b/proto/gateway/v1/chat.proto index 909afba7f..f2a3334a1 100644 --- a/proto/gateway/v1/chat.proto +++ b/proto/gateway/v1/chat.proto @@ -52,15 +52,10 @@ message Message { string text = 6; string page = 7; google.protobuf.Timestamp at = 8; - // budget_key is the source an inbound message is charged against by the - // Gateway's inbound rate limiter, for a channel that has no per-person - // sender id but does have a stable, operator-controlled source of its own - // -- a webhook's configured route path. Transport-only: a channel frontend - // sets it on inbound and it is never persisted, exactly like page. Empty - // means the message is not rate limited. - string budget_key = 9; + reserved 9; + reserved "budget_key"; // platform is the channel that carried this message ("telegram", "email", - // "webhook", "web"), as the frontend that owns that channel knows it. It is + // "web"), as the frontend that owns that channel knows it. It is // how the Gateway learns which channel it is serving: one Router serves every // channel, so its own name is "web" even for a Telegram turn, which made // Source.Platform -- the first component of the session natural key -- a