fix(server): isolate session cookie per port to prevent login conflicts across instances

This commit is contained in:
JOJO 2026-05-31 23:35:07 +08:00
parent f2d7d8f3b1
commit ad20853965

View File

@ -1334,6 +1334,11 @@ def initialize_system(path: str, thinking_mode: bool = False):
def run_server(path: str, thinking_mode: bool = False, port: int = DEFAULT_PORT, debug: bool = False):
"""运行Web服务器"""
if not os.environ.get("WEB_SESSION_COOKIE_NAME"):
# 浏览器 Cookie 按域名/路径隔离,不按端口隔离。
# 同一台机器同时启动 8091/8092 等多个实例时,若都使用默认 "session"
# 登录 Cookie 会互相覆盖,表现为两个端口无法同时保持登录。
app.config['SESSION_COOKIE_NAME'] = f"agents_session_{port}"
initialize_system(path, thinking_mode)
start_background_jobs()
socketio.run(