Agents: persist bootstrap marker after clean sessions_yield

This commit is contained in:
Ted Li
2026-04-10 12:07:57 -07:00
committed by Ayaan Zaidi
parent c42fcf5f7b
commit 7f071a6a8e
3 changed files with 106 additions and 6 deletions

View File

@@ -0,0 +1,78 @@
import { describe, expect, it } from "vitest";
import { shouldPersistCompletedBootstrapTurn } from "./attempt.thread-helpers.js";
describe("runEmbeddedAttempt bootstrap completion marker", () => {
it("keeps marker persistence enabled for clean sessions_yield exits", () => {
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: true,
promptError: undefined,
aborted: false,
yieldAborted: true,
timedOutDuringCompaction: false,
compactionOccurredThisAttempt: false,
}),
).toBe(true);
});
it("skips marker persistence when recording is disabled", () => {
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: false,
promptError: undefined,
aborted: false,
yieldAborted: false,
timedOutDuringCompaction: false,
compactionOccurredThisAttempt: false,
}),
).toBe(false);
});
it("skips marker persistence when the attempt aborted", () => {
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: true,
promptError: undefined,
aborted: true,
yieldAborted: false,
timedOutDuringCompaction: false,
compactionOccurredThisAttempt: false,
}),
).toBe(false);
});
it("skips marker persistence for prompt errors and compaction-side outcomes", () => {
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: true,
promptError: new Error("prompt failed"),
aborted: false,
yieldAborted: false,
timedOutDuringCompaction: false,
compactionOccurredThisAttempt: false,
}),
).toBe(false);
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: true,
promptError: undefined,
aborted: false,
yieldAborted: false,
timedOutDuringCompaction: true,
compactionOccurredThisAttempt: false,
}),
).toBe(false);
expect(
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn: true,
promptError: undefined,
aborted: false,
yieldAborted: false,
timedOutDuringCompaction: false,
compactionOccurredThisAttempt: true,
}),
).toBe(false);
});
});

View File

@@ -88,3 +88,22 @@ export function appendAttemptCacheTtlIfNeeded(params: {
});
return true;
}
export function shouldPersistCompletedBootstrapTurn(params: {
shouldRecordCompletedBootstrapTurn: boolean;
promptError: unknown;
aborted: boolean;
yieldAborted: boolean;
timedOutDuringCompaction: boolean;
compactionOccurredThisAttempt: boolean;
}): boolean {
if (!params.shouldRecordCompletedBootstrapTurn || params.promptError || params.aborted) {
return false;
}
if (params.timedOutDuringCompaction || params.compactionOccurredThisAttempt) {
return false;
}
// Intentionally allow clean sessions_yield exits here so continuation-skip
// can treat the next relay/user turn as an existing bootstrap session.
return true;
}

View File

@@ -200,6 +200,7 @@ import {
appendAttemptCacheTtlIfNeeded,
composeSystemPromptWithHookContext,
resolveAttemptSpawnWorkspaceDir,
shouldPersistCompletedBootstrapTurn,
shouldUseOpenAIWebSocketTransport,
} from "./attempt.thread-helpers.js";
import {
@@ -2169,12 +2170,14 @@ export async function runEmbeddedAttempt(
}
if (
shouldRecordCompletedBootstrapTurn &&
!promptError &&
!aborted &&
!yieldAborted &&
!timedOutDuringCompaction &&
!compactionOccurredThisAttempt
shouldPersistCompletedBootstrapTurn({
shouldRecordCompletedBootstrapTurn,
promptError,
aborted,
yieldAborted,
timedOutDuringCompaction,
compactionOccurredThisAttempt,
})
) {
try {
sessionManager.appendCustomEntry(FULL_BOOTSTRAP_COMPLETED_CUSTOM_TYPE, {