From fcab72f8b88bd658782a83ece18c9ac04e248cd7 Mon Sep 17 00:00:00 2001 From: kitadesign Date: Mon, 7 Sep 2026 04:52:57 +0000 Subject: [PATCH] fix(session): preserve the starred flag in AddSession SQLiteSessionStore.AddSession built its own INSERT that omitted the starred column, while UpdateSession, addSessionTx and PersistCompaction all set it. Forking a starred session therefore dropped the star, since copySessionMetadata copies it and ForkSession persists via AddSession. The INSERT was otherwise identical to addSessionTx, so call that instead of maintaining a second column list that can drift again. Noticed while mapping the session schema for #4181. --- pkg/session/store.go | 17 +---------------- pkg/session/store_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/session/store.go b/pkg/session/store.go index 0e9006383..81c7f8f27 100644 --- a/pkg/session/store.go +++ b/pkg/session/store.go @@ -626,11 +626,6 @@ func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) e return ErrEmptyID } - fields, err := sessionPersistedFieldsOf(session) - if err != nil { - return err - } - // Use a transaction to insert session and its items tx, err := s.db.BeginTx(ctx, nil) if err != nil { @@ -638,17 +633,7 @@ func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) e } defer func() { _ = tx.Rollback() }() - _, err = tx.ExecContext(ctx, - `INSERT INTO sessions ( - id, origin, tools_approved, safety_policy, input_tokens, output_tokens, title, cost, send_user_message, - max_iterations, working_dir, created_at, permissions, agent_model_overrides, - custom_models_used, thinking, parent_id, instruction_context, attributes - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, - session.ID, session.Origin, session.ToolsApproved, string(session.SafetyPolicy), session.InputTokens, session.OutputTokens, session.Title, - session.Cost, session.SendUserMessage, session.MaxIterations, session.WorkingDir, - session.CreatedAt.Format(time.RFC3339), fields.PermissionsJSON, fields.AgentModelOverridesJSON, - fields.CustomModelsUsedJSON, false, fields.ParentID, fields.InstructionContextJSON, fields.AttributesJSON) - if err != nil { + if err := s.addSessionTx(ctx, tx, session); err != nil { return err } diff --git a/pkg/session/store_test.go b/pkg/session/store_test.go index 149f0a920..58dbfebf0 100644 --- a/pkg/session/store_test.go +++ b/pkg/session/store_test.go @@ -1220,3 +1220,17 @@ func TestAddSessionTerminationRoundTrip(t *testing.T) { // Termination markers are not conversation messages. assert.Len(t, retrieved.GetAllMessages(), 2) } + +func TestAddSession_PreservesStarred(t *testing.T) { + store, err := newSQLiteStoreForTest(t, filepath.Join(t.TempDir(), "sessions.db")) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, store.Close()) }) + + sess := New(WithID("starred-session")) + sess.Starred = true + require.NoError(t, store.AddSession(t.Context(), sess)) + + loaded, err := store.GetSession(t.Context(), "starred-session") + require.NoError(t, err) + assert.True(t, loaded.Starred) +}