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
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,7 @@ describe("session lifecycle remote commands", () => {
}) {
const sessionService = {
settleSession: vi.fn(() => true),
settleSessionReportingAbort: vi.fn(() => ({ found: true, settled: true })),
unsettleSession: vi.fn(() => true),
settleSessions: vi.fn(() => ["session-1"]),
unsettleSessions: vi.fn(),
Expand All @@ -2369,7 +2370,7 @@ describe("session lifecycle remote commands", () => {
sessionId: "session-1",
outcome: "PR #841 merged",
}))).resolves.toEqual({ ok: true, sessionId: "session-1" });
expect(sessionService.settleSession).toHaveBeenCalledWith("session-1", { outcome: "PR #841 merged" });
expect(sessionService.settleSessionReportingAbort).toHaveBeenCalledWith("session-1", { outcome: "PR #841 merged" });

await expect(service.execute(makePayload("session.unsettleSession", { sessionId: "session-1" })))
.resolves.toEqual({ ok: true, sessionId: "session-1" });
Expand All @@ -2393,7 +2394,7 @@ describe("session lifecycle remote commands", () => {
}))).resolves.toEqual({ ok: true, sessionId: "session-1" });

expect(handleSessionSettled).not.toHaveBeenCalled();
expect(sessionService.settleSession).toHaveBeenCalledWith("session-1", {});
expect(sessionService.settleSessionReportingAbort).toHaveBeenCalledWith("session-1", {});
});

// `dismissPendingInputBeforeSettle` mutates and can then throw for a row with
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, dialog, ipcMain, Menu, nativeImage, Notification, powerMonitor, protocol, safeStorage, shell } from "electron";

Check warning on line 1 in apps/desktop/src/main/main.ts

View workflow job for this annotation

GitHub Actions / lint-desktop

'shell' is defined but never used. Allowed unused vars must match /^_/u

if (app.isPackaged && process.env.ADE_RUNTIME_PACKAGED === undefined) {
process.env.ADE_RUNTIME_PACKAGED = "1";
Expand Down Expand Up @@ -210,7 +210,7 @@
import { localIpcListenOptions } from "../../../ade-cli/src/services/runtime/localIpcListenOptions";
import { normalizeProjectRootPath } from "../../../ade-cli/src/services/projects/projectRoots";
import {
ACCOUNT_SESSION_CREDENTIAL_KEY,

Check warning on line 213 in apps/desktop/src/main/main.ts

View workflow job for this annotation

GitHub Actions / lint-desktop

'ACCOUNT_SESSION_CREDENTIAL_KEY' is defined but never used. Allowed unused vars must match /^_/u
getSignedInAccountAccessToken,
} from "../../../ade-cli/src/services/account/accountAuthService";
import { createPushRelayClient } from "../../../ade-cli/src/services/push/pushRelayClient";
Expand Down Expand Up @@ -3589,6 +3589,12 @@
db,
sessionService,
emitEvent: emitPrEvent,
getChatLiveness: async (sessionId) => {
const summary = await agentChatService.getSessionSummary(sessionId);
return summary
? { status: summary.status, awaitingInput: summary.awaitingInput }
: null;
},
});
laneTeardownDeps.agentChatService = {
countActiveForLane: (laneId) => agentChatService.countActiveForLane(laneId),
Expand Down
9 changes: 7 additions & 2 deletions apps/desktop/src/main/services/adeActions/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@
const requestAttention = vi.fn(() => true);
const setStatusNote = vi.fn(() => true);
const settleSession = vi.fn(() => true);
const settleSessionReportingAbort = vi.fn(() => ({ found: true, settled: true }));
const unsettleSession = vi.fn(() => true);
const markSessionAttentionRequested = vi.fn();
const setSessionRuntimeState = vi.fn(() => true);
Expand All @@ -1642,6 +1643,7 @@
requestAttention,
setStatusNote,
settleSession,
settleSessionReportingAbort,
unsettleSession,
},
ptyService: {
Expand Down Expand Up @@ -1853,11 +1855,13 @@
it("dismisses pending chat input before settling through the session action", async () => {
const dismissPendingInputForSettlement = vi.fn(async () => undefined);
const settleSession = vi.fn(() => true);
const settleSessionReportingAbort = vi.fn(() => ({ found: true, settled: true }));
const runtime = {
sessionService: {
get: vi.fn(() => ({ id: "chat-1", toolType: "codex-chat" })),
list: vi.fn(),
settleSession,
settleSessionReportingAbort,
},
agentChatService: {
dismissPendingInputForSettlement,
Expand All @@ -1875,14 +1879,15 @@
dismissPendingInput: true,
})).resolves.toEqual({ ok: true, sessionId: "chat-1" });
expect(dismissPendingInputForSettlement).toHaveBeenCalledWith({ sessionId: "chat-1" });
expect(settleSession).toHaveBeenCalledWith("chat-1", { source: "user" });
expect(settleSessionReportingAbort).toHaveBeenCalledWith("chat-1", { source: "user" });
expect(dismissPendingInputForSettlement.mock.invocationCallOrder[0]).toBeLessThan(
settleSession.mock.invocationCallOrder[0]!,
settleSessionReportingAbort.mock.invocationCallOrder[0]!,
);
});

