Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/desktop/src/main/services/ipc/registerIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5859,9 +5859,16 @@ export function registerIpc({
_event,
arg: { sessionId?: string; maxEvents?: number },
): Promise<AgentChatEventHistorySnapshot> => {
const ctx = ensureAgentChatContext();
const ctx = getCtx();
const sessionId = typeof arg?.sessionId === "string" ? arg.sessionId.trim() : "";
if (!sessionId) return { sessionId: "", events: [], truncated: false, sessionFound: false };
const service = ctx.agentChatService;
if (
!service ||
typeof (service as unknown as { getChatEventHistory?: unknown }).getChatEventHistory !== "function"
) {
return { sessionId, events: [], truncated: false, sessionFound: false };
}
// Only forward maxEvents when it is a finite positive number; the service
// layer applies its own clamp but guarding here avoids ambiguous NaN/0
// inputs from untrusted renderer IPC.
Expand All @@ -5870,7 +5877,7 @@ export function registerIpc({
rawMaxEvents != null && Number.isFinite(rawMaxEvents) && rawMaxEvents > 0
? rawMaxEvents
: undefined;
return ctx.agentChatService.getChatEventHistory(sessionId, maxEvents != null ? { maxEvents } : undefined);
return service.getChatEventHistory(sessionId, maxEvents != null ? { maxEvents } : undefined);
});

ipcMain.handle(IPC.agentChatReadTranscript, async (
Expand Down
93 changes: 93 additions & 0 deletions apps/desktop/src/main/services/ipc/runtimeBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,99 @@ describe("registerIpc sync bridge", () => {
expect(listSessions).toHaveBeenCalledWith("lane-1", { includeAutomation: true });
});

it("returns an empty chat event history when the agent chat service is unavailable", async () => {
registerIpc({
getCtx: () => ({
agentChatService: null,
}) as any,
getWindowSession: () => ({
windowId: 7,
project: { rootPath: "/repo", displayName: "Repo" } as any,
binding: localBinding("/repo"),
}),
switchProjectFromDialog: vi.fn(),
closeCurrentProject: vi.fn(),
closeProjectByPath: vi.fn(),
globalStatePath: "/tmp/ade-state.json",
});

await expect(
ipcHandlers.get(IPC.agentChatGetEventHistory)?.(
eventForSender(),
{ sessionId: " chat-1 ", maxEvents: 10 },
),
).resolves.toEqual({
sessionId: "chat-1",
events: [],
truncated: false,
sessionFound: false,
});
});
Comment thread
greptile-apps[bot] marked this conversation as resolved.

it("returns an empty chat event history when the agent chat service lacks event history support", async () => {
registerIpc({
getCtx: () => ({
agentChatService: {},
}) as any,
getWindowSession: () => ({
windowId: 7,
project: { rootPath: "/repo", displayName: "Repo" } as any,
binding: localBinding("/repo"),
}),
switchProjectFromDialog: vi.fn(),
closeCurrentProject: vi.fn(),
closeProjectByPath: vi.fn(),
globalStatePath: "/tmp/ade-state.json",
});

await expect(
ipcHandlers.get(IPC.agentChatGetEventHistory)?.(
eventForSender(),
{ sessionId: " chat-1 ", maxEvents: 10 },
),
).resolves.toEqual({
sessionId: "chat-1",
events: [],
truncated: false,
sessionFound: false,
});
});

it("forwards chat event history requests when the agent chat service is available", async () => {
const snapshot = {
sessionId: "chat-1",
events: [],
truncated: false,
sessionFound: true,
};
const getChatEventHistory = vi.fn(() => snapshot);
registerIpc({
getCtx: () => ({
agentChatService: {
getChatEventHistory,
},
}) as any,
getWindowSession: () => ({
windowId: 7,
project: { rootPath: "/repo", displayName: "Repo" } as any,
binding: localBinding("/repo"),
}),
switchProjectFromDialog: vi.fn(),
closeCurrentProject: vi.fn(),
closeProjectByPath: vi.fn(),
globalStatePath: "/tmp/ade-state.json",
});

await expect(
ipcHandlers.get(IPC.agentChatGetEventHistory)?.(
eventForSender(),
{ sessionId: " chat-1 ", maxEvents: 25 },
),
).resolves.toBe(snapshot);

expect(getChatEventHistory).toHaveBeenCalledWith("chat-1", { maxEvents: 25 });
});

it("disposes a live terminal runtime before deleting the session", async () => {
const terminalSession = {
id: "terminal-1",
Expand Down
Loading