oficina / equipo Public

chat: Design steps carry the creator's taste, refreshed after a forget

Design feedback 1, Task 9 (spec 2026-11-28, sections 2, 8.6 Feeding,
8.7). explore.go: only writeChoice moved before the dispatch.

What it does:
- tasteFor(person, project): the task creator's design notes only,
  that project's and team-wide, project first then newest, at most 60,
  each cut to 300 characters, at most 6 KiB as quoted (QuotedData of
  body and question), stopping at the first that does not fit; plus
  the notebook revision and forget revision. An inactive or removed
  creator gets no notes and revisions 0; the step still runs. Choice
  notes keep their empty question. TasteSkipped stays false (TODO Task
  10, the discovery record).
- boundDispatch (now a txn method) puts them on a design-v1 dispatch;
  chat_steps.taste_revision (0125, additive) records the revision.
- designStale: a Design attempt not yet started is stale on a lease
  below 39 or when the creator's revision moved on. Authorize refuses
  it ("withdrawn") and replaces it (t.replace: old command acked,
  attempt moves on, fresh notes, or waits as design_runner_old). The
  runner's failover advance is fenced the same way.
- designCause: a runner below 39 is design_runner_old (waits, never
  fails at Encode).
- answerDirection writes the choice note before dispatching the round
  or the built task, else every More like this / Build round would be
  stale at its own start.
- Runner: sessionFence gains ForgetRevision (kept_sessions column
  forget_revision INTEGER NOT NULL DEFAULT 0); a Design fix round
  resumes only when pack digest and forget revision both match. Old
  sessions read 0, so never resume after a forget.
- Tests pinned to protocol 38 moved to 39 (designRig, TestDesignPlacement
  adds a 38 wait case); legacy-rule tests mark their attempt dispatched
  at 38 (designRunning, pushed, TestOldReportStillShown).

TDD: CGO_ENABLED=0 go test ./internal/equipo/chat/ -run
'TestTasteOrderAndCaps|TestDesignDispatchCarriesTaste|
TestForgetRefusesQueuedStart|TestOldCommandFenced|TestForgetFencesFailover|
TestChoiceNoteBeforeTheRound|TestOldRunnerWaits|TestReconnectBelow39Refused'
failed first with a stub tasteFor: revisions 0 0; dispatched at 0 with 0
notes; stale start ""; advanced attempt not replaced; on a 38 runner
dispatched (DispatchProtocol 38); a start at 38 "". After designStale,
TestChoiceNoteBeforeTheRound still failed (book at 1, dispatch at 0)
until writeChoice moved. Runner: go test ./internal/runner/thin/ -run
'TestForgetFreshSession|TestFixRoundForgetStartsFresh' failed (kept fence
without forget revision; round 1 resumed). All pass; whole chat package
passes (Task 12's direction_live tests were red in the shared tree
before its commit); thin
'Design|Kept|Ask|Fix|Session|Resume|State|Pack|Forget|Taste', thintest
'Design|Explore|Taste', internal/equipo Migration (TestMigrationModels)
pass; vet, gofmt clean; staticcheck only the known baseline U1000.

Mutations (each alone, restored), all caught:
M1 project filter dropped: TestTasteOrderAndCaps
M2 project-first order dropped: TestTasteOrderAndCaps, DispatchCarriesTaste
M3 61 notes: TestTasteOrderAndCaps
M4 no 6 KiB cap: TestTasteOrderAndCaps
M5 skip instead of stop: TestTasteOrderAndCaps
M6 no per-note clip: TestTasteOrderAndCaps
M7 tasteFor ignores membership: TestTasteOrderAndCaps
M8 tasteRevisions ignores membership: TestRemovedCreatorStale
M9 another person's notes: TestTasteOrderAndCaps
M10 step does not record the revision: 6 tests incl. ForgetRefusesQueuedStart
M11 no taste in the dispatch: 6 tests incl. DesignDispatchCarriesTaste
M12 revision never stale: ForgetRefusesQueuedStart, OldCommandFenced,
    ForgetFencesFailover, RemovedCreatorStale
M13 no protocol check at start: TestReconnectBelow39Refused
M14 refused without replace: ForgetRefusesQueuedStart, OldCommandFenced,
    ReconnectBelow39Refused
M15 start check removed: same three
M16 failover not fenced: TestForgetFencesFailover
M17 placement at 38: TestOldRunnerWaits, TestDesignPlacement,
    TestReconnectBelow39Refused
M18 choice note after the dispatch: TestChoiceNoteBeforeTheRound,
    TestFixRoundInheritsAsk
R1 fence without forget revision: TestForgetFreshSession,
   TestFixRoundForgetStartsFresh
R2 kept at 0: both
R3 column default 1: TestForgetFreshSession
R4 fixSession compares the pack only: both
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 32a32deefe41bc1d447f1339906bfb29d66999a6 parent 5490715
18 files changed, +778 −47
  • internal/equipo/chat/design_captures_test.go +5 −0
  • internal/equipo/chat/design_feedback_options_test.go +8 −6
  • internal/equipo/chat/design_routing.go +5 −3
  • internal/equipo/chat/design_routing_test.go +9 −4
  • internal/equipo/chat/explore.go +11 −8
  • internal/equipo/chat/grants.go +41 −3
  • internal/equipo/chat/runners.go +18 −0
  • internal/equipo/chat/specialist_added_test.go +3 −3
  • internal/equipo/chat/tasks.go +15 −3
  • internal/equipo/chat/taste.go +79 −0
  • internal/equipo/chat/taste_dispatch_test.go +427 −0
  • internal/equipo/migrations/0125_design_feedback.sql +5 −0
  • internal/equipo/migrations/schema.sql +5 −0
  • internal/runner/thin/ask.go +13 −8
  • internal/runner/thin/design_step.go +2 −2
  • internal/runner/thin/engineer.go +4 −2
  • internal/runner/thin/forget_session_linux_test.go +119 −0
  • internal/runner/thin/state.go +9 −5
