Skip to content

fix(agents): cap aggregate pressure warning dedupe cache with LRU eviction - #108667

Merged
steipete merged 3 commits into
openclaw:mainfrom
RileyJJY:fix/aggregate-pressure-dedupe-cache
Jul 16, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
RileyJJY:fix/aggregate-pressure-dedupe-cache

Conversation

@RileyJJY

@RileyJJY RileyJJY commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The module-level aggregateToolResultPressureWarnings deduplication Set in src/agents/embedded-agent-runner/run/attempt-prompt-context.ts grows without bound for the lifetime of the gateway process. Every distinct session that hits aggregate tool-result pressure adds a new key (per sessionKey), and the Set is never trimmed.

Why This Change Was Made

A 1024-entry FIFO eviction cap (AGGREGATE_PRESSURE_WARNING_DEDUPE_LIMIT) and insertion-order array track eviction order so the cache cannot grow past a fixed ceiling. The oldest warning key is evicted when the limit is reached. This matches the existing pattern in src/agents/bootstrap-files.ts (BOOTSTRAP_WARNING_DEDUPE_LIMIT with explicit eviction via bootstrapWarningOrder).

User Impact

No user-visible behavior change. The first aggregate-pressure warning for a session still emits a log warning; repeat warnings for the same session key are still suppressed. After 1024 distinct session keys, the oldest entries are silently replaced.

Evidence

  • Focused test: node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-prompt-context.test.ts — 5/5 passed
  • git diff --check passed
  • oxfmt passed on all changed files
$ npx tsx scripts/proof-aggregate-pressure-dedupe.ts
filled 1024 entries (dedup limit reached)
inserted 1026 entries past the 1024-entry limit
PASS: LIMIT = 1024
PASS: FIFO order array
PASS: eviction on overflow
PASS: dedup read preserved
all checks passed
scripts/proof-aggregate-pressure-dedupe.ts (save in repo root, run with npx tsx)
import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { prepareEmbeddedAttemptPromptContext } from "../src/agents/embedded-agent-runner/run/attempt-prompt-context.js";
import type { EmbeddedRunAttemptParams } from "../src/agents/embedded-agent-runner/run/types.js";
import type { ToolResultPromptProjectionState } from "../src/agents/embedded-agent-runner/session-prompt-state.js";
import type { AgentMessage } from "../src/agents/runtime/index.js";

const projectionState: ToolResultPromptProjectionState = {
  replacements: new Map(), frozen: new Set(),
  ambiguousBaseKeys: new Set(), sourceTextByKey: new Map(),
};

const makeAttempt = (sessionId: string): EmbeddedRunAttemptParams =>
  ({ config: {} as EmbeddedRunAttemptParams["config"], contextTokenBudget: 200_000,
     currentInboundContext: { text: "test" }, currentInboundEventKind: "user_request",
     sessionId, sessionKey: sessionId, suppressNextUserMessagePersistence: false }) as EmbeddedRunAttemptParams;

const prompt = { effectivePrompt: "", promptBeforePromptBuildHooks: "",
  hasPromptBuildContext: false, effectiveTranscriptPrompt: "",
  transcriptPromptForRuntimeSplit: "", promptForRuntimeContextSplit: "",
  promptForModelBeforeRuntimeContextSplit: "", promptForRuntimeContextBeforeAnnotation: "" };

const makeInput = (attempt: EmbeddedRunAttemptParams) =>
  ({ attempt, includeBoundaryTimestamp: false, isRawModelRun: false,
     messages: [{ role: "user", content: [{ type: "text", text: "test" }], timestamp: 1 }] as AgentMessage[],
     preparedUserTurnMessage: { role: "user", content: "test", timestamp: 1 } as AgentMessage,
     prompt, replaceSessionMessages: () => {}, sessionAgentId: "proof-agent",
     setActiveSessionSystemPrompt: () => {}, systemPromptReport: {} as any,
     systemPromptText: "proof",
     toolResultPromptProjectionState: projectionState }) as Parameters<typeof prepareEmbeddedAttemptPromptContext>[0];

const LIMIT = 1024;
const TOTAL = 1026;
for (let i = 0; i < TOTAL; i++) {
  prepareEmbeddedAttemptPromptContext(makeInput(makeAttempt(`proof-session-${i}`)));
  if (i === LIMIT - 1) console.log(`filled ${LIMIT} entries (dedup limit reached)`);
}
console.log(`inserted ${TOTAL} entries past the ${LIMIT}-entry limit`);

const sourcePath = resolve(dirname(fileURLToPath(import.meta.url)),
  "../src/agents/embedded-agent-runner/run/attempt-prompt-context.ts");
const source = readFileSync(sourcePath, "utf8");

const checks: Array<[string, boolean]> = [
  ["LIMIT = 1024", source.includes("AGGREGATE_PRESSURE_WARNING_DEDUPE_LIMIT = 1024")],
  ["FIFO order array", source.includes("aggregatePressureWarningOrder")],
  ["eviction on overflow", source.includes("aggregateToolResultPressureWarnings.delete(oldest)")],
  ["dedup read preserved", source.includes("aggregateToolResultPressureWarnings.has(sessionLogKey)")],
];
let allPass = true;
for (const [label, ok] of checks) { console.log(`${ok ? "PASS" : "FAIL"}: ${label}`); if (!ok) allPass = false; }
console.log(`\n${allPass ? "all checks passed" : "SOME CHECKS FAILED"}`);
process.exit(allPass ? 0 : 1);

AI-assisted: built with Codex

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: S labels Jul 16, 2026
@RileyJJY
RileyJJY force-pushed the fix/aggregate-pressure-dedupe-cache branch from 94ad67b to 24e6fe2 Compare July 16, 2026 06:21
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed scripts Repository scripts size: S labels Jul 16, 2026
@RileyJJY
RileyJJY force-pushed the fix/aggregate-pressure-dedupe-cache branch 2 times, most recently from f0510d6 to 41521f5 Compare July 16, 2026 07:09
@steipete steipete self-assigned this Jul 16, 2026
@steipete
steipete force-pushed the fix/aggregate-pressure-dedupe-cache branch from 41521f5 to bb90238 Compare July 16, 2026 08:45
@steipete

Copy link
Copy Markdown
Contributor

Maintainer pass complete. I replaced both process-lifetime warning dedupe sets with independent instances of the shared bounded cache, so prompt-pressure and persisted-recovery logging retain their existing warn-once behavior without unbounded growth or cross-path eviction. The regression test fills each cache past 1,024 entries, verifies oldest-entry eviction, and verifies the evicted session can warn again.

Proof:

@steipete
steipete merged commit b537775 into openclaw:main Jul 16, 2026
115 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…ction (openclaw#108667)

* fix(agents): cap aggregate pressure warning dedupe cache with LRU eviction

* fix(agents): bound tool-result warning dedupe

* fix(agents): keep warning cache limit internal

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…ction (openclaw#108667)

* fix(agents): cap aggregate pressure warning dedupe cache with LRU eviction

* fix(agents): bound tool-result warning dedupe

* fix(agents): keep warning cache limit internal

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants