Skip to content

Commit 7e0fe73

Browse files
committed
chore(release): v0.4.0 - High Availability, Progressive Discovery, and Stability Improvements
1 parent 15ee224 commit 7e0fe73

21 files changed

+1285
-430
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.4.0] - 2026-01-14
6+
### 🚀 High Availability & Scalability
7+
- **Failover Mechanism**: Implemented automatic Guest-to-Host promotion. If the Host process dies, a Guest detects usage of the port/lock and takes over immediately with data persistence.
8+
- **Progressive Discovery**: Added `search_projects` tool. Allows AI to find relevant projects by query without loading the entire 1000+ project registry, reducing context usage.
9+
- **Immediate Handshake**: Implementing Request Buffering allows the server to accept IDE requests immediately (<10ms) while the Host Election runs in background (~300ms). Fixes startup race conditions.
10+
- **Stability**: Added explicit E2E tests for process failover (`tests/failover.test.ts`) and request buffering (`tests/buffered_requests.test.ts`).
11+
512
## [0.3.9] - 2026-01-11
613
### 🚀 Online First Architecture
714
- **Performance**: Removed top-level blocking await for election. Server now starts in <300ms (Online First), reducing startup time by 99% in congested networks.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
```
9393

9494
- **Zero Config**: Just run `npx @datafrog-io/n2n-nexus` - no `--id` or `--host` required.
95-
- **Auto Election**: First instance binds port 5688 and becomes Host; others join as Guests.
96-
- **Cross-Project Sync**: All IDEs share the same Hub, enabling real-time cross-project meetings.
97-
- **Hot Failover**: If Host disconnects, a Guest automatically promotes within 10 seconds.
95+
- **Immediate Handshake**: Stdio connects instantly (<10ms) for static requests (`tools/list`), buffering dynamic requests until election completes.
96+
- **Parallel Election**: Concurrent port scanning ensures Host/Guest resolution in <300ms.
97+
- **Hot Failover**: If Host disconnects, a Guest automatically promotes itself to Host and others reconnect.
9898

9999
## 🚀 Quick Start
100100

docs/ARCHITECTURE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,18 @@ To ensure clarity and prevent collisions in the flat local namespace, all Projec
6161
| `bot_` | Bots (Discord, Slack, DingTalk, etc.) | `bot_auto-moderator` |
6262
| `infra_` | Infrastructure as Code, CI/CD, DevOps scripts | `infra_k8s-config` |
6363
| `doc_` | Pure technical handbooks, strategies, roadmaps | `doc_coding-guide` |
64+
65+
## 🌐 Host-Guest Network Architecture (v2)
66+
67+
### Zero-Config Startup & Election
68+
The system aims for a "magic" user experience where multiple instances on the same machine automatically discover each other without manual configuration.
69+
70+
1. **Parallel Race Election**: Upon startup, every instance scans the first 5 ports (5688-5692) concurrently (<300ms).
71+
2. **Role Resolution**:
72+
* **Host**: If a port is free, the instance binds it and becomes the Host.
73+
* **Guest**: If a Host is found, the instance connects via SSE (Server-Sent Events) and becomes a Guest.
74+
3. **Immediate Handshake**: The `StdioServerTransport` connects immediately (<10ms) to the IDE. Static requests (`tools/list`) are served locally, preventing IDE timeouts. Dynamic requests are **buffered** until the election concludes.
75+
76+
### Failover & Resilience
77+
* **Smart Proxy**: Guest instances proxy IDE requests to the Host via HTTP/SSE. They handle backpressure and buffering to prevent data loss during connection blips.
78+
* **Auto-Failover**: If the Host process terminates (e.g., user closes the Host IDE window), Guest instances detect the connection loss (via `ECONNREFUSED` or SSE `end`) and trigger a **Re-Election**. One of the surviving Guests will promote itself to become the new Host, restoring the cluster automatically.

docs/ARCHITECTURE_zh.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ Nexus_Storage/
4141
**自我修复 (Self-healing)**: 核心数据文件(如 `registry.json`, `discussion.json`)具备自动检测与修复机制。如果文件损坏或意外丢失,系统会自动重建初始状态,确保服务不中断。
4242

4343
**多并发安全 (Concurrency Safety)**: 对共享文件(`discussion.json`, `registry.json`)的所有写入操作均受 `AsyncMutex` 锁保护,防止多个 AI 代理同时通信时发生竞争条件。
44+
45+
## 🌐 Host-Guest 网络架构 (v2)
46+
47+
### 零配置启动与选举
48+
系统旨在提供“魔法般”的用户体验,同一台机器上的多个实例无需手动配置即可自动发现并组网。
49+
50+
1. **并行竞速选举**: 启动时,每个实例并发扫描前 5 个端口 (5688-5692) (<300ms)。
51+
2. **角色解析**:
52+
* **Host**: 如果发现空闲端口,实例绑定该端口并成为 Host。
53+
* **Guest**: 如果发现已有 Host,实例通过 SSE (Server-Sent Events) 连接并成为 Guest。
54+
3. **立即握手**: `StdioServerTransport` 对 IDE 的连接是立即完成的 (<10ms)。静态请求(如 `tools/list`)由本地直接响应,避免 IDE 超时;动态请求被**缓冲**,直到选举完成。
55+
56+
### 故障转移与高可用
57+
* **智能代理 (Smart Proxy)**: Guest 实例通过 HTTP/SSE 将 IDE 请求代理给 Host。它们处理背压和缓冲,防止网络抖动导致数据丢失。
58+
* **自动故障转移**: 如果 Host 进程终止(例如用户关闭了 Host IDE 窗口),Guest 实例会检测到连接断开(通过 `ECONNREFUSED` 或 SSE `end`),并触发 **重新选举**。其中一个幸存的 Guest 将自动晋升为新的 Host,自动恢复集群服务。

docs/ASSISTANT_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Nexus 助手协作指令 (v0.3.0)
1+
# Nexus Assistant Guide
22

33
你现在是 **n2ns Nexus** 协作网络的一员。该系统集成了实时通信、结构化资产管理、**异步任务流 (Task Primitives)** 以及 **全局 Hub 架构 (v0.3.0)**,所有操作均落地在本地文件系统。
44

docs/CHANGELOG_zh.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
本项目的所有重大变更都将记录在此文件中。
44

5+
## [0.4.0] - 2026-01-14
6+
### 🚀 高可用与高扩展 (High Availability & Scalability)
7+
- **Failover Mechanism**: 实现了自动的 Guest-to-Host 故障转移。如果 Host 进程意外退出,Guest 会检测到端口/锁释放并立即接管 Host 角色,同时保证数据持久性。
8+
- **Progressive Discovery**: 新增 `search_projects` 工具。允许 AI 根据意图搜索相关项目,而无需读取包含 1000+ 项目的完整注册表,大幅节省 Token。
9+
- **Immediate Handshake**: 实现了请求缓冲机制 (Request Buffering),允许 Server 在 Host 选举 (~300ms) 完成前就立即接受 (<10ms) IDE 的请求,彻底解决了启动时的竞态条件。
10+
- **Stability**: 增加了针对进程故障转移 (`tests/failover.test.ts`) 和请求缓冲 (`tests/buffered_requests.test.ts`) 的端到端测试。
11+
12+
## [0.3.9] - 2026-01-14
13+
### 🚀 故障切换与立即握手
14+
- **立即握手**: 实现了基于缓冲区的设计,Stdio 启动后 <10ms 内即可响应,不再阻塞 IDE 等待选举。
15+
- **自动故障切换**: 新增了 `Failover` 机制。如果 Host 进程被杀或崩溃,存活的 Guest 会在检测到连接断开后立即触发重新选举,并自动晋升为新 Host。
16+
- **零配置 V2**: 进一步优化了启动流程,完全无需用户干预即可组建高可用集群。
17+
518
## [0.3.5] - 2026-01-10
619
### 协议与稳定性
720
- **修复 (僵尸 Host)**: 实现了“智能重试”和“重新选举”逻辑。如果 Guest 反复连接到僵尸 Host(握手成功但 SSE 断开),现在会自动触发重新选举流程,将坏端口加入黑名单,并在必要时在从端口上将自身提升为 Host。

docs/README_zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
```
9393

