oficina / equipo Public

A go-ahead whose work has gone in closes itself

Paul's recipes job (2026-11-28): the merge landed at 18:52 as 336405a,
but Base's card still read "This is ready: it could not be fully
tested. Go ahead?". The Assistant's outcome card kept the merge card's
question once answered or withdrawn, and touchOutcomes only cleared its
links when the task ended, so a merged go-ahead went on asking.

- chat/outcome.go: landed(task) is true once the task is done and not
  an exploration built as another task. fillMirror gives a merge card's
  outcome card closed words once its work has landed, however it went
  in (the person's tap, Equipo's merge, by hand on the hub): the line
  assistant.outcome.merge_done, the result assistant.job.detail.done,
  no preview; answered stays answered, anything else is resolved.
  touchOutcomes refills ended outcome cards from their merge card, so
  an answered go-ahead closes when the merge is confirmed. mirrorCard
  raises no go-ahead for a merge card whose work has already landed.
- copy.go: assistant.outcome.merge_done "This went ahead."
  (COPY REVIEW PENDING).
- thintest: TestContractOutcomeClosesOnceMergedByTap and
  TestContractOutcomeClosesOnceMergedElsewhere (watch-reported merge).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 70552b5916ec2a903b33b8542521377d631d2997 parent 57f370c
3 files changed, +155 −3
  • internal/equipo/chat/outcome.go +51 −3
  • internal/equipo/copy.go +3 −0
  • internal/thintest/assistant_outcome_merged_test.go +101 −0
