translate: find first user message regardless of leading system/developer prompt - #1073
Conversation
|
PR author is not in the allowed authors list. |
|
@aminsamir45 have a look |
|
Thank you for this — you found a real bug that had been hiding in plain sight. I've opened #1078 as a rewrite so it lands against our internal conventions. To be clear: none of this is your fault — these conventions are internal, still evolving, and genuinely not discoverable from the outside. Your diagnosis and fix are the substance of that PR, and you're credited via What changed, for next time:
Your tests carried over as-is; the subtests read well. Thanks again for digging into the session-key path — this one was a genuinely good find. |
Summary
Fixes
FirstUserMessageTextininternal/translate/envelope.goto find the first message withrole == "user"by walking the messages array instead of only checkingmessages.0.Problem
In OpenAI Chat Completions and envelopes with leading
systemordeveloperprompts,messages.0is notrole == "user". As a result,FirstUserMessageText()returned an empty string"". When deriving session keys (DeriveSessionKey), this caused all OpenAI conversations under the same API key sharing a standard system prompt to derive identical session keys, leading to session pin collisions, cross-session pin thrashing, and degraded cache affinity.Changes
FirstUserMessageTextto iterate throughmessagesto find the firstrole == "user"block across all supported wire formats.internal/translate/envelope_extras_test.gofor leading system and developer messages.internal/proxy/session_key_test.goasserting that independent OpenAI conversations sharing a system prompt produce distinct session keys.internal/proxy/conformance_golden_test.gofor cross-platform test stability.