Repository navigation
fix(llmpool): keep trimmed provider errors on a rune boundary - #338
Merged
Merged
Conversation
trimErr cut the error text at byte 300, which can split a multi-byte character. The result is stored as llm_profile_health.last_error, and PostgreSQL rejects the invalid UTF-8, so the breaker state of a profile whose provider answers in Chinese is never persisted and the write is retried every second.
BaaRai
approved these changes
Nov 18, 2026
BaaRai
left a comment
Owner
There was a problem hiding this comment.
Cutting back to the previous rune start keeps the value valid UTF-8, and the Chinese-body test pins the PostgreSQL failure mode. Thanks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an LLM profile's provider answers a failover-eligible error in Chinese, the circuit-breaker state for that profile never reaches the database. The error text is
<prefix>: status <code>: <body>, andtrimErrinllmpool/pool.goshortens it withs[:300], which can cut a multi-byte character in half. That string becomesState.LastError, andhealthSyncwrites it tollm_profile_health.last_error(TEXT). PostgreSQL rejects the invalid UTF-8, so the row is not saved, the op is put back and retried every second with the same error, and a cooling-off window does not survive a restart.With the error
openai: status 503:followed by服务暂时不可用,请稍后重试。repeated,trimErrreturns a string ending in\xe7…. Copying that value into thellm_profile_healthtable fromdb/schema.sqlon postgres:16 fails withinvalid byte sequence for encoding "UTF8": 0xe7 0xe2 0x80.The fix moves the cut back to the start of the rune, so the result is valid UTF-8 and still at most 300 bytes plus the ellipsis.
TestTrimErrKeepsValidUTF8fails before the fix with the trailing\xe7and passes after.go test ./llmpoolpasses, and the fixed value copies into the same postgres:16 table without error.Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.