diff --git a/internal/equipo/chat/outcome.go b/internal/equipo/chat/outcome.go
index 42cb14dd..6a825773 100644
--- a/internal/equipo/chat/outcome.go
+++ b/internal/equipo/chat/outcome.go
@@ -117,6 +117,12 @@ func (t *txn) mirrorCard(src cardRecord) error {
}
return t.projectJob(h)
}
+ if src.Kind == wire.CardMerge {
+ // Never a go-ahead for work that is already in.
+ if in, err := t.landed(src.TaskID); err != nil || in {
+ return err
+ }
+ }
h, ok, err := t.handoffFor(src)
if err != nil || !ok {
return err
@@ -199,6 +205,23 @@ func (t *txn) handoffFor(src cardRecord) (handoffRecord, bool, error) {
// site's); a preview, which goes when the task ends or it expires, is
// read with the card (mirrorView).
func (t *txn) fillMirror(m *cardRecord, src cardRecord) error {
+ if src.Kind == wire.CardMerge {
+ // A go-ahead whose work has gone in asks nothing any more, however
+ // it went in (the person's tap, Equipo's own merge, by hand on the
+ // hub): closed words, no options to answer, no preview.
+ in, err := t.landed(src.TaskID)
+ if err != nil {
+ return err
+ }
+ if in {
+ m.Question, m.Result, m.Links = t.copy("assistant.outcome.merge_done"), t.copy("assistant.job.detail.done"), "[]"
+ m.State = wire.CardResolved
+ if src.State == wire.CardAnswered {
+ m.State = wire.CardAnswered
+ }
+ return nil
+ }
+ }
open := src.State == wire.CardOpen || src.Kind == wire.CardHome && src.State == wire.CardHomeAsk
links := []wire.CardLink{}
var options []wire.CardOption
@@ -264,6 +287,21 @@ func (t *txn) fillMirror(m *cardRecord, src cardRecord) error {
return nil
}
+// landed: the task's work is on its default branch. A task is done only
+// when its merge was confirmed (mergeDone) or the runner's watch saw it
+// land (merged); an exploration is done once built as another task,
+// which merges nothing of its own.
+func (t *txn) landed(taskID string) (bool, error) {
+ if taskID == "" {
+ return false, nil
+ }
+ var k taskRecord
+ if err := t.db.Where("id = ?", taskID).Limit(1).Find(&k).Error; err != nil || k.ID == "" {
+ return false, err
+ }
+ return k.Stage == wire.StageDone && k.BuiltAs == "", nil
+}
+
// publishOutcome is what became of the person's answer on a publish
// card, and the site's address once there is one: declined; publishing
// until its step ends; then published, sent and not confirmed, or not
@@ -426,8 +464,9 @@ func (t *txn) mirrorView(v *wire.AssistantCard, c cardRecord) error {
// touchOutcomes moves the Assistant cards of a task's merge cards that
// are no longer open when the task ends, so the person's lane hears that
-// the preview went (the open ones change with their merge card, which
-// withdrawMergeCards resolves).
+// the preview went, and, when the task went in, that it did (landed);
+// the open ones change with their merge card, which withdrawMergeCards
+// resolves.
func (t *txn) touchOutcomes(k taskRecord) error {
var rows []cardRecord
if err := t.db.Where("lane = ? AND state <> ? AND source_card IN (SELECT id FROM chat_cards WHERE task_id = ? AND kind = ?)", wire.LaneAssistant, wire.CardOpen, k.ID, wire.CardMerge).Find(&rows).Error; err != nil {
@@ -435,10 +474,19 @@ func (t *txn) touchOutcomes(k taskRecord) error {
}
for i := range rows {
m := &rows[i]
+ var src cardRecord
+ if err := t.db.Where("id = ? AND person = ?", m.SourceCard, m.Person).Limit(1).Find(&src).Error; err != nil {
+ return err
+ }
+ if src.ID != "" {
+ if err := t.fillMirror(m, src); err != nil {
+ return err
+ }
+ }
m.Revision++
m.UpdatedAt = t.now()
m.Links = "[]"
- if err := t.db.Model(&cardRecord{}).Where("id = ?", m.ID).Select("links", "revision", "updated_at").Updates(m).Error; err != nil {
+ if err := t.db.Model(&cardRecord{}).Where("id = ?", m.ID).Select("state", "question", "options", "links", "result", "revision", "updated_at").Updates(m).Error; err != nil {
return err
}
if err := t.cardEvent(*m); err != nil {
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 76bca07c..bf724613 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -2934,6 +2934,9 @@ var runnerDraftCopy = map[string]string{
"assistant.outcome.needs_you": "This needs you to finish it.", // COPY APPROVED (Paul, 2026-11-13, copy-review c3ipwcupsvwv7rpbj2kdbgrsyy, unchanged)
"assistant.outcome.open": "Take a look", // COPY APPROVED (Paul, 2026-11-13, copy-review c3ipwcupsvwv7rpbj2kdbgrsyy, unchanged)
"assistant.outcome.resolved": "This no longer needs an answer.", // COPY APPROVED (Paul, 2026-11-13, copy-review jbltdd2mvwblrz4en6xfhv6d2y, unchanged)
+ // A go-ahead whose work has gone in (chat/outcome.go, landed): its
+ // line once it asks nothing; its result is assistant.job.detail.done.
+ "assistant.outcome.merge_done": "This went ahead.", // COPY REVIEW PENDING
// A publish card's (chat/outcome.go): the question and its two
// options, then what became of the answer; the published address's
// label. The preview link's label is assistant.outcome.preview.
diff --git a/internal/thintest/assistant_outcome_merged_test.go b/internal/thintest/assistant_outcome_merged_test.go
new file mode 100644
index 00000000..afc3bd05
--- /dev/null
+++ b/internal/thintest/assistant_outcome_merged_test.go
@@ -0,0 +1,101 @@
+package thintest
+
+import (
+ "slices"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/equipo"
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// A go-ahead whose work has gone in asks nothing any more (Paul's
+// recipes job, 2026-11-28: merged at 18:52, Base still read "This is
+// ready: it could not be fully tested. Go ahead?"). Once the task is
+// merged, its outcome card says so in closed words, whether the person's
+// own tap merged it or it went in some other way, and no go-ahead is
+// raised for work that is already in.
+
+func mergedOutcome(t *testing.T, c wire.AssistantCard) {
+ t.Helper()
+ if c.State == wire.CardOpen {
+ t.Fatalf("still asking %+v", c)
+ }
+ if c.Question != equipo.RunnerCopy("assistant.outcome.merge_done") || strings.Contains(c.Question, "?") {
+ t.Fatalf("question %q, want the closed line", c.Question)
+ }
+ if c.Result != equipo.RunnerCopy("assistant.job.detail.done") {
+ t.Fatalf("result %q, want the finished line", c.Result)
+ }
+ if len(c.Links) != 0 {
+ t.Fatalf("links %+v", c.Links)
+ }
+}
+
+func TestContractOutcomeClosesOnceMergedByTap(t *testing.T) {
+ o := newTeamRigAt(t, wire.ProtocolCurrent)
+ o.sitesOn(wire.ProtocolCurrent, false)
+ o.ask("Can you make me an app for sharing recipes?")
+ _, cmd := o.handoff("mt1", "an app for sharing recipes", "")
+ base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40)
+ var id string
+ o.in(cmd.TurnID, func() { id, _ = o.websiteReady("mt", "Recipe sharing app", base, cand, false) })
+ card := o.assistantCard("the go-ahead", isMergeOutcome)
+ if card.State != wire.CardOpen || card.Question != mergeQuestion("environment_reason") {
+ t.Fatalf("go-ahead %+v", card)
+ }
+ ans, err := o.a.Answer(o.ctx, card.ID, wire.ChoiceMerge, card.Revision)
+ if err != nil || ans.Card.State != wire.CardAnswered {
+ t.Fatalf("answer %+v %v", ans, err)
+ }
+ m := o.dispatched(wire.SpecialistMerge, base, cand, 0)
+ o.mergedStep("mt-m", m, strings.Repeat("e", 40))
+ o.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone })
+ var done wire.AssistantCard
+ o.until("the go-ahead closed", func() bool {
+ done = o.assistantCard("the go-ahead", func(c wire.AssistantCard) bool { return c.ID == card.ID })
+ return done.Question != card.Question
+ })
+ mergedOutcome(t, done)
+ if done.State != wire.CardAnswered || done.Revision <= ans.Card.Revision {
+ t.Fatalf("after the merge %+v (answered %+v)", done, ans.Card)
+ }
+ // Tapping the old go-ahead again changes nothing.
+ if _, err := o.a.Answer(o.ctx, card.ID, wire.ChoiceMerge, done.Revision); err == nil {
+ t.Fatal("a merged go-ahead took an answer")
+ }
+ if n := o.rows("SELECT count(*) FROM chat_steps WHERE task_id = ? AND specialist = ?", id, wire.SpecialistMerge); n != 1 {
+ t.Fatalf("%d merge steps", n)
+ }
+}
+
+func TestContractOutcomeClosesOnceMergedElsewhere(t *testing.T) {
+ o := newTeamRigAt(t, wire.ProtocolCurrent)
+ o.sitesOn(wire.ProtocolCurrent, false)
+ o.ask("Can you make me an app for sharing recipes?")
+ _, cmd := o.handoff("me1", "an app for sharing recipes", "")
+ base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40)
+ var id string
+ o.in(cmd.TurnID, func() { id, _ = o.websiteReady("me", "Recipe sharing app", base, cand, false) })
+ card := o.assistantCard("the go-ahead", isMergeOutcome)
+ if card.State != wire.CardOpen {
+ t.Fatalf("go-ahead %+v", card)
+ }
+ // Merged on the hub by hand: the runner's watch reports it.
+ if err := o.runner.Send(o.ctx, "me-merged", wire.FrameMerged, wire.MergedReport{TaskID: id, CandidateSHA: cand}); err != nil {
+ t.Fatal(err)
+ }
+ o.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone })
+ var done wire.AssistantCard
+ o.until("the go-ahead closed", func() bool {
+ done = o.assistantCard("the go-ahead", func(c wire.AssistantCard) bool { return c.ID == card.ID })
+ return done.State != wire.CardOpen
+ })
+ mergedOutcome(t, done)
+ if !slices.ContainsFunc(o.assistantCards(), func(c wire.AssistantCard) bool { return c.ID == card.ID }) {
+ t.Fatal("the closed go-ahead left the conversation")
+ }
+ if _, err := o.a.Answer(o.ctx, card.ID, wire.ChoiceMerge, done.Revision); err == nil {
+ t.Fatal("a merged go-ahead took an answer")
+ }
+}