mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-20 05:31:30 +00:00
fix(tui): tolerate clock skew in pending-history reconciliation
This commit is contained in:
@@ -138,12 +138,23 @@ describe("ChatLog", () => {
|
||||
expect(chatLog.countPendingUsers()).toBe(0);
|
||||
});
|
||||
|
||||
it("reconciles pending users when the gateway clock is slightly behind the client", () => {
|
||||
const chatLog = new ChatLog(40);
|
||||
|
||||
chatLog.addPendingUser("run-1", "queued hello", 65_000);
|
||||
|
||||
expect(chatLog.reconcilePendingUsers([{ text: "queued hello", timestamp: 20_000 }])).toEqual([
|
||||
"run-1",
|
||||
]);
|
||||
expect(chatLog.countPendingUsers()).toBe(0);
|
||||
});
|
||||
|
||||
it("does not hide a new repeated prompt when only older history matches", () => {
|
||||
const chatLog = new ChatLog(40);
|
||||
|
||||
chatLog.addPendingUser("run-1", "continue", 5_000);
|
||||
|
||||
expect(chatLog.reconcilePendingUsers([{ text: "continue", timestamp: 4_000 }])).toEqual([]);
|
||||
expect(chatLog.reconcilePendingUsers([{ text: "continue", timestamp: -56_000 }])).toEqual([]);
|
||||
expect(chatLog.countPendingUsers()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,8 @@ import { BtwInlineMessage } from "./btw-inline-message.js";
|
||||
import { ToolExecutionComponent } from "./tool-execution.js";
|
||||
import { UserMessageComponent } from "./user-message.js";
|
||||
|
||||
const PENDING_HISTORY_CLOCK_SKEW_TOLERANCE_MS = 60_000;
|
||||
|
||||
export class ChatLog extends Container {
|
||||
private readonly maxComponents: number;
|
||||
private toolById = new Map<string, ToolExecutionComponent>();
|
||||
@@ -156,7 +158,9 @@ export class ChatLog extends Container {
|
||||
}
|
||||
const matchIndex = normalizedHistory.findIndex(
|
||||
(historyEntry) =>
|
||||
historyEntry.text === pendingText && (historyEntry.timestamp ?? 0) >= entry.createdAt,
|
||||
historyEntry.text === pendingText &&
|
||||
(historyEntry.timestamp ?? 0) >=
|
||||
entry.createdAt - PENDING_HISTORY_CLOCK_SKEW_TOLERANCE_MS,
|
||||
);
|
||||
if (matchIndex === -1) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user