Merge pull request #382 from N1neSun/fix/allow-null-flow-trace-id

fix(flows): allow pending trace IDs in flow responses
This commit is contained in:
Dmitry Ng
2026-08-03 15:44:28 +04:00
committed by GitHub
6 changed files with 63 additions and 8 deletions
-2
View File
@@ -8592,7 +8592,6 @@ const docTemplate = `{
"status",
"title",
"tool_call_id_template",
"trace_id",
"user_id"
],
"properties": {
@@ -8746,7 +8745,6 @@ const docTemplate = `{
"tasks",
"title",
"tool_call_id_template",
"trace_id",
"user_id"
],
"properties": {
+1 -3
View File
@@ -8584,7 +8584,6 @@
"status",
"title",
"tool_call_id_template",
"trace_id",
"user_id"
],
"properties": {
@@ -8738,7 +8737,6 @@
"tasks",
"title",
"tool_call_id_template",
"trace_id",
"user_id"
],
"properties": {
@@ -10642,4 +10640,4 @@
"in": "header"
}
}
}
}
-2
View File
@@ -664,7 +664,6 @@ definitions:
- status
- title
- tool_call_id_template
- trace_id
- user_id
type: object
models.FlowExecutionStats:
@@ -777,7 +776,6 @@ definitions:
- tasks
- title
- tool_call_id_template
- trace_id
- user_id
type: object
models.FlowUsageResponse:
+1 -1
View File
@@ -56,7 +56,7 @@ type Flow struct {
Language string `form:"language" json:"language" validate:"max=70,required" gorm:"type:TEXT;NOT NULL"`
Functions *tools.Functions `form:"functions,omitempty" json:"functions,omitempty" validate:"omitempty,valid" gorm:"type:JSON;NOT NULL;default:'{}'"`
ToolCallIDTemplate string `form:"tool_call_id_template" json:"tool_call_id_template" validate:"max=70,required" gorm:"type:TEXT;NOT NULL"`
TraceID *string `form:"trace_id" json:"trace_id" validate:"max=70,required" gorm:"type:TEXT;NOT NULL"`
TraceID *string `form:"trace_id" json:"trace_id" validate:"omitempty,max=70" gorm:"type:TEXT"`
UserID uint64 `form:"user_id" json:"user_id" validate:"min=0,numeric,required" gorm:"type:BIGINT;NOT NULL"`
CreatedAt time.Time `form:"created_at,omitempty" json:"created_at,omitempty" validate:"omitempty" gorm:"type:TIMESTAMPTZ;default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `form:"updated_at,omitempty" json:"updated_at,omitempty" validate:"omitempty" gorm:"type:TIMESTAMPTZ;default:CURRENT_TIMESTAMP"`
+15
View File
@@ -374,6 +374,21 @@ func TestFlowValid(t *testing.T) {
assert.NoError(t, validFlow.Valid())
})
t.Run("valid flow while trace id is pending", func(t *testing.T) {
t.Parallel()
f := validFlow
f.TraceID = nil
assert.NoError(t, f.Valid())
})
t.Run("trace id exceeds maximum length", func(t *testing.T) {
t.Parallel()
traceID := "trace-id-that-is-longer-than-the-supported-seventy-character-validation-limit-123"
f := validFlow
f.TraceID = &traceID
assert.Error(t, f.Valid())
})
t.Run("missing title", func(t *testing.T) {
t.Parallel()
f := validFlow
+46
View File
@@ -0,0 +1,46 @@
package services
import (
"encoding/json"
"net/http"
"testing"
"pentagi/pkg/server/models"
"github.com/stretchr/testify/require"
)
func TestGetFlowsAllowsPendingTraceID(t *testing.T) {
db := setupFlowFileServiceTestDB(t)
require.NoError(t, db.Exec(`
INSERT INTO flows (
id, user_id, model, model_provider_name, model_provider_type,
tool_call_id_template, trace_id
) VALUES (1, 42, 'gpt', 'openai', 'openai', 'tcid', NULL)
`).Error)
c, w := newFlowFileTestContext(
http.MethodGet,
"/flows/?page=1&pageSize=5&type=init",
nil,
[]string{"flows.view"},
42,
0,
)
NewFlowService(db, nil, nil, nil).GetFlows(c)
require.Equal(t, http.StatusOK, w.Code)
var resp struct {
Status string `json:"status"`
Data struct {
Flows []models.Flow `json:"flows"`
Total uint64 `json:"total"`
} `json:"data"`
}
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &resp))
require.Equal(t, "success", resp.Status)
require.Equal(t, uint64(1), resp.Data.Total)
require.Len(t, resp.Data.Flows, 1)
require.Nil(t, resp.Data.Flows[0].TraceID)
}