Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(context): stop conflicts eating the evidence budget
KageBinary6e79e2952938
diff --git a/ix-cli/src/cli/__tests__/context.test.ts b/ix-cli/src/cli/__tests__/context.test.tsindex e0c02487..eee47ea6 100644--- a/ix-cli/src/cli/__tests__/context.test.ts+++ b/ix-cli/src/cli/__tests__/context.test.ts@@ -339,6 +339,72 @@ describe("ix context bundle", () => {expect(second.intents).toEqual(first.intents);});+ it("keeps conflicts out of the evidence list", () => {+ const conflicts: ConflictReport[] = Array.from({ length: 8 }, (_, i) => ({+ id: `c-${i}`,+ claimA: `12e6db16-e88f-34d1-92ab-4d1700fd67a${i}`,+ claimB: `494d48cd-fff5-37a9-93f5-060c0760c52${i}`,+ reason: "Potential inconsistency (same field prefix)",+ recommendation: "rec",+ }));++ const bundle = buildBundle({ ...input(), context: makeContext({ conflicts }) });++ expect(bundle.evidence.some((item) => item.kind === "conflict")).toBe(false);+ // A claim uuid is not something an agent can act on; none should be+ // reachable through the evidence list at all.+ const rendered = JSON.stringify(bundle.evidence);+ expect(rendered).not.toContain("12e6db16");+ // The reports themselves are still carried, and still counted.+ expect(bundle.conflicts).toHaveLength(8);+ });++ it("leaves the evidence budget to real structure when conflicts are present", () => {+ // The regression this exists for: 8 conflicts used to take 8 of the 10+ // slots and push the structural facts out of the bundle entirely.+ const conflicts: ConflictReport[] = Array.from({ length: 8 }, (_, i) => ({+ id: `c-${i}`,+ claimA: `claim-a-${i}`,+ claimB: `claim-b-${i}`,+ reason: "Potential inconsistency (same field prefix)",+ recommendation: "rec",+ }));+ const budgets = { maxEntities: 50, maxRelationships: 100, maxEvidence: 10, maxChars: 12000 };++ const withConflicts = buildBundle({ ...input(), budgets, context: makeContext({ conflicts }) });+ const without = buildBundle({ ...input(), budgets, context: makeContext() });++ const structural = (b: typeof withConflicts) => b.evidence.filter((i) => i.kind === "structural").length;+ expect(structural(withConflicts)).toBe(structural(without));+ expect(structural(withConflicts)).toBeGreaterThan(0);+ });++ it("caps the conflict reports it carries and says how many it dropped", () => {+ const conflicts: ConflictReport[] = Array.from({ length: 31 }, (_, i) => ({+ id: `c-${String(i).padStart(2, "0")}`,+ claimA: `claim-a-${String(i).padStart(2, "0")}`,+ claimB: `claim-b-${String(i).padStart(2, "0")}`,+ reason: "Potential inconsistency (same field prefix)",+ recommendation: "rec",+ }));++ const bundle = buildBundle({ ...input(), context: makeContext({ conflicts }) });++ expect(bundle.conflicts).toHaveLength(10);+ expect(bundle.truncation.conflictsTruncated).toBe(21);+ // Kept + dropped still reports the true count to the renderers.+ expect(bundle.conflicts.length + bundle.truncation.conflictsTruncated).toBe(31);+ // The cut is taken after the deterministic sort, so it is reproducible.+ expect(bundle.conflicts.map((c) => c.claimA)).toEqual(+ Array.from({ length: 10 }, (_, i) => `claim-a-${String(i).padStart(2, "0")}`),+ );+ });++ it("reports no conflict truncation when the bundle is under the cap", () => {+ const bundle = buildBundle({ ...input(), context: makeContext() });+ expect(bundle.truncation.conflictsTruncated).toBe(0);+ });+it("bounds evidence by the exact serialized representation, not an estimate", () => {const claims = Array.from({ length: 60 }, (_, i) => makeClaim(`statement number ${i} with some padding text`, 0.5));const budgets = { maxEntities: 50, maxRelationships: 100, maxEvidence: 25, maxChars: 500 };diff --git a/ix-cli/src/cli/commands/context.ts b/ix-cli/src/cli/commands/context.tsindex 21fd306b..f4faade7 100644--- a/ix-cli/src/cli/commands/context.ts+++ b/ix-cli/src/cli/commands/context.ts@@ -48,6 +48,13 @@ interface BudgetSnapshot {* this table, and `--help` interpolates it, so the number a user is told is* the number that is applied.*/+/**+ * Hard cap on the conflict reports carried in a bundle. Not a `--max-*` flag:+ * the bundle reports the count it saw either way, and a caller who needs every+ * report wants `ix conflicts`, not a bigger context bundle.+ */+const MAX_CONFLICTS = 10;+const BUDGETS = [{ key: "maxEntities", flag: "--max-entities", label: "entities", help: "Maximum entities in the bundle", min: 1, max: 500, fallback: 50 },{ key: "maxRelationships", flag: "--max-relationships", label: "relationships", help: "Maximum relationships in the bundle", min: 1, max: 1000, fallback: 100 },@@ -203,6 +210,7 @@ interface ContextBundle {relationshipsTruncated: number;evidenceTruncated: number;charactersTruncated: number;+ conflictsTruncated: number;};metadata: {asOfRev?: number;@@ -1457,6 +1465,7 @@ export function buildBundle(input: BuildInput): ContextBundle {relationshipsTruncated: 0,evidenceTruncated: 0,charactersTruncated: 0,+ conflictsTruncated: 0,},metadata: {asOfRev,@@ -1522,6 +1531,15 @@ export function buildBundle(input: BuildInput): ContextBundle {const fullChars = sizedEvidence.reduce((sum, entry) => sum + entry.size, 0);bundle.truncation.charactersTruncated = Math.max(0, fullChars - chars);+ // `conflicts[]` was the one list with no budget at all, and it is the one the+ // backend can hand back by the dozen: it reached 12,922 of 23,030 JSON bytes+ // on a recorded bundle. The evidence budgets never bounded it because they+ // bound `evidence`. Cap it at a fixed depth -- a caller who wants the full+ // set has `ix conflicts`, which is the command that renders them properly.+ const conflictLimit = Math.min(bundle.conflicts.length, MAX_CONFLICTS);+ bundle.truncation.conflictsTruncated = bundle.conflicts.length - conflictLimit;+ bundle.conflicts = bundle.conflicts.slice(0, conflictLimit);+return bundle;}@@ -1595,17 +1613,12 @@ function rankEvidence(input: {refs: decision.entityId ? [decision.entityId] : [],});}- for (const conflict of input.context.conflicts) {- items.push({- id: `conflict:${conflict.id}`,- kind: "conflict",- source: "context.conflicts",- title: `${conflict.claimA} vs ${conflict.claimB}`,- score: 22,- reason: conflict.reason,- refs: [],- });- }+ // Conflicts are deliberately NOT evidence. A report names its two claims by+ // uuid, which is nothing an agent can act on, and at score 22 they outranked+ // every relationship: on recorded bundles they were taking 12 to 17 of the 25+ // slots and truncating away the members and imports that answer the question.+ // The count is carried in the bundle header and the reports themselves stay+ // in `conflicts[]` for a caller that wants them; `ix conflicts` renders them.for (const intent of input.context.intents) {items.push({id: `intent:${intent.id}`,@@ -1667,7 +1680,7 @@ export function renderBundle(bundle: ContextBundle, format: string): void {relationships: bundle.relationships.length,claims: bundle.claims.length,decisions: bundle.decisions.length,- conflicts: bundle.conflicts.length,+ conflicts: bundle.conflicts.length + bundle.truncation.conflictsTruncated,intents: bundle.intents.length,evidence: bundle.evidence.length,truncated_entities: bundle.truncation.entitiesTruncated,@@ -1691,7 +1704,12 @@ export function renderBundle(bundle: ContextBundle, format: string): void {console.log(` relationships: ${bundle.relationships.length}`);console.log(` claims: ${bundle.claims.length}`);console.log(` decisions: ${bundle.decisions.length}`);- console.log(` conflicts: ${bundle.conflicts.length}`);+ // Named, not listed: see rankEvidence. The hint is what makes the count+ // actionable, since the reports are no longer in the evidence list.+ const conflictCount = bundle.conflicts.length + bundle.truncation.conflictsTruncated;+ console.log(+ ` conflicts: ${conflictCount}${conflictCount > 0 ? " (run ix conflicts to inspect)" : ""}`,+ );console.log(` intents: ${bundle.intents.length}`);if (bundle.freshness.stale) {renderWarning("Source has changed since last ingest. Run ix map to update.");diff --git a/ix-cli/src/cli/context-bundle-schema.ts b/ix-cli/src/cli/context-bundle-schema.tsindex f5240d82..9136b4cc 100644--- a/ix-cli/src/cli/context-bundle-schema.ts+++ b/ix-cli/src/cli/context-bundle-schema.ts@@ -94,6 +94,10 @@ export const contextBundleSchema = z.object({relationshipsTruncated: z.number().int().nonnegative(),evidenceTruncated: z.number().int().nonnegative(),charactersTruncated: z.number().int().nonnegative(),+ // Optional on the way in, always written on the way out: a bundle saved+ // before the conflict cap existed has no such counter, and refusing to+ // read it back would break `--diff` against every investigation on disk.+ conflictsTruncated: z.number().int().nonnegative().optional(),}),// `asOfRev` and `depth` are the two saved values `ix context --diff` re-sends// to the backend, so they are typed rather than accepted as anything.