Gateway wire contract carries no channel dimension, so per-user identity never resolves #1255

Closed
opened 2026-10-27 13:39:39 +00:00 by sam · 0 comments
Owner

Found while implementing archie-core-ga6i/oyna. ga6i landed on main as 28f7d2a0, with the identical patch to the lane commit 56fc7231 this issue originally cited. oyna was subsequently closed by a different route (1fe4691b) which did NOT need this issue; see consequence 2.

EVIDENCE (re-verified on main)

  • gateway.NewRouter(b.stateStore, nil, "web") at internal/app/archied/gateway_runtime.go is the SOLE production Router.
  • Every session write stamps Platform from r.gatewayName: internal/gateway/session_commands.go (the resolve path, via the r.gatewayName argument to sessionTracker.resolve, plus handleNew and the branch handler). CORRECTION: earlier revisions pointed at internal/app/archied/session_commands.go -- the file is internal/gateway/session_commands.go, and the resolve path takes a platform parameter whose only production supplier is r.gatewayName. The substance is unchanged.
  • The LLM turn runner is built with the literal channel "web" (internal/app/archied/gateway_runtime.go, the only caller of makeChatLLMResponder; gateway.NewTurnRunner has one non-test constructor call at internal/app/archied/chat_setup.go), so UserIdentity: userIdentityResolver(channel) is fed "web" for every turn and Subject.UserID is always empty in production.
  • Channels cannot supply the channel today: client.Route is a gRPC hop from archie-messaging to that one Gateway (internal/infrastructure/gatewayrpc, dialled at internal/app/archiemessaging/run.go); messaging.Inbound carries no platform; pb.RouteRequest is { Message message = 1; } (proto/gateway/v1/chat.proto) and Message carries no platform either.

CONSEQUENCES

  1. The per-user identity allowlist is real code that no production call site reaches with a real channel name.

  2. This issue does NOT block archie-core-oyna, and oyna is closed. oyna's recorded fix direction needed this issue, but that direction was abandoned: the route path no longer enters SenderID at all, so no channel dimension is needed to stop it becoming a user identity (1fe4691b). This issue therefore stands on its own remaining scope only -- consequences 1, 3, 4 and 5.

  3. The session-memory curator's criterion 4 (a pass writes a record a later turn reads) does not hold end to end for any channel: the curator writes agent-user memory addressed to a real sender id, while the turn reads with UserID always empty, so the read names agent and global scopes only (domain/memory.Subject.Scopes).

  4. SessionSource.Platform is the FIRST COMPONENT OF THE SESSION NATURAL KEY: sessionStore.GetByChannel filters WHERE platform = ? AND channel_id = ?, and sessionTracker.resolve matches on BotUser/ChannelID/ThreadID for the rows it returns. It is a constant today, so nothing separates channels at the key level. The field's own documentation calls it "the adapter name (telegram, discord, web)" (internal/domain/messaging/session_store.go) and it is false for every non-web channel. Two costs follow for any fix: a collision needs a Telegram numeric chat id to equal an email recipient or a route path, so that is latent rather than live; and stamping the truthful platform changes live session lookup, because Save upserts excluded.platform. A chat with no /new re-resolves onto the same deterministic id and heals silently, but a chat whose active session came from /new or /branch falls back to the deterministic session once, orphaning that session's history until the operator picks it from /sessions.

  5. Two further call sites hard-code r.gatewayName in that same lookup and would silently stop finding their own sessions if only the session-creation path were fixed: internal/gateway/session_commands.go's topic list and topic-switch handlers, both of which take a messaging.Message rather than an Inbound. session_tools.go has four more, and already takes platform as a parameter.

  6. A green test asserts unreachable policy: internal/app/archied/chat_identity_test.go covers userIdentityResolver("webhook")/("telegram")/("email") for channels the sole production call site never passes. The wiring -- the Gateway's TurnRunnerConfig.UserIdentity is built from the real channel of the session it serves -- has no test and cannot pass today.

FIX DIRECTION

Thread the channel through RouteRequest/Inbound/SessionSource, following the precedent pb.Message.page sets for transport-only inbound context, and decide whether a turn runner is per-channel or per-message. A per-channel Router is not available -- there is exactly one Gateway process -- so the live choice is per-message vs a per-channel runner cache.

Then either accept the session-key change in consequence 4 and document the one-time active-session reset, or carry the channel in a new field and leave SessionSource.Platform as the gateway name, in which case Platform's own documentation has to stop claiming it names the adapter. That is a wire-contract decision for the maintainer, not a mechanical seam.

Close reason

Fixed in 3cdaba25 (2026-09-22): pb.Message.platform carries the channel (telegram/email/webhook set it), Router.sessionPlatform stamps SessionSource.Platform from it for every session lookup including the topic handlers and session tools, and userIdentityResolver reads the platform per inbound. The one-time active-session re-resolve was accepted.


Imported from beads archie-core-c1qx · GitHub #1045 · type bug · priority P1 · created 2026-09-21 · closed 2026-09-26

