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

推荐订阅源

雷峰网
雷峰网
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 叶小钗
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - 司徒正美
博客园 - 【当耐特】
IT之家
IT之家

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 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 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(tui): preserve pending local runs during session sync...
nao860226-rg · 2026-05-31 · via Recent Commits to openclaw:main

@@ -15,6 +15,8 @@ type SelectableOverlay = {

1515

};

1616

type SetActivityStatusMock = ReturnType<typeof vi.fn> & ((text: string) => void);

1717

type SetSessionMock = ReturnType<typeof vi.fn> & ((key: string) => Promise<void>);

18+

type ConsumeCompletedRunMock = ReturnType<typeof vi.fn> & ((runId: string) => boolean);

19+

type FlushPendingHistoryRefreshMock = ReturnType<typeof vi.fn> & (() => void);

18201921

async function flushAsyncSelect() {

2022

await new Promise<void>((resolve) => setImmediate(resolve));

@@ -81,6 +83,8 @@ function createHarness(params?: {

8183

currentAgentId?: string;

8284

currentSessionKey?: string;

8385

abortActive?: AbortActiveMock;

86+

consumeCompletedRunForPendingSend?: ConsumeCompletedRunMock;

87+

flushPendingHistoryRefreshIfIdle?: FlushPendingHistoryRefreshMock;

8488

}) {

8589

const sendChat = params?.sendChat ?? vi.fn().mockResolvedValue({ runId: "r1" });

8690

const getGatewayStatus = params?.getGatewayStatus ?? vi.fn().mockResolvedValue({});

@@ -101,6 +105,7 @@ function createHarness(params?: {

101105

const refreshSessionInfo = params?.refreshSessionInfo ?? vi.fn().mockResolvedValue(undefined);

102106

const applySessionInfoFromPatch = params?.applySessionInfoFromPatch ?? vi.fn();

103107

const setActivityStatus = params?.setActivityStatus ?? (vi.fn() as SetActivityStatusMock);

108+

const forgetLocalRunId = vi.fn();

104109

const openOverlay = vi.fn();

105110

const closeOverlay = vi.fn();

106111

const requestExit = vi.fn();

@@ -150,8 +155,10 @@ function createHarness(params?: {

150155

applySessionInfoFromPatch: applySessionInfoFromPatch as never,

151156

noteLocalRunId,

152157

noteLocalBtwRunId,

153-

forgetLocalRunId: vi.fn(),

158+

forgetLocalRunId,

154159

forgetLocalBtwRunId: vi.fn(),

160+

consumeCompletedRunForPendingSend: params?.consumeCompletedRunForPendingSend,

161+

flushPendingHistoryRefreshIfIdle: params?.flushPendingHistoryRefreshIfIdle,

155162

runAuthFlow,

156163

requestExit,

157164

});

@@ -180,6 +187,7 @@ function createHarness(params?: {

180187

setActivityStatus,

181188

noteLocalRunId,

182189

noteLocalBtwRunId,

190+

forgetLocalRunId,

183191

requestExit,

184192

abortActive,

185193

state,

@@ -508,18 +516,21 @@ describe("tui command handlers", () => {

508516

expect(addSystem).toHaveBeenCalledWith("agent set to work; use /crestodian to return");

509517

});

510518511-

it("defers local run binding until gateway events provide a real run id", async () => {

512-

const { handleCommand, noteLocalRunId, state } = createHarness();

519+

it("marks the generated runId as local before gateway events arrive", async () => {

520+

const { handleCommand, sendChat, noteLocalRunId, state } = createHarness();

513521514522

await handleCommand("/context detail");

515523516-

expect(noteLocalRunId).not.toHaveBeenCalled();

524+

const sentRunId = (firstMockArg(sendChat, "sendChat") as { runId: string }).runId;

525+

expect(noteLocalRunId).toHaveBeenCalledWith(sentRunId);

517526

expect(state.activeChatRunId).toBeNull();

518527

expect(state.pendingOptimisticUserMessage).toBe(true);

519528

});

520529521530

it("tracks the in-flight runId so escape can abort during the wait", async () => {

522-

const sendChat = vi.fn().mockResolvedValue({ runId: "ignored" });

531+

const sendChat = vi.fn().mockImplementation(async (opts: { runId: string }) => ({

532+

runId: opts.runId,

533+

}));

523534

const { handleCommand, state } = createHarness({ sendChat });

524535525536

await handleCommand("hello");

@@ -531,6 +542,55 @@ describe("tui command handlers", () => {

531542

expect(state.pendingChatRunId).toBe(sentRunId);

532543

});

533544545+

it("does not reintroduce the pending runId when an early event already consumed it", async () => {

546+

const sendChat = vi.fn();

547+

const { handleCommand, state } = createHarness({ sendChat });

548+

sendChat.mockImplementation(async (opts: { runId: string }) => {

549+

state.pendingOptimisticUserMessage = false;

550+

return { runId: opts.runId };

551+

});

552+553+

await handleCommand("hello");

554+555+

expect(state.pendingChatRunId).toBeNull();

556+

expect(state.pendingOptimisticUserMessage).toBe(false);

557+

});

558+559+

it("tracks the backend-accepted runId when it differs from the generated runId", async () => {

560+

const sendChat = vi.fn().mockResolvedValue({ runId: "run-accepted" });

561+

const { handleCommand, state, noteLocalRunId, forgetLocalRunId } = createHarness({ sendChat });

562+563+

await handleCommand("hello");

564+565+

const sentRunId = (firstMockArg(sendChat, "sendChat") as { runId: string }).runId;

566+

expect(state.pendingChatRunId).toBe("run-accepted");

567+

expect(forgetLocalRunId).toHaveBeenCalledWith(sentRunId);

568+

expect(noteLocalRunId).toHaveBeenCalledWith("run-accepted");

569+

});

570+571+

it("does not reintroduce a backend-accepted runId after an early terminal event", async () => {

572+

const sendChat = vi.fn().mockResolvedValue({ runId: "run-accepted" });

573+

const consumeCompletedRunForPendingSend = vi.fn((runId: string) => runId === "run-accepted");

574+

const flushPendingHistoryRefreshIfIdle = vi.fn();

575+

const { handleCommand, state, noteLocalRunId, forgetLocalRunId, setActivityStatus } =

576+

createHarness({

577+

sendChat,

578+

consumeCompletedRunForPendingSend,

579+

flushPendingHistoryRefreshIfIdle,

580+

});

581+582+

await handleCommand("hello");

583+584+

const sentRunId = (firstMockArg(sendChat, "sendChat") as { runId: string }).runId;

585+

expect(consumeCompletedRunForPendingSend).toHaveBeenCalledWith("run-accepted");

586+

expect(forgetLocalRunId).toHaveBeenCalledWith(sentRunId);

587+

expect(noteLocalRunId).not.toHaveBeenCalledWith("run-accepted");

588+

expect(state.pendingChatRunId).toBeNull();

589+

expect(state.pendingOptimisticUserMessage).toBe(false);

590+

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

591+

expect(flushPendingHistoryRefreshIfIdle).toHaveBeenCalledTimes(1);

592+

});

593+534594

it("clears the pending runId if sendChat fails", async () => {

535595

const sendChat = vi.fn().mockRejectedValue(new Error("boom"));

536596

const { handleCommand, state } = createHarness({ sendChat });