feat: Antigravity 会话粘性选号(防会话内跨账号漂移) - #410
Open
neverforget-1 wants to merge 1 commit into
Open
neverforget-1 wants to merge 1 commit into
neverforget-1 wants to merge 1 commit into
Conversation
同一会话固定使用同一上游凭证:提高上游上下文缓存命中, 并消除同一场对话 sessionId 出现在多个账号上的风控信号。 - credential_manager: get_valid_credential 支持 sticky_file 优先选号; 新增 StickySessionStore(进程内会话→凭证绑定,TTL 30 分钟,容量上限 2048) - sqlite/psql/mongodb: get_next_available_credential 支持 preferred_filename 优先排序(仅影响排序,不绕过 disabled/冷却/preview 过滤) - antigravity: stream/non_stream 按会话指纹粘性选号,换号后重绑定; 发往上游的请求字节完全不变 - 存储层 SQL 全部改为固定字符串 + 白名单值替换,DDL 逐列字面量内联 (配合静态扫描加固,行为不变) - 新增 tests/test_sticky_credential.py(上游 .gitignore 忽略 tests/,此处强制纳入)
This branch has not been deployed
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.
背景 / Background
多账号场景下,
get_valid_credential每次请求都随机选号。同一会话的多轮对话可能在轮换后落到不同凭证上,导致:方案 / Solution
为 Antigravity 模式增加会话粘性选号:
sessionId(或首条用户消息的稳定哈希)派生会话指纹StickySessionStore记录 会话指纹 → 凭证 的绑定(带缓存命中)改动范围 / Scope
src/api/antigravity.py:流式/非流式请求接入粘性选号src/credential_manager.py:get_valid_credential支持sticky_file参数 +StickySessionStoresrc/storage/{sqlite,mongodb,psql}_manager.py:三个存储后端的绑定读写tests/test_sticky_credential.py:新增测试测试 / Testing
pytest tests/test_sticky_credential.py:2 passedEnglish TL;DR: Add session-sticky credential selection for Antigravity mode. Session fingerprint (sessionId or first-user-message hash) is bound to the last-used credential; retries after rotation refresh the binding. Requests without a stable fingerprint fall back to random selection. Includes tests for all three storage backends.