diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb3bdcae..892ba469c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ # Change Log +NOTE: all releases may include dependency updates, not specifically mentioned + +## 2025-06-25 - Runtime v0.18.2 + +- fix: validate inference history is valid json [#916](https://github.com/hypermodeinc/modus/pull/916) + ## 2025-06-24 - Runtime v0.18.1 - fix: subscribing to events should not be blocked by agent actor state [#910](https://github.com/hypermodeinc/modus/pull/910) diff --git a/runtime/db/db.go b/runtime/db/db.go index b7a229435..6014c5fcd 100644 --- a/runtime/db/db.go +++ b/runtime/db/db.go @@ -57,7 +57,9 @@ func logDbWarningOrError(ctx context.Context, err error, msg string) { logger.Warn(ctx).Msgf("Database has not been configured. %s", msg) } } else { - logger.Err(ctx, err).Msg(msg) + // not really an error, but we log it as such + // but user-visible so it doesn't flag in Sentry + logger.Err(ctx, err).Bool("user_visible", true).Msg(msg) } } diff --git a/runtime/db/inferencehistory.go b/runtime/db/inferencehistory.go index a9206205b..4def4725f 100644 --- a/runtime/db/inferencehistory.go +++ b/runtime/db/inferencehistory.go @@ -19,6 +19,7 @@ import ( "github.com/hypermodeinc/modus/runtime/plugins" "github.com/hypermodeinc/modus/runtime/secrets" "github.com/hypermodeinc/modus/runtime/utils" + "github.com/tidwall/gjson" "github.com/hypermodeinc/modusgraph" "github.com/jackc/pgx/v5" @@ -161,21 +162,27 @@ func getInferenceDataJson(val any) ([]byte, error) { // It might be formatted, but we don't care because we store in a JSONB column in Postgres, // which doesn't preserve formatting. For all other types, we serialize to JSON ourselves. - var bytes []byte + var result []byte switch t := val.(type) { case []byte: - bytes = t + result = t case string: - bytes = []byte(t) + result = []byte(t) default: if b, err := utils.JsonSerialize(val); err == nil { - bytes = b + result = b } else { return nil, err } } - return utils.SanitizeUTF8(bytes), nil + result = utils.SanitizeUTF8(result) + + if !gjson.ValidBytes(result) { + return nil, fmt.Errorf("invalid JSON data: %s", result) + } + + return result, nil } func WritePluginInfo(ctx context.Context, plugin *plugins.Plugin) {