Skip to content

fix(gateway): 未连接远程时发布队列快照不再报 outbound stream is offline - #952

Merged
xiaozhou26 merged 1 commit into
Stack-Cairn:v2-kbrianfrom
AlphaCatMeow:fix-gateway-offline-queue-event-warning
Oct 10, 2026
Merged

xiaozhou26 merged 1 commit into
Stack-Cairn:v2-kbrianfrom
AlphaCatMeow:fix-gateway-offline-queue-event-warning

Conversation

@AlphaCatMeow

Copy link
Copy Markdown
Contributor

关联

Closes #949

根因

前端 useChatTurnQueue.ts 的 publishChatQueueSnapshot() 在每次队列变化(入队/出队)时调用 gateway_publish_chat_queue_event。后端 GatewayController::publish_chat_queue_event 无条件 send_agent_envelope,而未启用/未连上 Gateway 时 current_outbound_sender() 固定返回 Err("gateway outbound stream is offline"),前端 catch 后 console.warn。

同类的尽力而为发布早已把离线当作正常状态:publish_settings_sync 离线直接 Ok(()),runtime status 发布用字符串匹配吞掉离线错误。队列快照是唯一不一致的路径。

改动

  • connection.rs:离线文案提取为常量 GATEWAY_OUTBOUND_OFFLINE_ERROR,新增 ignore_gateway_outbound_offline(),只吞精确的离线错误,其它发送失败照常上抛。
  • chat.rs:publish_chat_queue_event 离线时返回 Ok(());信封构造拆为 build_chat_queue_event_envelope() 以便测试。
  • chat_inbox.rs:runtime status 发布改用同一个 helper,替换原来的 contains("outbound stream is offline")。
  • 前端不改:真实发送失败仍会 console.warn,告警依然有意义。

测试

  • 新增 3 个单测:离线被忽略、其它错误(lock poisoned / control lane offline / lane closed)仍上抛、队列事件信封字段正确。
  • cargo test --no-default-features --lib services::gateway:79 passed, 0 failed。

实测(Windows 11 · tauri dev · Gateway enabled=true / online=false)

通过 WebView2 CDP 订阅 console 计数:

evidence

修复前(排队场景,console 2 条 warn) 修复后(同场景,0 条)
before after

未处理

Issue 附注里的 [MCP][BRIDGE][WARN] Script injection request: not available 来自仅开发构建使用的 tauri-plugin-mcp-bridge,按 issue 说明留给维护者决定。

未启用或未连上 Gateway 时,publish_chat_queue_event 把出站流离线当作错误返回,
前端每次排队变化都会 console.warn 一次。改为与 runtime status 发布一致:
离线时视为无需投递直接返回 Ok,真实发送失败仍然上抛。
离线错误文案提取为常量 GATEWAY_OUTBOUND_OFFLINE_ERROR,避免字符串匹配漂移。

Closes Stack-Cairn#949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants