From 0f4ca18957e9b63b3a980dfd851ae1bf8a1bb508 Mon Sep 17 00:00:00 2001 From: weichen Date: Thu, 15 Oct 2026 07:14:17 +0000 Subject: [PATCH] Honor explicit follow-up questions after a submitted work choice Why: A fresh question referencing an earlier result could be mistaken for a duplicate background request. Evidence: The new English-summary reference regression failed with the old receipt branch and passes with the explicit-reference distinction. Impact: Deduplicate inferred pending choices while allowing explicit new requests to use the saved result. Refs: feature/workbench-flow-completion review P1 --- internal/runmgr/workcard.go | 3 ++- internal/runmgr/workcard_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/runmgr/workcard.go b/internal/runmgr/workcard.go index 7d1f9ee..560c699 100644 --- a/internal/runmgr/workcard.go +++ b/internal/runmgr/workcard.go @@ -292,6 +292,7 @@ func materialPurposeRequest(text string) bool { } func (m *Manager) bindWorkContext(conv core.Conversation, msg core.Message, ref *WorkReference, runIDs ...core.ID) (string, error) { + inferred := ref == nil if ref == nil { ref = m.directWorkReference(conv, messageText(msg)) } @@ -304,7 +305,7 @@ func (m *Manager) bindWorkContext(conv core.Conversation, msg core.Message, ref return "", err } if d := card.Work.Decision; d != nil && materialPurposeRequest(messageText(msg)) { - if d.State == "dispatching" || d.State == "submitted" { + if inferred && (d.State == "dispatching" || d.State == "submitted") { return workReceiptPrefix + card.ID, nil } if d.State == "open" || d.State == "deferred" { diff --git a/internal/runmgr/workcard_test.go b/internal/runmgr/workcard_test.go index 1f8d58f..7034265 100644 --- a/internal/runmgr/workcard_test.go +++ b/internal/runmgr/workcard_test.go @@ -169,6 +169,24 @@ func TestDirectMaterialSummaryUsesExistingForegroundOnly(t *testing.T) { } } +func TestExplicitWorkReferenceAllowsNewSummaryAfterPreviousChoice(t *testing.T) { + c, card := completedMaterialWork(t) + _, err := c.mgr.WorkCardAction(c.run.Owner, card.ID, "work.submit", core.WorkCardAction{ResultVersion: 1, SelectedIDs: []string{"summary"}}) + if err != nil { + t.Fatal(err) + } + waitBackgroundIdle(t, c) + conv, err := c.mgr.st.GetConversation(c.run.Owner, c.run.ConversationID) + if err != nil { + t.Fatal(err) + } + msg := core.Message{Parts: []core.Part{{Type: core.PartText, Text: "请把这份材料的重点总结为英文"}}} + context, err := c.mgr.bindWorkContext(conv, msg, &WorkReference{card.ID, 1}) + if err != nil || strings.HasPrefix(context, workReceiptPrefix) || !strings.Contains(context, card.Work.Result) { + t.Fatalf("explicit follow-up request discarded: %q %v", context, err) + } +} + func TestButtonAndDirectSummaryRaceKeepsOneExecution(t *testing.T) { c, card := completedMaterialWork(t) hold := &holdRunner{release: make(chan struct{})}