chat: a Design republish needs a kept set for its commit
Task 4 review, fix round 1. designShort exempted every republish (and rebase), so a Design exploration whose push failed reached Review after its Retry: the republish publishes the commit without running Design and reports no options, and a failed attempt keeps none. - The rebase and republish exemptions are gone. keptFor (design_captures.go) is the step's kept set for its commit: its current attempt's, or for a republish its source attempt's (FromAttempt) when kept for the very commit it publishes (designKept gains Candidate, recorded at keep time; records without it never carry). designShort is short unless keptFor holds an Explore set. - keepCaptures: a republish's report without options keeps its source attempt's same-commit set (keptFor) instead of clearing it; else nothing, and advanceExplore starts the fix round with designFeedbackOptions. - With today's runner a push_failed attempt never sends options, so every republish of an exploration gets the fix round; the carry-over covers a source set kept for the same commit. TDD evidence: - go test ./internal/equipo/chat/ -run 'TestRepublish' against 92ad5bbd's code: TestRepublishWithoutOptionsFixRound failed "a short set reached Review: 1 Review steps"; TestRepublishKeepsSourceOptions failed "the source set is not shown: <nil>". Both pass after the fix, with TestKeptForSameCommit; the chat package and go vet are ok. Mutations (each alone, restored after), all FAILED their tests: - F1 republish exempt again: TestRepublishWithoutOptionsFixRound, TestKeptForSameCommit - F2 rebase exempt again: TestKeptForSameCommit - F3 republish keeps nothing of its source: TestRepublishKeepsSourceOptions - F4 carry ignores the commit: TestKeptForSameCommit - F5 carry without Republish: TestKeptForSameCommit - F6 candidate not recorded at keep: TestRepublishKeepsSourceOptions - F7 short ignores a missing set: TestExploreTwoOptionsFixRound (panic)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+151
−17
internal/equipo/chat/design_captures.go+37 −7internal/equipo/chat/design_feedback_options_test.go+105 −0internal/equipo/chat/review.go+9 −10
diff --git a/internal/equipo/chat/design_captures.go b/internal/equipo/chat/design_captures.go| index 26725bd8..da2ba02b 100644 |
| --- a/internal/equipo/chat/design_captures.go |
| +++ b/internal/equipo/chat/design_captures.go |
| @@ -36,13 +36,35 @@ import ( |
| var ErrDirectionNote = fmt.Errorf("%w: build needs a note", ErrCardConflict) |
| // designKept is a step's DesignOptions: the done attempt and its |
| -// options, each with its capture ids in the report's order. Explore: |
| -// the set passed wire.ValidExploreOptions (an exploration under the |
| -// protocol-39 rules), so it may go to Review (designOptionsShort). |
| +// options, each with its capture ids in the report's order. Candidate |
| +// is the commit they were kept for ("" in records from before it). |
| +// Explore: the set passed wire.ValidExploreOptions (an exploration |
| +// under the protocol-39 rules), so it may go to Review |
| +// (designOptionsShort). |
| type designKept struct { |
| - Attempt int64 `json:"attempt"` |
| - Explore bool `json:"explore,omitempty"` |
| - Options []keptOption `json:"options"` |
| + Attempt int64 `json:"attempt"` |
| + Candidate string `json:"candidate,omitempty"` |
| + Explore bool `json:"explore,omitempty"` |
| + Options []keptOption `json:"options"` |
| +} |
| + |
| +// keptFor is the step's kept record when it holds options its attempt |
| +// kept for the commit it has now: its current attempt's, or for a |
| +// republish (which publishes the commit its source attempt FromAttempt |
| +// made, without running Design) that source attempt's, for the same |
| +// commit. nil when none is. |
| +func keptFor(s stepRecord) (*designKept, error) { |
| + if s.DesignOptions == "" { |
| + return nil, nil |
| + } |
| + var kept designKept |
| + if err := json.Unmarshal([]byte(s.DesignOptions), &kept); err != nil { |
| + return nil, err |
| + } |
| + if kept.Attempt == s.Attempt || s.Republish && s.FromAttempt > 0 && kept.Attempt == s.FromAttempt && kept.Candidate != "" && kept.Candidate == s.CandidateSHA { |
| + return &kept, nil |
| + } |
| + return nil, nil |
| } |
| // keptOption is one kept option. Under the protocol-39 rules it keeps |
| @@ -192,6 +214,14 @@ type keptCapture struct { |
| // otherwise nothing. Saving the ended step then deletes every file it |
| // sent and did not keep (saveStep). |
| func (t *txn) keepCaptures(k *taskRecord, s *stepRecord, opts []wire.DesignOption, protocol int) error { |
| + if s.Republish && len(opts) == 0 { |
| + // A republish runs no Design and reports no options: it keeps |
| + // what its source attempt kept for this same commit (keptFor), |
| + // and otherwise nothing. |
| + if kept, err := keptFor(*s); err != nil || kept != nil { |
| + return err |
| + } |
| + } |
| rules := designRules(*s, protocol) |
| explore := wire.NormalKind(k.Kind) == wire.KindExplore |
| keep, ok, err := t.checkCaptures(k, s, opts, rules, explore) |
| @@ -201,7 +231,7 @@ func (t *txn) keepCaptures(k *taskRecord, s *stepRecord, opts []wire.DesignOptio |
| s.DesignOptions = "" |
| if ok { |
| labelled := rules >= wire.ProtocolDesignFeedback |
| - kept := designKept{Attempt: s.Attempt, Explore: labelled && explore, Options: []keptOption{}} |
| + kept := designKept{Attempt: s.Attempt, Candidate: s.CandidateSHA, Explore: labelled && explore, Options: []keptOption{}} |
| for _, o := range opts { |
| ko := keptOption{Name: o.Name, Captures: []string{}} |
| if labelled { |
diff --git a/internal/equipo/chat/design_feedback_options_test.go b/internal/equipo/chat/design_feedback_options_test.go| index ea210cc7..e1e0db0b 100644 |
| --- a/internal/equipo/chat/design_feedback_options_test.go |
| +++ b/internal/equipo/chat/design_feedback_options_test.go |
| @@ -1,6 +1,7 @@ |
| package chat |
| import ( |
| + "encoding/json" |
| "io" |
| "log/slog" |
| "strings" |
| @@ -302,3 +303,107 @@ func TestPackDigestKept(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// pushFailedRepublished: s's attempt (which made candidateSHA) fails to |
| +// push; the person's Retry publishes that commit again as a republish, |
| +// which starts and reports it pushed, with no options (the runner runs |
| +// no Design for a republish). |
| +func (r *hkRig) pushFailedRepublished(l Lease, task string, s stepRecord) stepRecord { |
| + r.t.Helper() |
| + r.report(l, s, wire.StepReport{State: wire.StepFailed, Reason: "push_failed", BaseSHA: strings.Repeat("b", 40), CandidateSHA: candidateSHA, Termination: true}) |
| + if _, err := r.s.RetryTask(r.ctx, paul, task); err != nil { |
| + r.t.Fatal(err) |
| + } |
| + re := r.stepNow(s.ID) |
| + if !re.Republish || re.FromAttempt != s.Attempt || re.Attempt != s.Attempt+1 || re.CandidateSHA != candidateSHA { |
| + r.t.Fatalf("not a republish: %+v", re) |
| + } |
| + r.ackDispatches(re.ID) |
| + if refused := r.authorize(l, re, ""); refused != "" { |
| + r.t.Fatalf("start the republish: %q", refused) |
| + } |
| + r.report(l, re, wire.StepReport{State: wire.StepRunning, BaseSHA: strings.Repeat("b", 40), CandidateSHA: candidateSHA}) |
| + r.doneWith(l, r.stepNow(re.ID), candidateSHA, nil) |
| + return r.stepNow(re.ID) |
| +} |
| + |
| +// TestRepublishWithoutOptionsFixRound: a push_failed exploration |
| +// attempt kept no options; its republish publishes the commit without |
| +// running Design, so the candidate still has no valid set: no Review, |
| +// and a fix round with Equipo's fixed feedback. |
| +func TestRepublishWithoutOptionsFixRound(t *testing.T) { |
| + r, l, task, s := designAt(t, wire.ProtocolDesignFeedback, wire.KindExplore) |
| + re := r.pushFailedRepublished(l, task, s) |
| + if re.State != wire.StepDone || !re.Pushed { |
| + t.Fatalf("republish %s pushed %v", re.State, re.Pushed) |
| + } |
| + r.shortFixRound(task, re, 1) |
| +} |
| + |
| +// TestRepublishKeepsSourceOptions: when the source attempt had a valid |
| +// set kept for the same commit, the republish carries it: the options |
| +// still show, and the candidate goes to Review with no fix round. |
| +func TestRepublishKeepsSourceOptions(t *testing.T) { |
| + r, l, task, s := designAt(t, wire.ProtocolDesignFeedback, wire.KindExplore) |
| + opts := []wire.DesignOption{r.option39(l, s, 1, "Calm", 1), r.option39(l, s, 2, "Bold", 1), r.option39(l, s, 3, "Plain", 1)} |
| + // The source attempt's set, validated and kept for candidateSHA. |
| + r.must(r.tx(func(tx *txn) error { |
| + k, err := tx.loadTask(task) |
| + if err != nil { |
| + return err |
| + } |
| + st := r.stepNow(s.ID) |
| + if err := tx.keepCaptures(&k, &st, opts, wire.ProtocolDesignFeedback); err != nil { |
| + return err |
| + } |
| + if st.DesignOptions == "" { |
| + t.Fatal("the source set was not kept") |
| + } |
| + return tx.db.Model(&stepRecord{}).Where("id = ?", st.ID).Update("design_options", st.DesignOptions).Error |
| + })) |
| + re := r.pushFailedRepublished(l, task, s) |
| + d := r.stepDesign(task, re.ID) |
| + if d == nil || d.Attempt != s.Attempt || len(d.Options) != 3 || d.Options[2].Direction != opts[2].Direction { |
| + t.Fatalf("the source set is not shown: %+v", d) |
| + } |
| + if n := r.reviews(task); n != 1 { |
| + t.Fatalf("%d Review steps", n) |
| + } |
| + if next := r.makerStep(task); next.ID != re.ID { |
| + t.Fatalf("a fix round %s", next.ID) |
| + } |
| +} |
| + |
| +// TestKeptForSameCommit: a step holds a kept set for its commit only |
| +// when its current attempt kept it, or, for a republish, its source |
| +// attempt kept it for the very commit it publishes. A rebase or a |
| +// republish holding none is short like any attempt. |
| +func TestKeptForSameCommit(t *testing.T) { |
| + other := strings.Repeat("9", 40) |
| + record := func(attempt int64, candidate string) string { |
| + raw, _ := json.Marshal(designKept{Attempt: attempt, Candidate: candidate, Explore: true, Options: []keptOption{}}) |
| + return string(raw) |
| + } |
| + for name, c := range map[string]struct { |
| + s stepRecord |
| + kept bool |
| + }{ |
| + "current attempt": {stepRecord{Attempt: 2, CandidateSHA: candidateSHA, DesignOptions: record(2, candidateSHA)}, true}, |
| + "republish, same commit": {stepRecord{Attempt: 2, Republish: true, FromAttempt: 1, CandidateSHA: candidateSHA, DesignOptions: record(1, candidateSHA)}, true}, |
| + "republish, other commit": {stepRecord{Attempt: 2, Republish: true, FromAttempt: 1, CandidateSHA: candidateSHA, DesignOptions: record(1, other)}, false}, |
| + "republish, no commit": {stepRecord{Attempt: 2, Republish: true, FromAttempt: 1, CandidateSHA: candidateSHA, DesignOptions: record(1, "")}, false}, |
| + "not a republish": {stepRecord{Attempt: 2, FromAttempt: 1, CandidateSHA: candidateSHA, DesignOptions: record(1, candidateSHA)}, false}, |
| + "none": {stepRecord{Attempt: 2, Republish: true, FromAttempt: 1, CandidateSHA: candidateSHA}, false}, |
| + } { |
| + got, err := keptFor(c.s) |
| + if err != nil || (got != nil) != c.kept { |
| + t.Errorf("%s: kept %v %v", name, got, err) |
| + } |
| + } |
| + for _, s := range []stepRecord{{Rebase: true}, {Republish: true, FromAttempt: 1}} { |
| + s.SpecialistID, s.DispatchProtocol, s.State, s.Pushed, s.Attempt, s.CandidateSHA = "sp_design", wire.ProtocolDesignFeedback, wire.StepDone, true, 2, candidateSHA |
| + if p := (progress{explore: true, eng: &s, candidate: candidateSHA}); !p.optionsShort() { |
| + t.Errorf("rebase %v republish %v with no set is not short", s.Rebase, s.Republish) |
| + } |
| + } |
| +} |
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go| index 76933a3b..db159a20 100644 |
| --- a/internal/equipo/chat/review.go |
| +++ b/internal/equipo/chat/review.go |
| @@ -557,9 +557,11 @@ const designFeedbackOptions = "Your last attempt ended without a valid set of op |
| // pushed (the candidate p judges), whose report kept no set of options |
| // that passed wire.ValidExploreOptions (designKept.Explore). A step |
| // dispatched before 39 (0 for rows from before it) keeps the old rules |
| -// and is never short; so are a rebase and a republish, which make no |
| -// options. A kept record that does not decode kept nothing readable, so |
| -// it is short too (designOptionsShort reports it as an error instead). |
| +// and is never short. A rebase or a republish runs no Design: it is |
| +// short unless it holds a set kept for its commit (keptFor: a |
| +// republish's source attempt's, for the same commit). A kept record |
| +// that does not decode kept nothing readable, so it is short too |
| +// (designOptionsShort reports it as an error instead). |
| func (p progress) optionsShort() bool { |
| short, _ := p.designShort() |
| return short |
| @@ -567,17 +569,14 @@ func (p progress) optionsShort() bool { |
| func (p progress) designShort() (bool, error) { |
| e := p.eng |
| - if !p.explore || e == nil || e.SpecialistID == "" || e.DispatchProtocol < wire.ProtocolDesignFeedback || e.State != wire.StepDone || !e.Pushed || e.Rebase || e.Republish || e.CandidateSHA == "" || e.CandidateSHA != p.candidate { |
| + if !p.explore || e == nil || e.SpecialistID == "" || e.DispatchProtocol < wire.ProtocolDesignFeedback || e.State != wire.StepDone || !e.Pushed || e.CandidateSHA == "" || e.CandidateSHA != p.candidate { |
| return false, nil |
| } |
| - if e.DesignOptions == "" { |
| - return true, nil |
| - } |
| - var kept designKept |
| - if err := json.Unmarshal([]byte(e.DesignOptions), &kept); err != nil { |
| + kept, err := keptFor(*e) |
| + if err != nil { |
| return true, err |
| } |
| - return !kept.Explore || kept.Attempt != e.Attempt, nil |
| + return kept == nil || !kept.Explore, nil |
| } |
| // designOptionsShort is optionsShort for advanceExplore, where a kept |