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

Commit a2f2e3f

Browse files
fix: validate inference history is valid json (#916)
1 parent 1ac9ebe commit a2f2e3f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# Change Log
44

5+
NOTE: all releases may include dependency updates, not specifically mentioned
6+
7+
## 2025-06-25 - Runtime v0.18.2
8+
9+
- fix: validate inference history is valid json [#916](https://github.com/hypermodeinc/modus/pull/916)
10+
511
## 2025-06-24 - Runtime v0.18.1
612

713
- fix: subscribing to events should not be blocked by agent actor state [#910](https://github.com/hypermodeinc/modus/pull/910)

runtime/db/db.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ func logDbWarningOrError(ctx context.Context, err error, msg string) {
5757
logger.Warn(ctx).Msgf("Database has not been configured. %s", msg)
5858
}
5959
} else {
60-
logger.Err(ctx, err).Msg(msg)
60+
// not really an error, but we log it as such
61+
// but user-visible so it doesn't flag in Sentry
62+
logger.Err(ctx, err).Bool("user_visible", true).Msg(msg)
6163
}
6264
}
6365

runtime/db/inferencehistory.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/hypermodeinc/modus/runtime/plugins"
2020
"github.com/hypermodeinc/modus/runtime/secrets"
2121
"github.com/hypermodeinc/modus/runtime/utils"
22+
"github.com/tidwall/gjson"
2223

2324
"github.com/hypermodeinc/modusgraph"
2425
"github.com/jackc/pgx/v5"
@@ -161,21 +162,27 @@ func getInferenceDataJson(val any) ([]byte, error) {
161162
// It might be formatted, but we don't care because we store in a JSONB column in Postgres,
162163
// which doesn't preserve formatting. For all other types, we serialize to JSON ourselves.
163164

164-
var bytes []byte
165+
var result []byte
165166
switch t := val.(type) {
166167
case []byte:
167-
bytes = t
168+
result = t
168169
case string:
169-
bytes = []byte(t)
170+
result = []byte(t)
170171
default:
171172
if b, err := utils.JsonSerialize(val); err == nil {
172-
bytes = b
173+
result = b
173174
} else {
174175
return nil, err
175176
}
176177
}
177178

178-
return utils.SanitizeUTF8(bytes), nil
179+
result = utils.SanitizeUTF8(result)
180+
181+
if !gjson.ValidBytes(result) {
182+
return nil, fmt.Errorf("invalid JSON data: %s", result)
183+
}
184+
185+
return result, nil
179186
}
180187

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

0 commit comments

Comments
 (0)