fix: count steering prompts in checkpoints

This commit is contained in:
Rishin Georgy Anil authored and Julius Marminge committed 2026-07-20 17:45:27 +02:00
1 parent ad96886dca
commit 4bc760bc1f
2 files changed
+23 -4

No files matched your search

@@ -35,7 +35,7 @@ import * as VcsDriverRegistry from "../../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../../vcs/VcsProcess.ts";
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
import * as RepositoryIdentityResolver from "../../project/RepositoryIdentityResolver.ts";
import { CheckpointReactorLive } from "./CheckpointReactor.ts";
import { CheckpointReactorLive, conversationTurnCountForTurn } from "./CheckpointReactor.ts";
import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
@@ -229,6 +229,24 @@ function gitShowFileAtRef(cwd: string, ref: string, filePath: string): string {
return runGit(cwd, ["show", `${ref}:${filePath}`]);
}
describe("conversationTurnCountForTurn", () => {
it("counts steering prompts through the last assistant message for the same turn", () => {
const steeredTurnId = asTurnId("steered-turn");
const laterTurnId = asTurnId("later-turn");
const messages = [
{ role: "user", turnId: null },
{ role: "assistant", turnId: steeredTurnId },
{ role: "user", turnId: null },
{ role: "assistant", turnId: steeredTurnId },
{ role: "user", turnId: null },
{ role: "assistant", turnId: laterTurnId },
];
expect(conversationTurnCountForTurn(messages, steeredTurnId)).toBe(2);
expect(conversationTurnCountForTurn(messages, laterTurnId)).toBe(3);
});
});
async function waitForGitRefExists(cwd: string, ref: string, timeoutMs = 15_000) {
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
const poll = async (): Promise<void> => {
@@ -62,7 +62,7 @@ export function countConversationTurns(messages: ReadonlyArray<{ readonly role:
return messages.reduce((count, message) => count + (message.role === "user" ? 1 : 0), 0);
}
function conversationTurnCountForTurn(
export function conversationTurnCountForTurn(
messages: ReadonlyArray<{
readonly role: string;
readonly turnId: TurnId | null;
@@ -70,15 +70,16 @@ function conversationTurnCountForTurn(
turnId: TurnId,
): number | undefined {
let turnCount = 0;
let matchedTurnCount: number | undefined;
for (const message of messages) {
if (message.role === "user") {
turnCount += 1;
}
if (message.role === "assistant" && sameId(message.turnId, turnId)) {
return turnCount > 0 ? turnCount : undefined;
matchedTurnCount = turnCount > 0 ? turnCount : undefined;
}
}
return undefined;
return matchedTurnCount;
}
function maxCheckpointTurnCount(