feat(timeline): scale axis to async tail, enrich span payloads, polish UI
The post-process stage closes in ~9ms (just enqueue work) but its async subspans (postprocess.summary, postprocess.question, postprocess.graph) keep producing rows for tens of seconds AFTER the root finalizes. The old timeline used trace.duration_ms as the time axis maximum, which clipped those subspan bars past the right edge. Timeline: - totalMs now always takes max(trace.duration_ms, observed-tail), so the axis stretches to fit the latest descendant end regardless of parse_status. - Render a faint dashed wrapping outline behind a parent span when its descendants extend past its own finished_at, so the postprocess stage row visibly spans the full window without overloading the 9ms self-time bar. - Tree expand/collapse caret bumped from 10 to 14px in a 16x16 hit area; copy icons in detail panel bumped from 11/14 to 14/18px; .kp-kv-copy button grown from 18 to 22px. - Short input/output payloads (<= 8 entries / <= 600 bytes JSON) auto-expand inline so users see the actual data without an extra click; longer payloads keep the click-to-expand summary. Span payloads (subspans only - root keeps the canonical identity, no duplicate knowledge_id/kb_id/tenant_id on every child): - extract.go: graph subspan output gains chunk_chars, chunk_preview, sample_nodes, sample_relations. - summary subspan output gains model_id, summary_preview. - question subspan output gains model_id and a sample_question captured from the first non-empty LLM response. i18n: new key knowledgeStages.detail.includingChildren for the wrapping-bar tooltip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -236,6 +236,13 @@ func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
|
||||
handleErr = err
|
||||
return err
|
||||
}
|
||||
// Capture chunk content shape on output — lets traces answer "WHAT
|
||||
// did the LLM call see?" without joining back to the chunk store.
|
||||
// Preview is truncated to keep span rows reasonable.
|
||||
if gSpan != nil {
|
||||
graphOut["chunk_chars"] = len([]rune(chunk.Content))
|
||||
graphOut["chunk_preview"] = previewText(chunk.Content, 200)
|
||||
}
|
||||
kb, err := s.knowledgeBaseRepo.GetKnowledgeBaseByID(ctx, chunk.KnowledgeBaseID)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "failed to get knowledge base: %v", err)
|
||||
@@ -293,6 +300,32 @@ func (s *ChunkExtractService) Handle(ctx context.Context, t *asynq.Task) error {
|
||||
}
|
||||
graphOut["nodes_added"] = len(graph.Node)
|
||||
graphOut["relations_added"] = len(graph.Relation)
|
||||
// Capture a couple of sample nodes/relations so the trace viewer can
|
||||
// answer "what did the LLM actually extract?" without round-tripping
|
||||
// to the graph store. Cap to two each — anything more bloats span
|
||||
// rows and the full graph is queryable elsewhere.
|
||||
if len(graph.Node) > 0 {
|
||||
samples := graph.Node
|
||||
if len(samples) > 2 {
|
||||
samples = samples[:2]
|
||||
}
|
||||
names := make([]string, 0, len(samples))
|
||||
for _, n := range samples {
|
||||
names = append(names, n.Name)
|
||||
}
|
||||
graphOut["sample_nodes"] = names
|
||||
}
|
||||
if len(graph.Relation) > 0 {
|
||||
samples := graph.Relation
|
||||
if len(samples) > 2 {
|
||||
samples = samples[:2]
|
||||
}
|
||||
out := make([]string, 0, len(samples))
|
||||
for _, r := range samples {
|
||||
out = append(out, fmt.Sprintf("%s --[%s]--> %s", r.Node1, r.Type, r.Node2))
|
||||
}
|
||||
graphOut["sample_relations"] = out
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -893,7 +893,9 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
|
||||
// Closes via the deferred handler below — every return path lands in
|
||||
// the defer, including the early returns ahead.
|
||||
span := s.beginPostprocessSubspan(ctx, payload.KnowledgeID, payload.Attempt, "postprocess.summary",
|
||||
types.JSONMap{"language": payload.Language})
|
||||
types.JSONMap{
|
||||
"language": payload.Language,
|
||||
})
|
||||
var summaryErr error
|
||||
summaryOut := types.JSONMap{}
|
||||
defer func() {
|
||||
@@ -914,6 +916,11 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
|
||||
summaryErr = err
|
||||
return nil
|
||||
}
|
||||
// Capture the resolved model id on the span output the moment we
|
||||
// know it — debugging "summary stage took 60s" benefits hugely from
|
||||
// seeing WHICH chat model was actually used (kb config drift, fall-
|
||||
// throughs to a slow upstream, etc.).
|
||||
summaryOut["model_id"] = kb.SummaryModelID
|
||||
|
||||
if kb.SummaryModelID == "" {
|
||||
logger.Warn(ctx, "Knowledge base summary model ID is empty, skipping summary generation")
|
||||
@@ -1026,6 +1033,11 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
|
||||
knowledge.SummaryStatus = types.SummaryStatusCompleted
|
||||
knowledge.UpdatedAt = time.Now()
|
||||
summaryOut["summary_chars"] = len([]rune(summary))
|
||||
// Preview the generated summary on the span output so the trace
|
||||
// viewer can show "this is what the LLM produced" at a glance,
|
||||
// without hopping to the knowledge-detail page. Capped to keep
|
||||
// span rows compact.
|
||||
summaryOut["summary_preview"] = previewText(summary, 240)
|
||||
if err := s.repo.UpdateKnowledge(ctx, knowledge); err != nil {
|
||||
logger.Errorf(ctx, "Failed to update knowledge description: %v", err)
|
||||
summaryErr = err
|
||||
@@ -1141,6 +1153,12 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
|
||||
indexEntriesPrepared := 0
|
||||
indexBatchAttempted := false
|
||||
indexBatchSucceeded := false
|
||||
// Sample question + model id surfaced on the span output so the
|
||||
// trace viewer can answer "what did the LLM actually produce?" and
|
||||
// "which model did it run on?" without joining back to the chunk
|
||||
// store. Captured the first time we see a non-empty question batch.
|
||||
var sampleQuestion string
|
||||
var resolvedModelID string
|
||||
// Postprocess subspan for the trace viewer. Opened lazily after we
|
||||
// unmarshal the payload (so we have payload.Attempt) and closed in
|
||||
// the defer below alongside the stats log so the span output mirrors
|
||||
@@ -1190,6 +1208,16 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
|
||||
"retry": retryCount,
|
||||
"max_retry": maxRetry,
|
||||
}
|
||||
// Surface the resolved model id and a sample question on the
|
||||
// span output. These help debugging "why is question generation
|
||||
// slow" — both questions ("which model was hit?") and ("what
|
||||
// did it produce?") are hard to answer from logs alone.
|
||||
if resolvedModelID != "" {
|
||||
out["model_id"] = resolvedModelID
|
||||
}
|
||||
if sampleQuestion != "" {
|
||||
out["sample_question"] = sampleQuestion
|
||||
}
|
||||
// Treat any non-success exitStatus as a failed run; the
|
||||
// existing stats-string already enumerates them. qErr stays
|
||||
// optional for callers that want to surface a Go error.
|
||||
@@ -1289,6 +1317,7 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
|
||||
logger.Errorf(ctx, "Failed to get chat model: %v", err)
|
||||
return fmt.Errorf("failed to get chat model: %w", err)
|
||||
}
|
||||
resolvedModelID = kb.SummaryModelID
|
||||
|
||||
// Initialize embedding model and retrieval engine
|
||||
embeddingModel, err := s.modelService.GetEmbeddingModel(ctx, kb.EmbeddingModelID)
|
||||
@@ -1368,6 +1397,9 @@ func (s *knowledgeService) ProcessQuestionGeneration(ctx context.Context, t *asy
|
||||
}
|
||||
llmCallSuccess++
|
||||
generatedQuestionsTotal += len(questions)
|
||||
if sampleQuestion == "" && len(questions) > 0 {
|
||||
sampleQuestion = previewText(questions[0], 200)
|
||||
}
|
||||
|
||||
// Update chunk metadata with unique IDs for each question
|
||||
generatedQuestions := make([]types.GeneratedQuestion, len(questions))
|
||||
|
||||
Reference in New Issue
Block a user