Skip to content

fix(hosts): reconnect idle SSH hosts during aggregation - #5099

Merged
7Sageer merged 2 commits into
release/2026-11-19from
fix/ssh-idle-aggregation-1119
Nov 19, 2026
Merged

7Sageer merged 2 commits into
release/2026-11-19from
fix/ssh-idle-aggregation-1119

Conversation

@7Sageer

@7Sageer 7Sageer commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

SSH Host 空闲退出后,跨 Host 的项目列表、会话列表和按 ID 查找可能持续漏掉远端数据。Web 和桌面端依赖代理 WebSocket 唤醒远端,首屏查询可能先返回。只轮询列表的 KAP 客户端会持续拿到部分结果。

Bug Reproduction Steps

  1. 连接一个带项目和会话的 SSH Host。
  2. 关闭连接该 Host 的界面,让本地服务继续运行。等远端在没有活跃会话或 WebSocket 的情况下空闲退出。
  3. 重复调用 GET /api/v1/workspaces?hosts=include 与 GET /api/v1/sessions?hosts=include。项目列表缺少该 Host 的项目,会话列表把它列入 unavailable_hosts,而 GET /api/v1/hosts 仍报告 ready。

Root Cause

SSH 以退出码 0 结束后,桥接会清空会话连接并保留 ready,等待有请求时再连接。代理请求能触发连接,聚合查询原先只读取现有连接。修复把聚合也接入按需连接。

Code Changes

sequenceDiagram
    participant API as 跨 Host 查询
    participant Fanout as Host 聚合
    participant SSH as SSH 桥接
    API->>Fanout: 读取项目或会话
    Fanout->>SSH: 获取会话连接
    alt 已连接
        SSH-->>Fanout: 返回现有连接
    else 先前连接后正常退出
        Fanout->>SSH: 按需唤醒,共享在途连接
        alt 2 秒内连接成功
            SSH-->>Fanout: 返回恢复的连接
        else 等待超时或连接失败
            Fanout-->>API: 仅使用可用来源
        end
    end
Loading

sshKapBridge.ts 负责识别正常退出的桥接并复用在途连接。hostFanout.ts 限定单次等待时间,超时后在途连接仍可以完成。项目列表、会话列表、按 ID 查询远端会话共用这条路径。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
查询跨 Host 项目和会话 正常退出的 Host 被立即跳过,直到有其他请求建立连接 查询会唤醒该 Host,等待最多 2 秒,连接成功后包含远端数据 使用 SSH 项目的 Web、桌面端,以及调用 hosts=include 的 KAP 客户端。调用方的超时预算可能受冷启动影响 仅需本机数据的 API 客户端可省略 hosts=include
按 ID 查找远端会话 正常退出的 Host 会使查找返回 HOST_UNAVAILABLE 使用同一唤醒机制,等候超时仍走原有不可用处理 使用远端会话 ID 的客户端,首次查询可能等待 SSH 冷启动 已知 Host 时,可直接使用该 Host 的代理入口

回归覆盖并发项目与会话查询共用一次 SSH 连接,以及慢启动超时后下一次查询能获取远端数据。验证使用模拟 SSH 进程和真实服务端路由。

验证
  • 主分支基底上 kap-server 全量 1,420 项测试通过。
  • 在 release/2026-11-19 基底上,Host 聚合、SSH 桥接、空闲退出和 API 快照共 80 项测试通过,类型检查及改动文件的 lint 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue. 本次复现步骤在正文中。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset. 按此次发布安排省略 changeset。
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d35fe76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T10:14:22.915612Z d35fe76 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@7Hanrui

7Hanrui commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d35fe76
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d35fe76

commit: d35fe76

@7Hanrui

7Hanrui commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: d35fe7666d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Sageer
7Sageer merged commit 44bcf37 into release/2026-11-19 Nov 19, 2026
16 checks passed
@7Sageer
7Sageer deleted the fix/ssh-idle-aggregation-1119 branch November 19, 2026 10:21
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