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
12 changes: 5 additions & 7 deletions packages/junior/src/chat/task-execution/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,17 @@ export async function startConversationWork(args: {
return result;
}

/** Extend the durable execution lease when the worker checks in. */
/**
* Extend the durable execution lease when the worker checks in. It does not
* write the stored execution: after a Turn ends, that write reads as new work.
*/
export async function checkInConversationWork(args: {
conversationId: string;
leaseToken: string;
conversationStore?: ConversationStore | undefined;
nowMs?: number;
state?: StateAdapter | undefined;
}) {
const result = await workState.checkInConversationWork(args);
if (result) {
await recordExecutionMetadata(args);
}
return result;
return await workState.checkInConversationWork(args);
}

/** Drain pending mailbox entries after the caller accepts responsibility. */
Expand Down
2 changes: 0 additions & 2 deletions packages/junior/src/chat/task-execution/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function startLeaseCheckIn(args: {
void checkInConversationWork({
conversationId: args.conversationId,
leaseToken: args.leaseToken,
conversationStore: args.options.conversationStore,
nowMs,
state: args.options.state,
}).then(
Expand Down Expand Up @@ -463,7 +462,6 @@ async function processConversationWorkInContext(
const checkedIn = await checkInConversationWork({
conversationId,
leaseToken: lease.leaseToken,
conversationStore: options.conversationStore,
nowMs: now(options),
state: options.state,
});
Expand Down
63 changes: 1 addition & 62 deletions packages/junior/tests/component/conversation-sql-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
requestAnotherSlice,
startConversationWork,
} from "@/chat/task-execution/store";
import { processConversationWork } from "@/chat/task-execution/worker";
import { disconnectStateAdapter, getStateAdapter } from "@/chat/state/adapter";
import { upsertTurnRecord } from "@/chat/task-execution/turn-cursor";
import {
Expand All @@ -20,13 +19,7 @@ import {
} from "@/db/schema";
import { eq } from "drizzle-orm";
import { readConversationFeedFromSql } from "@/api/conversations/list";
import {
CONVERSATION_ID,
conversationQueueMessage,
createConversationWorkQueueTestAdapter,
deferred,
inboundMessage,
} from "../fixtures/conversation-work";
import { CONVERSATION_ID, inboundMessage } from "../fixtures/conversation-work";
import {
createConfiguredJuniorSqlFixture,
createJuniorSqlFixture,
Expand Down Expand Up @@ -1583,60 +1576,6 @@ ORDER BY metric
}
});

it("mirrors worker check-ins into SQL execution progress", async () => {
const fixture = await createJuniorSqlFixture();

try {
vi.useFakeTimers({ now: 1_000 });
await disconnectStateAdapter();
const state = getStateAdapter();
const store = createSqlStore(fixture.sql);
await migrateSchema(fixture.sql);
await appendInboundMessage({
message: inboundMessage("check-in"),
conversationStore: store,
nowMs: 1_000,
state,
});
const queue = createConversationWorkQueueTestAdapter();
const entered = deferred<void>();
const finish = deferred<void>();

const running = processConversationWork(conversationQueueMessage(), {
checkInIntervalMs: 15_000,
conversationStore: store,
queue,
run: async (context) => {
await context.attempt.drain(async () => {});
entered.resolve();
await finish.promise;
return { status: "completed" };
},
state,
});
await entered.promise;

await vi.advanceTimersByTimeAsync(15_000);
await vi.waitFor(async () => {
await expect(
store.get({ conversationId: CONVERSATION_ID }),
).resolves.toMatchObject({
execution: {
status: "running",
updatedAtMs: 16_000,
},
});
});

finish.resolve();
await expect(running).resolves.toEqual({ status: "completed" });
} finally {
vi.useRealTimers();
await disconnectStateAdapter();
await fixture.close();
}
});

it("stores a paused execution as paused", async () => {
const fixture = await createJuniorSqlFixture();

Expand Down
34 changes: 32 additions & 2 deletions packages/junior/tests/integration/api/conversations/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import {
CONVERSATION_WORK_LEASE_TTL_MS,
CONVERSATION_WORK_MAX_RETRIES,
} from "@/chat/task-execution/state";
import { startConversationWork } from "@/chat/task-execution/store";
import {
checkInConversationWork,
startConversationWork,
} from "@/chat/task-execution/store";
import { runNextPausedTurn } from "@/chat/task-execution/paused-turn";
import { upsertTurnRecord } from "@/chat/task-execution/turn-cursor";
import {
recordTurnSummary,
upsertTurnRecord,
} from "@/chat/task-execution/turn-cursor";
import { createPausedTurns } from "@/chat/task-execution/turn-wake";
import { getAppContext } from "@/app/context";
import { sendVercelPluginTask } from "@/chat/plugins/task-queue";
Expand Down Expand Up @@ -65,6 +71,30 @@ describe("conversation status", () => {
await expect(fixture.status(conversationId)).resolves.toBe("failed");
});

it("stays done when its worker checks in after its Turn ends", async () => {
const fixture = await createStatusFixture();
const conversationId = await fixture.start("stored-check-in");
const work = await startConversationWork({
conversationId,
state: fixture.state,
});
if (work.status !== "acquired") throw new Error("Expected the lease");
await recordTurnStart(conversationId, "stored-check-in");
await recordTurnSummary({
conversationId,
sliceId: 1,
state: "completed",
turnId: "stored-check-in",
});
await recordTurnCompletion(conversationId, "stored-check-in");
await checkInConversationWork({
conversationId,
leaseToken: work.leaseToken,
state: fixture.state,
});
await expect(fixture.status(conversationId)).resolves.toBe("done");
});

it("is failed when a paused Turn cannot resume", async () => {
const fixture = await createStatusFixture();
const conversationId = await recordSlackRoot(
Expand Down
Loading