Skip to content

Commit bd05ef3

Browse files
committed
fix(db): count prompt_source in export message byte preflight
artifactMessageRawBytesSQL bounds the raw string bytes materialized for one artifact export, but it omitted the new prompt_source column, so preflight undercounted message bytes against the explicit MessageBytes limit. Include the column and pin the boundary with a PromptSource raw-byte test.
1 parent 8b5f16b commit bd05ef3

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal/db/artifact_export_load.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const artifactMessageRawBytesSQL = `
4545
length(CAST(source_type AS BLOB)) +
4646
length(CAST(source_subtype AS BLOB)) +
4747
length(CAST(source_uuid AS BLOB)) +
48-
length(CAST(source_parent_uuid AS BLOB))`
48+
length(CAST(source_parent_uuid AS BLOB)) +
49+
length(CAST(prompt_source AS BLOB))`
4950

5051
const artifactToolCallRawBytesSQL = `
5152
length(CAST(tool_name AS BLOB)) +

internal/db/artifact_export_load_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ func TestLoadArtifactExportDataRawByteBoundaries(t *testing.T) {
225225
require.ErrorIs(t, err, ErrArtifactExportLimit)
226226
})
227227

228+
t.Run("prompt source data", func(t *testing.T) {
229+
database := artifactExportLoadTestDB(t)
230+
require.NoError(t, database.ReplaceSessionMessages("session", []Message{{
231+
SessionID: "session", Ordinal: 0, Role: "user", Content: "abcd",
232+
PromptSource: "typed",
233+
}}))
234+
limits := smallArtifactExportLoadLimits()
235+
limits.MessageBytes = 13
236+
data, err := database.LoadArtifactExportData(t.Context(), "session", limits)
237+
require.NoError(t, err)
238+
assert.Len(t, data.Messages, 1)
239+
240+
limits.MessageBytes = 12
241+
_, err = database.LoadArtifactExportData(t.Context(), "session", limits)
242+
require.ErrorIs(t, err, ErrArtifactExportLimit)
243+
})
244+
228245
t.Run("usage data", func(t *testing.T) {
229246
database := artifactExportLoadTestDB(t)
230247
require.NoError(t, database.ReplaceSessionUsageEvents("session", []UsageEvent{{

0 commit comments

Comments
 (0)