fix: revert skipAfterTurn, let finalize ingest the final message

- Remove loopHookActive flag, skipAfterTurn param, and the conditional skip in finalizeAttemptContextEngineTurn
- The finalize afterTurn must run to ingest the final assistant message which is appended after the last transformContext call
- lossless-claw deduplicates internally so the overlap with the loop hook's earlier ingestion is benign
This commit is contained in:
Bikkies
2026-04-10 14:57:01 +10:00
committed by Josh Lehman
parent 954a1d7005
commit e0b82c3ff8
2 changed files with 2 additions and 9 deletions

View File

@@ -199,9 +199,6 @@ export async function finalizeAttemptContextEngineTurn(params: {
}) => Promise<unknown>;
sessionManager: unknown;
warn: (message: string) => void;
/** When true, skip the afterTurn/ingest calls because the loop hook already
* handled per-iteration ingestion during the tool loop. Maintenance still runs. */
skipAfterTurn?: boolean;
}) {
if (!params.contextEngine) {
return { postTurnFinalizationSucceeded: true };
@@ -209,8 +206,7 @@ export async function finalizeAttemptContextEngineTurn(params: {
let postTurnFinalizationSucceeded = true;
if (!params.skipAfterTurn) {
if (typeof params.contextEngine.afterTurn === "function") {
if (typeof params.contextEngine.afterTurn === "function") {
try {
await params.contextEngine.afterTurn({
sessionId: params.sessionIdUsed,
@@ -255,7 +251,7 @@ export async function finalizeAttemptContextEngineTurn(params: {
}
}
}
}
if (
!params.promptError &&

View File

@@ -997,7 +997,6 @@ export async function runEmbeddedAttempt(
queueYieldInterruptForSession = () => {
queueSessionsYieldInterruptMessage(activeSession);
};
let loopHookActive = false;
if (params.contextEngine?.info?.ownsCompaction !== true) {
removeToolResultContextGuard = installToolResultContextGuard({
agent: activeSession.agent,
@@ -1018,7 +1017,6 @@ export async function runEmbeddedAttempt(
tokenBudget: params.contextTokenBudget,
modelId: params.modelId,
});
loopHookActive = true;
}
const cacheTrace = createCacheTrace({
cfg: params.config,
@@ -2218,7 +2216,6 @@ export async function runEmbeddedAttempt(
prePromptMessageCount,
tokenBudget: params.contextTokenBudget,
runtimeContext: afterTurnRuntimeContext,
skipAfterTurn: loopHookActive,
runMaintenance: async (contextParams) =>
await runContextEngineMaintenance({
contextEngine: contextParams.contextEngine as never,