Repository navigation
fix(context-poisoning): honour configured maxEntriesPerSession - #4232
PratikDhanave (PratikDhanave) wants to merge 2 commits into
Conversation
ContextPoisoningConfig.maxEntriesPerSession (default 200) was accepted and stored, but addEntry evicted based on the hard-coded static MAX_ENTRIES_PER_KEY (1000), so a caller setting e.g. maxEntriesPerSession: 50 silently got a 1000-entry cap. The sibling maxContextSizeBytes is honoured, so the config is meant to be live. Evict against the configured per-session cap, bounded by MAX_ENTRIES_PER_KEY as an absolute memory ceiling (so an over-large config can't grow unbounded). Add a test asserting the configured cap is applied. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Pratik Dhanave <i.pratikdhanave@gmail.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
PR Review Summary
Verdict: AI review comments are untrusted advisory output. The summary reports workflow-generated completion status only, not model-authored pass/fail claims. |
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
MohammadHaroonAbuomar
left a comment
There was a problem hiding this comment.
- Please replace the description with the repository PR template and complete it (Type of Change, Packages Affected, Checklist, Attribution, AI Assistance including the autonomous-submission attestation, IP). The commit records Claude Code as co-author, so the AI Assistance attestations are the ones that matter here, as on #4226.
…ive values Math.max(1, NaN) is NaN, so `entries.length >= NaN` was never true and eviction was disabled for a non-finite maxEntriesPerSession (NaN retained every entry, breaking the absolute ceiling the change promised). Resolve the cap like resolveTimeoutMs in sandbox.ts: a finite value > 0 is used, otherwise the default (200), then capped at MAX_ENTRIES_PER_KEY. 0/negative now fall back to the default rather than clamping to 1. Add tests for NaN, 0, and negative. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Pratik Dhanave <i.pratikdhanave@gmail.com>
|
Thanks MohammadHaroonAbuomar — fixed the non-finite case. You're right: const resolved =
Number.isFinite(configured) && configured > 0 ? configured : DEFAULT_CONFIG.maxEntriesPerSession;
const perSessionCap = Math.min(resolved, ContextPoisoningDetector.MAX_ENTRIES_PER_KEY);So I'll also complete the PR description against the repo template (including the AI-assistance attestations) — PratikDhanave (@PratikDhanave) will confirm those attestations on his side. |
MohammadHaroonAbuomar
left a comment
There was a problem hiding this comment.
- The code change is now complete and verified, thank you. What remains is the description: please replace it with the repository PR template and complete it (Type of Change, Packages Affected, Checklist, Attribution, AI Assistance, IP). The AI Assistance attestations need to come from you as the author, in particular "No part of this PR was autonomously submitted by an AI agent without my review" and "I can explain every meaningful change": the commits carry a Claude co-author trailer and the latest comment refers to you in the third person, so I need the human confirmation before approving. The same applies to #4226, #4233 and #4234.
Related Issue
None — Problem & Solution, Impact, and Alternatives completed below.
Problem & Solution
Problem:
ContextPoisoningConfig.maxEntriesPerSession(default 200) was accepted and stored but never honoured —addEntryevicted against the hard-coded staticMAX_ENTRIES_PER_KEY(1000), so a custom per-session cap was silently ignored (the siblingmaxContextSizeBytesis honoured, so the config is meant to be live). The first revision usedMath.max(1, maxEntriesPerSession), which isNaNfor a non-finite config, soentries.length >= NaNwas never true and eviction was disabled entirely — aNaNcap retained every entry, breaking the absolute ceiling the change promised.Solution: Resolve the cap the way this repo's
src/sandbox.tsresolvestimeoutSeconds(resolveTimeoutMs): a finite value> 0is used, otherwise the default (200); then cap atMAX_ENTRIES_PER_KEY. So0/ negative /NaNfall back to the default rather than1/NaN, and eviction plus the absolute ceiling always hold.Impact on Your Work
Surfaced during a review/hardening pass over the toolkit's TypeScript governance components. A silently-ignored per-session cap is a latent governance/memory-bound correctness gap (a caller setting a small cap still got 1000, and a non-finite cap disabled eviction).
Timeline
None.
Alternatives Considered
Clamping non-positive values to
1(rejected — diverges frommain's effective 1000 cap and surprises callers) versus falling back to the documented default (chosen: matchessandbox.tsparity and the maintainer's review guidance).Type of Change
Package(s) Affected
TypeScript SDK
@microsoft/agent-governance-sdk(agent-governance-typescript) —src/context-poisoning.ts(ContextPoisoningDetector). None of the checkboxes below name the TypeScript SDK directly, so noting it here in text.Testing
Unit Testing
Extended
agent-governance-typescript/tests/context-poisoning.test.ts:maxEntriesPerSession: 3retains 3 of 5 entries for one session.NaN,0, and-5each fall back to the default (200) and keep eviction active. This case fails on the pre-fix code (205 retained) and passes after.Manual Testing
N/A — behaviour is covered by the unit tests above (
tsc --noEmitclean,jest tests/context-poisoning.test.ts28/28).Checklist
tsc --noEmitcleanjest28/28Attribution & Prior Art
Prior art / related projects (if any): resolution pattern mirrors this repo's own
src/sandbox.tsresolveTimeoutMs, credited in the code comment.AI Assistance
Disclosure: This change was developed by Claude Code (an AI agent) operating under the direction of PratikDhanave (@PratikDhanave) — the AI located the bug, wrote the fix and tests, and ran verification (
tsc+jest). The commit records Claude Code as co-author. Submitted via PratikDhanave (@PratikDhanave)'s account.IP, Patents, and Licensing