fix(security): OC-65 prevent compaction counter reset to enforce context exhaustion limit — Aether AI Agent

Remove the `overflowCompactionAttempts = 0` reset inside the inner loop's
tool-result-truncation branch. The counter was being zeroed on each truncation
cycle, allowing prompt-injection attacks to bypass the MAX_OVERFLOW_COMPACTION_ATTEMPTS
guard and trigger unbounded auto-compaction, exhausting context window resources (DoS).

CWE-400 / GHSA-x2g4-7mj7-2hhj
This commit is contained in:
Aether AI Agent
2026-02-18 15:27:57 +11:00
committed by Peter Steinberger
parent 2b76901f35
commit 084f621025

View File

@@ -714,8 +714,8 @@ export async function runEmbeddedPiAgent(
log.info(
`[context-overflow-recovery] Truncated ${truncResult.truncatedCount} tool result(s); retrying prompt`,
);
// Session is now smaller; allow compaction retries again.
overflowCompactionAttempts = 0;
// Do NOT reset overflowCompactionAttempts here — the global cap must remain
// enforced across all iterations to prevent unbounded compaction cycles (OC-65).
continue;
}
log.warn(