Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions packages/core/src/sessions/sessionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,16 @@ export class SessionService {
return connectPromise;
}

private stampRunConfig(session: AgentSession, params: ConnectParams): void {
Comment thread
pauldambra marked this conversation as resolved.
session.adapter = params.adapter;
session.model = params.model;
session.executionMode = params.executionMode;
session.reasoningLevel = params.reasoningLevel;
if (params.initialPrompt?.length) {
Comment thread
pauldambra marked this conversation as resolved.
session.initialPrompt = params.initialPrompt;
}
}

private async doConnect(params: ConnectParams): Promise<void> {
const {
task,
Expand Down Expand Up @@ -693,9 +703,7 @@ export class SessionService {
session.status = "error";
session.errorMessage =
"Authentication required. Please sign in to continue.";
if (initialPrompt?.length) {
session.initialPrompt = initialPrompt;
}
this.stampRunConfig(session, params);
this.d.store.setSession(session);
return;
}
Expand Down Expand Up @@ -784,9 +792,7 @@ export class SessionService {

const taskRunId = latestRun?.id ?? `error-${taskId}`;
const session = createBaseSession(taskRunId, taskId, taskTitle);
if (initialPrompt?.length) {
session.initialPrompt = initialPrompt;
}
this.stampRunConfig(session, params);
if (latestRun?.log_url) {
try {
const { rawEntries } = await this.fetchSessionLogs(
Expand Down
75 changes: 75 additions & 0 deletions packages/core/src/sessions/sessionServiceRetryConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AgentSession } from "@posthog/shared";
import type { Task } from "@posthog/shared/domain-types";
import { describe, expect, it, vi } from "vitest";
import { SessionService, type SessionServiceDeps } from "./sessionService";

Expand Down Expand Up @@ -90,3 +91,77 @@ describe("SessionService.clearSessionError retry config", () => {
);
});
});

describe("SessionService.connectToTask start failure", () => {
it("persists the run configuration on the error session so retry keeps the model", async () => {
const setSession = vi.fn();
const deps = {
store: {
getSessionByTaskId: () => undefined,
getSessions: () => ({}),
setSession,
},
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
settings: { customInstructions: "" },
DEFAULT_GATEWAY_MODEL: "claude-opus-4-8",
// Online for the create-branch check, offline in the catch so the
Comment thread
pauldambra marked this conversation as resolved.
// auto-retry loop is skipped and the stored error session is asserted.
getIsOnline: vi
.fn<() => boolean>()
.mockReturnValueOnce(true)
.mockReturnValue(false),
trpc: {
agent: {
start: {
mutate: vi
.fn()
.mockRejectedValue(new Error("session start timeout")),
},
onSessionIdleKilled: {
subscribe: () => ({ unsubscribe: vi.fn() }),
},
},
},
} as unknown as SessionServiceDeps;

const service = new SessionService(deps);
vi.spyOn(
service as unknown as {
getAuthCredentialsStatus: () => Promise<unknown>;
},
"getAuthCredentialsStatus",
).mockResolvedValue({
kind: "ready",
auth: {
client: { createTaskRun: vi.fn().mockResolvedValue({ id: "run-1" }) },
apiHost: "https://app",
projectId: 1,
},
});

await service.connectToTask({
task: {
id: "task-1",
title: "Test task",
description: "Ship the fix",
latest_run: null,
} as unknown as Task,
repoPath: "/repo",
initialPrompt: [{ type: "text", text: "Ship the fix" }],
executionMode: "auto",
adapter: "claude",
model: "claude-fable-5",
reasoningLevel: "high",
});

const stored = setSession.mock.calls.at(-1)?.[0] as AgentSession;
expect(stored.status).toBe("error");
expect(stored.model).toBe("claude-fable-5");
expect(stored.adapter).toBe("claude");
expect(stored.executionMode).toBe("auto");
expect(stored.reasoningLevel).toBe("high");
expect(stored.initialPrompt).toEqual([
{ type: "text", text: "Ship the fix" },
]);
});
});
Comment thread
robbie-c marked this conversation as resolved.
Loading