From 9c61d991bd7ac787222c50e225b7bdb7183e5161 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Wed, 15 Jul 2026 16:48:02 +0800 Subject: [PATCH] feat(onebot): report stalled receive health Separate account login state from receive-path health in get_status. A logged-in account remains online while good becomes false only after the receive path has been confirmed stale. Apply the same health value to OneBot lifecycle and heartbeat events so API polling and event consumers observe consistent status semantics. Regenerate the MCP action catalog with the clarified contract and add regression coverage for the online-but-degraded response. Refs #233. --- packages/mcp/src/generated/catalog.json | 4 ++-- packages/mcp/src/generated/catalog.ts | 4 ++-- packages/onebot/src/actions/info.ts | 7 +++---- packages/onebot/src/instance.ts | 4 ++-- packages/onebot/tests/status-health.test.ts | 18 ++++++++++++++++++ 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 packages/onebot/tests/status-health.test.ts diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index 5d55e7c8..bf0e73e1 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -5689,7 +5689,7 @@ { "name": "get_status", "aliases": [], - "returns": "运行状态。`online`/`good` 均表示账号是否在线。", + "returns": "运行状态。`online` 表示账号在线;`good` 仅在接收链路确认停滞时为 `false`。", "returnsSchema": { "type": "object", "properties": { @@ -5699,7 +5699,7 @@ }, "good": { "type": "boolean", - "description": "状态是否正常(与 online 一致)" + "description": "接收链路健康状态;仅在确认停滞时为 false" } }, "required": [ diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index daa649f0..55f5cd05 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -5692,7 +5692,7 @@ export const ACTIONS: CatalogAction[] = [ { "name": "get_status", "aliases": [], - "returns": "运行状态。`online`/`good` 均表示账号是否在线。", + "returns": "运行状态。`online` 表示账号在线;`good` 仅在接收链路确认停滞时为 `false`。", "returnsSchema": { "type": "object", "properties": { @@ -5702,7 +5702,7 @@ export const ACTIONS: CatalogAction[] = [ }, "good": { "type": "boolean", - "description": "状态是否正常(与 online 一致)" + "description": "接收链路健康状态;仅在确认停滞时为 false" } }, "required": [ diff --git a/packages/onebot/src/actions/info.ts b/packages/onebot/src/actions/info.ts index 2fa50e2d..e4724e83 100644 --- a/packages/onebot/src/actions/info.ts +++ b/packages/onebot/src/actions/info.ts @@ -27,19 +27,19 @@ export const actions = [ defineAction({ name: 'get_status', readOnly: true, - returns: '运行状态。`online`/`good` 均表示账号是否在线。', + returns: '运行状态。`online` 表示账号在线;`good` 仅在接收链路确认停滞时为 `false`。', returnsSchema: { type: 'object', properties: { online: { type: 'boolean', description: '是否在线' }, - good: { type: 'boolean', description: '状态是否正常(与 online 一致)' }, + good: { type: 'boolean', description: '接收链路健康状态;仅在确认停滞时为 false' }, }, required: ['online', 'good'], }, params: {}, run: (_p, ctx) => { const online = ctx.isOnline(); - return okResponse({ online, good: online }); + return okResponse({ online, good: online && ctx.bridge.receiveHealthy }); }, }), @@ -96,4 +96,3 @@ export const actions = [ }, }), ]; - diff --git a/packages/onebot/src/instance.ts b/packages/onebot/src/instance.ts index 7bc46ee9..93375e6f 100644 --- a/packages/onebot/src/instance.ts +++ b/packages/onebot/src/instance.ts @@ -465,7 +465,7 @@ export class OneBotInstance { sub_type: subType, status: { online: this.online, - good: this.online, + good: this.online && this.bridge.receiveHealthy, }, }; } @@ -484,7 +484,7 @@ export class OneBotInstance { self_id: selfId, post_type: 'meta_event', meta_event_type: 'heartbeat', - status: { online: this.online, good: this.online }, + status: { online: this.online, good: this.online && this.bridge.receiveHealthy }, interval: OneBotInstance.HEARTBEAT_INTERVAL, }; } diff --git a/packages/onebot/tests/status-health.test.ts b/packages/onebot/tests/status-health.test.ts new file mode 100644 index 00000000..c99db9a5 --- /dev/null +++ b/packages/onebot/tests/status-health.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest'; +import { ApiHandler, type ApiActionContext } from '../src/api-handler'; + +describe('get_status receive health (#233)', () => { + it('keeps online true while reporting a stalled receive path as not good', async () => { + const ctx = { + isOnline: () => true, + bridge: { receiveHealthy: false }, + } as unknown as ApiActionContext; + const response = await new ApiHandler(ctx).handle('get_status', {}); + + expect(response).toMatchObject({ + status: 'ok', + retcode: 0, + data: { online: true, good: false }, + }); + }); +});