惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 test: merge chat context notice checks · openclaw/openclaw@5c2f4af feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248
TUI/streaming: add watchdog that resets the activity indi...
2026-04-16 · via Recent Commits to openclaw:main
1-

import { describe, expect, it, vi } from "vitest";

1+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

22

import { createEventHandlers } from "./tui-event-handlers.js";

33

import type { AgentEvent, BtwEvent, ChatEvent, TuiStateAccess } from "./tui-types.js";

44

@@ -651,3 +651,188 @@ describe("tui-event-handlers: handleAgentEvent", () => {

651651

expect(loadHistory).toHaveBeenCalledTimes(1);

652652

});

653653

});

654+655+

describe("tui-event-handlers: streaming watchdog", () => {

656+

beforeEach(() => {

657+

vi.useFakeTimers();

658+

});

659+660+

afterEach(() => {

661+

vi.useRealTimers();

662+

});

663+664+

const makeState = (overrides?: Partial<TuiStateAccess>): TuiStateAccess => ({

665+

agentDefaultId: "main",

666+

sessionMainKey: "agent:main:main",

667+

sessionScope: "global",

668+

agents: [],

669+

currentAgentId: "main",

670+

currentSessionKey: "agent:main:main",

671+

currentSessionId: "session-1",

672+

activeChatRunId: null,

673+

pendingOptimisticUserMessage: false,

674+

historyLoaded: true,

675+

sessionInfo: { verboseLevel: "on" },

676+

initialSessionApplied: true,

677+

isConnected: true,

678+

autoMessageSent: false,

679+

toolsExpanded: false,

680+

showThinking: false,

681+

connectionStatus: "connected",

682+

activityStatus: "idle",

683+

statusTimeout: null,

684+

lastCtrlCAt: 0,

685+

...overrides,

686+

});

687+688+

const createHarness = (options?: { streamingWatchdogMs?: number }) => {

689+

const state = makeState();

690+

const chatLog = createMockChatLog();

691+

const btw = createMockBtwPresenter();

692+

const tui = { requestRender: vi.fn() } as unknown as MockTui & HandlerTui;

693+

const setActivityStatus = vi.fn();

694+

const handlers = createEventHandlers({

695+

chatLog,

696+

btw,

697+

tui,

698+

state,

699+

setActivityStatus,

700+

streamingWatchdogMs: options?.streamingWatchdogMs,

701+

});

702+

return { state, chatLog, tui, setActivityStatus, handlers };

703+

};

704+705+

it("resets activityStatus to idle when no stream delta arrives for the watchdog window", () => {

706+

const { state, chatLog, setActivityStatus, handlers } = createHarness({

707+

streamingWatchdogMs: 5_000,

708+

});

709+710+

handlers.handleChatEvent({

711+

runId: "run-stuck",

712+

sessionKey: state.currentSessionKey,

713+

state: "delta",

714+

message: { content: "hello" },

715+

} satisfies ChatEvent);

716+717+

expect(setActivityStatus).toHaveBeenLastCalledWith("streaming");

718+

expect(state.activeChatRunId).toBe("run-stuck");

719+720+

vi.advanceTimersByTime(5_001);

721+722+

expect(setActivityStatus).toHaveBeenLastCalledWith("idle");

723+

expect(state.activeChatRunId).toBeNull();

724+

expect(chatLog.addSystem).toHaveBeenCalledWith(

725+

expect.stringContaining("streaming watchdog"),

726+

);

727+728+

handlers.dispose?.();

729+

});

730+731+

it("refreshes the watchdog window on each new stream delta", () => {

732+

const { state, setActivityStatus, handlers } = createHarness({

733+

streamingWatchdogMs: 5_000,

734+

});

735+736+

handlers.handleChatEvent({

737+

runId: "run-flow",

738+

sessionKey: state.currentSessionKey,

739+

state: "delta",

740+

message: { content: "first" },

741+

} satisfies ChatEvent);

742+743+

vi.advanceTimersByTime(3_000);

744+745+

handlers.handleChatEvent({

746+

runId: "run-flow",

747+

sessionKey: state.currentSessionKey,

748+

state: "delta",

749+

message: { content: "second" },

750+

} satisfies ChatEvent);

751+752+

vi.advanceTimersByTime(3_000);

753+754+

// 6s total, but the latest delta was only 3s ago, so the watchdog must not

755+

// have fired yet.

756+

expect(setActivityStatus).not.toHaveBeenCalledWith("idle");

757+

expect(state.activeChatRunId).toBe("run-flow");

758+759+

vi.advanceTimersByTime(2_500);

760+761+

expect(setActivityStatus).toHaveBeenLastCalledWith("idle");

762+

expect(state.activeChatRunId).toBeNull();

763+764+

handlers.dispose?.();

765+

});

766+767+

it("cancels the watchdog when the run finalizes normally", () => {

768+

const { state, chatLog, setActivityStatus, handlers } = createHarness({

769+

streamingWatchdogMs: 5_000,

770+

});

771+772+

handlers.handleChatEvent({

773+

runId: "run-normal",

774+

sessionKey: state.currentSessionKey,

775+

state: "delta",

776+

message: { content: "hi" },

777+

} satisfies ChatEvent);

778+

handlers.handleChatEvent({

779+

runId: "run-normal",

780+

sessionKey: state.currentSessionKey,

781+

state: "final",

782+

message: { content: [{ type: "text", text: "done" }], stopReason: "stop" },

783+

} satisfies ChatEvent);

784+785+

vi.advanceTimersByTime(10_000);

786+787+

// After a normal final, the watchdog timer must have been cancelled and

788+

// cannot later re-overwrite the status or emit the warning banner.

789+

const statusCalls = setActivityStatus.mock.calls.map((c) => c[0]);

790+

expect(statusCalls.filter((s) => s === "idle").length).toBe(1);

791+

expect(chatLog.addSystem).not.toHaveBeenCalledWith(

792+

expect.stringContaining("streaming watchdog"),

793+

);

794+

expect(state.activeChatRunId).toBeNull();

795+796+

handlers.dispose?.();

797+

});

798+799+

it("is disabled when streamingWatchdogMs is 0", () => {

800+

const { state, chatLog, setActivityStatus, handlers } = createHarness({

801+

streamingWatchdogMs: 0,

802+

});

803+804+

handlers.handleChatEvent({

805+

runId: "run-no-watchdog",

806+

sessionKey: state.currentSessionKey,

807+

state: "delta",

808+

message: { content: "hi" },

809+

} satisfies ChatEvent);

810+811+

vi.advanceTimersByTime(60_000);

812+813+

expect(setActivityStatus).not.toHaveBeenCalledWith("idle");

814+

expect(chatLog.addSystem).not.toHaveBeenCalled();

815+

expect(state.activeChatRunId).toBe("run-no-watchdog");

816+817+

handlers.dispose?.();

818+

});

819+820+

it("dispose clears a pending watchdog without firing it", () => {

821+

const { setActivityStatus, chatLog, handlers, state } = createHarness({

822+

streamingWatchdogMs: 5_000,

823+

});

824+825+

handlers.handleChatEvent({

826+

runId: "run-dispose",

827+

sessionKey: state.currentSessionKey,

828+

state: "delta",

829+

message: { content: "hi" },

830+

} satisfies ChatEvent);

831+832+

handlers.dispose?.();

833+

vi.advanceTimersByTime(10_000);

834+835+

expect(setActivityStatus).not.toHaveBeenCalledWith("idle");

836+

expect(chatLog.addSystem).not.toHaveBeenCalled();

837+

});

838+

});