fix(G6): 修复 Rust IPC 字段名映射 + cluster_only 模式 + consolidation timeout
- client.go: Result 字段名从 clusters/noise 改为 clusters_found/noise_points(匹配 Rust) - consolidation_pipe.go: 使用 cluster_only 避免 LLM 阻塞;GraphPruned 改为 0(cluster_only 不做 pruning) - server.go: consolidation handler 加 30s timeout,避免 HTTP 挂起
This commit is contained in:
@@ -49,7 +49,8 @@ func (cp *ConsolidationPipeline) Run() (*ConsolidationReport, error) {
|
||||
// ─── 尝试 Rust sidecar ──────────────────────────────
|
||||
var report *ConsolidationReport
|
||||
if cp.dataDir != "" && cp.sqlitePath != "" {
|
||||
if rustReport, err := consolidate.Run(cp.dataDir, cp.sqlitePath, "full"); err == nil {
|
||||
// 用 cluster_only 避免 LLM 调用阻塞(clustering 不需要 LLM)
|
||||
if rustReport, err := consolidate.Run(cp.dataDir, cp.sqlitePath, "cluster_only"); err == nil {
|
||||
report = &ConsolidationReport{
|
||||
StartedAt: time.Now(),
|
||||
FinishedAt: time.Now(),
|
||||
@@ -57,7 +58,7 @@ func (cp *ConsolidationPipeline) Run() (*ConsolidationReport, error) {
|
||||
Merged: rustReport.Clusters,
|
||||
ConflictsFound: 0,
|
||||
Patterns: []string{fmt.Sprintf("decay_rates=%v", rustReport.DecayRates)},
|
||||
GraphPruned: rustReport.Noise,
|
||||
GraphPruned: 0,
|
||||
}
|
||||
if rustReport.Quality != nil {
|
||||
report.Patterns = append(report.Patterns,
|
||||
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -538,13 +539,26 @@ func NewServer() http.Handler {
|
||||
|
||||
// 管理
|
||||
mux.HandleFunc("/api/v1/admin/consolidate", func(w http.ResponseWriter, r *http.Request) {
|
||||
report, err := consolPipe.Run()
|
||||
if err != nil {
|
||||
respondJSON(w, 500, map[string]string{"error": err.Error()})
|
||||
// 30 秒超时,避免阻塞
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
done := make(chan *routes.ConsolidationReport, 1)
|
||||
go func() {
|
||||
report, _ := consolPipe.Run()
|
||||
done <- report
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
respondJSON(w, 408, map[string]string{"error": "consolidation timeout (30s)"})
|
||||
return
|
||||
case report := <-done:
|
||||
if report == nil {
|
||||
respondJSON(w, 500, map[string]string{"error": "consolidation failed"})
|
||||
return
|
||||
}
|
||||
respondJSON(w, 200, report)
|
||||
governance.PushDistillationComplete(report.Merged, report.ConflictsFound)
|
||||
}
|
||||
respondJSON(w, 200, report)
|
||||
governance.PushDistillationComplete(report.Merged, report.ConflictsFound)
|
||||
})
|
||||
mux.HandleFunc("/api/v1/admin/forget", adminAPI.Forget)
|
||||
mux.HandleFunc("/api/v1/admin/dedup", api.Dedup)
|
||||
|
||||
@@ -42,8 +42,8 @@ type ConsolidateResponse struct {
|
||||
type Result struct {
|
||||
Mode string `json:"mode"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Clusters int `json:"clusters,omitempty"`
|
||||
Noise int `json:"noise,omitempty"`
|
||||
Clusters int `json:"clusters_found,omitempty"`
|
||||
Noise int `json:"noise_points,omitempty"`
|
||||
DecayRates map[string]float64 `json:"decay_rates,omitempty"`
|
||||
Quality *QualityResult `json:"quality,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user