fix(runtime): 隔离线程任务上下文 (#6420)

* fix(runtime): isolate thread task contexts

* test: use canonical message schema import
This commit is contained in:
InfinityPacer
2026-08-23 20:10:23 +08:00
committed by GitHub
parent 45b41a5caa
commit 146f8649f6
8 changed files with 154 additions and 16 deletions
+11 -2
View File
@@ -3,6 +3,7 @@ import threading
import time
import uuid
from concurrent.futures import ThreadPoolExecutor
from contextvars import Context, copy_context
from dataclasses import dataclass, field
from typing import Any, Callable, Optional, Protocol
from urllib.parse import urlparse
@@ -288,7 +289,11 @@ class BrowserSessionHelper:
executor = cls._get_existing_session_executor(session_key)
if executor:
future = executor.submit(
context = copy_context()
# 会话线程保持空底层上下文,每次操作只使用当前调用快照。
future = Context().run(
executor.submit,
context.run,
cls._run_session_task,
session_key,
cls._close_session_in_thread,
@@ -387,7 +392,11 @@ class BrowserSessionHelper:
for _ in range(2):
executor = cls._get_session_executor(session_key)
try:
future = executor.submit(
context = copy_context()
# 会话线程保持空底层上下文,每次操作只使用当前调用快照。
future = Context().run(
executor.submit,
context.run,
cls._run_session_task,
session_key,
callback,