Repository navigation
fix(cache-warming): Skip NUL escapes when the history scan reads a message - #3528
Conversation
…ssage Co-Authored-By: Burak Yigit Kaya <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
left a comment
There was a problem hiding this comment.
Okay what exactly are we doing with the message text during warm up data refill? Like why do we even need it and why are we casting it to jsonb?
|
The re-fill doesn't use the message text. It needs a few small fields of each stored
Schema v2 stores the whole Pi message as one JSON string in Other options:
This PR keeps the cast and drops the escape, which is the smallest fix that makes existing history readable. I can add (1) and/or (3) here or in a follow-up if you want. |
|
24 screenshot changes — 24 changed · 0 added · 0 removed Review screenshots in Frameshift Show 12 more changed screenshots6 more changed screenshots in Frameshift. |
|
Options 1 and 3 are in #3529, a draft follow-up against |
Follow-up to #3528. The cache warming history scan reads `stopReason`, `timestamp`, `toolName`, and `isError` of each assistant message and tool result. In schema v2 they are only in the `message` JSON string, so each row had to be parsed with `::jsonb`. - `encodeHistoryPayload` now also writes these fields as payload keys, next to `model` and `usage`. - `loadEvents` reads a row with these keys directly and parses the message string only for rows from older releases. - `modelId` comes from the `model` payload key, which v1 and v2 rows both have. <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A1e35b4e6bddd6e31a352f1d86ec131e7 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A1e35b4e6bddd6e31a352f1d86ec131e7) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A1e35b4e6bddd6e31a352f1d86ec131e7/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
… parses a message (#3557) #3528 dropped only the `\u0000` escape before the history scan casts an older stored message to `jsonb`. Text cut inside an emoji keeps half of a surrogate pair, `JSON.stringify` writes it as a lone `\ud83d`, and `jsonb` rejects that too (`invalid input syntax for type json`). One such message fails the query of its batch, so the savings re-fill stops again. The stored text comes from `JSON.stringify`, so it is valid JSON. `jsonb` rejects only some `\uXXXX` escapes in it. The cast now drops every `\uXXXX` escape that is not itself escaped, which covers this class of errors instead of one escape at a time. The fields that replay reads (`stopReason`, `timestamp`, `toolName`, `isError`) have no escapes, so their values do not change. This replaces the NUL-only regex. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A1e35b4e6bddd6e31a352f1d86ec131e7 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A1e35b4e6bddd6e31a352f1d86ec131e7) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A1e35b4e6bddd6e31a352f1d86ec131e7/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Burak Yigit Kaya <[email protected]>
The history scan of the cache warming backfill and the savings re-fill casts the stored message text of each schema v2 event to
jsonb. A message with a NUL character is stored with a\u0000escape, andjsonbrejects it (unsupported Unicode escape sequence, 22P05). That failed the query of the whole batch. The scan skips a batch only when the query is canceled, so a re-fill retried the same batch on each slice and never finished. The gap backfill reads events with the same query, so it failed the same way.loadEventsnow removes each\u0000escape before the cast. The regex keeps an escaped backslash followed byu0000as it is. Text without the escape skips the regex. The other fields of the message stay, so the event still counts. This works on all Postgres versions;pg_input_is_validneeds Postgres 16 and would drop the whole message.via @BYK.
--
View Session [Sentry]