惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
D
Docker
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
D
DataBreaches.Net
月光博客
月光博客
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
MyScale Blog
MyScale Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(shared): use UTF-16 safe truncation in assistant erro...
zenglingbiao · 2026-06-29 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -650,6 +650,33 @@ describe("formatRawAssistantErrorForUi", () => {

650650

"The provider returned an HTML error page instead of an API response. This usually means a CDN or gateway (e.g. Cloudflare) blocked the request. Retry in a moment or check provider status.",

651651

);

652652

});

653+
654+

it("truncates fallback raw error text on UTF-16 code-point boundary without dangling surrogates", () => {

655+

// 601 UTF-16 code units: emoji (surrogate pair) straddles the 600-unit truncation boundary

656+

const prefix = "x".repeat(599);

657+

const emoji = "🎉"; // U+1F389 — high surrogate 0xD83C + low surrogate 0xDF89

658+

const raw = prefix + emoji; // 601 code units total

659+
660+

const result = formatRawAssistantErrorForUi(raw);

661+
662+

// Result must end with "…" after truncation

663+

expect(result).toMatch(/$/);

664+
665+

// Verify the truncated portion contains no dangling surrogates

666+

for (let i = 0; i < result.length - 1; i++) {

667+

const codeUnit = result.charCodeAt(i);

668+

// High surrogate (0xD800-0xDBFF) must be followed by a low surrogate

669+

if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {

670+

const next = result.charCodeAt(i + 1);

671+

expect(next >= 0xdc00 && next <= 0xdfff).toBe(true);

672+

}

673+

// Low surrogate (0xDC00-0xDFFF) must be preceded by a high surrogate

674+

if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {

675+

const prev = i > 0 ? result.charCodeAt(i - 1) : -1;

676+

expect(prev >= 0xd800 && prev <= 0xdbff).toBe(true);

677+

}

678+

}

679+

});

653680

});

654681
655682

describe("raw API error payload helpers", () => {

Original file line numberDiff line numberDiff line change

@@ -14,6 +14,7 @@ import {

1414

isGenericProviderInternalError,

1515

parseApiErrorInfo,

1616

} from "../../shared/assistant-error-format.js";

17+

import { truncateUtf16Safe } from "../../shared/utf16-slice.js";

1718

export {

1819

extractLeadingHttpStatus,

1920

formatRawAssistantErrorForUi,

@@ -1540,7 +1541,7 @@ export function formatAssistantErrorText(

15401541

if (raw.length > 600) {

15411542

log.warn(`Long error truncated: ${raw.slice(0, 200)}`);

15421543

}

1543-

return raw.length > 600 ? `${raw.slice(0, 600)}…` : raw;

1544+

return raw.length > 600 ? `${truncateUtf16Safe(raw, 600)}…` : raw;

15441545

}

15451546
15461547

export function isRawAssistantErrorPassthrough(params: {

@@ -1560,7 +1561,7 @@ export function isRawAssistantErrorPassthrough(params: {

15601561

friendlyError.startsWith("HTTP ");

15611562

return (

15621563

friendlyError === rawError ||

1563-

(rawError.length > 600 && friendlyError === `${rawError.slice(0, 600)}…`) ||

1564+

(rawError.length > 600 && friendlyError === `${truncateUtf16Safe(rawError, 600)}…`) ||

15641565

Boolean(parsedMessage && hasRawDerivedProviderPrefix) ||

15651566

Boolean(leadingStatusRest && friendlyError.startsWith("HTTP "))

15661567

);

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,5 @@

11

// Assistant error formatting helpers normalize assistant-visible error payloads.

2+

import { truncateUtf16Safe } from "./utf16-slice.js";

23

const ERROR_PAYLOAD_PREFIX_RE =

34

/^(?:error|(?:[a-z][\w-]*\s+)?api\s*error|apierror|openai\s*error|anthropic\s*error|gateway\s*error|codex\s*error)(?:\s+\d{3})?[:\s-]+/i;

45

const HTTP_STATUS_DELIMITER_RE = /(?:\s*:\s*|\s+)/;

@@ -246,5 +247,5 @@ export function formatRawAssistantErrorForUi(raw?: string): string {

246247

return `${prefix}${type}: ${info.message}`;

247248

}

248249
249-

return trimmed.length > 600 ? `${trimmed.slice(0, 600)}…` : trimmed;

250+

return trimmed.length > 600 ? `${truncateUtf16Safe(trimmed, 600)}…` : trimmed;

250251

}