diff --git a/internal/equipo/chat/design_captures_test.go b/internal/equipo/chat/design_captures_test.go
index d3544058..7e38c3fe 100644
--- a/internal/equipo/chat/design_captures_test.go
+++ b/internal/equipo/chat/design_captures_test.go
@@ -157,6 +157,11 @@ func designRunning(t *testing.T) (*hkRig, Lease, specialistRecord, string, stepR
}
sp := r.active(l, "Patrix", "p_patrix")
task, s := r.runningDesign(l, sp, wire.KindExplore)
+ // These tests keep slice 1's report rules: the attempt is one
+ // dispatched at 38, before Design feedback (every Design dispatch
+ // now goes to a runner at 39; design_feedback_options_test.go
+ // covers 39's rules).
+ r.exec("UPDATE chat_steps SET dispatch_protocol = ? WHERE id = ?", wire.ProtocolDesign, s.ID)
r.report(l, s, wire.StepReport{State: wire.StepRunning, BaseSHA: strings.Repeat("b", 40), CandidateSHA: candidateSHA})
return r, l, sp, task, r.stepNow(s.ID)
}
diff --git a/internal/equipo/chat/design_feedback_options_test.go b/internal/equipo/chat/design_feedback_options_test.go
index e1e0db0b..0da81eb1 100644
--- a/internal/equipo/chat/design_feedback_options_test.go
+++ b/internal/equipo/chat/design_feedback_options_test.go
@@ -147,15 +147,17 @@ func TestOldReportStillShown(t *testing.T) {
name = "legacy row"
}
t.Run(name, func(t *testing.T) {
- r, l, task, s := designAt(t, wire.ProtocolDesign, wire.KindExplore)
- if s.DispatchProtocol != wire.ProtocolDesign {
- t.Fatalf("dispatched at %d", s.DispatchProtocol)
- }
+ // Every Design dispatch now goes to a runner at 39: an
+ // attempt dispatched at 38 (reporting over its 38
+ // connection) or a legacy row is one from before.
+ r, l, task, s := designAt(t, wire.ProtocolDesignFeedback, wire.KindExplore)
if legacy {
r.exec("UPDATE chat_steps SET dispatch_protocol = 0 WHERE id = ?", s.ID)
- l.Protocol = wire.ProtocolDesignFeedback
- s = r.stepNow(s.ID)
+ } else {
+ r.exec("UPDATE chat_steps SET dispatch_protocol = ? WHERE id = ?", wire.ProtocolDesign, s.ID)
+ l.Protocol = wire.ProtocolDesign
}
+ s = r.stepNow(s.ID)
var opts []wire.DesignOption
for i, n := range []string{"Calm", "Bold"} {
data := capturePNG(t, 20, 20, uint8(i))
diff --git a/internal/equipo/chat/design_routing.go b/internal/equipo/chat/design_routing.go
index 2bed5192..e551ed9c 100644
--- a/internal/equipo/chat/design_routing.go
+++ b/internal/equipo/chat/design_routing.go
@@ -37,7 +37,7 @@ const (
// Why a Design step waits, on the step while it waits (its Reason; the
// task page's words for it are work.reason.<reason>): the runner it would
-// run on is below wire.ProtocolDesign, its page renderer is not ok, the
+// run on is below wire.ProtocolDesignFeedback, its page renderer is not ok, the
// person has no Claude connection there, or the autonomy limit holds it.
const (
reasonDesignProtocol = "design_runner_old"
@@ -92,7 +92,9 @@ func (t *txn) routeMaker(r turnRecord, task, id string) (string, *wire.ToolResul
}
// designCause is why the runner a Design step of person would run on
-// cannot run it now ("" when it can): it speaks wire.ProtocolDesign, its
+// cannot run it now ("" when it can): it speaks
+// wire.ProtocolDesignFeedback (every Design dispatch needs it: Encode
+// refuses one below, so an older runner waits, never fails), its
// page renderer said ok, and the person has a Claude connection there
// that is not an API key's (the runner runs Design on Claude only).
func (t *txn) designCause(person, runner string) (string, error) {
@@ -100,7 +102,7 @@ func (t *txn) designCause(person, runner string) (string, error) {
if err := t.db.Where("runner_id = ?", runner).Limit(1).Find(&sess).Error; err != nil {
return "", err
}
- if sess.RunnerID == "" || sess.Protocol < wire.ProtocolDesign {
+ if sess.RunnerID == "" || sess.Protocol < wire.ProtocolDesignFeedback {
return reasonDesignProtocol, nil
}
var h wire.Hello
diff --git a/internal/equipo/chat/design_routing_test.go b/internal/equipo/chat/design_routing_test.go
index 8a0f7d98..a7e145ae 100644
--- a/internal/equipo/chat/design_routing_test.go
+++ b/internal/equipo/chat/design_routing_test.go
@@ -192,7 +192,7 @@ func TestStatusListsSpecialists(t *testing.T) {
}
}
-// TestDesignPlacement: a Design step goes only to a runner at 38 whose
+// TestDesignPlacement: a Design step goes only to a runner at 39 whose
// renderer is ok and that holds a Claude connection of the person (not
// an API key's); otherwise it waits with design_runner, saying why, and
// nothing is sent. Placement sends it once the runner can.
@@ -220,6 +220,9 @@ func TestDesignPlacement(t *testing.T) {
}
place := func() { r.t.Helper(); r.must(r.tx(func(tx *txn) error { return tx.placeWaiting(paul) })) }
waits("a runner at 37", reasonDesignProtocol)
+ r.setHello(wire.ProtocolDesign, designHello(wire.ToolHealthy, claudeSub))
+ place()
+ waits("a runner at 38", reasonDesignProtocol)
for _, c := range []struct {
what, renderer, reason string
conns []wire.HeldConnection
@@ -231,11 +234,11 @@ func TestDesignPlacement(t *testing.T) {
{"a Claude API key only", wire.ToolHealthy, reasonDesignClaude, []wire.HeldConnection{{LocalID: "key-1", Person: paul, Provider: wire.ProviderClaude, Kind: wire.KindAPIKey}}},
{"someone else's Claude", wire.ToolHealthy, reasonDesignClaude, []wire.HeldConnection{{LocalID: "claude-2", Person: "nora@tito.io", Provider: wire.ProviderClaude, Kind: wire.KindSubscription}}},
} {
- r.setHello(wire.ProtocolDesign, designHello(c.renderer, c.conns...))
+ r.setHello(wire.ProtocolDesignFeedback, designHello(c.renderer, c.conns...))
place()
waits(c.what, c.reason)
}
- r.setHello(wire.ProtocolDesign, designHello(wire.ToolHealthy, claudeSub))
+ r.setHello(wire.ProtocolDesignFeedback, designHello(wire.ToolHealthy, claudeSub))
place()
got := r.stepNow(s.ID)
if got.Placement != "" || got.Reason != "" || got.RunnerID != "RUNNER1" {
@@ -436,9 +439,11 @@ func (r *hkRig) directionCard(l Lease, task string, verdict string) cardRecord {
}
// pushed reports the maker step's candidate, then its done and pushed
-// end, proven.
+// end, proven. The attempt keeps slice 1's report rules (no options
+// needed): it is marked dispatched at 38, before Design feedback.
func (r *hkRig) pushed(l Lease, s stepRecord) {
r.t.Helper()
+ r.exec("UPDATE chat_steps SET dispatch_protocol = ? WHERE id = ?", wire.ProtocolDesign, s.ID)
r.report(l, s, wire.StepReport{State: wire.StepRunning, BaseSHA: strings.Repeat("b", 40), CandidateSHA: candidateSHA})
r.report(l, s, wire.StepReport{State: wire.StepDone, BaseSHA: strings.Repeat("b", 40), CandidateSHA: candidateSHA, Pushed: true, Termination: true})
}
diff --git a/internal/equipo/chat/explore.go b/internal/equipo/chat/explore.go
index 220c25be..c56d5789 100644
--- a/internal/equipo/chat/explore.go
+++ b/internal/equipo/chat/explore.go
@@ -302,6 +302,17 @@ func (t *txn) answerDirection(person string, c cardRecord, in wire.AnswerCard) (
if err := t.saveCard(&c); err != nil {
return wire.Card{}, wire.Card{}, err
}
+ if chosen != nil {
+ // Build this one or More like this on an option teaches taste
+ // (spec 8.6, Choices): a choice note, in this transaction, so a
+ // refused or retried answer writes none. Written before the
+ // round or the built task is dispatched, so its Design step
+ // carries the note at the notebook's revision now, and is not
+ // refused at its start for a note of its own answer.
+ if err := t.writeChoice(person, k, c.ID, in.Choice, chosen.Option); err != nil {
+ return wire.Card{}, wire.Card{}, err
+ }
+ }
switch in.Choice {
case wire.ChoiceBuild:
if err := t.buildThisOne(&k, p, note, chosen); err != nil {
@@ -345,14 +356,6 @@ func (t *txn) answerDirection(person string, c cardRecord, in wire.AnswerCard) (
return wire.Card{}, wire.Card{}, err
}
}
- if chosen != nil {
- // Build this one or More like this on an option teaches taste
- // (spec 8.6, Choices): a choice note, in this transaction, so a
- // refused or retried answer writes none.
- if err := t.writeChoice(person, k, c.ID, in.Choice, chosen.Option); err != nil {
- return wire.Card{}, wire.Card{}, err
- }
- }
out, err := t.cardView(c)
return out, wire.Card{}, err
}
diff --git a/internal/equipo/chat/grants.go b/internal/equipo/chat/grants.go
index 9d0cb8c7..a1a9c5a8 100644
--- a/internal/equipo/chat/grants.go
+++ b/internal/equipo/chat/grants.go
@@ -145,13 +145,23 @@ func bind(s *stepRecord, sp specialistRecord) {
// dispatch of task k (protocol 38), with whether k is an exploration and
// sp's brief as its owner added it, and step s's round request
// (protocol 39: More options or More like this, on the round and each
-// of its fix rounds).
-func boundDispatch(cmd *wire.DispatchCommand, sp specialistRecord, k taskRecord, s stepRecord) error {
- a, err := stepAsk(s)
+// of its fix rounds). A Design step's also carries the task creator's
+// taste (protocol 39, tasteFor) and its notebook's revision and forget
+// revision; s records the revision (the caller saves s), which its
+// start authorization compares (designStale).
+func (t *txn) boundDispatch(cmd *wire.DispatchCommand, sp specialistRecord, k taskRecord, s *stepRecord) error {
+ a, err := stepAsk(*s)
if err != nil {
return err
}
cmd.DesignAsk = a
+ s.TasteRevision = 0
+ if sp.Profile == specialist.ProfileDesign {
+ if cmd.Taste, cmd.TasteRevision, cmd.ForgetRevision, cmd.TasteSkipped, err = t.tasteFor(k.Creator, k.ProjectID); err != nil {
+ return err
+ }
+ s.TasteRevision = cmd.TasteRevision
+ }
b := bindingOf(sp)
cmd.SpecialistID, cmd.SpecialistRevision, cmd.SpecialistProject, cmd.Profile = b.ID, b.Revision, b.Project, sp.Profile
cmd.Explore, cmd.SpecialistBrief = wire.NormalKind(k.Kind) == wire.KindExplore, clipText(sp.Brief, wire.MaxSpecialistBrief)
@@ -185,6 +195,34 @@ func (t *txn) bindingHolds(s stepRecord, k taskRecord) (bool, error) {
return bindingOf(*sp) == stepBinding(s), nil
}
+// designStale reports whether a Design attempt of task k that has not
+// started must not start as dispatched (spec 2026-11-28, sections 2,
+// 8.6 Feeding and 8.7): its connection l speaks below
+// wire.ProtocolDesignFeedback (a runner that reconnected older after
+// placement), or the creator's notebook has moved on from the revision
+// its dispatch carried (a note written or forgotten since, or the
+// creator no longer an active member). The caller replaces the attempt
+// (replace), so the old command can never start and the next one waits
+// for a runner at 39 or carries fresh notes. Any other step is never
+// stale.
+func (t *txn) designStale(l Lease, k taskRecord, s stepRecord) (bool, error) {
+ if s.Specialist != wire.SpecialistEngineering || s.SpecialistID == "" {
+ return false, nil
+ }
+ var row specialistRecord
+ if err := t.db.Where("id = ?", s.SpecialistID).Limit(1).Find(&row).Error; err != nil || row.Profile != specialist.ProfileDesign {
+ return false, err
+ }
+ if l.Protocol < wire.ProtocolDesignFeedback {
+ return true, nil
+ }
+ rev, _, err := t.tasteRevisions(k.Creator)
+ if err != nil {
+ return false, err
+ }
+ return rev != s.TasteRevision, nil
+}
+
// makerGrant is the specialist the task's maker step runs as at its
// dispatch: the task's maker, found by grantFor for the task's project,
// and the one the step is already bound to when it is (an earlier
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go
index f7001021..5ec4e961 100644
--- a/internal/equipo/chat/runners.go
+++ b/internal/equipo/chat/runners.go
@@ -1022,6 +1022,24 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i
refused = wire.CodeAbilityOff
return nil
}
+ // A Design attempt starts only as dispatched for a runner at 39
+ // with the creator's notes as they stand (designStale): else it
+ // is refused and replaced, so this command never starts and the
+ // next attempt carries fresh notes or waits for a runner at 39.
+ if k, err := t.loadTask(st.TaskID); err != nil {
+ return err
+ } else if stale, err := t.designStale(l, k, st); err != nil {
+ return err
+ } else if stale {
+ refused = "withdrawn"
+ if wire.FinalStage(k.Stage) || k.CancelRequested {
+ return nil
+ }
+ if err := t.replace(&k, &st); err != nil {
+ return err
+ }
+ return t.saveStep(&st, &k)
+ }
if st.Specialist == wire.SpecialistEngineering {
// Placement is decided again before Engineering starts: one
// dispatched to the Linux primary before Mac work waited for a
diff --git a/internal/equipo/chat/specialist_added_test.go b/internal/equipo/chat/specialist_added_test.go
index 32be1d0f..4909e20c 100644
--- a/internal/equipo/chat/specialist_added_test.go
+++ b/internal/equipo/chat/specialist_added_test.go
@@ -48,11 +48,11 @@ func designRig(t *testing.T) (*hkRig, Lease) {
}
r.must(r.s.db.G.Create(&projectRecord{ID: "p_patrix", Repo: repoPatrix, Title: "Patrix", TitleSet: true, State: wire.ProjectActive, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now}).Error)
r.must(r.s.db.G.Create(&projectRecord{ID: "p_suite", Repo: repoSuite, Title: "Suite", TitleSet: true, State: wire.ProjectActive, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now}).Error)
- // A runner that can run Design: at 38, its page renderer ok, and
+ // A runner that can run Design: at 39, its page renderer ok, and
// Paul's Claude subscription there (task 17's placement).
hello, _ := json.Marshal(designHello(wire.ToolHealthy, wire.HeldConnection{LocalID: "claude-1", Person: paul, Provider: wire.ProviderClaude, Kind: wire.KindSubscription, State: wire.ConnHealthy}))
- r.must(r.s.db.G.Create(&runnerSessionRecord{RunnerID: "RUNNER1", Protocol: wire.ProtocolDesign, Hello: string(hello), Connected: true, SeenAt: r.now}).Error)
- return r, Lease{Runner: RunnerPrincipal{RunnerID: "RUNNER1", Person: paul}, Protocol: wire.ProtocolDesign}
+ r.must(r.s.db.G.Create(&runnerSessionRecord{RunnerID: "RUNNER1", Protocol: wire.ProtocolDesignFeedback, Hello: string(hello), Connected: true, SeenAt: r.now}).Error)
+ return r, Lease{Runner: RunnerPrincipal{RunnerID: "RUNNER1", Person: paul}, Protocol: wire.ProtocolDesignFeedback}
}
// asked records Paul's message in a person turn of lane, in flight.
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go
index 999fb1f2..fe81e550 100644
--- a/internal/equipo/chat/tasks.go
+++ b/internal/equipo/chat/tasks.go
@@ -341,6 +341,11 @@ type stepRecord struct {
// copied onto each of its fix rounds (fixRound), and carried on every
// dispatch of the step (boundDispatch). Written once, at creation.
DesignAsk string `gorm:"not null;default:''"`
+ // TasteRevision is the task creator's design notebook revision a
+ // Design attempt's dispatch carried its notes at (boundDispatch; 0
+ // none). Its start is refused, and the attempt replaced with fresh
+ // notes, once the notebook has moved on (designStale).
+ TasteRevision int64 `gorm:"not null;default:0"`
}
func (stepRecord) TableName() string { return "chat_steps" }
@@ -874,7 +879,7 @@ func (t *txn) writeStep(s *stepRecord) error {
}
s.Revision++
s.UpdatedAt = t.now()
- if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "specialist_id", "specialist_revision", "specialist_project", "specialist_caps", "design_options", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model", "xcode_access", "outcome_phase", "session_id", "publication_runner", "on_worker", "ability_held", "dispatch_protocol", "pack_digest").Updates(s).Error; err != nil {
+ if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "specialist_id", "specialist_revision", "specialist_project", "specialist_caps", "design_options", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model", "xcode_access", "outcome_phase", "session_id", "publication_runner", "on_worker", "ability_held", "dispatch_protocol", "pack_digest", "taste_revision").Updates(s).Error; err != nil {
return err
}
if s.Retired {
@@ -1408,7 +1413,7 @@ func (t *txn) dispatchStep(k *taskRecord, s *stepRecord) error {
// The step's full binding (protocol 38; Encode refuses the
// dispatch below it, so it never runs there as plain
// Engineering), and the grant's use audited.
- if err := boundDispatch(&cmd, *maker, *k, *s); err != nil {
+ if err := t.boundDispatch(&cmd, *maker, *k, s); err != nil {
return err
}
if err := t.specialistUsed(*maker, *k, *s); err != nil {
@@ -1658,7 +1663,14 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error {
// limit it is not launched: the runner's start of it is refused
// (the attempt moves on), and the step is held for the person
// through the held-step card (designGate, via the dispatch).
- if k.DesignRuns >= wire.DesignRunLimit {
+ // Nor is it launched as dispatched when its notes are stale or
+ // its runner speaks below 39 now (designStale): it is replaced
+ // with fresh notes, or waits for a runner that can run it.
+ stale, err := t.designStale(l, k, s)
+ if err != nil {
+ return err
+ }
+ if k.DesignRuns >= wire.DesignRunLimit || stale {
s.Attempt = v.Attempt
if err := t.replace(&k, &s); err != nil {
return err
diff --git a/internal/equipo/chat/taste.go b/internal/equipo/chat/taste.go
index 849141b9..090ec7f3 100644
--- a/internal/equipo/chat/taste.go
+++ b/internal/equipo/chat/taste.go
@@ -310,3 +310,82 @@ func (s *Store) ForgetAllTaste(ctx context.Context, person string) error {
return nil
})
}
+
+// What a Design prompt carries of a notebook (spec 2026-11-28, sections
+// 2 and 8.6, Feeding): at most tasteNotesMax notes, each at most
+// wire.MaxTasteBox characters, and tasteBytesMax bytes in all, counted
+// as the prompt quotes them (wire.QuotedData of each body and question).
+const (
+ tasteNotesMax = 60
+ tasteBytesMax = 6 << 10
+)
+
+// tasteRevisions is person's design notebook revision and forget
+// revision as a Design step reads them: 0 and 0 when the person is not
+// an active member now (their notes stop being used at once) or has
+// never written one.
+func (t *txn) tasteRevisions(person string) (revision, forgetRevision int64, err error) {
+ ok, err := t.activeMember(person)
+ if err != nil || !ok {
+ return 0, 0, err
+ }
+ var books []tasteBookRecord
+ if err := t.db.Where("person = ? AND discipline = ?", person, TasteDesign).Limit(1).Find(&books).Error; err != nil {
+ return 0, 0, err
+ }
+ if len(books) == 0 {
+ return 0, 0, nil
+ }
+ return books[0].Revision, books[0].ForgetRevision, nil
+}
+
+// tasteFor is what a Design step of a task person created in project
+// carries of their taste: only that person's design notes, only
+// project's and their team-wide ones (project ""), project notes first
+// and then newest first, at most tasteNotesMax, each body and question
+// cut to wire.MaxTasteBox characters, stopping before the first note
+// that would take the quoted total past tasteBytesMax; and the
+// notebook's revision and forget revision (tasteRevisions). A person
+// who is not an active member gets no notes and revisions 0, and the
+// step still runs, without taste. skipped is always false for now.
+func (t *txn) tasteFor(person, project string) (notes []wire.TasteNote, revision, forgetRevision int64, skipped bool, err error) {
+ // TODO(Task 10): skipped comes from the discovery ask record.
+ ok, err := t.activeMember(person)
+ if err != nil || !ok {
+ return nil, 0, 0, false, err
+ }
+ if revision, forgetRevision, err = t.tasteRevisions(person); err != nil {
+ return nil, 0, 0, false, err
+ }
+ var rows []tasteNoteRecord
+ q := t.db.Where("person = ? AND discipline = ? AND (project_id = ? OR project_id = '')", person, TasteDesign, project)
+ if err := q.Order("CASE WHEN project_id = '' THEN 1 ELSE 0 END, created_at DESC, rowid DESC").Limit(tasteNotesMax).Find(&rows).Error; err != nil {
+ return nil, 0, 0, false, err
+ }
+ size := 0
+ for _, n := range rows {
+ body, question := clipRunes(n.Body, wire.MaxTasteBox), clipRunes(n.Question, wire.MaxTasteBox)
+ cost := len(wire.QuotedData(body))
+ if question != "" {
+ cost += len(wire.QuotedData(question))
+ }
+ if size+cost > tasteBytesMax {
+ break
+ }
+ size += cost
+ scope := wire.TasteScopeTeam
+ if n.ProjectID != "" {
+ scope = wire.TasteScopeProject
+ }
+ notes = append(notes, wire.TasteNote{ID: n.ID, Source: n.Source, Scope: scope, Body: body, Question: question, Date: n.CreatedAt.UTC().Format("2006-01-02")})
+ }
+ return notes, revision, forgetRevision, false, nil
+}
+
+// clipRunes is s cut to at most n characters.
+func clipRunes(s string, n int) string {
+ if utf8.RuneCountInString(s) <= n {
+ return s
+ }
+ return string([]rune(s)[:n])
+}
diff --git a/internal/equipo/chat/taste_dispatch_test.go b/internal/equipo/chat/taste_dispatch_test.go
new file mode 100644
index 00000000..0655dacc
--- /dev/null
+++ b/internal/equipo/chat/taste_dispatch_test.go
@@ -0,0 +1,427 @@
+package chat
+
+import (
+ "strings"
+ "testing"
+ "time"
+ "unicode/utf8"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Design feedback 1, Task 9 (spec 2026-11-28-dynamic-specialists.md,
+// sections 2, 8.6 Feeding and 8.7): a Design step's dispatch carries the
+// task creator's design notes (that project's first, then the team's,
+// newest first, at most 60, 300 characters each, 6 KiB), the notebook's
+// revision and its forget revision. Its start authorization refuses an
+// attempt whose revision is stale and replaces it as a new attempt with
+// fresh notes, and refuses a Design attempt on a connection below
+// protocol 39; placement keeps a Design step waiting for a runner at 39.
+
+// note inserts one design note of person's for project ("" the team's),
+// written at r.now plus minute minutes.
+func (r *hkRig) note(person, project, source, body, question string, minute int) string {
+ r.t.Helper()
+ n := tasteNoteRecord{ID: newID("tn_"), Person: person, Discipline: TasteDesign, ProjectID: project, Source: source, Body: body, Question: question, CreatedAt: r.now.Add(time.Duration(minute) * time.Minute)}
+ r.must(r.s.db.G.Create(&n).Error)
+ return n.ID
+}
+
+// tasteOf runs tasteFor in a transaction.
+func (r *hkRig) tasteOf(person, project string) ([]wire.TasteNote, int64, int64, bool) {
+ r.t.Helper()
+ var notes []wire.TasteNote
+ var rev, forget int64
+ var skipped bool
+ r.must(r.tx(func(t *txn) error {
+ var err error
+ notes, rev, forget, skipped, err = t.tasteFor(person, project)
+ return err
+ }))
+ return notes, rev, forget, skipped
+}
+
+// promptBytes is what the notes take in the prompt: each body and
+// question as wire.QuotedData quotes it.
+func promptBytes(notes []wire.TasteNote) int {
+ n := 0
+ for _, x := range notes {
+ n += len(wire.QuotedData(x.Body))
+ if x.Question != "" {
+ n += len(wire.QuotedData(x.Question))
+ }
+ }
+ return n
+}
+
+// TestTasteOrderAndCaps: tasteFor reads only the creator's notes, only
+// that project's and the team's, project notes first then newest; at
+// most 60, each at most 300 characters, 6 KiB in all, stopping at the
+// first that does not fit; a choice note keeps its empty question; a
+// removed or inactive creator gets none (and no revisions).
+func TestTasteOrderAndCaps(t *testing.T) {
+ r, _ := designRig(t)
+ r.exec("INSERT INTO members(address, active, role) VALUES ('nora@tito.io', 1, 'member')")
+ // 61 notes: 30 for Patrix, 31 team-wide, interleaved in time.
+ var project, team []string
+ for i := 0; i < 61; i++ {
+ if i%2 == 0 && len(project) < 30 {
+ project = append(project, r.note(paul, "p_patrix", wire.TasteSourceWords, "Project note "+itoa64(int64(i)), "", i))
+ } else {
+ team = append(team, r.note(paul, "", wire.TasteSourceWords, "Team note "+itoa64(int64(i)), "", i))
+ }
+ }
+ // Never read: another project's, another discipline's, another person's.
+ r.note(paul, "p_suite", wire.TasteSourceWords, "Suite only", "", 100)
+ r.must(r.s.db.G.Create(&tasteNoteRecord{ID: newID("tn_"), Person: paul, Discipline: "security", Source: wire.TasteSourceWords, Body: "Other notebook", CreatedAt: r.now.Add(time.Hour)}).Error)
+ r.note("nora@tito.io", "p_patrix", wire.TasteSourceWords, "Nora's", "", 101)
+ r.exec("INSERT INTO chat_taste_books(person, discipline, revision, forget_revision) VALUES (?, ?, 7, 2)", paul, TasteDesign)
+
+ notes, rev, forget, skipped := r.tasteOf(paul, "p_patrix")
+ if rev != 7 || forget != 2 || skipped {
+ t.Fatalf("revisions %d %d skipped %v", rev, forget, skipped)
+ }
+ if len(notes) != 60 {
+ t.Fatalf("%d notes sent", len(notes))
+ }
+ var want []string
+ for i := len(project) - 1; i >= 0; i-- {
+ want = append(want, project[i])
+ }
+ for i := len(team) - 1; i >= 0; i-- {
+ want = append(want, team[i])
+ }
+ want = want[:60]
+ for i, n := range notes {
+ if n.ID != want[i] {
+ t.Fatalf("note %d is %s (%q), want %s", i, n.ID, n.Body, want[i])
+ }
+ scope := wire.TasteScopeTeam
+ if i < len(project) {
+ scope = wire.TasteScopeProject
+ }
+ if n.Scope != scope || n.Source != wire.TasteSourceWords || n.Date == "" {
+ t.Fatalf("note %d: %+v", i, n)
+ }
+ }
+ if promptBytes(notes) > 6<<10 {
+ t.Fatalf("%d bytes", promptBytes(notes))
+ }
+
+ // 6 KiB: long notes stop at the first that does not fit, in order.
+ r2, _ := designRig(t)
+ var long []string
+ for i := 0; i < 30; i++ {
+ long = append(long, r2.note(paul, "p_patrix", wire.TasteSourceWords, strings.Repeat(string(rune('a'+i%26)), 300), "", 100-i))
+ }
+ // An older short note that would fit after a long one that does
+ // not: never sent ahead of it.
+ r2.note(paul, "p_patrix", wire.TasteSourceWords, "Short.", "", 0)
+ notes, _, _, _ = r2.tasteOf(paul, "p_patrix")
+ size := promptBytes(notes)
+ if size > 6<<10 || len(notes) == 0 || size+len(wire.QuotedData(strings.Repeat("a", 300))) <= 6<<10 {
+ t.Fatalf("%d notes, %d bytes", len(notes), size)
+ }
+ for i, n := range notes {
+ if i >= len(long) || n.ID != long[i] {
+ t.Fatalf("long note %d is %s (%q)", i, n.ID, n.Body)
+ }
+ }
+
+ // Each note at most 300 characters, whatever was stored; a choice
+ // note keeps its empty question, a feel its question.
+ r3, _ := designRig(t)
+ r3.note(paul, "", wire.TasteSourceWords, strings.Repeat("é", 400), "", 1)
+ r3.note(paul, "", wire.TasteSourceChoice, "Build: \"Calm\"", "", 2)
+ r3.note(paul, "", wire.TasteSourceChoice, "Calm", "What feel are you after?", 3)
+ notes, rev, _, _ = r3.tasteOf(paul, "p_patrix")
+ if len(notes) != 3 || rev != 0 {
+ t.Fatalf("notes %+v rev %d", notes, rev)
+ }
+ if notes[0].Question != "What feel are you after?" || notes[1].Question != "" || notes[1].Source != wire.TasteSourceChoice {
+ t.Fatalf("choices %+v", notes[:2])
+ }
+ if c := utf8.RuneCountInString(notes[2].Body); c != 300 {
+ t.Fatalf("a stored long note sent at %d characters", c)
+ }
+
+ // A removed or inactive creator: no notes, no revisions.
+ for _, how := range []string{"UPDATE members SET active = 0 WHERE address = ?", "DELETE FROM members WHERE address = ?"} {
+ r.exec(how, paul)
+ if notes, rev, forget, _ := r.tasteOf(paul, "p_patrix"); len(notes) != 0 || rev != 0 || forget != 0 {
+ t.Fatalf("%s: %d notes, revisions %d %d", how, len(notes), rev, forget)
+ }
+ }
+}
+
+// designReady is grantRig with Design active for Patrix: a task
+// started with it (designTask) is dispatched to RUNNER1 at protocol 39
+// and not yet started.
+func designReady(t *testing.T) (*hkRig, Lease) {
+ r, l, _ := grantRig(t)
+ r.active(l, "Patrix", "p_patrix")
+ return r, l
+}
+
+// TestDesignDispatchCarriesTaste: a Design dispatch carries the
+// creator's notes for its project and the team, and both revisions;
+// the step records the revision. A creator with no notebook sends none,
+// and the step still goes.
+func TestDesignDispatchCarriesTaste(t *testing.T) {
+ r, l := designReady(t)
+ r.must(r.s.AddTaste(r.ctx, paul, "p_patrix", "Warm paper."))
+ r.must(r.s.AddTaste(r.ctx, paul, "", "No gradients."))
+ r.must(r.s.AddTaste(r.ctx, paul, "p_suite", "Suite only."))
+ r.must(r.s.ForgetTaste(r.ctx, paul, r.tasteRows(paul)[2].ID))
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ _, d := r.dispatched(s.ID)
+ if d.TasteRevision != 4 || d.ForgetRevision != 1 || s.TasteRevision != 4 || d.TasteSkipped {
+ t.Fatalf("revisions: dispatch %d %d, step %d", d.TasteRevision, d.ForgetRevision, s.TasteRevision)
+ }
+ if len(d.Taste) != 2 || d.Taste[0].Body != "Warm paper." || d.Taste[0].Scope != wire.TasteScopeProject || d.Taste[1].Body != "No gradients." || d.Taste[1].Scope != wire.TasteScopeTeam {
+ t.Fatalf("taste %+v", d.Taste)
+ }
+ if refused := r.authorize(l, s, ""); refused != "" {
+ t.Fatalf("a current revision refused: %q", refused)
+ }
+ // Engineering's own step carries none.
+ plain := r.plainTask(l, "k_plain")
+ if _, d := r.dispatched(plain.ID); d.Taste != nil || d.TasteRevision != 0 || d.ForgetRevision != 0 {
+ t.Fatalf("Engineering's dispatch %+v", d)
+ }
+}
+
+// makerSpecialist is the active Patrix Design row.
+func (r *hkRig) makerSpecialist() specialistRecord {
+ r.t.Helper()
+ var sp specialistRecord
+ r.must(r.s.db.G.Where("project_id = ? AND state = ?", "p_patrix", wire.SpecialistActive).First(&sp).Error)
+ return sp
+}
+
+// TestForgetRefusesQueuedStart: a step dispatched at revision 4 whose
+// creator then forgets a note (revision 5) is refused at its start and
+// replaced as a new attempt, dispatched with revision 5 and without the
+// forgotten note.
+func TestForgetRefusesQueuedStart(t *testing.T) {
+ r, l := designReady(t)
+ for _, n := range []string{"One.", "Two.", "Three.", "Four."} {
+ r.must(r.s.AddTaste(r.ctx, paul, "p_patrix", n))
+ }
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ if _, d := r.dispatched(s.ID); d.TasteRevision != 4 || len(d.Taste) != 4 {
+ t.Fatalf("dispatched at %d with %d notes", d.TasteRevision, len(d.Taste))
+ }
+ forgotten := r.tasteRows(paul)[1]
+ r.must(r.s.ForgetTaste(r.ctx, paul, forgotten.ID))
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, s, ""); refused != "withdrawn" {
+ t.Fatalf("a stale start: %q", refused)
+ }
+ next := r.stepNow(s.ID)
+ if next.Attempt != s.Attempt+1 || next.StartedAt != nil || next.State != wire.StepQueued || next.TasteRevision != 5 {
+ t.Fatalf("not replaced: %+v", next)
+ }
+ _, d := r.dispatched(s.ID)
+ if d.Attempt != next.Attempt || d.TasteRevision != 5 || d.ForgetRevision != 1 || len(d.Taste) != 3 {
+ t.Fatalf("replacement dispatch attempt %d revisions %d %d, %d notes", d.Attempt, d.TasteRevision, d.ForgetRevision, len(d.Taste))
+ }
+ for _, n := range d.Taste {
+ if n.ID == forgotten.ID || n.Body == forgotten.Body {
+ t.Fatalf("the forgotten note was sent: %+v", n)
+ }
+ }
+ // A note added (no forget) is stale too: the next start is refused
+ // once more and the next dispatch carries it.
+ r.must(r.s.AddTaste(r.ctx, paul, "", "Five."))
+ if refused := r.authorize(l, next, ""); refused != "withdrawn" {
+ t.Fatalf("a start after an add: %q", refused)
+ }
+ third := r.stepNow(s.ID)
+ if _, d := r.dispatched(s.ID); third.Attempt != next.Attempt+1 || d.TasteRevision != 6 || len(d.Taste) != 4 {
+ t.Fatalf("after an add: attempt %d, dispatch at %d with %d notes", third.Attempt, d.TasteRevision, len(d.Taste))
+ }
+ if refused := r.authorize(l, third, ""); refused != "" {
+ t.Fatalf("the fresh attempt: %q", refused)
+ }
+}
+
+// TestOldCommandFenced: once the replacement is dispatched, the old
+// attempt's command is never served again (acknowledged) and its start
+// is refused, before and after the new attempt starts.
+func TestOldCommandFenced(t *testing.T) {
+ r, l := designReady(t)
+ r.must(r.s.AddTaste(r.ctx, paul, "p_patrix", "One."))
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ old := r.makerStep(task)
+ r.must(r.s.ForgetTaste(r.ctx, paul, r.tasteRows(paul)[0].ID))
+ // The old dispatch was not delivered yet: the replacement voids it.
+ if refused := r.authorize(l, old, ""); refused != "withdrawn" {
+ t.Fatalf("stale start %q", refused)
+ }
+ if n := r.count("SELECT count(*) FROM runner_commands WHERE kind = ? AND acked_at IS NULL AND body LIKE ?", wire.FrameDispatch, attemptLike(old.ID, old.Attempt)); n != 0 {
+ t.Fatalf("the old attempt's dispatch is still served: %d", n)
+ }
+ next := r.stepNow(old.ID)
+ if !r.attemptSent(next) {
+ t.Fatal("no replacement dispatched")
+ }
+ if refused := r.authorize(l, old, ""); refused != "withdrawn" {
+ t.Fatalf("the old command after the replacement: %q", refused)
+ }
+ if refused := r.authorize(l, next, ""); refused != "" {
+ t.Fatalf("the replacement: %q", refused)
+ }
+ if refused := r.authorize(l, old, ""); refused != "withdrawn" {
+ t.Fatalf("the old command after the replacement started: %q", refused)
+ }
+ if got := r.stepNow(old.ID); got.Attempt != next.Attempt || got.StartedAt == nil {
+ t.Fatalf("after: %+v", got)
+ }
+}
+
+// TestForgetFencesFailover: a Design attempt the runner moves on after
+// the provider refused it (the instance's advance) is a new attempt
+// that has not started: with a stale revision it is replaced, and the
+// runner's start of the advanced attempt is refused.
+func TestForgetFencesFailover(t *testing.T) {
+ r, l := designReady(t)
+ r.must(r.s.AddTaste(r.ctx, paul, "p_patrix", "One."))
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, s, ""); refused != "" {
+ t.Fatalf("start %q", refused)
+ }
+ s = r.stepNow(s.ID)
+ r.must(r.s.ForgetTaste(r.ctx, paul, r.tasteRows(paul)[0].ID))
+ r.report(l, s, wire.StepReport{State: wire.StepRunning, Attempt: s.Attempt + 1})
+ got := r.stepNow(s.ID)
+ if got.Attempt != s.Attempt+2 || got.TasteRevision != 2 {
+ t.Fatalf("the advanced attempt was not replaced: %+v", got)
+ }
+ if refused, err := r.s.Authorize(r.ctx, l, s.ID, s.Attempt+1, "", "", ""); err != nil || refused != "withdrawn" {
+ t.Fatalf("the advanced attempt's start: %q %v", refused, err)
+ }
+ if _, d := r.dispatched(s.ID); d.Attempt != got.Attempt || len(d.Taste) != 0 || d.TasteRevision != 2 {
+ t.Fatalf("replacement %+v", d)
+ }
+ // With a current revision an advance goes on as before.
+ r.ackDispatches(s.ID)
+ if refused := r.authorize(l, got, ""); refused != "" {
+ t.Fatalf("start %q", refused)
+ }
+ r.report(l, got, wire.StepReport{State: wire.StepRunning, Attempt: got.Attempt + 1})
+ if after := r.stepNow(s.ID); after.Attempt != got.Attempt+1 {
+ t.Fatalf("a current advance: attempt %d", after.Attempt)
+ }
+}
+
+// TestChoiceNoteBeforeTheRound: More like this writes its choice note
+// before the round's step is dispatched, so the round carries it and
+// starts at once (never replaced for its own note).
+func TestChoiceNoteBeforeTheRound(t *testing.T) {
+ r, l, task, s, c := roundOfThree(t)
+ if err := r.answerCard(c, wire.AnswerCard{Choice: wire.ChoiceLike, Option: &wire.OptionRef{Step: s.ID, Index: 1}}); err != nil {
+ t.Fatal(err)
+ }
+ like := r.makerStep(task)
+ rev, _ := r.book(paul)
+ _, d := r.dispatched(like.ID)
+ if rev != 1 || d.TasteRevision != rev || len(d.Taste) != 1 || d.Taste[0].Source != wire.TasteSourceChoice {
+ t.Fatalf("book at %d, dispatch at %d with %+v", rev, d.TasteRevision, d.Taste)
+ }
+ r.ackDispatches(like.ID)
+ if refused := r.authorize(l, like, ""); refused != "" {
+ t.Fatalf("the round's start: %q", refused)
+ }
+}
+
+// TestOldRunnerWaits: a Design step on a runner at 38 waits with
+// design_runner_old (nothing is sent, so nothing fails at Encode), and
+// goes once the runner speaks 39.
+func TestOldRunnerWaits(t *testing.T) {
+ r, l, _ := grantRig(t)
+ sp := r.active(l, "Patrix", "p_patrix")
+ r.setHello(wire.ProtocolDesign, designHello(wire.ToolHealthy, claudeSub))
+ task := r.designTask(l, sp, wire.KindChange)
+ s := r.makerStep(task)
+ if s.Placement != wire.PlacementDesign || s.Reason != reasonDesignProtocol || s.RunnerID != "" || r.attemptSent(s) {
+ t.Fatalf("on a 38 runner: %+v", s)
+ }
+ r.setHello(wire.ProtocolDesignFeedback, designHello(wire.ToolHealthy, claudeSub))
+ r.must(r.tx(func(tx *txn) error { return tx.placeWaiting(paul) }))
+ got := r.stepNow(s.ID)
+ if got.Placement != "" || got.Reason != "" || got.RunnerID != "RUNNER1" || !r.attemptSent(got) || got.DispatchProtocol != wire.ProtocolDesignFeedback {
+ t.Fatalf("at 39: %+v", got)
+ }
+}
+
+// TestReconnectBelow39Refused: a Design step placed on a runner at 39
+// that reconnects at 38 is refused at its start; the attempt moves on
+// and the step waits with design_runner_old until the runner is at 39.
+func TestReconnectBelow39Refused(t *testing.T) {
+ r, l := designReady(t)
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ if s.RunnerID != "RUNNER1" || s.DispatchProtocol != wire.ProtocolDesignFeedback {
+ t.Fatalf("placed %+v", s)
+ }
+ r.ackDispatches(s.ID)
+ r.setHello(wire.ProtocolDesign, designHello(wire.ToolHealthy, claudeSub))
+ old := l
+ old.Protocol = wire.ProtocolDesign
+ if refused := r.authorize(old, s, ""); refused != "withdrawn" {
+ t.Fatalf("a start at 38: %q", refused)
+ }
+ got := r.stepNow(s.ID)
+ if got.Attempt != s.Attempt+1 || got.StartedAt != nil || got.Placement != wire.PlacementDesign || got.Reason != reasonDesignProtocol || got.RunnerID != "" || r.attemptSent(got) {
+ t.Fatalf("after a 38 start: %+v", got)
+ }
+ if refused := r.authorize(l, s, ""); refused != "withdrawn" {
+ t.Fatalf("the old attempt at 39: %q", refused)
+ }
+ r.setHello(wire.ProtocolDesignFeedback, designHello(wire.ToolHealthy, claudeSub))
+ r.must(r.tx(func(tx *txn) error { return tx.placeWaiting(paul) }))
+ got = r.stepNow(s.ID)
+ if got.RunnerID != "RUNNER1" || !r.attemptSent(got) {
+ t.Fatalf("at 39 again: %+v", got)
+ }
+ if refused := r.authorize(l, got, ""); refused != "" {
+ t.Fatalf("start at 39: %q", refused)
+ }
+}
+
+// TestRemovedCreatorStale: once the creator is no longer an active
+// member their notebook reads as revision 0, so an attempt dispatched
+// with their notes is stale at its start (and its replacement carries
+// none); back as a member, the revision it carried holds again.
+func TestRemovedCreatorStale(t *testing.T) {
+ r, l := designReady(t)
+ r.must(r.s.AddTaste(r.ctx, paul, "p_patrix", "One."))
+ task := r.designTask(l, r.makerSpecialist(), wire.KindChange)
+ s := r.makerStep(task)
+ stale := func() bool {
+ t.Helper()
+ var out bool
+ r.must(r.tx(func(tx *txn) error {
+ var err error
+ out, err = tx.designStale(l, r.load(task), s)
+ return err
+ }))
+ return out
+ }
+ if s.TasteRevision != 1 || stale() {
+ t.Fatalf("dispatched at %d, stale %v", s.TasteRevision, stale())
+ }
+ r.exec("UPDATE members SET active = 0 WHERE address = ?", paul)
+ if !stale() {
+ t.Fatal("an attempt with a removed creator's notes is not stale")
+ }
+ r.exec("UPDATE members SET active = 1 WHERE address = ?", paul)
+ if stale() {
+ t.Fatal("stale with the creator back")
+ }
+}
diff --git a/internal/equipo/migrations/0125_design_feedback.sql b/internal/equipo/migrations/0125_design_feedback.sql
index 4a753e71..df95cc76 100644
--- a/internal/equipo/migrations/0125_design_feedback.sql
+++ b/internal/equipo/migrations/0125_design_feedback.sql
@@ -21,3 +21,8 @@ ALTER TABLE chat_steps ADD COLUMN design_ask text NOT NULL DEFAULT "";
CREATE TABLE chat_taste_notes (id text PRIMARY KEY, person text, discipline text, project_id text NOT NULL DEFAULT "", source text, body text, question text NOT NULL DEFAULT "", task_id text NOT NULL DEFAULT "", card_id text NOT NULL DEFAULT "", created_at datetime);
CREATE INDEX chat_taste_note_person ON chat_taste_notes(person, discipline);
CREATE TABLE chat_taste_books (person text, discipline text, revision integer NOT NULL DEFAULT 0, forget_revision integer NOT NULL DEFAULT 0, PRIMARY KEY (person, discipline));
+-- The task creator's design notebook revision each Design step attempt's
+-- dispatch carried its notes at (section 8.6, Feeding): its start is
+-- refused, and the step dispatched again with fresh notes, once the
+-- notebook has moved on. 0 for every step from before this round.
+ALTER TABLE chat_steps ADD COLUMN taste_revision integer NOT NULL DEFAULT 0;
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql
index f5362e00..88aed7f7 100644
--- a/internal/equipo/migrations/schema.sql
+++ b/internal/equipo/migrations/schema.sql
@@ -939,3 +939,8 @@ ALTER TABLE chat_steps ADD COLUMN design_ask text NOT NULL DEFAULT "";
CREATE TABLE chat_taste_notes (id text PRIMARY KEY, person text, discipline text, project_id text NOT NULL DEFAULT "", source text, body text, question text NOT NULL DEFAULT "", task_id text NOT NULL DEFAULT "", card_id text NOT NULL DEFAULT "", created_at datetime);
CREATE INDEX chat_taste_note_person ON chat_taste_notes(person, discipline);
CREATE TABLE chat_taste_books (person text, discipline text, revision integer NOT NULL DEFAULT 0, forget_revision integer NOT NULL DEFAULT 0, PRIMARY KEY (person, discipline));
+-- The task creator's design notebook revision each Design step attempt's
+-- dispatch carried its notes at (section 8.6, Feeding): its start is
+-- refused, and the step dispatched again with fresh notes, once the
+-- notebook has moved on. 0 for every step from before this round.
+ALTER TABLE chat_steps ADD COLUMN taste_revision integer NOT NULL DEFAULT 0;
diff --git a/internal/runner/thin/ask.go b/internal/runner/thin/ask.go
index 2038d753..72e8e577 100644
--- a/internal/runner/thin/ask.go
+++ b/internal/runner/thin/ask.go
@@ -57,22 +57,27 @@ type keptSession struct {
}
// sessionFence is what a kept session must match for a fix round to
-// resume it: PackDigest, the prompt pack it ran with ("" for none,
+// resume it, each field with its kept_sessions column, written once with
+// the session: PackDigest, the prompt pack it ran with ("" for none,
// Engineering's), since a resumed session keeps its first prompt's pack
-// and a pack edit keeps the profile id (spec 8.8). Fields compared the
-// same way go beside it (the notebook's forget revision, spec 8.6), each
-// with its kept_sessions column, written once with the session.
+// and a pack edit keeps the profile id (spec 8.8); and ForgetRevision,
+// the task creator's design notebook forget revision its dispatch
+// carried (0 for none, Engineering's), since a resumed session keeps
+// every note it was given: one that predates a forget starts afresh
+// (spec 8.6, Feeding). A session kept before the column reads 0, so it
+// never resumes Design after a forget.
type sessionFence struct {
- PackDigest string
+ PackDigest string
+ ForgetRevision int64
}
// keptColumns are a kept_sessions row as scanKept reads it.
-const keptColumns = "step_id, attempt, task_id, person, specialist, account, session_id, dir, candidate_sha, bytes, model, family, pack_digest"
+const keptColumns = "step_id, attempt, task_id, person, specialist, account, session_id, dir, candidate_sha, bytes, model, family, pack_digest, forget_revision"
// scanKept reads one row of keptColumns.
func scanKept(row *sql.Row) (keptSession, bool, error) {
var k keptSession
- err := row.Scan(&k.StepID, &k.Attempt, &k.TaskID, &k.Person, &k.Specialist, &k.Account, &k.SessionID, &k.Dir, &k.Candidate, &k.Bytes, &k.Model, &k.Family, &k.Fence.PackDigest)
+ err := row.Scan(&k.StepID, &k.Attempt, &k.TaskID, &k.Person, &k.Specialist, &k.Account, &k.SessionID, &k.Dir, &k.Candidate, &k.Bytes, &k.Model, &k.Family, &k.Fence.PackDigest, &k.Fence.ForgetRevision)
if errors.Is(err, sql.ErrNoRows) {
return k, false, nil
}
@@ -89,7 +94,7 @@ func (s *State) keepSession(ctx context.Context, r stepRow, specialist, account,
func (s *State) keepFenced(ctx context.Context, r stepRow, fence sessionFence, specialist, account, model, family, session, dir, candidate string, bytes int64) error {
// The model, family and fence are written once, with the session: a
// later keep of the same attempt never rebinds them.
- _, err := s.db.ExecContext(ctx, "INSERT INTO kept_sessions(step_id, attempt, task_id, person, specialist, account, session_id, dir, candidate_sha, bytes, created_at, used_at, model, family, pack_digest) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(step_id, attempt) DO UPDATE SET session_id=excluded.session_id, dir=excluded.dir, candidate_sha=excluded.candidate_sha, bytes=excluded.bytes, used_at=excluded.used_at", r.StepID, r.Attempt, r.TaskID, r.Person, specialist, account, session, dir, candidate, bytes, now(), now(), model, family, fence.PackDigest)
+ _, err := s.db.ExecContext(ctx, "INSERT INTO kept_sessions(step_id, attempt, task_id, person, specialist, account, session_id, dir, candidate_sha, bytes, created_at, used_at, model, family, pack_digest, forget_revision) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(step_id, attempt) DO UPDATE SET session_id=excluded.session_id, dir=excluded.dir, candidate_sha=excluded.candidate_sha, bytes=excluded.bytes, used_at=excluded.used_at", r.StepID, r.Attempt, r.TaskID, r.Person, specialist, account, session, dir, candidate, bytes, now(), now(), model, family, fence.PackDigest, fence.ForgetRevision)
return err
}
diff --git a/internal/runner/thin/design_step.go b/internal/runner/thin/design_step.go
index 35041a1b..b198762d 100644
--- a/internal/runner/thin/design_step.go
+++ b/internal/runner/thin/design_step.go
@@ -553,10 +553,10 @@ func designPackDigest() string {
}
// sessionFenceFor is the fence r's attempt runs under: a Design step's
-// pack digest; Engineering's none.
+// pack digest and its dispatch's forget revision; Engineering's none.
func sessionFenceFor(r stepRow) sessionFence {
if r.Profile == specialist.ProfileDesign {
- return sessionFence{PackDigest: designPackDigest()}
+ return sessionFence{PackDigest: designPackDigest(), ForgetRevision: r.ForgetRevision}
}
return sessionFence{}
}
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go
index 1745b9ba..718bc096 100644
--- a/internal/runner/thin/engineer.go
+++ b/internal/runner/thin/engineer.go
@@ -1089,8 +1089,10 @@ func (e *Engineer) fixSession(ctx context.Context, r stepRow, base string) (kept
if !found {
return keptSession{}, false
}
- // A session made under another fence (a pack edit since) starts
- // afresh: resuming it would keep its first prompt's pack.
+ // A session made under another fence (a pack edit since, or a
+ // forget since its dispatch: another forget revision) starts afresh:
+ // resuming it would keep its first prompt's pack, or a forgotten
+ // note.
if k.Fence != sessionFenceFor(r) {
return keptSession{}, false
}
diff --git a/internal/runner/thin/forget_session_linux_test.go b/internal/runner/thin/forget_session_linux_test.go
new file mode 100644
index 00000000..9ee9b1a5
--- /dev/null
+++ b/internal/runner/thin/forget_session_linux_test.go
@@ -0,0 +1,119 @@
+package thin
+
+import (
+ "encoding/json"
+ "os"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/specialist"
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Design feedback 1, Task 9 (spec 2026-11-28-dynamic-specialists.md,
+// sections 2 and 8.6, Feeding): a kept Design session is stored with the
+// notebook's forget revision its dispatch carried, and a fix round
+// resumes it only when its own dispatch carries the same one: a session
+// that predates a forget starts afresh, so nothing forgotten stays in a
+// resumed transcript.
+
+// keptRound runs a first Design round at forget revision forget and
+// returns its report and the next round's row (a fix round from its
+// commit, at forget revision next, asking More like this).
+func keptRound(t *testing.T, forget, next int64) (*designRig, wire.StepReport, stepRow) {
+ t.Helper()
+ r := newDesignRig(t)
+ r.e.Note = designNote
+ d := designDispatch("ds1", 1)
+ d.ForgetRevision = forget
+ first := stepRow{DispatchCommand: d}
+ rep := r.exec(first)
+ if rep.State != wire.StepDone || !rep.Pushed {
+ t.Fatalf("round 0: %+v", rep)
+ }
+ r.finish(first, rep)
+ f := designDispatch("ds2", 1)
+ f.Round, f.BaseSHA, f.Feedback, f.ForgetRevision = 1, rep.CandidateSHA, "Fix round 1 of 2. Review asked for more.", next
+ f.DesignAsk = &wire.DesignAsk{
+ Kind: wire.DesignAskLike,
+ Option: &wire.StepDesignOption{Name: "Quiet editorial", Direction: "say:direction-carried", Page: "quiet-editorial"},
+ Current: []wire.StepDesignOption{{Name: "Quiet editorial", Direction: "say:direction-carried", Page: "quiet-editorial"}},
+ Note: "say:note-carried",
+ }
+ r.e.Note = " create:mockups/tk1/more/index.html|<h1>More</h1>\n"
+ return r, rep, stepRow{DispatchCommand: f, Base: rep.CandidateSHA}
+}
+
+// TestForgetFreshSession: a session kept at forget revision 1 is stored
+// with it; a fix round dispatched at 1 may resume it, one at 2 may not,
+// and an old kept session (no stored forget revision, read as 0) does
+// not resume Design after a forget.
+func TestForgetFreshSession(t *testing.T) {
+ p, _ := specialist.Lookup(specialist.ProfileDesign)
+ r, rep, row := keptRound(t, 1, 1)
+ k, found, err := r.e.O.State.keptCommit(r.ctx, "tk1", connPerson, wire.SpecialistEngineering, rep.CandidateSHA)
+ if err != nil || !found || k.Fence != (sessionFence{PackDigest: p.Pack, ForgetRevision: 1}) {
+ t.Fatalf("kept %+v %v %v", k, found, err)
+ }
+ if _, ok := r.e.fixSession(r.ctx, row, row.Base); !ok {
+ t.Fatal("the same forget revision's session is not resumable")
+ }
+ row.ForgetRevision = 2
+ if _, ok := r.e.fixSession(r.ctx, row, row.Base); ok {
+ t.Fatal("a session from before a forget is resumable")
+ }
+ fix := r.exec(row)
+ if fix.State != wire.StepDone || strings.Contains(fix.Summary, "(resumed session)") {
+ t.Fatalf("round 1 resumed a session from before a forget: %+v", fix)
+ }
+ // An old kept session, kept before the column: it reads the
+ // column's default, 0, which a dispatch after any forget never
+ // carries.
+ var dflt string
+ if err := r.e.O.State.db.QueryRowContext(r.ctx, "SELECT dflt_value FROM pragma_table_info('kept_sessions') WHERE name='forget_revision'").Scan(&dflt); err != nil || dflt != "0" {
+ t.Fatalf("forget_revision default %q %v", dflt, err)
+ }
+ r2, _, old := keptRound(t, 0, 0)
+ if _, ok := r2.e.fixSession(r2.ctx, old, old.Base); !ok {
+ t.Fatal("a session at 0 before any forget is not resumable")
+ }
+ old.ForgetRevision = 1
+ if _, ok := r2.e.fixSession(r2.ctx, old, old.Base); ok {
+ t.Fatal("an old session is resumable after a forget")
+ }
+}
+
+// TestFixRoundForgetStartsFresh (the forget variant of the instance's
+// TestFixRoundInheritsAsk): after a More like this round, a forget makes
+// its fix round start a fresh session, and that launch's prompt still
+// names the option, its direction and the person's note.
+func TestFixRoundForgetStartsFresh(t *testing.T) {
+ r, _, row := keptRound(t, 0, 1)
+ fix := r.exec(row)
+ if fix.State != wire.StepDone || strings.Contains(fix.Summary, "(resumed session)") {
+ t.Fatalf("round 1 resumed: %+v", fix)
+ }
+ for _, want := range []string{"direction-carried", "note-carried"} {
+ if !strings.Contains(fix.Summary, want) {
+ t.Errorf("the fresh launch's prompt lacked %q: %q", want, fix.Summary)
+ }
+ }
+ // The prompt the fresh launch was given, from its transcript.
+ k, found, err := r.e.O.State.keptSessionFor(r.ctx, "ds2")
+ if err != nil || !found || k.Fence.ForgetRevision != 1 {
+ t.Fatalf("kept %+v %v %v", k, found, err)
+ }
+ raw, err := os.ReadFile(keptTranscript(k.Dir, k.SessionID))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var first struct{ Type, Text string }
+ if err := json.Unmarshal([]byte(strings.SplitN(string(raw), "\n", 2)[0]), &first); err != nil || first.Type != "user" {
+ t.Fatalf("transcript %q: %v", raw, err)
+ }
+ for _, want := range []string{"[Equipo: design]", "Its name: " + wire.QuotedData("Quiet editorial"), wire.QuotedData("say:direction-carried"), wire.QuotedData("say:note-carried")} {
+ if !strings.Contains(first.Text, want) {
+ t.Errorf("the fresh launch's prompt lacks %q:\n%s", want, first.Text)
+ }
+ }
+}
diff --git a/internal/runner/thin/state.go b/internal/runner/thin/state.go
index 33b08f81..245831ca 100644
--- a/internal/runner/thin/state.go
+++ b/internal/runner/thin/state.go
@@ -131,11 +131,15 @@ func OpenState(ctx context.Context, dir string) (*State, error) {
return nil, err
}
// Added with Design feedback (spec 8.8): the pack a kept session ran
- // with, part of its sessionFence. Its later fields (the notebook's
- // forget revision) get their columns here beside it.
- if _, err = d.ExecContext(ctx, "ALTER TABLE kept_sessions ADD COLUMN pack_digest TEXT NOT NULL DEFAULT ''"); err != nil && !strings.Contains(err.Error(), "duplicate column") {
- d.Close()
- return nil, err
+ // with, part of its sessionFence; and (spec 8.6) the design
+ // notebook's forget revision its dispatch carried, the fence's other
+ // field. A session kept before reads 0: it never resumes Design
+ // after a forget.
+ for _, col := range []string{"pack_digest TEXT NOT NULL DEFAULT ''", "forget_revision INTEGER NOT NULL DEFAULT 0"} {
+ if _, err = d.ExecContext(ctx, "ALTER TABLE kept_sessions ADD COLUMN "+col); err != nil && !strings.Contains(err.Error(), "duplicate column") {
+ d.Close()
+ return nil, err
+ }
}
// Added in Connections slice 1 review round 2: the home a sign-out
// still has to delete, and its provider, kept until it is gone.