Found while implementing archie-core-ga6i/oyna. ga6i landed on main as 28f7d2a0, with the identical patch to the lane commit 56fc7231 this issue originally cited. oyna was subsequently closed by a different route (1fe4691b) which did NOT need this issue; see consequence 2. EVIDENCE (re-verified on main) - gateway.NewRouter(b.stateStore, nil, "web") at internal/app/archied/gateway_runtime.go is the SOLE production Router. - Every session write stamps Platform from r.gatewayName: internal/gateway/session_commands.go (the resolve path, via the r.gatewayName argument to sessionTracker.resolve, plus handleNew and the branch handler). CORRECTION: earlier revisions pointed at internal/app/archied/session_commands.go -- the file is internal/gateway/session_commands.go, and the resolve path takes a platform parameter whose only production supplier is r.gatewayName. The substance is unchanged. - The LLM turn runner is built with the literal channel "web" (internal/app/archied/gateway_runtime.go, the only caller of makeChatLLMResponder; gateway.NewTurnRunner has one non-test constructor call at internal/app/archied/chat_setup.go), so UserIdentity: userIdentityResolver(channel) is fed "web" for every turn and Subject.UserID is always empty in production. - Channels cannot supply the channel today: client.Route is a gRPC hop from archie-messaging to that one Gateway (internal/infrastructure/gatewayrpc, dialled at internal/app/archiemessaging/run.go); messaging.Inbound carries no platform; pb.RouteRequest is { Message message = 1; } (proto/gateway/v1/chat.proto) and Message carries no platform either. CONSEQUENCES 1. The per-user identity allowlist is real code that no production call site reaches with a real channel name. 2. This issue does NOT block archie-core-oyna, and oyna is closed. oyna's recorded fix direction needed this issue, but that direction was abandoned: the route path no longer enters SenderID at all, so no channel dimension is needed to stop it becoming a user identity (1fe4691b). This issue therefore stands on its own remaining scope only -- consequences 1, 3, 4 and 5. 3. The session-memory curator's criterion 4 (a pass writes a record a later turn reads) does not hold end to end for any channel: the curator writes agent-user memory addressed to a real sender id, while the turn reads with UserID always empty, so the read names agent and global scopes only (domain/memory.Subject.Scopes). 4. SessionSource.Platform is the FIRST COMPONENT OF THE SESSION NATURAL KEY: sessionStore.GetByChannel filters WHERE platform = ? AND channel_id = ?, and sessionTracker.resolve matches on BotUser/ChannelID/ThreadID for the rows it returns. It is a constant today, so nothing separates channels at the key level. The field's own documentation calls it "the adapter name (telegram, discord, web)" (internal/domain/messaging/session_store.go) and it is false for every non-web channel. Two costs follow for any fix: a collision needs a Telegram numeric chat id to equal an email recipient or a route path, so that is latent rather than live; and stamping the truthful platform changes live session lookup, because Save upserts excluded.platform. A chat with no /new re-resolves onto the same deterministic id and heals silently, but a chat whose active session came from /new or /branch falls back to the deterministic session once, orphaning that session's history until the operator picks it from /sessions. 5. Two further call sites hard-code r.gatewayName in that same lookup and would silently stop finding their own sessions if only the session-creation path were fixed: internal/gateway/session_commands.go's topic list and topic-switch handlers, both of which take a messaging.Message rather than an Inbound. session_tools.go has four more, and already takes platform as a parameter. 6. A green test asserts unreachable policy: internal/app/archied/chat_identity_test.go covers userIdentityResolver("webhook")/("telegram")/("email") for channels the sole production call site never passes. The wiring -- the Gateway's TurnRunnerConfig.UserIdentity is built from the real channel of the session it serves -- has no test and cannot pass today. FIX DIRECTION Thread the channel through RouteRequest/Inbound/SessionSource, following the precedent pb.Message.page sets for transport-only inbound context, and decide whether a turn runner is per-channel or per-message. A per-channel Router is not available -- there is exactly one Gateway process -- so the live choice is per-message vs a per-channel runner cache. Then either accept the session-key change in consequence 4 and document the one-time active-session reset, or carry the channel in a new field and leave SessionSource.Platform as the gateway name, in which case Platform's own documentation has to stop claiming it names the adapter. That is a wire-contract decision for the maintainer, not a mechanical seam. ### Close reason Fixed in 3cdaba25 (2026-09-22): pb.Message.platform carries the channel (telegram/email/webhook set it), Router.sessionPlatform stamps SessionSource.Platform from it for every session lookup including the topic handlers and session tools, and userIdentityResolver reads the platform per inbound. The one-time active-session re-resolve was accepted. --- _Imported from beads `archie-core-c1qx` · GitHub #1045 · type bug · priority P1 · created 2026-09-21 · closed 2026-09-26_
sam added the highbug labels 2026-10-27 13:39:39 +00:00
sam self-assigned this 2026-10-27 13:39:39 +00:00
sam closed this issue 2026-10-27 13:39:39 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#1255