Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(analysis-view): bound the spelling summary of shared positions
spellingSummary classified every observed value with three full-size
replaceAll copies and a set per distinct character, so a donor holding
a multi-megabyte segment cost unaccounted memory and time in finish().
Characters are now classified in one pass, and a value longer than 128
characters takes no part in spelling comparisons: it shares a position
only as an exactly observed value. The 50 showcase captures give the
same tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 20, 2026
commit 03b66df90301a146627a9c025eb6fd41d76b4161
4 changes: 3 additions & 1 deletion docs/specs/agent-environments/prefix-variance/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ the parameter another tool already uses at that position, so the write becomes
the literal has that length and uses only their character classes, so an
identifier that happens to hold no digit still qualifies. An empty literal, a
stop word or a `v1`-style version never qualifies. Each parameter's spelling
is summarised once, so a literal is checked without rescanning its values.
is summarised once, so a literal is checked without rescanning its values,
and a value longer than 128 characters is compared only exactly, so a huge
segment costs no classification.
- Positions templated by the four format rules are never shared, so
`/api/teams/{numeric}` still absorbs no literal.
- Values stay with the parameter that observed them: when parameters of
Expand Down
6 changes: 6 additions & 0 deletions docs/specs/agent-environments/prefix-variance/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ here. The gates above passed again (domain and services 7255 passed with 5
pre-existing skips; the focused boundaries 76; `jscpd` 3.49%). Over the 50
showcase captures the tools with and without `prefix-variance` are unchanged,
name for name: 69 literal tools templated, 25 of them writes.

A second review round bounded the spelling summary: characters are classified
in one pass, and a value longer than 128 characters is compared only exactly.
Its test fails on the previous head, the gates passed again (domain and
services 7257, focused boundaries 76, `jscpd` 3.49%), and the census over the 50
captures is again unchanged.
29 changes: 29 additions & 0 deletions src/domain/analysisView/environmentManifestSpelling.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";

import {
spelledLikeObserved,
spellingSummary,
} from "./environmentManifestSpelling.js";

describe("spelledLikeObserved", () => {
it("compares digit-bearing values by length and character classes, and digit-free ones by family", () => {
const observed = spellingSummary(["ydr9n16753tzr7zc"]);
expect(spelledLikeObserved("ab1cd23ef4gh5ij6", observed)).toBe(true);
expect(spelledLikeObserved("fkmwxmxngagvsxfg", observed)).toBe(true);
expect(spelledLikeObserved("FkMwxmXNGaGVsXFG", observed)).toBe(false);
expect(spelledLikeObserved("notifications", observed)).toBe(false);
});

it("compares no value longer than the spelling limit, observed or candidate", () => {
const long = (length: number, last: string) =>
`${"a".repeat(length - 1)}${last}`;
expect(
spelledLikeObserved(long(128, "2"), spellingSummary([long(128, "1")])),
).toBe(true);
const beyond = spellingSummary([long(129, "1")]);
expect(beyond).toEqual({ shapes: new Set(), family: undefined });
expect(spelledLikeObserved(long(129, "2"), beyond)).toBe(false);
// A multi-megabyte segment is summarised without classifying its characters.
expect(spellingSummary([`${"é".repeat(4_000_000)}1`]).shapes.size).toBe(0);
});
});
39 changes: 25 additions & 14 deletions src/domain/analysisView/environmentManifestSpelling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import {
/** Fewest characters of a fixed-length identifier family whose members need not carry a digit. */
const FIXED_LENGTH_MINIMUM = 8;

/** The distinct classes of a text's characters: digits, lower case, upper case and each other character. */
const characterClasses = (text: string): string =>
[
...new Set(
text
.replaceAll(/\d/gu, "0")
.replaceAll(/[a-z]/gu, "a")
.replaceAll(/[A-Z]/gu, "A"),
),
]
.sort(compare)
.join("");
/** Longest value, in UTF-16 units, compared by spelling; a longer one shares a position only as an observed value. */
const SPELLED_LENGTH_LIMIT = 128;

/** The distinct classes of a text's characters, digits, lower case, upper case and each other character, in one pass; undefined past the spelling limit. */
const characterClasses = (text: string): string | undefined => {
if (text.length > SPELLED_LENGTH_LIMIT) return undefined;
const classes = new Set<string>();
for (const character of text)
classes.add(
character >= "0" && character <= "9"
? "0"
: character >= "a" && character <= "z"
? "a"
: character >= "A" && character <= "Z"
? "A"
: character,
);
return [...classes].sort(compare).join("");
};

const shapeOf = (length: number, classes: string): string =>
compositeKey([length, classes]);
Expand All @@ -39,16 +46,19 @@ export const spellingSummary = (
const lengths = new Set<number>();
const classes = new Set<string>();
for (const value of observed) {
lengths.add(value.length);
const kinds = characterClasses(value);
if (kinds === undefined) continue;
shapes.add(shapeOf(value.length, kinds));
lengths.add(value.length);
for (const kind of kinds) classes.add(kind);
}
const [length] = lengths;
return {
shapes,
family:
lengths.size === 1 && length! >= FIXED_LENGTH_MINIMUM
lengths.size === 1 &&
length! >= FIXED_LENGTH_MINIMUM &&
length! <= SPELLED_LENGTH_LIMIT
? { length: length!, classes }
: undefined,
};
Expand All @@ -60,6 +70,7 @@ export const spelledLikeObserved = (
observed: SpellingSummary,
): boolean => {
const classes = characterClasses(value);
if (classes === undefined) return false;
const { family } = observed;
if (
family !== undefined &&
Expand Down
Loading