Files
Maven/cmd/mavend/querysource.go
T
claude 888c1c6768 the query source that claimed a turn is readable on /chat (V-539)
V-539 said SearXNG claims every world question, including invented terms,
so Kiwix is never reached. Measured today against the configured instance:
seven of eight invented Russian questions now return zero results, and
Response.Empty() already passes those to the ZIM. The premise moved with the
upstream engine set in three days.

The three quality signals the task named were recorded per query and none
separate the sets. Token overlap is zero for the one bad claim and also zero
for "столица Франции", whose answer is Париж. Empty snippets never fire,
because ParseResponse already drops a hit with no text. SearXNG returned no
corrections or suggestions even for the query it silently respelled. So no
threshold is built: it would cost a real answer to save one invented word.

What ships is the second half. The claiming query source crosses the IPC seam
on ipc.ChatReply.Source and renders as a badge beside the reply on /chat. It
rides the context rather than a return value, because handleText answers every
reach through one string and the mic, telegram and the web all share it.
Chat now returns ChatReply instead of a bare string.

Full -race suite green.
2026-08-05 15:28:26 +04:00

57 lines
1.9 KiB
Go

package main
import (
"context"
"sync"
)
// The query source that claimed a turn was visible in the daemon log and
// nowhere else (V-539). A QA step reading /chat could see a wrong answer but
// not tell a wrong answer from a wrongly ordered chain: "почему небо голубое"
// answered badly reads the same whether search claimed it, the ZIM did, or the
// resident model answered from memory.
//
// It rides the context rather than a return value because handleText answers
// every reach through one string, and threading a second value through the
// whole action dispatch would change a signature the mic, telegram and the web
// all share. The sink is per turn, created by the caller that wants to read it;
// a turn with no sink notes nothing, which is what the mic path does.
type querySourceKey struct{}
// querySourceSink holds the name of the source that claimed one turn. The mutex
// is there because a query source may fan out to goroutines of its own, not
// because two turns share a sink.
type querySourceSink struct {
mu sync.Mutex
name string
}
func (s *querySourceSink) note(name string) {
s.mu.Lock()
defer s.mu.Unlock()
s.name = name
}
// Name is the source that claimed, or empty when nothing did or the turn was
// not a query at all.
func (s *querySourceSink) Name() string {
s.mu.Lock()
defer s.mu.Unlock()
return s.name
}
// withQuerySourceSink returns a context that collects the claiming source, and
// the sink to read after the turn has answered.
func withQuerySourceSink(ctx context.Context) (context.Context, *querySourceSink) {
sink := &querySourceSink{}
return context.WithValue(ctx, querySourceKey{}, sink), sink
}
// noteQuerySource records which source claimed the turn. It is a no-op when the
// caller did not ask for one.
func noteQuerySource(ctx context.Context, name string) {
if sink, ok := ctx.Value(querySourceKey{}).(*querySourceSink); ok {
sink.note(name)
}
}