Repository navigation
修复:会话粘性写入收成唯一出口 + 失效日志(issue #2) - #4
Open
xrj-dsh-agent wants to merge 1 commit into
Open
xrj-dsh-agent wants to merge 1 commit into
xrj-dsh-agent wants to merge 1 commit into
Conversation
xrj-dsh-agent
force-pushed
the
agent/fix-sticky-routing-0c9e9cb8d18c
branch
2 times, most recently
from
November 3, 2026 12:31
23df757 to
83f1378
Compare
xrj-dsh-agent
force-pushed
the
agent/fix-sticky-routing-0c9e9cb8d18c
branch
2 times, most recently
from
November 3, 2026 14:25
c85bb59 to
17463fa
Compare
1. 修复:自定义提供商成功分支漏写会话粘性 —— 内置 / 会话式 / 自定义三条成功 路径收成一个 remember_session 出口,空键、TTL 档位、清除代次等判据下沉到 StickySessions::bind,新增转发路径不会再因为「忘了调 sticky_bind」而静默 不粘。 2. 修复:会话粘滞列表按查询档位淘汰绑定 —— 打开一次管理页(auto 5 分钟档) 会把 6 小时档的绑定一起清掉;改为按每条绑定自己的 TTL 清理,读取不再有 副作用(查找只判不删,也不再改写写下时的 TTL)。 3. 新增:粘性失效/变化日志(logs 表)—— account-switch、identity-changed、 evicted-ttl、evicted-capacity、cleared、skipped-empty-key(每进程一次)、 skipped-stale-generation。 4. 优化:会话键提取链与来源标签同源(不再两份名单),补不带 x- 前缀的 opencode-session / session-affinity;请求日志的路由快照新增 stickySource, 直接看出这次会话键来自哪个字段。 5. 测试:绑定→查找闭环、TTL 过期、列表读取不淘汰、来源标签一致性、选路层 「同会话第二条请求命中并置顶」。
xrj-dsh-agent
force-pushed
the
agent/fix-sticky-routing-0c9e9cb8d18c
branch
from
November 3, 2026 15:07
17463fa to
afd9056
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is by an automated agent, not a human.
修复 issue #2(上游 aimod-cc#443):
routingSticky = session不生效、route.stickyHit恒为 false、会话映射从未记录。根因
粘性有两个半边,任何一侧漏掉都不会报错 —— 请求照样成功、账号照样轮换,只有
requests.route.stickyHit悄悄一直是 false:attempt_custom成功分支里没有sticky_bind(内置家与会话式路径有),所以经自定义提供商转发的会话从来不粘 —— 与 issue 里「写入或查找至少一侧是死代码」的受控实验结论一致(order策略下账号本来就固定,stickyHit仍恒为 false)。logs表里没有任何记录,所以「根本没写」和「写了但每次都被淘汰」在外部看起来完全一样。选用的会话键
RouteState::conversation_key,显式标识优先、内容哈希兜底(顺序即优先级,端点无关):AH-Thread-Id(AxonHub 会话级;AH-Trace-Id是单条消息级,刻意不用)X-Opencode-Session→X-Session-Id→X-Session-Affinity→(不带x-的Opencode-Session/Session-Affinity)prompt_cache_key(经翻译网关接入时唯一能拿到的那条)metadata.user_id(Claude Code 的 v2 JSON / legacy 形态)Session_id/Session-Id,或X-Codex-Turn-Metadata里的session_id显式标识有 256 字符长度闸;超限按内容哈希处理(来源标签也随之如实报
content-hash)。写入与查找路径
attempt_queue的三条成功出口(内置无状态 / 会话式 / 自定义)→ 唯一remember_session→StickySessions::bind。键 =SHA-256(模型小写 + "\0" + 会话键),值 = 账号 id + 来源标签 + 时间。空会话键、TTL 为 0(off / turn 档)、清除代次变化都在bind里判,调用方不再各写一份闸门。select_target_account→snapshot_for_model(conv_key, 请求模型, now, TTL)→plan_route把命中账号置顶并置stickyHit=true(账号不可用时如实报 false 并让位,行为未改)。order/rotate/ 家内轮询三条策略的选择行为未改动:粘性只影响「置顶哪一个」,不改变策略排序本身。本次改动
/api/routing/sticky列表按「查询档位」淘汰绑定(切到 auto 看一眼会把 6 小时档的绑定全清掉)→ 改为按每条绑定自己的 TTL 清理;选路查找同理 —— 当前档位更短时只是「本轮不沿用」,不再顺手删掉别人写下的绑定,读取与短档位都没有破坏性副作用。logs表):account-switch、identity-changed、evicted-ttl、evicted-capacity、cleared、skipped-empty-key(会话键为空,每进程提示一次)、skipped-stale-generation。x-前缀的两个写法;请求日志的路由快照新增stickySource,直接看出这次会话键来自哪个字段(只记标签,不记原始键值)。验证
手工复现(同一会话键连发两条完全相同的请求):
预期:第 2 行
stickyHit=1、stickySource='X-Session-Id'、picked与第 1 行相同;GET /api/routing/sticky能看到该绑定的keyPreview/hits/source。改用不带显式标识的请求时,stickySource='content-hash'且背靠背两条同样命中。影响面与限制
stickyHit的既有语义未改:只有「查到绑定 且 该账号本轮可用并被置顶」才为 true;账号禁用 / 冷却 / 熔断时仍报 false(会记account-switch说明换到了谁)。stickySource字段。pipeline.rs不再在差异里 —— main 已有同一处修复)。🤖 本条回复由 AI Agent 生成
Generated by an AI agent.