it("does not pretend a native CLI prompt was dismissed while its process is still blocked", async () => {
const settleSession = vi.fn(() => true);
const settleSessionReportingAbort = vi.fn(() => ({ found: true, settled: true }));

Check warning on line 1890 in apps/desktop/src/main/services/adeActions/registry.test.ts

View workflow job for this annotation

GitHub Actions / lint-desktop

'settleSessionReportingAbort' is assigned a value but never used. Allowed unused vars must match /^_/u
const setSessionRuntimeState = vi.fn(() => true);
const runtime = {
sessionService: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ describe("createCtoOperatorTools", () => {
...row,
})),
settleSession: vi.fn(() => true),
settleSessionReportingAbort: vi.fn(() => ({ found: true, settled: true })),
unsettleSession: vi.fn(() => true),
setSettleOverride: vi.fn(() => true),
snoozeSession: vi.fn(() => true),
Expand Down Expand Up @@ -548,7 +549,7 @@ describe("createCtoOperatorTools", () => {
sessionId: "chat-1",
outcome: "CI green",
})).resolves.toMatchObject({ success: true });
expect(sessionService.settleSession).toHaveBeenCalledWith("chat-1", {
expect(sessionService.settleSessionReportingAbort).toHaveBeenCalledWith("chat-1", {
outcome: "CI green",
source: "operator",
});
Expand Down
11 changes: 9 additions & 2 deletions apps/desktop/src/main/services/ai/tools/ctoOperatorTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { createCtoStateService } from "../../cto/ctoStateService";
import type { CtoMemoryService } from "../../cto/ctoMemoryService";
import { getErrorMessage, nowIso, parseIsoToEpoch } from "../../shared/utils";
import { buildAdePrUrl } from "../../../../shared/deeplinks";
import { settleAbortMessage } from "../../sessions/settleTerminalSession";

export interface CtoOperatorToolDeps {
currentSessionId: string;
Expand All @@ -49,6 +50,7 @@ export interface CtoOperatorToolDeps {
| "updateMeta"
| "get"
| "settleSession"
| "settleSessionReportingAbort"
| "unsettleSession"
| "setSettleOverride"
| "snoozeSession"
Expand Down Expand Up @@ -552,11 +554,16 @@ export function createCtoOperatorTools(deps: CtoOperatorToolDeps): Record<string
}),
execute: async ({ sessionId, outcome }) => {
try {
const ok = deps.sessionService.settleSession(sessionId, {
const result = deps.sessionService.settleSessionReportingAbort(sessionId, {
...(outcome ? { outcome } : {}),
source: "operator",
});
if (!ok) return { success: false, error: `Session not found: ${sessionId}` };
if (!result.found) return { success: false, error: `Session not found: ${sessionId}` };
if (!result.settled) {
// The reason matters: `teardown_failed` and `joined_in_flight` do not
// mean the session went active, and saying so misdirects the operator.
return { success: false, error: settleAbortMessage(sessionId, result.abortedBy) };
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return { success: true, sessionId, ...readSessionLifecycle(deps, sessionId) };
} catch (error) {
return { success: false, error: getErrorMessage(error) };
Expand Down
Loading
Loading