Skip to content

Commit b58b205

Browse files
steipetePeter Steinberger
andauthored
perf(tests): bound compaction identifier scans (#118422)
* perf(tests): bound compaction identifier scans * chore: keep release notes out of test PR --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 9e3b874 commit b58b205

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎src/agents/agent-hooks/compaction-safeguard-quality.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ function summaryIncludesIdentifier(summary: string, identifier: string): boolean
146146

147147
/** Extracts likely exact identifiers that summaries should preserve literally. */
148148
export function extractOpaqueIdentifiers(text: string): string[] {
149+
// Host/port candidates start at token boundaries so a long non-identifier
150+
// does not retry the greedy branch at every character.
149151
const matches =
150152
text.match(
151-
/([A-Fa-f0-9]{8,}|https?:\/\/\S+|\/[\w.-]{2,}(?:\/[\w.-]+)+|[A-Za-z]:\\[\w\\.-]+|[A-Za-z0-9._-]+\.[A-Za-z0-9._/-]+:\d{1,5}|\b\d{6,}\b)/g,
153+
/([A-Fa-f0-9]{8,}|https?:\/\/\S+|\/[\w.-]{2,}(?:\/[\w.-]+)+|[A-Za-z]:\\[\w\\.-]+|(?<![A-Za-z0-9._-])[A-Za-z0-9._-]+\.[A-Za-z0-9._/-]+:\d{1,5}|\b\d{6,}\b)/g,
152154
) ?? [];
153155
return uniqueStrings(
154156
matches

‎src/agents/agent-hooks/compaction-safeguard.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,20 @@ describe("compaction-safeguard recent-turn preservation", () => {
10961096
).toBe(1);
10971097
});
10981098

1099+
it("keeps valid host/port identifiers after a long non-identifier token", () => {
1100+
const identifiers = extractOpaqueIdentifiers(
1101+
`${"x".repeat(120_000)} host.local:18789 ` +
1102+
"api.example.com/v1:443 127.0.0.1:8080 sub-domain.example.test:65535",
1103+
);
1104+
1105+
expect(identifiers).toStrictEqual([
1106+
"host.local:18789",
1107+
"api.example.com/v1:443",
1108+
"127.0.0.1:8080",
1109+
"sub-domain.example.test:65535",
1110+
]);
1111+
});
1112+
10991113
it("dedupes identifiers before applying the result cap", () => {
11001114
const noisyPrefix = Array.from({ length: 10 }, () => "a0b0c0d0").join(" ");
11011115
const uniqueTail = Array.from(

0 commit comments

Comments
 (0)