refactor(store,tools): migrate IDs from UUID to bigserial int64
Some checks failed
CI / build-and-test (push) Failing after -31m12s
Some checks failed
CI / build-and-test (push) Failing after -31m12s
All internal entity lookups now use bigserial primary keys (int64) while GUIDs are retained for external/public identification. Updated store functions (TouchProject, UpdateThoughtMetadata, AddThoughtAttachment) to query by id instead of guid, added GetThoughtByID, changed semanticSearch and all tool helpers to use *int64 project IDs, and updated retry/backfill workers to use int64 thought IDs throughout.
This commit is contained in:
@@ -2,11 +2,11 @@ package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
@@ -53,11 +53,12 @@ func NewBackfillTool(db *store.DB, embeddings *ai.EmbeddingRunner, sessions *ses
|
||||
|
||||
// QueueThought queues a single thought for background embedding generation.
|
||||
// It is used by capture when the embedding provider is temporarily unavailable.
|
||||
func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content string) {
|
||||
func (t *BackfillTool) QueueThought(ctx context.Context, id int64, content string) {
|
||||
go func() {
|
||||
started := time.Now()
|
||||
idStr := fmt.Sprint(id)
|
||||
t.logger.Info("background embedding started",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", t.embeddings.PrimaryProvider()),
|
||||
slog.String("model", t.embeddings.PrimaryModel()),
|
||||
)
|
||||
@@ -65,7 +66,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s
|
||||
result, err := t.embeddings.Embed(ctx, content)
|
||||
if err != nil {
|
||||
t.logger.Warn("background embedding error",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", t.embeddings.PrimaryProvider()),
|
||||
slog.String("model", t.embeddings.PrimaryModel()),
|
||||
slog.String("stage", "embed"),
|
||||
@@ -76,7 +77,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s
|
||||
}
|
||||
if err := t.store.UpsertEmbedding(ctx, id, result.Model, result.Vector); err != nil {
|
||||
t.logger.Warn("background embedding error",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", t.embeddings.PrimaryProvider()),
|
||||
slog.String("model", result.Model),
|
||||
slog.String("stage", "upsert"),
|
||||
@@ -86,7 +87,7 @@ func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content s
|
||||
return
|
||||
}
|
||||
t.logger.Info("background embedding complete",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", t.embeddings.PrimaryProvider()),
|
||||
slog.String("model", result.Model),
|
||||
slog.Duration("duration", time.Since(started)),
|
||||
@@ -105,9 +106,9 @@ func (t *BackfillTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in
|
||||
return nil, BackfillOutput{}, err
|
||||
}
|
||||
|
||||
var projectID *uuid.UUID
|
||||
var projectID *int64
|
||||
if project != nil {
|
||||
projectID = &project.ID
|
||||
projectID = &project.NumericID
|
||||
}
|
||||
|
||||
primaryModel := t.embeddings.PrimaryModel()
|
||||
@@ -140,24 +141,25 @@ func (t *BackfillTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in
|
||||
break
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(id uuid.UUID, content string) {
|
||||
go func(id int64, content string) {
|
||||
defer wg.Done()
|
||||
defer sem.Release(1)
|
||||
|
||||
idStr := fmt.Sprint(id)
|
||||
result, embedErr := t.embeddings.Embed(ctx, content)
|
||||
if embedErr != nil {
|
||||
mu.Lock()
|
||||
out.Failures = append(out.Failures, BackfillFailure{ID: id.String(), Error: embedErr.Error()})
|
||||
out.Failures = append(out.Failures, BackfillFailure{ID: idStr, Error: embedErr.Error()})
|
||||
mu.Unlock()
|
||||
t.logger.Warn("backfill embed failed", slog.String("thought_id", id.String()), slog.String("error", embedErr.Error()))
|
||||
t.logger.Warn("backfill embed failed", slog.String("thought_id", idStr), slog.String("error", embedErr.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if upsertErr := t.store.UpsertEmbedding(ctx, id, result.Model, result.Vector); upsertErr != nil {
|
||||
mu.Lock()
|
||||
out.Failures = append(out.Failures, BackfillFailure{ID: id.String(), Error: upsertErr.Error()})
|
||||
out.Failures = append(out.Failures, BackfillFailure{ID: idStr, Error: upsertErr.Error()})
|
||||
mu.Unlock()
|
||||
t.logger.Warn("backfill upsert failed", slog.String("thought_id", id.String()), slog.String("error", upsertErr.Error()))
|
||||
t.logger.Warn("backfill upsert failed", slog.String("thought_id", idStr), slog.String("error", upsertErr.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user