Startup and update sequence

1. Version mismatch restart loop (pkg/hooks/worker.go):
    - Added versionsCompatible() and extractBaseVersion() functions
    - Hooks no longer restart worker when base versions match (e.g., v0.3.5-dirty ≈ v0.3.5-2-gca711a8-dirty)
2. Auto-update detection (internal/update/update.go):
    - isNewerVersion() now extracts base version before comparing
    - No longer always reports updates for dirty/dev builds
3. Non-blocking ChromaDB sync (internal/worker/handlers.go):
    - SyncUserPrompt now runs in a goroutine with 10-second timeout
    - /api/sessions/init responds immediately without waiting for ChromaDB
This commit is contained in:
2025-12-19 02:17:06 +00:00
parent c715413c09
commit 816af36dd3
4 changed files with 53 additions and 10 deletions
+7 -5
View File
@@ -537,14 +537,16 @@ func isNewerVersion(latest, current string) bool {
latest = strings.TrimPrefix(latest, "v")
current = strings.TrimPrefix(current, "v")
// Handle dev/dirty versions
if strings.Contains(current, "-dirty") || strings.Contains(current, "-dev") {
return true // Always show update available for dev builds
// For dev/dirty builds, extract the base version for comparison
// e.g., "0.3.5-2-gca711a8-dirty" -> "0.3.5"
currentBase := current
if idx := strings.Index(current, "-"); idx > 0 {
currentBase = current[:idx]
}
// Simple semver comparison
// Simple semver comparison using base version
latestParts := strings.Split(latest, ".")
currentParts := strings.Split(current, ".")
currentParts := strings.Split(currentBase, ".")
for i := 0; i < len(latestParts) && i < len(currentParts); i++ {
latestNum, _ := strconv.Atoi(latestParts[i])
+9 -4
View File
@@ -2,6 +2,7 @@
package worker
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -153,7 +154,7 @@ func (s *Service) handleSessionInit(w http.ResponseWriter, r *http.Request) {
log.Warn().Err(err).Msg("Failed to save user prompt")
// Non-fatal: continue with session initialization
} else if s.chromaSync != nil {
// Sync to vector DB
// Sync to vector DB asynchronously (non-blocking)
now := time.Now()
promptWithSession := &models.UserPromptWithSession{
UserPrompt: models.UserPrompt{
@@ -168,9 +169,13 @@ func (s *Service) handleSessionInit(w http.ResponseWriter, r *http.Request) {
Project: req.Project,
SDKSessionID: req.ClaudeSessionID,
}
if err := s.chromaSync.SyncUserPrompt(r.Context(), promptWithSession); err != nil {
log.Warn().Err(err).Int64("id", promptID).Msg("Failed to sync user prompt to ChromaDB")
}
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := s.chromaSync.SyncUserPrompt(ctx, promptWithSession); err != nil {
log.Warn().Err(err).Int64("id", promptID).Msg("Failed to sync user prompt to ChromaDB")
}
}()
}
log.Info().