Agents: preserve bootstrap warning dedupe across followup runs

This commit is contained in:
Gustavo Madeira Santana
2026-03-03 18:55:27 -05:00
parent d95cf256e7
commit 0d97101665
5 changed files with 172 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import crypto from "node:crypto";
import fs from "node:fs";
import type { AgentMessage } from "@mariozechner/pi-agent-core";
import { resolveBootstrapWarningSignaturesSeen } from "../../agents/bootstrap-budget.js";
import { estimateMessagesTokens } from "../../agents/compaction.js";
import { runWithModelFallback } from "../../agents/model-fallback.js";
import { isCliProvider } from "../../agents/model-selection.js";
@@ -452,6 +453,10 @@ export async function runMemoryFlushIfNeeded(params: {
let activeSessionEntry = entry ?? params.sessionEntry;
const activeSessionStore = params.sessionStore;
let bootstrapPromptWarningSignaturesSeen = resolveBootstrapWarningSignaturesSeen(
activeSessionEntry?.systemPromptReport ??
(params.sessionKey ? activeSessionStore?.[params.sessionKey]?.systemPromptReport : undefined),
);
const flushRunId = crypto.randomUUID();
if (params.sessionKey) {
registerAgentRunContext(flushRunId, {
@@ -469,7 +474,7 @@ export async function runMemoryFlushIfNeeded(params: {
try {
await runWithModelFallback({
...resolveModelFallbackOptions(params.followupRun.run),
run: (provider, model) => {
run: async (provider, model) => {
const { authProfile, embeddedContext, senderContext } = buildEmbeddedRunContexts({
run: params.followupRun.run,
sessionCtx: params.sessionCtx,
@@ -483,7 +488,7 @@ export async function runMemoryFlushIfNeeded(params: {
runId: flushRunId,
authProfile,
});
return runEmbeddedPiAgent({
const result = await runEmbeddedPiAgent({
...embeddedContext,
...senderContext,
...runBaseParams,
@@ -493,6 +498,9 @@ export async function runMemoryFlushIfNeeded(params: {
cfg: params.cfg,
}),
extraSystemPrompt: flushSystemPrompt,
bootstrapPromptWarningSignaturesSeen,
bootstrapPromptWarningSignature:
bootstrapPromptWarningSignaturesSeen[bootstrapPromptWarningSignaturesSeen.length - 1],
onAgentEvent: (evt) => {
if (evt.stream === "compaction") {
const phase = typeof evt.data.phase === "string" ? evt.data.phase : "";
@@ -502,6 +510,10 @@ export async function runMemoryFlushIfNeeded(params: {
}
},
});
bootstrapPromptWarningSignaturesSeen = resolveBootstrapWarningSignaturesSeen(
result.meta?.systemPromptReport,
);
return result;
},
});
let memoryFlushCompactionCount =