9494
- **零配置**: 只需运行 `npx @datafrog-io/n2n-nexus` — 无需 `--id``--host`
95-
- **自动选举**: 首个实例绑定 5688 端口成为 Host;其余自动加入为 Guest
96-
- **跨项目同步**: 所有 IDE 共享同一个 Hub,实现实时跨项目会议
97-
- **热故障转移**: 若 Host 断开,Guest 将在 10 秒内自动升迁
95+
- **立即握手**: Stdio 瞬间响应 (<10ms) 静态请求 (`tools/list`),动态请求自动缓冲
96+
- **并行选举**: 并发端口探测保证选举过程在 <300ms 完成
97+
- **热故障转移**: 若 Host 断开,Guest 自动检测并选举成为新 Host,实现自动修复
9898

9999
## 🚀 快速启动
100100

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datafrog-io/n2n-nexus",
3-
"version": "0.3.9",
3+
"version": "0.4.0",
44
"description": "Modular MCP Server for multi-AI assistant coordination",
55
"main": "build/index.js",
66
"type": "module",
@@ -41,6 +41,7 @@
4141
"start": "node build/index.js",
4242
"dev": "tsc -w",
4343
"test": "vitest run",
44+
"test:integration": "vitest run tests/integration.test.ts tests/failover.test.ts tests/meeting.test.ts tests/guest_connection.test.ts",
4445
"lint": "eslint src/**",
4546
"prepublishOnly": "npm run build"
4647
},

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const PORT_RANGE_START = 5688;
1717
export const PORT_RANGE_END = 5800;
1818

1919
// Timeouts (milliseconds)
20-
export const HANDSHAKE_TIMEOUT = 500;
20+
export const HANDSHAKE_TIMEOUT = 200;
2121
export const HEARTBEAT_INTERVAL = 30000;
2222

2323
// Task cleanup

0 commit comments

Comments
 (0)