Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 5ef3fd4

Browse files
fix: ensure valid UTF8 byte sequence for inference history (#911)
1 parent 758e079 commit 5ef3fd4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## 2025-06-24 - Runtime v0.18.1
66

77
- fix: subscribing to events should not be blocked by agent actor state [#910](https://github.com/hypermodeinc/modus/pull/910)
8+
- fix: ensure valid UTF8 byte sequence for inference history [#911](https://github.com/hypermodeinc/modus/pull/911)
89

910
## 2025-06-23 - Runtime v0.18.0
1011

runtime/db/inferencehistory.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,23 @@ func getInferenceDataJson(val any) ([]byte, error) {
159159

160160
// If the value is a byte slice or string, it must already have been serialized as JSON.
161161
// It might be formatted, but we don't care because we store in a JSONB column in Postgres,
162-
// which doesn't preserve formatting.
162+
// which doesn't preserve formatting. For all other types, we serialize to JSON ourselves.
163+
164+
var bytes []byte
163165
switch t := val.(type) {
164166
case []byte:
165-
return t, nil
167+
bytes = t
166168
case string:
167-
return []byte(t), nil
169+
bytes = []byte(t)
170+
default:
171+
if b, err := utils.JsonSerialize(val); err == nil {
172+
bytes = b
173+
} else {
174+
return nil, err
175+
}
168176
}
169177

170-
// For all other types, we serialize to JSON ourselves.
171-
bytes, err := utils.JsonSerialize(val)
172-
if err != nil {
173-
return nil, err
174-
}
175-
return bytes, nil
178+
return utils.SanitizeUTF8(bytes), nil
176179
}
177180

178181
func WritePluginInfo(ctx context.Context, plugin *plugins.Plugin) {

0 commit comments

Comments
 (0)