fix: keep merged and resolved threads out of the draft queue (#33)
The draft predicate only looked at the auto_thread marker, so a cluster merged into another (resolved, zero observations left) stayed on the list forever and the queue could never drain: 6 of 13 candidates on this index were merged or resolved. IsDraft now owns the predicate for both surfaces: auto-threaded, not resolved, and still holding at least one observation.
This commit is contained in:
+1
-1
@@ -340,7 +340,7 @@ func NewMCPServer(kdb *db.KnoxDB) *mcp.Server {
|
||||
}
|
||||
selected := make([]db.Thread, 0, len(threads))
|
||||
for _, t := range threads {
|
||||
if strings.Contains(t.Provenance, "auto_thread") || strings.HasPrefix(t.Motivation, "Auto-detected") {
|
||||
if t.IsDraft() {
|
||||
selected = append(selected, t)
|
||||
}
|
||||
if len(selected) >= limit {
|
||||
|
||||
@@ -390,7 +390,7 @@ a better title and motivation. Apply changes with ` + "`knox thread update <id>`
|
||||
}
|
||||
var shown int
|
||||
for _, t := range threads {
|
||||
if !isAutoThreaded(t) {
|
||||
if !t.IsDraft() {
|
||||
continue
|
||||
}
|
||||
obs, _ := kdb.ThreadObservations(t.ID)
|
||||
@@ -419,13 +419,6 @@ a better title and motivation. Apply changes with ` + "`knox thread update <id>`
|
||||
}
|
||||
}
|
||||
|
||||
func isAutoThreaded(t db.Thread) bool {
|
||||
if strings.Contains(t.Provenance, "auto_thread") {
|
||||
return true
|
||||
}
|
||||
return strings.HasPrefix(t.Motivation, "Auto-detected")
|
||||
}
|
||||
|
||||
func newThreadUpdateCmd(kdb *db.KnoxDB) *cobra.Command {
|
||||
var title, motivation, priority, tags string
|
||||
cmd := &cobra.Command{
|
||||
|
||||
@@ -1602,6 +1602,17 @@ type Thread struct {
|
||||
LastActivity string // newest linked observation's signal time (created_at)
|
||||
}
|
||||
|
||||
// IsDraft reports whether a thread still carries the heuristic auto-threader's
|
||||
// editorial copy and is worth offering for polish. Merged clusters are resolved
|
||||
// and left with no observations, so they are excluded: there is nothing to
|
||||
// rewrite and the queue could never drain.
|
||||
func (t Thread) IsDraft() bool {
|
||||
if t.Status == "resolved" || t.EntryCount == 0 {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(t.Provenance, "auto_thread") || strings.HasPrefix(t.Motivation, "Auto-detected")
|
||||
}
|
||||
|
||||
// stallAfterDays is how long a thread may go without activity before it is
|
||||
// considered stalled (derived, reversible — not a stored state).
|
||||
const stallAfterDays = 14
|
||||
|
||||
@@ -805,3 +805,28 @@ func TestUpdateThreadClearsAutoThreadMarker(t *testing.T) {
|
||||
t.Fatalf("unrelated provenance was rewritten: %s", got.Provenance)
|
||||
}
|
||||
}
|
||||
|
||||
// The draft queue is "auto-threaded clusters still worth polishing". A merged
|
||||
// cluster is resolved and empty, so it must not come back as a candidate.
|
||||
func TestThreadIsDraft(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
t Thread
|
||||
draft bool
|
||||
}{
|
||||
{"marker", Thread{Status: "active", EntryCount: 12, Provenance: `{"trigger":"auto_thread"}`}, true},
|
||||
{"prefix", Thread{Status: "stalled", EntryCount: 3, Motivation: "Auto-detected cluster of 4"}, true},
|
||||
{"groomed", Thread{Status: "active", EntryCount: 12,
|
||||
Provenance: `{"groomed":true,"cluster":"plant"}`, Motivation: "Plant watering"}, false},
|
||||
{"merged", Thread{Status: "resolved", EntryCount: 0, Provenance: `{"trigger":"auto_thread"}`}, false},
|
||||
{"resolved with work", Thread{Status: "resolved", EntryCount: 9, Provenance: `{"trigger":"auto_thread"}`}, false},
|
||||
{"empty cluster", Thread{Status: "active", EntryCount: 0, Motivation: "Auto-detected cluster"}, false},
|
||||
{"manual", Thread{Status: "active", EntryCount: 4,
|
||||
Provenance: `{"trigger":"display-watch"}`, Motivation: "By hand"}, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := c.t.IsDraft(); got != c.draft {
|
||||
t.Errorf("%s: IsDraft()=%v, want %v", c.name, got, c.draft)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user