mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:20:43 +00:00
Agents: persist bootstrap marker after clean sessions_yield
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user