Repository navigation
fix(remote-access): 修复远程设备上机构模型一直加载失败(关联 #333) - #338
Merged
freedomkk-qfeng merged 2 commits intoNov 19, 2026
Merged
Conversation
…ntext Node's WebSocket can take over an idle connection of the global fetch pool, and its events then run in the async context of the request that opened that connection. With the relay on the model gateway's origin that is a model call, made inside dsh-oidc's authorization scope. Every request of a remote device inherited the scope, and once the member signed in again the device's model picker failed with "Gateway authorization changed; start a new model request" (ECNU#333). Open the relay sockets as a WebSocket that dispatches its events in the context it was opened in.
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.
关联 #333
问题与修改
#333:华为平板通过学校中继打开模型选择器,“华东师范大学”分组每次都报
Gateway authorization changed; start a new model request,关掉重开、刷新远程页面都不恢复。同一时间电脑上能列出学校模型;平板上的对话和其他服务商的模型都正常。原因:电脑连中继的 WebSocket 接着用了一次模型请求留下的网络连接,那次请求的授权就跟着进了平板的每个请求。
WebSocket会复用全局fetch连接池里的空闲连接。复用时,它的事件运行在当初打开这条 TCP 连接的那次请求的异步上下文里,而不是new WebSocket()时的上下文。Node 24.18、24.22.1(桌面版内置的版本)和 26.13 都是这样。AuthorizationScopedAdapter的storage.run(授权, …)里用全局fetch请求网关,请求结束后连接留在池里。resolveApiKey从上下文里取到的正是它,于是每次都报错。对话每次都会新建授权,所以不受影响;电脑上的请求不经过这条连接,所以正常。plugin.ts里的loadContext让远程访问在插件加载时的上下文里启动,但它只管得到new WebSocket()那一刻,管不了复用来的连接。修改:
src/relay-link/link.ts新增HostSocket:继承WebSocket,打开时记下当时的异步上下文,所有事件都在这个上下文里派发。控制连接和每条设备连接都改用它。这样不管底层连接是从哪来的,平板的请求都在远程访问启动时的上下文里处理。验证
npm run check:类型检查、构建、89 个测试通过。新增的测试先在一份“授权”里向中继所在的域名发一次请求,再启动连接,检查设备发来的消息在干净的上下文里处理。去掉修复时这个测试失败(拿到的是那次请求的上下文);加上修复后,在 Node 24.18、24.22.1、26.13 上都通过。RemoteAccess、加密通道和隧道,加上 dsh-oidc 的AuthorizationScopedAdapter,网关和中继同源。按“电脑上对话 → 平板配对 → 重新登录 → 平板取模型列表”的顺序:修改前,平板报Gateway authorization changed; start a new model request,电脑正常;修改后,平板也能列出模型。兼容性
0.1.8 — Unreleased条目。