Let a question go after it has stepped aside three times (V-654)

A side query suspends the parked question rather than dropping it. Nothing bounded that. No attempt is spent, so MaxAttempts never applies, and noteSuspended restarts the 90s clock, so the TTL cannot arrive while he keeps talking. Measured 2026-08-07: one unfilled time slot rode the tail of six consecutive unrelated replies.

PendingQuestion.Suspends counts the step-asides, MaxSuspends is 3, and past it she lets the request go with the same clarifyDropped line every other drop uses. The count is of consecutive step-asides and resets the moment he answers.

Also splits the re-ask off the answer into its own sentence. The comma splice buried the question in the tail of a reply about something else.
This commit is contained in:
2026-08-07 12:16:15 +04:00
parent beb093aebb
commit 4fdecf9a25
4 changed files with 211 additions and 22 deletions
+42 -22
View File
@@ -6,7 +6,6 @@ import (
"math/rand"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/kami/maven/internal/dialogue"
@@ -162,12 +161,13 @@ func withNotice(notice, reply string) string {
// напоминание?" — answer first, then the open question. A question in front of
// its own answer would read as ignoring what he asked.
//
// A statement's full stop is folded into a comma, so the two acts read as one
// sentence — that is the owner's own punctuation, "в Риме сейчас ..., на какое
// время поставить напоминание?". An answer that is ITSELF a question keeps its
// mark and the resume starts a new sentence: she sometimes answers a side query
// by asking him to say it again, and "переформулировать?, на какое время" folds
// two questions into one unreadable line.
// Two sentences, not one (V-654). This used to fold the answer's full stop into
// a comma, on the strength of the owner having written it that way once. Spliced
// onto a real answer it reads as one run-on thought — "вот что я нашла: вайфай
// пароль лежит в ящике стола, на какое время поставить напоминание?" — and the
// question disappears into the tail of a sentence about something else. A reply
// with no terminator of its own is given one, so the join never depends on how
// the phraser chose to end.
//
// A resume with no answer in front of it is just the question.
func withResumed(reply, resumed string) string {
@@ -178,23 +178,17 @@ func withResumed(reply, resumed string) string {
if reply == "" {
return resumed
}
if strings.HasSuffix(reply, "?") {
return reply + " " + resumed
if !endsSentence(reply) {
reply += "."
}
if trimmed := strings.TrimRight(reply, ".!"); trimmed != "" {
reply = trimmed
}
return reply + ", " + lowerFirst(resumed)
return reply + " " + resumed
}
// lowerFirst lowercases the opening rune, so a deck line written as a standalone
// sentence reads as the second half of one. Only the first rune: "На какое
// время" must become "на какое время" and nothing else in it may move.
func lowerFirst(s string) string {
for i, r := range s {
return string(unicode.ToLower(r)) + s[i+utf8.RuneLen(r):]
}
return s
// endsSentence reports whether s already closes itself. The ellipsis counts: a
// trailing "…" is a deliberate end, and a full stop after it reads as a typo.
func endsSentence(s string) bool {
r, _ := utf8.DecodeLastRuneInString(s)
return strings.ContainsRune(".!?…", r)
}
// missingFor returns the slots a decision still needs, most important first.
@@ -381,6 +375,14 @@ func (h *reactiveHandler) resolveClarifyAnswer(ctx context.Context, text string)
return "", false
}
// He is answering, so the run of step-asides is over (V-654). Reset here
// rather than where a gap is FILLED: "позвонить маме" against a question
// about the time gives her nothing she asked for and still means he is in
// the exchange, and the retry it costs is bound enough on its own. The
// counter is for the case the bounds miss — he asked for other things and
// never came back.
q.Suspends = 0
merged := q.Answer(text, toDialogueSlots(answer))
// Fold a newly answered subject into the raw utterance. Downstream actions
// phrase from Utterance, not from the text slot — actionReminder stores it
@@ -467,6 +469,14 @@ func (h *reactiveHandler) noteDropped(ctx context.Context) {
//
// A slot with no resumed wording (clarifyResumedFor says so) resumes nothing and
// says nothing. She must not claim to be holding a question she cannot re-ask.
//
// Suspension is bounded, since V-654. Neither of the two things above is a
// limit: no attempt is spent, and restarting the clock means the TTL cannot
// arrive while he keeps talking. So the count is the only thing that ends it,
// and past MaxSuspends she lets the request go and says so with the same line
// every other drop uses. The rule is unchanged — a question ends by being
// answered or by being let go out loud — this only recognises three unrelated
// requests in a row as the second of those.
func (h *reactiveHandler) noteSuspended(ctx context.Context, q *dialogue.PendingQuestion) {
rt := turnRouteFrom(ctx)
if rt == nil || len(q.Missing) == 0 {
@@ -476,11 +486,18 @@ func (h *reactiveHandler) noteSuspended(ctx context.Context, q *dialogue.Pending
if !ok {
return
}
if !q.CanResume() {
h.clarifyStore.Delete(dialogueIDOf(ctx))
h.noteDropped(ctx)
log.Printf("voice: clarify — the question about %s stepped aside %d times; letting the request go", q.Missing[0], q.Suspends)
return
}
q.Suspends++
q.Asked = h.now()
h.clarifyStore.Put(dialogueIDOf(ctx), q)
rt.resume = question
rt.suspended = true
log.Printf("voice: clarify — is its own request; suspending the question about %s and resuming it in the same reply", q.Missing[0])
log.Printf("voice: clarify — is its own request; suspending the question about %s and resuming it in the same reply (suspend %d of %d)", q.Missing[0], q.Suspends, dialogue.MaxSuspends)
}
// foldAnswerIntoUtterance appends an answered subject to the original words,
@@ -520,6 +537,9 @@ func (h *reactiveHandler) askRemainingGap(ctx context.Context, q *dialogue.Pendi
if !ok || !q.CanAsk() {
return "", false
}
// Suspends is not carried, and by this point it is already zero: the answer
// path resets it (V-654). Left off the literal so the zero is stated where
// the struct is built, rather than inherited from a field nobody names.
h.clarifyStore.Put(dialogueIDOf(ctx), &dialogue.PendingQuestion{
Intent: q.Intent,
Slots: merged,