Skip to content

Commit 3469225

Browse files
authored
fix(skills): bound evaluator text without splitting surrogate pairs (#117673)
1 parent ff770f9 commit 3469225

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

‎src/skills/workshop/service-evaluation.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,61 @@ describe("Skill Workshop proposal evaluation", () => {
759759
});
760760
});
761761

762+
it("does not split surrogate pairs when bounding evaluator text", async () => {
763+
const workspaceDir = await tempDirs.make("openclaw-skill-evaluation-surrogate-");
764+
const proposal = await proposeCreateSkill({
765+
workspaceDir,
766+
agentId: "main",
767+
name: "Surrogate Bounds",
768+
description: "Bound evaluator text without splitting surrogates",
769+
content: "# Surrogate Bounds\n",
770+
});
771+
hookMocks.evaluate.mockResolvedValue([
772+
{
773+
evaluatorId: "emoji-bounds",
774+
pluginId: "evaluation-tests",
775+
status: "completed",
776+
result: {
777+
summary: `${"s".repeat(7_999)}🙂`,
778+
decisionReason: `${"r".repeat(1_999)}🙂`,
779+
metrics: { note: `${"m".repeat(3_999)}🙂` },
780+
},
781+
},
782+
{
783+
evaluatorId: "emoji-error",
784+
pluginId: "evaluation-tests",
785+
status: "error",
786+
error: `${"e".repeat(1_999)}🙂`,
787+
},
788+
]);
789+
790+
const evaluated = await evaluateSkillProposal({
791+
workspaceDir,
792+
agentId: "main",
793+
proposalId: proposal.record.id,
794+
expectedRevisionHash: proposal.revisionHash,
795+
});
796+
797+
expect(evaluated.evaluation.outcomes).toEqual([
798+
{
799+
evaluatorId: "emoji-bounds",
800+
pluginId: "evaluation-tests",
801+
status: "completed",
802+
result: {
803+
summary: "s".repeat(7_999),
804+
decisionReason: "r".repeat(1_999),
805+
metrics: { note: "m".repeat(3_999) },
806+
},
807+
},
808+
{
809+
evaluatorId: "emoji-error",
810+
pluginId: "evaluation-tests",
811+
status: "error",
812+
error: "e".repeat(1_999),
813+
},
814+
]);
815+
});
816+
762817
it("rejects evaluator results that exceed the aggregate persistence budget", async () => {
763818
const workspaceDir = await tempDirs.make("openclaw-skill-evaluation-size-budget-");
764819
const proposal = await proposeCreateSkill({

‎src/skills/workshop/service-evaluation.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomUUID } from "node:crypto";
22
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
3+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
34
import type {
45
PluginHookSkillEvaluationFinding,
56
PluginHookSkillProposalEvaluateResult,
@@ -346,18 +347,19 @@ function normalizeMetrics(
346347
) {
347348
return undefined;
348349
}
349-
normalized[key] = typeof value === "string" ? value.slice(0, 4_000) : value;
350+
normalized[key] = typeof value === "string" ? truncateUtf16Safe(value, 4_000) : value;
350351
}
351352
return normalized;
352353
}
353354

354355
function boundedRequired(value: string, maxLength: number, fallback: string): string {
355356
const normalized = normalizeOptionalString(value) ?? fallback;
356-
return normalized.slice(0, maxLength);
357+
return truncateUtf16Safe(normalized, maxLength);
357358
}
358359

359360
function boundedOptional(value: string | undefined, maxLength: number): string | undefined {
360-
return normalizeOptionalString(value)?.slice(0, maxLength);
361+
const normalized = normalizeOptionalString(value);
362+
return normalized === undefined ? undefined : truncateUtf16Safe(normalized, maxLength);
361363
}
362364

363365
function storeOptions(env?: NodeJS.ProcessEnv) {

0 commit comments

Comments
 (0)