Skip to content

Commit 4ee525d

Browse files
authored
fix(agent): resolve stuck "Starting agent" step on agent-proxy leg (#3045)
1 parent 06f1d07 commit 4ee525d

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

packages/agent/src/server/agent-server.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,38 @@ describe("AgentServer HTTP Mode", () => {
12341234
{ timeout: 15000, interval: 100 },
12351235
);
12361236
}, 30000);
1237+
1238+
it("emits a completed _posthog/progress for the agent step after session initialization", async () => {
1239+
await createServer().start();
1240+
1241+
// Resolves the setup card's "agent" step on the agent-proxy read leg,
1242+
// where the orchestrator's Django-only progress event never arrives.
1243+
await vi.waitFor(
1244+
() => {
1245+
const allEntries = appendLogCalls.flat() as Array<{
1246+
notification?: {
1247+
method?: string;
1248+
params?: Record<string, unknown>;
1249+
};
1250+
}>;
1251+
const agentProgress = allEntries.find(
1252+
(e) =>
1253+
e?.notification?.method === "_posthog/progress" &&
1254+
e?.notification?.params?.step === "agent",
1255+
);
1256+
expect(agentProgress).toBeDefined();
1257+
expect(agentProgress?.notification?.params).toMatchObject({
1258+
group: "setup:test-run-id",
1259+
step: "agent",
1260+
status: "completed",
1261+
});
1262+
expect(typeof agentProgress?.notification?.params?.label).toBe(
1263+
"string",
1264+
);
1265+
},
1266+
{ timeout: 15000, interval: 100 },
1267+
);
1268+
}, 30000);
12371269
});
12381270

12391271
describe("getInitialPromptOverride", () => {

packages/agent/src/server/agent-server.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,28 @@ export class AgentServer {
13361336
JSON.stringify(runStartedNotification),
13371337
);
13381338

1339+
// Mirror the "agent" setup step onto the ingest leg the client is reading;
1340+
// the orchestrator's completed progress only lands in Django.
1341+
const agentStartedProgress = {
1342+
jsonrpc: "2.0" as const,
1343+
method: POSTHOG_NOTIFICATIONS.PROGRESS,
1344+
params: {
1345+
group: `setup:${payload.run_id}`,
1346+
step: "agent",
1347+
status: "completed",
1348+
label: "Started agent",
1349+
},
1350+
};
1351+
this.broadcastEvent({
1352+
type: "notification",
1353+
timestamp: new Date().toISOString(),
1354+
notification: agentStartedProgress,
1355+
});
1356+
this.session.logWriter.appendRawLine(
1357+
payload.run_id,
1358+
JSON.stringify(agentStartedProgress),
1359+
);
1360+
13391361
// Signal in_progress so the UI can start polling for updates
13401362
this.posthogAPI
13411363
.updateTaskRun(payload.task_id, payload.run_id, {

0 commit comments

Comments
 (0)