From 2bccf57ca721aedba2d1b2319b6017c3e38dba24 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:11:25 -0500 Subject: [PATCH 1/6] teams: the global manager is not woken by a top-level manager's turn ending Its members are the managers of whole teams, each a conversation the person talks to, and every answer one of them gave ended a turn that woke the global manager. Measured in the desktop app: 22 wakes in one afternoon, 803,496 input tokens, all answered "[no change]"; one such wake had it send the person's own request back to a manager as a directive. It is still woken by a manager's post, question or failure, and it is told never to re-issue the person's request. Co-Authored-By: Claude Fable 5.2 --- internal/manual/chat/team-manager.md | 7 +++ internal/session/team.go | 15 +++++-- internal/session/team_nest_test.go | 66 ++++++++++++++++++++++++++++ internal/session/team_wakewatch.go | 29 +++++++++--- internal/session/teamevent.go | 2 +- 5 files changed, 109 insertions(+), 10 deletions(-) diff --git a/internal/manual/chat/team-manager.md b/internal/manual/chat/team-manager.md index e3c5b70058..eb866f4282 100644 --- a/internal/manual/chat/team-manager.md +++ b/internal/manual/chat/team-manager.md @@ -532,6 +532,13 @@ report to it, so their questions and conflicts between teams come to it before t you. It can start a new top-level team with `team_start` of kind `team`. Without a global manager, nothing here changes: each top-level manager reports to you. +A top-level manager's turn ending does not start the global manager's turn. You talk to +those managers directly and each answer ends a turn, so the endings stay in `All teams`' +traffic, where `team_status` reads them. The global manager is woken by what a manager posts +to it with `team_post`, by a manager's question or a permission it is held on, and by a +manager's turn failing. It is told never to send a manager your own request to that manager +back as a directive. + ## Conflicts between members and teams When two or more conversations need incompatible things (the form posts JSON, the endpoint diff --git a/internal/session/team.go b/internal/session/team.go index 96628cf284..2421b6f511 100644 --- a/internal/session/team.go +++ b/internal/session/team.go @@ -1712,7 +1712,9 @@ func teamManagerScope(role teamRole, file *teams.File) string { var parts []string if role.root { parts = append(parts, fmt.Sprintf("You are the global manager: %q holds every team, and your members are the managers of the top-level teams, never their members. "+ - "Direct those managers and they pass it on. Their questions and conflicts between teams come to you before the person. team_start with kind team starts a new top-level team.", role.name)) + "Direct those managers and they pass it on. Their questions and conflicts between teams come to you before the person. team_start with kind team starts a new top-level team. "+ + "A manager's turn ending does not start yours; team_status says where each of them stands. "+ + "The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.", role.name)) } else if home, ok := file.Home(role.key); ok && home.Team != role.id { boss := "its manager" if t, ok := file.Team(home.Team); ok { @@ -1751,7 +1753,13 @@ func teamManagerDelivery(role teamRole) string { if !role.wakes { return "This team's auto-wake is off: what you send, and your members' replies, wait for each conversation's next turn, so an idle member does not start on a directive until it next runs." } - return "A directive (team_send kind directive) starts an idle member's turn; a note waits for its next turn. team_send's answer says whether each member started: one the person paused does not start until they resume it, and work is under way only where the answer says so. Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle, so do not wait or poll for them." + // The global manager's turn is not started by a member's turn ending + // ([teamEventWakesManagerOf]). + back := "Members' replies to you, and their finishing, failing or asking," + if role.root { + back = "Members' replies to you, and their failing or asking," + } + return "A directive (team_send kind directive) starts an idle member's turn; a note waits for its next turn. team_send's answer says whether each member started: one the person paused does not start until they resume it, and work is under way only where the answer says so. " + back + " come back to you and start your turn when you are idle, so do not wait or poll for them." } // teamRoster names the manager's members by handle, with the start of each @@ -1806,7 +1814,8 @@ func teamMemberRole(role teamRole) string { } if role.root { return fmt.Sprintf("You are %s in %q because you manage a top-level team: you report to its manager, the global manager. Its directives reach you marked \"◆ from manager\", "+ - "your questions go to it before the person, and you report to it with team_post to the manager.", you, role.name) + "your questions go to it before the person, and you report to it with team_post to the manager. "+ + "Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.", you, role.name) } if role.boss != "" && role.boss != role.id && !role.shared { said := fmt.Sprintf("You are %s in the team %q, which has no manager of its own, so you answer to the manager of %q: team_post to the manager reaches it, and to the room or a teammate stays in %q.", diff --git a/internal/session/team_nest_test.go b/internal/session/team_nest_test.go index 3d76796870..cffd0dc14e 100644 --- a/internal/session/team_nest_test.go +++ b/internal/session/team_nest_test.go @@ -520,3 +520,69 @@ func TestAnUnmanagedSubTeamsMemberAnswersToTheManagerAbove(t *testing.T) { t.Fatalf("the question's packet: %+v", p) } } + +// THE GLOBAL MANAGER IS NOT WOKEN BY A TOP-LEVEL MANAGER'S TURN ENDING. The +// person talks to that manager directly and each answer ends a turn; what the +// global manager should act on is posted to it, and that still wakes it. +func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { + fastTeamWake(t) + n := newTeamTree(t, "gm", "boss", "web") + n.team(t, "harbor", "", "boss", n.member(t, "boss", "boss"), n.member(t, "web", "web")) + root := "" + if err := teams.Update(n.fixture.profile, func(f *teams.File) error { + root = f.MakeRoot(f.Teams[0].Made) + if err := f.AddMember(root, n.member(t, "gm", "all")); err != nil { + return err + } + return f.SetManager(root, n.key(t, "gm")) + }); err != nil { + t.Fatal(err) + } + gmCalls := oneAnswer(4) + teamAgent(t, n.fixture, n.paths["gm"], gmCalls, nil) + boss := teamAgent(t, n.fixture, n.paths["boss"], oneAnswer(4), nil) + + submitAndWait(t, boss, "plan the release") + boss.settleTeamEvents() + quietFor() + all := teamFixture{profile: n.fixture.profile, teamID: root} + if ended := trafficEvents(t, all, "finished"); len(ended) != 1 { + t.Fatalf("the top-level manager's ending was logged %d times in the team that holds every team, want once", len(ended)) + } + if got := gmCalls.requests(); got != 0 { + t.Fatalf("the global manager was woken %d times by a top-level manager's turn ending", got) + } + + if said, failed := callTool(t, boss.teamPostTool, `{"to":"manager","text":"harbor shipped"}`); failed { + t.Fatalf("the report to the global manager was refused: %q", said) + } + waitRequests(t, gmCalls, 1) + asked := userTextIn(gmCalls.request(0)) + for _, want := range []string{"from @boss: harbor shipped", "A manager's turn ending does not start yours", "and their failing or asking, come back to you"} { + if !strings.Contains(asked, want) { + t.Fatalf("the global manager's turn lacks %q:\n%s", want, asked) + } + } + if strings.Contains(asked, "their finishing") { + t.Fatalf("the global manager is still told a member's finishing starts its turn:\n%s", asked) + } +} + +func TestTeamEventWakesTheGlobalManager(t *testing.T) { + for _, c := range []struct { + state, text string + root, want bool + }{ + {teams.StateFinished, "finished", false, true}, + {teams.StateFinished, "finished", true, false}, + {teams.StateIdle, teams.StoppedByPerson, false, true}, + {teams.StateIdle, teams.StoppedByPerson, true, false}, + {teams.StateFailed, "failed: no key", true, true}, + {teams.StateAsking, "asks: which branch?", true, true}, + {teams.StateRunning, "no longer waiting", true, false}, + } { + if got := teamEventWakesManagerOf(c.root, c.state, c.text); got != c.want { + t.Errorf("root %v, %s %q wakes the manager: %v, want %v", c.root, c.state, c.text, got, c.want) + } + } +} diff --git a/internal/session/team_wakewatch.go b/internal/session/team_wakewatch.go index cc8878270d..0e548ef78a 100644 --- a/internal/session/team_wakewatch.go +++ b/internal/session/team_wakewatch.go @@ -441,6 +441,28 @@ func teamEventWakesManager(state, text string) bool { return false } +// teamEventWakesManagerOf is [teamEventWakesManager] for the manager of one +// team, root when that team is the one that holds every team. +// +// The global manager is not woken by a top-level manager's turn ending, +// finished or stopped. Its members are the managers of whole teams, each a +// conversation the person talks to, and every answer one of them gave the +// person ended a turn. Measured 2026-11-24 in the desktop app: one afternoon +// of the person talking to two crew managers woke the global manager 22 times, +// 803,496 input tokens, and it answered "[no change]" to all 22; the day +// before, one such wake had it read a manager's conversation and send the +// person's own request back to that manager as a directive. What a top-level +// manager wants the global manager to act on it posts (a note wakes), and what +// needs somebody still wakes: a failure, and a question or a permission it is +// held on. The ending itself stays in the team's traffic, where team_status +// reads it. +func teamEventWakesManagerOf(root bool, state, text string) bool { + if root { + return state == teams.StateFailed || state == teams.StateAsking + } + return teamEventWakesManager(state, text) +} + // teamWakes reports whether an entry starts this conversation's turn when it // is idle: a directive from the manager to its handle or to everyone, for a // member; a member's post to the manager, or a member's finished, failed or @@ -467,12 +489,7 @@ func teamWakes(role teamRole, entry teams.Entry) bool { case teams.KindNote: return entry.To == teams.ToManager && strings.TrimSpace(entry.Text) != "" case teams.KindEvent: - // The global manager is not woken by a stop the person made in a - // conversation they were talking to directly. - if role.root && entry.State == teams.StateIdle { - return false - } - return teamEventWakesManager(entry.State, entry.Text) + return teamEventWakesManagerOf(role.root, entry.State, entry.Text) } return false } diff --git a/internal/session/teamevent.go b/internal/session/teamevent.go index 4fd13b6bf3..697c2b9d8c 100644 --- a/internal/session/teamevent.go +++ b/internal/session/teamevent.go @@ -184,7 +184,7 @@ func (a *Agent) writeTeamEvent(event teamEvent) { if err != nil || !role.wakes { continue } - if teamEventWakesManager(event.state, text) && !(role.root && event.state == teams.StateIdle) { + if teamEventWakesManagerOf(role.root, event.state, text) { // These wake the manager, so a manager nobody has open is opened // (team_wakewatch.go). a.rouseManager(profile, role, event.origin.provenance(role.key)) From 9ff0c232bbf954d429cff33c1ddc005ce832a733 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:12:06 -0500 Subject: [PATCH 2/6] docs: change entry for the quiet global manager (#2906) Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2906-global-manager-quiet.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docs/changes/unreleased/2906-global-manager-quiet.md diff --git a/docs/changes/unreleased/2906-global-manager-quiet.md b/docs/changes/unreleased/2906-global-manager-quiet.md new file mode 100644 index 0000000000..5de538a807 --- /dev/null +++ b/docs/changes/unreleased/2906-global-manager-quiet.md @@ -0,0 +1,16 @@ +--- +kind: changed +title: The global manager is not woken each time a top-level team's manager ends a turn +pr: 2906 +surface: [engine, chat] +invalidates: + - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team a member's finished event no longer starts the global manager's turn either (teamEventWakesManagerOf): it is woken by a top-level manager's team_post to it, by that manager's failed or asking event, and by nothing else that manager's turn does. A manager nobody has open is likewise no longer opened by a finished event there. Every other team is unchanged." + - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\", and its scope adds \"A manager's turn ending does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\"" + - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.\"" +--- + +The global manager's members are the managers of whole teams, each a conversation +the person talks to, and every answer one of them gave ended a turn. Measured in +the desktop app, one afternoon of that woke the global manager 22 times for +803,496 input tokens, each answered "[no change]", and one earlier wake had it +send the person's own request back to a manager as a directive. From 4ea2a1238efa3b3ce445a9aeca50fade5e10085e Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:12:26 -0500 Subject: [PATCH 3/6] docs: end each changed statement in the quiet global manager entry with a full stop Co-Authored-By: Claude Fable 5.2 --- docs/changes/unreleased/2906-global-manager-quiet.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changes/unreleased/2906-global-manager-quiet.md b/docs/changes/unreleased/2906-global-manager-quiet.md index 5de538a807..fd50fd4b44 100644 --- a/docs/changes/unreleased/2906-global-manager-quiet.md +++ b/docs/changes/unreleased/2906-global-manager-quiet.md @@ -5,8 +5,8 @@ pr: 2906 surface: [engine, chat] invalidates: - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team a member's finished event no longer starts the global manager's turn either (teamEventWakesManagerOf): it is woken by a top-level manager's team_post to it, by that manager's failed or asking event, and by nothing else that manager's turn does. A manager nobody has open is likewise no longer opened by a finished event there. Every other team is unchanged." - - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\", and its scope adds \"A manager's turn ending does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\"" - - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.\"" + - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\", and its scope adds \"A manager's turn ending does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the note every turn of the global manager carries." + - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.\" The rest of that note is as it was." --- The global manager's members are the managers of whole teams, each a conversation From cedee0295bd879c0bf42ccea594a118e182f5f78 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:03:15 -0500 Subject: [PATCH 4/6] teams: review round 1 repairs for the quiet global manager The rule now covers only members that manage a top-level team, not everyone seated in the team that holds every team. team_send's answer no longer tells the global manager that endings wake it. The test that guarded the rule passed with the rule removed; it now waits past the settle, and a second test covers a global manager nobody has open. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2906-global-manager-quiet.md | 3 +- internal/manual/chat/team-manager.md | 10 ++- internal/session/team.go | 7 ++ internal/session/team_nest_test.go | 74 +++++++++++++++++-- internal/session/team_sendoutcome.go | 12 ++- internal/session/team_wakewatch.go | 34 +++++++-- internal/session/teamevent.go | 2 +- 7 files changed, 125 insertions(+), 17 deletions(-) diff --git a/docs/changes/unreleased/2906-global-manager-quiet.md b/docs/changes/unreleased/2906-global-manager-quiet.md index fd50fd4b44..4f06f87523 100644 --- a/docs/changes/unreleased/2906-global-manager-quiet.md +++ b/docs/changes/unreleased/2906-global-manager-quiet.md @@ -4,7 +4,8 @@ title: The global manager is not woken each time a top-level team's manager ends pr: 2906 surface: [engine, chat] invalidates: - - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team a member's finished event no longer starts the global manager's turn either (teamEventWakesManagerOf): it is woken by a top-level manager's team_post to it, by that manager's failed or asking event, and by nothing else that manager's turn does. A manager nobody has open is likewise no longer opened by a finished event there. Every other team is unchanged." + - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team the finished event of a member that manages a top-level team (teams.File.TopManagers, teamRole.quietEnding) no longer starts the global manager's turn either (teamEventWakesManagerOf): of that manager's events only failed and asking do, and its team_post, a decision packet it raises and a conflict it declares wake the global manager as before. A global manager nobody has open is likewise no longer opened by such a finished event. A member of that team that manages nothing, and every other team, are unchanged, so a stopped-by-the-person event from such a member wakes the global manager where the earlier rule kept every idle event in that team from doing so." + - "team_send answered every manager \"Replies and endings wake you when they arrive, so there is no need to wait or poll.\" In the team that holds every team it now answers \"Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A manager's turn ending on its own does not wake you: team_status says where it stands.\" The answer in every other team is as it was." - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\", and its scope adds \"A manager's turn ending does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the note every turn of the global manager carries." - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.\" The rest of that note is as it was." --- diff --git a/internal/manual/chat/team-manager.md b/internal/manual/chat/team-manager.md index eb866f4282..f95477b035 100644 --- a/internal/manual/chat/team-manager.md +++ b/internal/manual/chat/team-manager.md @@ -349,7 +349,8 @@ holds that conversation's transcript and the wait is under 30 minutes. When you stop a member's turn that had been handed the manager's work, its manager is woken and told the work is not done, that you chose to stop it, and not to hand it out again unless you ask. Stopping a turn that carried only what you typed to the member tells the manager -nothing, and neither does codeaf quitting or a paused member's stray wake being ended. +nothing, and neither does codeaf quitting or a paused member's stray wake being ended. The global +manager is not woken by a top-level team's manager being stopped (see **The global manager**). ## A stopped member's command is still running — why it did not start again when the command ended @@ -537,7 +538,8 @@ those managers directly and each answer ends a turn, so the endings stay in `All traffic, where `team_status` reads them. The global manager is woken by what a manager posts to it with `team_post`, by a manager's question or a permission it is held on, and by a manager's turn failing. It is told never to send a manager your own request to that manager -back as a directive. +back as a directive. A member of `All teams` that manages no team is an ordinary member +there: its turn ending wakes the global manager as in any team. ## Conflicts between members and teams @@ -597,7 +599,9 @@ working, that is straight away. When it is idle, it depends on the kind of messa without a reply, failing, starting to wait on you, or having a turn that carried the manager's work stopped by you, start an idle manager's turn. A reply and the end of the same turn are one wake, even if the ending arrives after the manager - already ran. Replies arriving within a few seconds are gathered into one turn. + already ran. Replies arriving within a few seconds are gathered into one turn. The global + manager is the exception: a top-level team's manager finishing or being stopped does not + start its turn (see **The global manager**). A member no window has open is opened by codeaf in the background so it can run, and a window that opens it later joins the running conversation. A manager that moved to another window, and diff --git a/internal/session/team.go b/internal/session/team.go index 2421b6f511..4138ba44b9 100644 --- a/internal/session/team.go +++ b/internal/session/team.go @@ -124,6 +124,12 @@ type teamRole struct { // manager is the global manager, and its other members are the top-level // teams' managers. root bool + // tops is, for the root, the keys of the members that manage a top-level + // team now ([teams.File.TopManagers]). The root can hold others, a manager + // that stopped being one or a conversation the person put there, and the + // rule that keeps a manager's turn ending from waking the global manager is + // about these members alone ([teamRole.quietEnding]). + tops map[string]bool // dissolvable says this conversation manages the team and the team has // never held anyone but it ([teams.File.Dissolvable]), which is when its // manager is given team_dissolve (team_dissolve.go). @@ -454,6 +460,7 @@ func rolesFor(file *teams.File, keys []string, d teams.Defaults) []teamRole { boss: boss, bossName: bossName, root: team.Root, + tops: topManagerKeys(file, team), key: member.Key, wakes: effective.Wake, questionsUp: effective.QuestionsUp, diff --git a/internal/session/team_nest_test.go b/internal/session/team_nest_test.go index cffd0dc14e..756161e6a9 100644 --- a/internal/session/team_nest_test.go +++ b/internal/session/team_nest_test.go @@ -13,6 +13,7 @@ import ( "path/filepath" "strings" "testing" + "time" "github.com/Agent-Field/codeaf/internal/teams" ) @@ -539,12 +540,14 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { t.Fatal(err) } gmCalls := oneAnswer(4) - teamAgent(t, n.fixture, n.paths["gm"], gmCalls, nil) + gm := teamAgent(t, n.fixture, n.paths["gm"], gmCalls, nil) boss := teamAgent(t, n.fixture, n.paths["boss"], oneAnswer(4), nil) submitAndWait(t, boss, "plan the release") boss.settleTeamEvents() - quietFor() + // Past the settle a wake waits out, with room: a wake the ending had armed + // would have fired by now. + time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) all := teamFixture{profile: n.fixture.profile, teamID: root} if ended := trafficEvents(t, all, "finished"); len(ended) != 1 { t.Fatalf("the top-level manager's ending was logged %d times in the team that holds every team, want once", len(ended)) @@ -552,6 +555,9 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { if got := gmCalls.requests(); got != 0 { t.Fatalf("the global manager was woken %d times by a top-level manager's turn ending", got) } + if woke := trafficEvents(t, all, teamWokePrefix); len(woke) != 0 { + t.Fatalf("the traffic says the global manager was woken by the ending: %+v", woke) + } if said, failed := callTool(t, boss.teamPostTool, `{"to":"manager","text":"harbor shipped"}`); failed { t.Fatalf("the report to the global manager was refused: %q", said) @@ -566,12 +572,70 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { if strings.Contains(asked, "their finishing") { t.Fatalf("the global manager is still told a member's finishing starts its turn:\n%s", asked) } + if strings.Contains(asked, "finished its turn") || strings.Contains(asked, "What your members in") { + t.Fatalf("the ending rode into the global manager's turn as something that woke it:\n%s", asked) + } + // Its own send's answer does not promise that an ending wakes it. + if said := sendDirective(t, gm, "boss"); strings.Contains(said, "endings wake you") || !strings.Contains(said, "A manager's turn ending on its own does not wake you") { + t.Fatalf("the global manager's send says endings wake it: %s", said) + } +} + +// A GLOBAL MANAGER NOBODY HAS OPEN IS NOT OPENED BY THE ENDING EITHER, and is +// still opened by a top-level manager's failure. A member of the team that +// holds every team that manages nothing is an ordinary member there: its +// ending opens the manager as it does in any team. +func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing.T) { + fastTeamWake(t) + n := newTeamTree(t, "gm", "boss", "web", "guest") + n.team(t, "harbor", "", "boss", n.member(t, "boss", "boss"), n.member(t, "web", "web")) + root := "" + if err := teams.Update(n.fixture.profile, func(f *teams.File) error { + root = f.MakeRoot(f.Teams[0].Made) + for _, m := range []teams.Member{n.member(t, "gm", "all"), n.member(t, "guest", "guest")} { + if err := f.AddMember(root, m); err != nil { + return err + } + } + return f.SetManager(root, n.key(t, "gm")) + }); err != nil { + t.Fatal(err) + } + recorder := &recordedResume{} + withTeamResume(t, recorder.open) + opened := func() int { + count := 0 + for _, seen := range recorder.seen() { + if strings.HasPrefix(seen, n.paths["gm"]+"|") { + count++ + } + } + return count + } + boss := teamAgent(t, n.fixture, n.paths["boss"], oneAnswer(2), nil) + submitAndWait(t, boss, "plan the release") + boss.settleTeamEvents() + time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) + if got := opened(); got != 0 { + t.Fatalf("a closed global manager was opened %d times by a top-level manager's turn ending", got) + } + + guest := teamAgent(t, n.fixture, n.paths["guest"], oneAnswer(2), nil) + submitAndWait(t, guest, "tidy the notes") + guest.settleTeamEvents() + deadline := time.Now().Add(5 * time.Second) + for opened() == 0 && time.Now().Before(deadline) { + time.Sleep(10 * time.Millisecond) + } + if got := opened(); got == 0 { + t.Fatal("a member of the team that holds every team that manages nothing ended its turn and its manager was not opened") + } } func TestTeamEventWakesTheGlobalManager(t *testing.T) { for _, c := range []struct { state, text string - root, want bool + top, want bool }{ {teams.StateFinished, "finished", false, true}, {teams.StateFinished, "finished", true, false}, @@ -581,8 +645,8 @@ func TestTeamEventWakesTheGlobalManager(t *testing.T) { {teams.StateAsking, "asks: which branch?", true, true}, {teams.StateRunning, "no longer waiting", true, false}, } { - if got := teamEventWakesManagerOf(c.root, c.state, c.text); got != c.want { - t.Errorf("root %v, %s %q wakes the manager: %v, want %v", c.root, c.state, c.text, got, c.want) + if got := teamEventWakesManagerOf(c.top, c.state, c.text); got != c.want { + t.Errorf("top-level manager %v, %s %q wakes the manager: %v, want %v", c.top, c.state, c.text, got, c.want) } } } diff --git a/internal/session/team_sendoutcome.go b/internal/session/team_sendoutcome.go index d901ca5dbc..8b643b7ae4 100644 --- a/internal/session/team_sendoutcome.go +++ b/internal/session/team_sendoutcome.go @@ -137,7 +137,7 @@ func (a *Agent) teamSendOutcome(ctx context.Context, profile string, team teams. said = append(said, strings.Join(asking, ", ")+" "+isAre(len(asking))+" waiting on the person and "+readsRead(len(asking))+" it once they answer.") } if len(started)+len(busy)+len(asking) > 0 { - said = append(said, "Replies and endings wake you when they arrive, so there is no need to wait or poll.") + said = append(said, teamSendWakesSentence(team.Root)) } for _, member := range paused { said = append(said, fmt.Sprintf("@%s did NOT start: %s. Tell the person it is paused; only they can resume it.", member.Handle, teamPausedWhy)) @@ -203,3 +203,13 @@ func itThey(n int) string { } return "they" } + +// teamSendWakesSentence is what a send's answer says comes back on its own. +// The global manager is not woken by a top-level manager's turn ending +// ([teamEventWakesManagerOf]), so its answer does not promise that. +func teamSendWakesSentence(root bool) string { + if root { + return "Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A manager's turn ending on its own does not wake you: team_status says where it stands." + } + return "Replies and endings wake you when they arrive, so there is no need to wait or poll." +} diff --git a/internal/session/team_wakewatch.go b/internal/session/team_wakewatch.go index 0e548ef78a..3ad9a38f47 100644 --- a/internal/session/team_wakewatch.go +++ b/internal/session/team_wakewatch.go @@ -441,8 +441,9 @@ func teamEventWakesManager(state, text string) bool { return false } -// teamEventWakesManagerOf is [teamEventWakesManager] for the manager of one -// team, root when that team is the one that holds every team. +// teamEventWakesManagerOf is [teamEventWakesManager] for one member's event, +// top when that member is a top-level team's manager seated in the team that +// holds every team ([teamRole.quietEnding]). // // The global manager is not woken by a top-level manager's turn ending, // finished or stopped. Its members are the managers of whole teams, each a @@ -456,18 +457,39 @@ func teamEventWakesManager(state, text string) bool { // needs somebody still wakes: a failure, and a question or a permission it is // held on. The ending itself stays in the team's traffic, where team_status // reads it. -func teamEventWakesManagerOf(root bool, state, text string) bool { - if root { +func teamEventWakesManagerOf(top bool, state, text string) bool { + if top { return state == teams.StateFailed || state == teams.StateAsking } return teamEventWakesManager(state, text) } +// quietEnding reports whether member is a top-level team's manager seated in +// the root: the one member whose turn ending does not wake the root's manager. +// Anybody else the root holds is an ordinary member there. +func (r teamRole) quietEnding(member string) bool { + return r.root && r.tops[member] +} + +// topManagerKeys is the keys [teamRole.tops] holds, nil for every team but the +// root. +func topManagerKeys(file *teams.File, team teams.Team) map[string]bool { + if file == nil || !team.Root { + return nil + } + tops := map[string]bool{} + for _, m := range file.TopManagers() { + tops[m.Key] = true + } + return tops +} + // teamWakes reports whether an entry starts this conversation's turn when it // is idle: a directive from the manager to its handle or to everyone, for a // member; a member's post to the manager, or a member's finished, failed or // asking event, for the manager. The watch suppresses a finished event when -// the same turn already posted a reply. +// the same turn already posted a reply, and the global manager is not woken by +// a top-level manager's turn ending ([teamEventWakesManagerOf]). func teamWakes(role teamRole, entry teams.Entry) bool { if !role.joinedAt.IsZero() && entry.At.Before(role.joinedAt) { return false @@ -489,7 +511,7 @@ func teamWakes(role teamRole, entry teams.Entry) bool { case teams.KindNote: return entry.To == teams.ToManager && strings.TrimSpace(entry.Text) != "" case teams.KindEvent: - return teamEventWakesManagerOf(role.root, entry.State, entry.Text) + return teamEventWakesManagerOf(role.quietEnding(entry.Member), entry.State, entry.Text) } return false } diff --git a/internal/session/teamevent.go b/internal/session/teamevent.go index 697c2b9d8c..80129ac866 100644 --- a/internal/session/teamevent.go +++ b/internal/session/teamevent.go @@ -184,7 +184,7 @@ func (a *Agent) writeTeamEvent(event teamEvent) { if err != nil || !role.wakes { continue } - if teamEventWakesManagerOf(role.root, event.state, text) { + if teamEventWakesManagerOf(role.quietEnding(role.key), event.state, text) { // These wake the manager, so a manager nobody has open is opened // (team_wakewatch.go). a.rouseManager(profile, role, event.origin.provenance(role.key)) From 0bee31a92d37d802fb45d8d5ac9bb4ec7e5b146d Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:33:28 -0500 Subject: [PATCH 5/6] teams: final review round 2 repairs for the quiet global manager A directive the global manager sends is answered with team_post, and its text, the top-level manager's text and the send answer all say so. A member of the team that holds every team that manages nothing is told what an ordinary member is told, since its ending does wake the global manager. The closed-manager test now covers a failure opening it. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2906-global-manager-quiet.md | 6 +- internal/manual/chat/team-manager.md | 9 ++- internal/session/team.go | 21 +++--- internal/session/team_nest_test.go | 66 +++++++++++++++---- internal/session/team_sendoutcome.go | 6 +- 5 files changed, 80 insertions(+), 28 deletions(-) diff --git a/docs/changes/unreleased/2906-global-manager-quiet.md b/docs/changes/unreleased/2906-global-manager-quiet.md index 4f06f87523..d5fe02a871 100644 --- a/docs/changes/unreleased/2906-global-manager-quiet.md +++ b/docs/changes/unreleased/2906-global-manager-quiet.md @@ -5,9 +5,9 @@ pr: 2906 surface: [engine, chat] invalidates: - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team the finished event of a member that manages a top-level team (teams.File.TopManagers, teamRole.quietEnding) no longer starts the global manager's turn either (teamEventWakesManagerOf): of that manager's events only failed and asking do, and its team_post, a decision packet it raises and a conflict it declares wake the global manager as before. A global manager nobody has open is likewise no longer opened by such a finished event. A member of that team that manages nothing, and every other team, are unchanged, so a stopped-by-the-person event from such a member wakes the global manager where the earlier rule kept every idle event in that team from doing so." - - "team_send answered every manager \"Replies and endings wake you when they arrive, so there is no need to wait or poll.\" In the team that holds every team it now answers \"Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A manager's turn ending on its own does not wake you: team_status says where it stands.\" The answer in every other team is as it was." - - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\", and its scope adds \"A manager's turn ending does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the note every turn of the global manager carries." - - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.\" The rest of that note is as it was." + - "team_send answered every manager \"Replies and endings wake you when they arrive, so there is no need to wait or poll.\" In the team that holds every team it now answers \"Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you, and team_status says where it stands.\" The answer in every other team is as it was." + - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\" and ends \"A top-level team's manager ending its turn does not start yours.\", and its scope adds \"A manager answers a directive of yours with team_post, since its turn ending tells you nothing; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the note every turn of the global manager carries." + - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending tells it nothing: answer each of its directives with team_post to the manager. Apart from those answers, post only what it should act on or tell the person.\" The rest of that note is as it was. Every member of that team was given that note, \"because you manage a top-level team\" included; a member there that manages nothing is now given the note a member of any team is given." --- The global manager's members are the managers of whole teams, each a conversation diff --git a/internal/manual/chat/team-manager.md b/internal/manual/chat/team-manager.md index aa51147ebd..60f4e283fc 100644 --- a/internal/manual/chat/team-manager.md +++ b/internal/manual/chat/team-manager.md @@ -540,9 +540,14 @@ A top-level manager's turn ending does not start the global manager's turn. You those managers directly and each answer ends a turn, so the endings stay in `All teams`' traffic, where `team_status` reads them. The global manager is woken by what a manager posts to it with `team_post`, by a manager's question or a permission it is held on, and by a -manager's turn failing. It is told never to send a manager your own request to that manager +manager's turn failing. So a directive the global manager sent is answered with `team_post`: +each manager is told to answer its directives that way, and apart from those answers to post +only what the global manager should act on or tell you. A manager that ends its turn on a +directive without posting has told the global manager nothing, and `team_status` is where it +finds out. The global manager is told never to send a manager your own request to that manager back as a directive. A member of `All teams` that manages no team is an ordinary member -there: its turn ending wakes the global manager as in any team. +there: it is told what a member of any team is told, and its turn ending wakes the global +manager as in any team. ## Conflicts between members and teams diff --git a/internal/session/team.go b/internal/session/team.go index 30e5647781..04ca2c51ad 100644 --- a/internal/session/team.go +++ b/internal/session/team.go @@ -1735,7 +1735,7 @@ func teamManagerScope(role teamRole, file *teams.File) string { if role.root { parts = append(parts, fmt.Sprintf("You are the global manager: %q holds every team, and your members are the managers of the top-level teams, never their members. "+ "Direct those managers and they pass it on. Their questions and conflicts between teams come to you before the person. team_start with kind team starts a new top-level team. "+ - "A manager's turn ending does not start yours; team_status says where each of them stands. "+ + "A manager answers a directive of yours with team_post, since its turn ending tells you nothing; team_status says where each of them stands. "+ "The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.", role.name)) } else if home, ok := file.Home(role.key); ok && home.Team != role.id { boss := "its manager" @@ -1775,13 +1775,14 @@ func teamManagerDelivery(role teamRole) string { if !role.wakes { return "This team's auto-wake is off: what you send, and your members' replies, wait for each conversation's next turn, so an idle member does not start on a directive until it next runs." } - // The global manager's turn is not started by a member's turn ending - // ([teamEventWakesManagerOf]). - back := "Members' replies to you, and their finishing, failing or asking," + // The global manager's turn is not started by a top-level manager's turn + // ending ([teamEventWakesManagerOf]). The root can hold ordinary members + // too, so the sentence names whose ending it is. + back, except := "Members' replies to you, and their finishing, failing or asking,", "" if role.root { - back = "Members' replies to you, and their failing or asking," + back, except = "Members' replies to you, and their failing or asking,", " A top-level team's manager ending its turn does not start yours." } - return "A directive (team_send kind directive) starts an idle member's turn; a note waits for its next turn. team_send's answer says whether each member started: one the person paused does not start until they resume it, and work is under way only where the answer says so. " + back + " come back to you and start your turn when you are idle, so do not wait or poll for them." + return "A directive (team_send kind directive) starts an idle member's turn; a note waits for its next turn. team_send's answer says whether each member started: one the person paused does not start until they resume it, and work is under way only where the answer says so. " + back + " come back to you and start your turn when you are idle, so do not wait or poll for them." + except } // teamRoster names the manager's members by handle, with the start of each @@ -1834,10 +1835,14 @@ func teamMemberRole(role teamRole) string { if role.handle != "" { you = "@" + role.handle } - if role.root { + // Only a top-level team's manager is told its ending is silent: anybody + // else the root holds is an ordinary member there, whose ending wakes the + // global manager ([teamRole.quietEnding]), and reads the text below. + if role.quietEnding(role.key) { return fmt.Sprintf("You are %s in %q because you manage a top-level team: you report to its manager, the global manager. Its directives reach you marked \"◆ from manager\", "+ "your questions go to it before the person, and you report to it with team_post to the manager. "+ - "Your turn ending does not start its turn: post what it should act on or tell the person, and nothing the person already has from you here.", you, role.name) + "Your turn ending tells it nothing: answer each of its directives with team_post to the manager. "+ + "Apart from those answers, post only what it should act on or tell the person.", you, role.name) } if role.boss != "" && role.boss != role.id && !role.shared { said := fmt.Sprintf("You are %s in the team %q, which has no manager of its own, so you answer to the manager of %q: team_post to the manager reaches it, and to the room or a teammate stays in %q.", diff --git a/internal/session/team_nest_test.go b/internal/session/team_nest_test.go index 756161e6a9..82e99d312b 100644 --- a/internal/session/team_nest_test.go +++ b/internal/session/team_nest_test.go @@ -9,12 +9,15 @@ package session // teams.json and real Traffic, through internal/teams. import ( + "context" + "errors" "os" "path/filepath" "strings" "testing" "time" + "github.com/Agent-Field/agentfield/sdk/go/ai" "github.com/Agent-Field/codeaf/internal/teams" ) @@ -524,7 +527,10 @@ func TestAnUnmanagedSubTeamsMemberAnswersToTheManagerAbove(t *testing.T) { // THE GLOBAL MANAGER IS NOT WOKEN BY A TOP-LEVEL MANAGER'S TURN ENDING. The // person talks to that manager directly and each answer ends a turn; what the -// global manager should act on is posted to it, and that still wakes it. +// global manager should act on is posted to it, and that still wakes it. A +// directive of the global manager's is answered the same way, and both sides +// are told so, because the ending that closes the loop in any other team says +// nothing here. func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { fastTeamWake(t) n := newTeamTree(t, "gm", "boss", "web") @@ -541,9 +547,13 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { } gmCalls := oneAnswer(4) gm := teamAgent(t, n.fixture, n.paths["gm"], gmCalls, nil) - boss := teamAgent(t, n.fixture, n.paths["boss"], oneAnswer(4), nil) + bossCalls := oneAnswer(4) + boss := teamAgent(t, n.fixture, n.paths["boss"], bossCalls, nil) submitAndWait(t, boss, "plan the release") + if role := strings.Join(roleNotes(bossCalls.request(0)), "\n"); !strings.Contains(role, "Your turn ending tells it nothing: answer each of its directives with team_post to the manager.") { + t.Fatalf("the top-level manager is not told to answer the global manager's directive with a post:\n%s", role) + } boss.settleTeamEvents() // Past the settle a wake waits out, with room: a wake the ending had armed // would have fired by now. @@ -564,7 +574,7 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { } waitRequests(t, gmCalls, 1) asked := userTextIn(gmCalls.request(0)) - for _, want := range []string{"from @boss: harbor shipped", "A manager's turn ending does not start yours", "and their failing or asking, come back to you"} { + for _, want := range []string{"from @boss: harbor shipped", "A manager answers a directive of yours with team_post", "and their failing or asking, come back to you", "A top-level team's manager ending its turn does not start yours."} { if !strings.Contains(asked, want) { t.Fatalf("the global manager's turn lacks %q:\n%s", want, asked) } @@ -575,8 +585,9 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { if strings.Contains(asked, "finished its turn") || strings.Contains(asked, "What your members in") { t.Fatalf("the ending rode into the global manager's turn as something that woke it:\n%s", asked) } - // Its own send's answer does not promise that an ending wakes it. - if said := sendDirective(t, gm, "boss"); strings.Contains(said, "endings wake you") || !strings.Contains(said, "A manager's turn ending on its own does not wake you") { + // Its own send's answer does not promise that an ending wakes it, and says + // what answers the directive. + if said := sendDirective(t, gm, "boss"); strings.Contains(said, "endings wake you") || !strings.Contains(said, "A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you") { t.Fatalf("the global manager's send says endings wake it: %s", said) } } @@ -584,7 +595,8 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { // A GLOBAL MANAGER NOBODY HAS OPEN IS NOT OPENED BY THE ENDING EITHER, and is // still opened by a top-level manager's failure. A member of the team that // holds every team that manages nothing is an ordinary member there: its -// ending opens the manager as it does in any team. +// ending opens the manager as it does in any team, and its role says nothing +// about managing a team or an ending nobody hears. func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing.T) { fastTeamWake(t) n := newTeamTree(t, "gm", "boss", "web", "guest") @@ -612,7 +624,18 @@ func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing } return count } - boss := teamAgent(t, n.fixture, n.paths["boss"], oneAnswer(2), nil) + waitOpened := func(want int) bool { + deadline := time.Now().Add(5 * time.Second) + for opened() < want && time.Now().Before(deadline) { + time.Sleep(10 * time.Millisecond) + } + return opened() >= want + } + bossCalls := oneAnswer(1) + bossCalls.steps = append(bossCalls.steps, func(context.Context, []ai.Message) (*ai.Response, error) { + return nil, errors.New("insufficient_quota: out of budget") + }) + boss := teamAgent(t, n.fixture, n.paths["boss"], bossCalls, nil) submitAndWait(t, boss, "plan the release") boss.settleTeamEvents() time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) @@ -620,16 +643,33 @@ func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing t.Fatalf("a closed global manager was opened %d times by a top-level manager's turn ending", got) } - guest := teamAgent(t, n.fixture, n.paths["guest"], oneAnswer(2), nil) + submitAndWait(t, boss, "ship it") + boss.settleTeamEvents() + all := teamFixture{profile: n.fixture.profile, teamID: root} + if failed := trafficEvents(t, all, "failed: "); len(failed) != 1 || failed[0].State != teams.StateFailed { + t.Fatalf("the top-level manager's failed turn is not one failed event in the team that holds every team: %+v", failed) + } + if !waitOpened(1) { + t.Fatal("a top-level manager's turn failed and the closed global manager was not opened") + } + + before := opened() + guestCalls := oneAnswer(2) + guest := teamAgent(t, n.fixture, n.paths["guest"], guestCalls, nil) submitAndWait(t, guest, "tidy the notes") guest.settleTeamEvents() - deadline := time.Now().Add(5 * time.Second) - for opened() == 0 && time.Now().Before(deadline) { - time.Sleep(10 * time.Millisecond) - } - if got := opened(); got == 0 { + if !waitOpened(before + 1) { t.Fatal("a member of the team that holds every team that manages nothing ended its turn and its manager was not opened") } + role := strings.Join(roleNotes(guestCalls.request(0)), "\n") + if !strings.Contains(role, `in the team "All teams", which has a manager.`) { + t.Fatalf("a member of the team that holds every team that manages nothing is not told it is a member there:\n%s", role) + } + for _, not := range []string{"you manage a top-level team", "Your turn ending tells it nothing"} { + if strings.Contains(role, not) { + t.Fatalf("a member that manages nothing is told %q, which is true of a top-level team's manager only:\n%s", not, role) + } + } } func TestTeamEventWakesTheGlobalManager(t *testing.T) { diff --git a/internal/session/team_sendoutcome.go b/internal/session/team_sendoutcome.go index 8b643b7ae4..c2c4d7db3c 100644 --- a/internal/session/team_sendoutcome.go +++ b/internal/session/team_sendoutcome.go @@ -206,10 +206,12 @@ func itThey(n int) string { // teamSendWakesSentence is what a send's answer says comes back on its own. // The global manager is not woken by a top-level manager's turn ending -// ([teamEventWakesManagerOf]), so its answer does not promise that. +// ([teamEventWakesManagerOf]), so its answer does not promise that, and says +// what closes a directive instead. The root can hold ordinary members too, so +// the sentence names whose ending it is. func teamSendWakesSentence(root bool) string { if root { - return "Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A manager's turn ending on its own does not wake you: team_status says where it stands." + return "Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you, and team_status says where it stands." } return "Replies and endings wake you when they arrive, so there is no need to wait or poll." } From 57fac548c033353099392275e427cf3416c03e92 Mon Sep 17 00:00:00 2001 From: Ara Ghukasyan <329227198+ZeroPoint95@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:11:23 -0500 Subject: [PATCH 6/6] teams: final review round 3 repairs for the quiet global manager No member's turn finishing or being stopped in the team that holds every team wakes or opens the global manager: it can see and direct only the current top-level managers, so a member left seated there after losing its team woke it on every answer for nothing. A team it starts is told to answer the brief it was started on with team_post, as a directive. Co-Authored-By: Claude Fable 5.2 --- .../unreleased/2906-global-manager-quiet.md | 9 +- internal/manual/chat/team-manager.md | 29 +-- internal/session/team.go | 34 +-- internal/session/team_nest.go | 8 +- internal/session/team_nest_test.go | 199 ++++++++++++++---- internal/session/team_sendoutcome.go | 10 +- internal/session/team_wakewatch.go | 66 +++--- internal/session/teamevent.go | 2 +- 8 files changed, 237 insertions(+), 120 deletions(-) diff --git a/docs/changes/unreleased/2906-global-manager-quiet.md b/docs/changes/unreleased/2906-global-manager-quiet.md index d5fe02a871..6c90bf417f 100644 --- a/docs/changes/unreleased/2906-global-manager-quiet.md +++ b/docs/changes/unreleased/2906-global-manager-quiet.md @@ -4,10 +4,11 @@ title: The global manager is not woken each time a top-level team's manager ends pr: 2906 surface: [engine, chat] invalidates: - - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team the finished event of a member that manages a top-level team (teams.File.TopManagers, teamRole.quietEnding) no longer starts the global manager's turn either (teamEventWakesManagerOf): of that manager's events only failed and asking do, and its team_post, a decision packet it raises and a conflict it declares wake the global manager as before. A global manager nobody has open is likewise no longer opened by such a finished event. A member of that team that manages nothing, and every other team, are unchanged, so a stopped-by-the-person event from such a member wakes the global manager where the earlier rule kept every idle event in that team from doing so." - - "team_send answered every manager \"Replies and endings wake you when they arrive, so there is no need to wait or poll.\" In the team that holds every team it now answers \"Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you, and team_status says where it stands.\" The answer in every other team is as it was." - - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\" and ends \"A top-level team's manager ending its turn does not start yours.\", and its scope adds \"A manager answers a directive of yours with team_post, since its turn ending tells you nothing; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the note every turn of the global manager carries." - - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending tells it nothing: answer each of its directives with team_post to the manager. Apart from those answers, post only what it should act on or tell the person.\" The rest of that note is as it was. Every member of that team was given that note, \"because you manage a top-level team\" included; a member there that manages nothing is now given the note a member of any team is given." + - "A member's finished, failed or asking event started its manager's turn in every team, the team that holds every team included, where only an idle (stopped) event did not. In that team no member's finished event starts the global manager's turn any longer (teamEventWakesManagerOf): of a member's events there only failed and asking do, and a team_post to the manager, a decision packet a member raises and a conflict it declares wake the global manager as before. A global manager nobody has open is likewise no longer opened by a finished event there. The rule is that whole team's: it covers a top-level team's manager, a manager that was replaced or whose team closed and kept its seat there, and a conversation the person put there, since the global manager lists and directs only the current top-level managers (managedView). Every other team is unchanged." + - "team_send answered every manager \"Replies and endings wake you when they arrive, so there is no need to wait or poll.\" In the team that holds every team it now answers \"Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn finishing or being stopped does not wake you, and team_status says where it stands.\" The answer in every other team is as it was." + - "The global manager's team note said \"Members' replies to you, and their finishing, failing or asking, come back to you and start your turn when you are idle\". For the global manager it now says \"Members' replies to you, and their failing or asking, come back to you\" and ends \"A member's turn finishing or being stopped does not start yours.\", and its scope adds \"A manager answers a directive of yours, and the brief you started it on, with team_post, since its turn finishing does not start yours; team_status says where each of them stands. The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.\" Both are in the global manager's role note, which it is handed when that note's text changes." + - "A top-level manager's note about its seat in the team that holds every team ended \"you report to it with team_post to the manager.\" It now adds \"Your turn ending tells it nothing: answer each of its directives, and the brief it started you on if it started you, with team_post to the manager. Apart from those answers, post only what it should act on or tell the person.\" The rest of that note is as it was. Every member of that team was given that note, \"because you manage a top-level team\" included; a member there that manages no top-level team now is given the note a member of any team is given." + - "The first turn of a team's new manager, on the brief team_start of kind team started it with, woke the manager that started it when it finished, and team_start answered every manager that the new conversation \"makes itself the manager of\" the team \"and reports to you.\" A team the global manager starts no longer wakes it that way, and team_start answers the global manager that the new manager \"reports to you with team_post: its turn finishing on your brief does not start yours, and team_status says where it stands.\" The answer to every other manager is as it was." --- The global manager's members are the managers of whole teams, each a conversation diff --git a/internal/manual/chat/team-manager.md b/internal/manual/chat/team-manager.md index 076641a83e..97ad954d9c 100644 --- a/internal/manual/chat/team-manager.md +++ b/internal/manual/chat/team-manager.md @@ -353,7 +353,7 @@ left that the member waits on. So a turn such a command's ending starts is still so is a turn you opened by typing to the member while it waits on one. Stopping a member with none of the manager's work under way tells the manager nothing, and neither does codeaf quitting or a paused member's stray wake being ended. The global -manager is not woken by a top-level team's manager being stopped (see **The global manager**). +manager is not woken by a member of `All teams` being stopped (see **The global manager**). ## A stopped member's command is still running — why it did not start again when the command ended @@ -540,18 +540,19 @@ report to it, so their questions and conflicts between teams come to it before t you. It can start a new top-level team with `team_start` of kind `team`. Without a global manager, nothing here changes: each top-level manager reports to you. -A top-level manager's turn ending does not start the global manager's turn. You talk to -those managers directly and each answer ends a turn, so the endings stay in `All teams`' -traffic, where `team_status` reads them. The global manager is woken by what a manager posts -to it with `team_post`, by a manager's question or a permission it is held on, and by a -manager's turn failing. So a directive the global manager sent is answered with `team_post`: -each manager is told to answer its directives that way, and apart from those answers to post -only what the global manager should act on or tell you. A manager that ends its turn on a -directive without posting has told the global manager nothing, and `team_status` is where it -finds out. The global manager is told never to send a manager your own request to that manager -back as a directive. A member of `All teams` that manages no team is an ordinary member -there: it is told what a member of any team is told, and its turn ending wakes the global -manager as in any team. +No turn in `All teams` that finishes or is stopped starts the global manager's turn. You talk +to the top-level managers directly and each answer ends a turn, so the endings stay in +`All teams`' traffic, where `team_status` reads them. The global manager is woken by what a +member posts to it with `team_post`, by a member's question or a permission it is held on, and +by a member's turn failing. So a directive the global manager sent, and the brief it started +a team on, are answered with `team_post`: each top-level manager is told so, and apart from +those answers to post only what the global manager should act on or tell you. A manager that +finishes a turn without posting has told it nothing, the first turn of a team it started +included: `team_start` says so, and `team_status` is where it finds out. The global manager +is told never to send a manager your own request to that manager back as a directive. +`All teams` can also hold a conversation that manages no team now, such as a manager you +replaced. The global manager neither lists nor directs it, its turn ending is as quiet, and +it is told what a member of any team is told. ## Conflicts between members and teams @@ -612,7 +613,7 @@ working, that is straight away. When it is idle, it depends on the kind of messa manager's work, start an idle manager's turn. A reply and the end of the same turn are one wake, even if the ending arrives after the manager already ran. Replies arriving within a few seconds are gathered into one turn. The global - manager is the exception: a top-level team's manager finishing or being stopped does not + manager is the exception: a member of `All teams` finishing or being stopped does not start its turn (see **The global manager**). A member no window has open is opened by codeaf in the background so it can run, and a window diff --git a/internal/session/team.go b/internal/session/team.go index 8b6e9f1c46..38b620999c 100644 --- a/internal/session/team.go +++ b/internal/session/team.go @@ -124,12 +124,12 @@ type teamRole struct { // manager is the global manager, and its other members are the top-level // teams' managers. root bool - // tops is, for the root, the keys of the members that manage a top-level - // team now ([teams.File.TopManagers]). The root can hold others, a manager - // that stopped being one or a conversation the person put there, and the - // rule that keeps a manager's turn ending from waking the global manager is - // about these members alone ([teamRole.quietEnding]). - tops map[string]bool + // top says this seat in the root is a top-level team's manager's now + // ([teams.File.TopManagers]). The root can hold others, a manager that + // stopped being one or a conversation the person put there, and only a + // manager is told it sits there because it manages a team + // ([teamMemberRole]). + top bool // dissolvable says this conversation manages the team and the team has // never held anyone but it ([teams.File.Dissolvable]), which is when its // manager is given team_dissolve (team_dissolve.go). @@ -461,7 +461,7 @@ func rolesFor(file *teams.File, keys []string, d teams.Defaults) []teamRole { boss: boss, bossName: bossName, root: team.Root, - tops: topManagerKeys(file, team), + top: team.Root && topManager(file, member.Key), key: member.Key, wakes: effective.Wake, questionsUp: effective.QuestionsUp, @@ -1736,7 +1736,7 @@ func teamManagerScope(role teamRole, file *teams.File) string { if role.root { parts = append(parts, fmt.Sprintf("You are the global manager: %q holds every team, and your members are the managers of the top-level teams, never their members. "+ "Direct those managers and they pass it on. Their questions and conflicts between teams come to you before the person. team_start with kind team starts a new top-level team. "+ - "A manager answers a directive of yours with team_post, since its turn ending tells you nothing; team_status says where each of them stands. "+ + "A manager answers a directive of yours, and the brief you started it on, with team_post, since its turn finishing does not start yours; team_status says where each of them stands. "+ "The person talks to those managers directly, and what the person asked one of them is that manager's work already: never send a manager the person's own request to it as a directive of yours.", role.name)) } else if home, ok := file.Home(role.key); ok && home.Team != role.id { boss := "its manager" @@ -1776,12 +1776,11 @@ func teamManagerDelivery(role teamRole) string { if !role.wakes { return "This team's auto-wake is off: what you send, and your members' replies, wait for each conversation's next turn, so an idle member does not start on a directive until it next runs." } - // The global manager's turn is not started by a top-level manager's turn - // ending ([teamEventWakesManagerOf]). The root can hold ordinary members - // too, so the sentence names whose ending it is. + // The global manager's turn is not started by a turn ending in the root, + // finished or stopped ([teamEventWakesManagerOf]). back, except := "Members' replies to you, and their finishing, failing or asking,", "" if role.root { - back, except = "Members' replies to you, and their failing or asking,", " A top-level team's manager ending its turn does not start yours." + back, except = "Members' replies to you, and their failing or asking,", " A member's turn finishing or being stopped does not start yours." } return "A directive (team_send kind directive) starts an idle member's turn; a note waits for its next turn. team_send's answer says whether each member started: one the person paused does not start until they resume it, and work is under way only where the answer says so. " + back + " come back to you and start your turn when you are idle, so do not wait or poll for them." + except } @@ -1836,13 +1835,14 @@ func teamMemberRole(role teamRole) string { if role.handle != "" { you = "@" + role.handle } - // Only a top-level team's manager is told its ending is silent: anybody - // else the root holds is an ordinary member there, whose ending wakes the - // global manager ([teamRole.quietEnding]), and reads the text below. - if role.quietEnding(role.key) { + // Only a top-level team's manager is told why it sits in the root and how + // to answer the global manager. Nobody's ending there wakes that manager + // ([teamEventWakesManagerOf]), but it directs only these, so anybody else + // the root holds reads the member's text below, which promises no wake. + if role.top { return fmt.Sprintf("You are %s in %q because you manage a top-level team: you report to its manager, the global manager. Its directives reach you marked \"◆ from manager\", "+ "your questions go to it before the person, and you report to it with team_post to the manager. "+ - "Your turn ending tells it nothing: answer each of its directives with team_post to the manager. "+ + "Your turn ending tells it nothing: answer each of its directives, and the brief it started you on if it started you, with team_post to the manager. "+ "Apart from those answers, post only what it should act on or tell the person.", you, role.name) } if role.boss != "" && role.boss != role.id && !role.shared { diff --git a/internal/session/team_nest.go b/internal/session/team_nest.go index 28c4cbecd3..867ba660a7 100644 --- a/internal/session/team_nest.go +++ b/internal/session/team_nest.go @@ -265,8 +265,14 @@ func (a *Agent) teamStartSubTeam(ctx context.Context, team teams.Team, role team case pool != "": money = fmt.Sprintf("It has no cap of its own and spends from %q's pool.", pool) } + reports := "reports to you" + if team.Root { + // The new manager's ending does not wake the global manager, its first + // turn on the brief included ([teamEventWakesManagerOf]). + reports = "reports to you with team_post: its turn finishing on your brief does not start yours, and team_status says where it stands" + } said := fmt.Sprintf("Made the team %q under %q and asked for its manager @%s (%s). The conversations view opens @%s in %q's folder as a member of %q; it is handed your brief marked as yours, "+ - "makes itself the manager of %q, and reports to you. %s", name, team.Name, handle, teams.ThreadNumber(startID), handle, team.Name, team.Name, name, money) + "makes itself the manager of %q, and %s. %s", name, team.Name, handle, teams.ThreadNumber(startID), handle, team.Name, team.Name, name, reports, money) if len(moved) > 0 { said += " Moved in: " + strings.Join(moved, ", ") + "; they are its manager's to direct now, not yours." } diff --git a/internal/session/team_nest_test.go b/internal/session/team_nest_test.go index 82e99d312b..2bf1e7e74d 100644 --- a/internal/session/team_nest_test.go +++ b/internal/session/team_nest_test.go @@ -551,7 +551,7 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { boss := teamAgent(t, n.fixture, n.paths["boss"], bossCalls, nil) submitAndWait(t, boss, "plan the release") - if role := strings.Join(roleNotes(bossCalls.request(0)), "\n"); !strings.Contains(role, "Your turn ending tells it nothing: answer each of its directives with team_post to the manager.") { + if role := strings.Join(roleNotes(bossCalls.request(0)), "\n"); !strings.Contains(role, "Your turn ending tells it nothing: answer each of its directives, and the brief it started you on if it started you, with team_post to the manager.") { t.Fatalf("the top-level manager is not told to answer the global manager's directive with a post:\n%s", role) } boss.settleTeamEvents() @@ -574,7 +574,7 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { } waitRequests(t, gmCalls, 1) asked := userTextIn(gmCalls.request(0)) - for _, want := range []string{"from @boss: harbor shipped", "A manager answers a directive of yours with team_post", "and their failing or asking, come back to you", "A top-level team's manager ending its turn does not start yours."} { + for _, want := range []string{"from @boss: harbor shipped", "A manager answers a directive of yours, and the brief you started it on, with team_post", "and their failing or asking, come back to you", "A member's turn finishing or being stopped does not start yours."} { if !strings.Contains(asked, want) { t.Fatalf("the global manager's turn lacks %q:\n%s", want, asked) } @@ -587,20 +587,21 @@ func TestTheGlobalManagerIsNotWokenByATopLevelManagersTurnEnding(t *testing.T) { } // Its own send's answer does not promise that an ending wakes it, and says // what answers the directive. - if said := sendDirective(t, gm, "boss"); strings.Contains(said, "endings wake you") || !strings.Contains(said, "A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you") { + if said := sendDirective(t, gm, "boss"); strings.Contains(said, "endings wake you") || !strings.Contains(said, "A top-level team's manager answers a directive with team_post: its turn finishing or being stopped does not wake you") { t.Fatalf("the global manager's send says endings wake it: %s", said) } } -// A GLOBAL MANAGER NOBODY HAS OPEN IS NOT OPENED BY THE ENDING EITHER, and is -// still opened by a top-level manager's failure. A member of the team that -// holds every team that manages nothing is an ordinary member there: its -// ending opens the manager as it does in any team, and its role says nothing -// about managing a team or an ending nobody hears. -func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing.T) { +// A GLOBAL MANAGER NOBODY HAS OPEN IS NOT OPENED BY AN ENDING IN ITS TEAM +// EITHER, whoever's it is: a top-level manager's, a member's that manages +// nothing, or a manager's that was replaced and kept its seat. It sees and +// directs only the managers of the top-level teams, so none of those endings +// is one it can act on. A failure still opens it. Only a top-level manager is +// told it sits there because it manages a team. +func TestAClosedGlobalManagerIsNotOpenedByATurnEndingInItsTeam(t *testing.T) { fastTeamWake(t) n := newTeamTree(t, "gm", "boss", "web", "guest") - n.team(t, "harbor", "", "boss", n.member(t, "boss", "boss"), n.member(t, "web", "web")) + harbor := n.team(t, "harbor", "", "boss", n.member(t, "boss", "boss"), n.member(t, "web", "web")) root := "" if err := teams.Update(n.fixture.profile, func(f *teams.File) error { root = f.MakeRoot(f.Teams[0].Made) @@ -613,6 +614,7 @@ func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing }); err != nil { t.Fatal(err) } + since := time.Now() recorder := &recordedResume{} withTeamResume(t, recorder.open) opened := func() int { @@ -624,58 +626,169 @@ func TestAClosedGlobalManagerIsNotOpenedByATopLevelManagersTurnEnding(t *testing } return count } - waitOpened := func(want int) bool { - deadline := time.Now().Add(5 * time.Second) - for opened() < want && time.Now().Before(deadline) { - time.Sleep(10 * time.Millisecond) + // due is the desktop app's question of a conversation it has not opened. + due := func() bool { + return TeamOpenPending(n.fixture.profile, n.paths["gm"], n.file(t), teams.DefaultsAt(n.fixture.profile), since) + } + all := teamFixture{profile: n.fixture.profile, teamID: root} + // quiet runs one turn of agent's and says what, if anything, opened the + // closed global manager on its ending. + endings := 0 + quiet := func(who string, agent *Agent) { + t.Helper() + submitAndWait(t, agent, "tidy the notes") + agent.settleTeamEvents() + endings++ + if ended := trafficEvents(t, all, "finished"); len(ended) != endings { + t.Fatalf("%s ended its turn and the team that holds every team has %d finished events, want %d", who, len(ended), endings) + } + time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) + if got := opened(); got != 0 { + t.Fatalf("a closed global manager was opened %d times by the turn ending of %s", got, who) + } + if due() { + t.Fatalf("the turn ending of %s leaves the closed global manager due an opening", who) } - return opened() >= want } - bossCalls := oneAnswer(1) + bossCalls := oneAnswer(2) bossCalls.steps = append(bossCalls.steps, func(context.Context, []ai.Message) (*ai.Response, error) { return nil, errors.New("insufficient_quota: out of budget") }) boss := teamAgent(t, n.fixture, n.paths["boss"], bossCalls, nil) - submitAndWait(t, boss, "plan the release") - boss.settleTeamEvents() - time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) - if got := opened(); got != 0 { - t.Fatalf("a closed global manager was opened %d times by a top-level manager's turn ending", got) + quiet("a top-level manager", boss) + + guestCalls := oneAnswer(1) + guest := teamAgent(t, n.fixture, n.paths["guest"], guestCalls, nil) + quiet("a member that manages nothing", guest) + ordinary := func(who, role string) { + t.Helper() + if !strings.Contains(role, `in the team "All teams", which has a manager.`) { + t.Fatalf("%s is not told it is a member of the team that holds every team:\n%s", who, role) + } + for _, not := range []string{"you manage a top-level team", "Your turn ending tells it nothing"} { + if strings.Contains(role, not) { + t.Fatalf("%s is told %q, which is said to a top-level team's manager only:\n%s", who, not, role) + } + } } + ordinary("a member that manages nothing", strings.Join(roleNotes(guestCalls.request(0)), "\n")) + // The team's manager is replaced. The old one keeps its seat in the team + // that holds every team, where the global manager no longer sees it. + if err := teams.Update(n.fixture.profile, func(f *teams.File) error { + return f.SetManager(harbor, n.key(t, "web")) + }); err != nil { + t.Fatal(err) + } + f := n.file(t) + if r, _ := f.Team(root); !r.Holds(n.key(t, "boss")) { + t.Fatal("the replaced manager lost its seat in the team that holds every team") + } + if tops := f.TopManagers(); len(tops) != 1 || tops[0].Key != n.key(t, "web") { + t.Fatalf("the top-level managers after the replacement: %+v", tops) + } + quiet("a replaced top-level manager", boss) + former := roleNotes(bossCalls.request(1)) + if len(former) == 0 { + t.Fatal("the replaced manager's next turn carries no new role") + } + ordinary("a replaced top-level manager", former[len(former)-1]) + + // A failure there still opens it, a member's it does not direct included. submitAndWait(t, boss, "ship it") boss.settleTeamEvents() - all := teamFixture{profile: n.fixture.profile, teamID: root} if failed := trafficEvents(t, all, "failed: "); len(failed) != 1 || failed[0].State != teams.StateFailed { - t.Fatalf("the top-level manager's failed turn is not one failed event in the team that holds every team: %+v", failed) + t.Fatalf("the failed turn is not one failed event in the team that holds every team: %+v", failed) + } + deadline := time.Now().Add(5 * time.Second) + for opened() == 0 && time.Now().Before(deadline) { + time.Sleep(10 * time.Millisecond) } - if !waitOpened(1) { - t.Fatal("a top-level manager's turn failed and the closed global manager was not opened") + if opened() == 0 { + t.Fatal("a turn failed in the team that holds every team and its closed manager was not opened") } + if !due() { + t.Fatal("a failed turn does not leave the closed global manager due an opening") + } +} - before := opened() - guestCalls := oneAnswer(2) - guest := teamAgent(t, n.fixture, n.paths["guest"], guestCalls, nil) - submitAndWait(t, guest, "tidy the notes") - guest.settleTeamEvents() - if !waitOpened(before + 1) { - t.Fatal("a member of the team that holds every team that manages nothing ended its turn and its manager was not opened") - } - role := strings.Join(roleNotes(guestCalls.request(0)), "\n") - if !strings.Contains(role, `in the team "All teams", which has a manager.`) { - t.Fatalf("a member of the team that holds every team that manages nothing is not told it is a member there:\n%s", role) - } - for _, not := range []string{"you manage a top-level team", "Your turn ending tells it nothing"} { - if strings.Contains(role, not) { - t.Fatalf("a member that manages nothing is told %q, which is true of a top-level team's manager only:\n%s", not, role) +// A TEAM THE GLOBAL MANAGER STARTS REPORTS ITS FIRST TURN WITH A POST. The new +// manager's turn on the brief ends like any other there and wakes nobody, so +// team_start's answer and both roles name the brief beside the directives. +func TestATeamTheGlobalManagerStartsAnswersItsBriefWithAPost(t *testing.T) { + fastTeamWake(t) + n := newTeamTree(t, "gm", "boss", "ops") + n.team(t, "harbor", "", "boss", n.member(t, "boss", "boss")) + root := "" + if err := teams.Update(n.fixture.profile, func(f *teams.File) error { + root = f.MakeRoot(f.Teams[0].Made) + if err := f.AddMember(root, n.member(t, "gm", "all")); err != nil { + return err } + return f.SetManager(root, n.key(t, "gm")) + }); err != nil { + t.Fatal(err) + } + gmCalls := oneAnswer(2) + gm := teamAgent(t, n.fixture, n.paths["gm"], gmCalls, nil) + gm.teamBoundary() + said, failed := callTool(t, gm.teamStartTool, `{"handle":"ops","brief":"Run the ops.","kind":"team","name":"ops"}`) + if failed { + t.Fatalf("the global manager could not start a top-level team: %q", said) + } + if want := `makes itself the manager of "ops", and reports to you with team_post: its turn finishing on your brief does not start yours, and team_status says where it stands.`; !strings.Contains(said, want) { + t.Fatalf("team_start's answer for a top-level team lacks %q:\n%s", want, said) + } + gm.mu.Lock() + role := gm.teamRoleText + gm.mu.Unlock() + if want := "A manager answers a directive of yours, and the brief you started it on, with team_post, since its turn finishing does not start yours"; !strings.Contains(role, want) { + t.Fatalf("the global manager's role lacks %q:\n%s", want, role) + } + + // The interface carries out the start, and the new manager runs its first + // turn on the brief without posting. + if err := teams.Update(n.fixture.profile, func(f *teams.File) error { + m := n.member(t, "ops", "ops") + m.Started = true + return f.AddMember(root, m) + }); err != nil { + t.Fatal(err) + } + opsCalls := oneAnswer(1) + ops := teamAgent(t, n.fixture, n.paths["ops"], opsCalls, nil) + submitAndWait(t, ops, "go") + first := opsCalls.request(0) + if asked := userTextIn(first); !strings.Contains(asked, "◆ brief from manager") || !strings.Contains(asked, "Run the ops.") { + t.Fatalf("the new manager's first turn lacks its brief:\n%s", asked) + } + if role := strings.Join(roleNotes(first), "\n"); !strings.Contains(role, "because you manage a top-level team") || + !strings.Contains(role, "answer each of its directives, and the brief it started you on if it started you, with team_post to the manager.") { + t.Fatalf("the new manager is not told to answer its brief with a post:\n%s", role) + } + ops.settleTeamEvents() + time.Sleep(teamWakeDelay() + 15*teamWatchInterval()) + all := teamFixture{profile: n.fixture.profile, teamID: root} + if ended := trafficEvents(t, all, "finished"); len(ended) != 1 { + t.Fatalf("the new manager's first turn was logged %d times in the team that holds every team, want once", len(ended)) + } + if got := gmCalls.requests(); got != 0 { + t.Fatalf("the global manager was woken %d times by the new manager's first turn ending", got) + } + + if said, failed := callTool(t, ops.teamPostTool, `{"to":"manager","text":"ops is set up"}`); failed { + t.Fatalf("the new manager's report was refused: %q", said) + } + waitRequests(t, gmCalls, 1) + if asked := userTextIn(gmCalls.request(0)); !strings.Contains(asked, "from @ops: ops is set up") { + t.Fatalf("the global manager's turn lacks the new manager's report:\n%s", asked) } } func TestTeamEventWakesTheGlobalManager(t *testing.T) { for _, c := range []struct { state, text string - top, want bool + root, want bool }{ {teams.StateFinished, "finished", false, true}, {teams.StateFinished, "finished", true, false}, @@ -685,8 +798,8 @@ func TestTeamEventWakesTheGlobalManager(t *testing.T) { {teams.StateAsking, "asks: which branch?", true, true}, {teams.StateRunning, "no longer waiting", true, false}, } { - if got := teamEventWakesManagerOf(c.top, c.state, c.text); got != c.want { - t.Errorf("top-level manager %v, %s %q wakes the manager: %v, want %v", c.top, c.state, c.text, got, c.want) + if got := teamEventWakesManagerOf(c.root, c.state, c.text); got != c.want { + t.Errorf("in the team that holds every team %v, %s %q wakes the manager: %v, want %v", c.root, c.state, c.text, got, c.want) } } } diff --git a/internal/session/team_sendoutcome.go b/internal/session/team_sendoutcome.go index c2c4d7db3c..23f1cadd60 100644 --- a/internal/session/team_sendoutcome.go +++ b/internal/session/team_sendoutcome.go @@ -205,13 +205,13 @@ func itThey(n int) string { } // teamSendWakesSentence is what a send's answer says comes back on its own. -// The global manager is not woken by a top-level manager's turn ending -// ([teamEventWakesManagerOf]), so its answer does not promise that, and says -// what closes a directive instead. The root can hold ordinary members too, so -// the sentence names whose ending it is. +// The global manager is not woken by a turn ending in the root, finished or +// stopped ([teamEventWakesManagerOf]), so its answer does not promise that, +// and says what closes a directive instead. Its sends reach top-level +// managers only ([managedView]), which is who the sentence names. func teamSendWakesSentence(root bool) string { if root { - return "Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn ending alone does not wake you, and team_status says where it stands." + return "Their replies, questions and failures wake you when they arrive, so there is no need to wait or poll. A top-level team's manager answers a directive with team_post: its turn finishing or being stopped does not wake you, and team_status says where it stands." } return "Replies and endings wake you when they arrive, so there is no need to wait or poll." } diff --git a/internal/session/team_wakewatch.go b/internal/session/team_wakewatch.go index 1996caa2be..3ef7dc983a 100644 --- a/internal/session/team_wakewatch.go +++ b/internal/session/team_wakewatch.go @@ -455,47 +455,43 @@ func teamEventWakesManager(state, text string) bool { return false } -// teamEventWakesManagerOf is [teamEventWakesManager] for one member's event, -// top when that member is a top-level team's manager seated in the team that -// holds every team ([teamRole.quietEnding]). +// teamEventWakesManagerOf is [teamEventWakesManager] for an event in one team, +// root when that is the team that holds every team. // -// The global manager is not woken by a top-level manager's turn ending, -// finished or stopped. Its members are the managers of whole teams, each a -// conversation the person talks to, and every answer one of them gave the -// person ended a turn. Measured 2026-11-24 in the desktop app: one afternoon -// of the person talking to two crew managers woke the global manager 22 times, -// 803,496 input tokens, and it answered "[no change]" to all 22; the day -// before, one such wake had it read a manager's conversation and send the -// person's own request back to that manager as a directive. What a top-level -// manager wants the global manager to act on it posts (a note wakes), and what -// needs somebody still wakes: a failure, and a question or a permission it is -// held on. The ending itself stays in the team's traffic, where team_status -// reads it. -func teamEventWakesManagerOf(top bool, state, text string) bool { - if top { +// The global manager is not woken by a turn ending in the root, finished or +// stopped. Its members are the managers of whole teams, each a conversation +// the person talks to, and every answer one of them gave the person ended a +// turn. Measured 2026-11-24 in the desktop app: one afternoon of the person +// talking to two crew managers woke the global manager 22 times, 803,496 input +// tokens, and it answered "[no change]" to all 22; the day before, one such +// wake had it read a manager's conversation and send the person's own request +// back to that manager as a directive. What a top-level manager wants the +// global manager to act on it posts (a note wakes), and what needs somebody +// still wakes: a failure, and a question or a permission it is held on. The +// ending itself stays in the team's traffic, where team_status reads it. +// +// The rule is the whole root's, not the top-level managers' alone. A seat in +// the root is never taken back, so it also holds a manager that was replaced +// or whose team closed, and whoever the person put there; the global manager +// neither sees nor directs those ([managedView]), so their endings are ones +// it can do nothing with. +func teamEventWakesManagerOf(root bool, state, text string) bool { + if root { return state == teams.StateFailed || state == teams.StateAsking } return teamEventWakesManager(state, text) } -// quietEnding reports whether member is a top-level team's manager seated in -// the root: the one member whose turn ending does not wake the root's manager. -// Anybody else the root holds is an ordinary member there. -func (r teamRole) quietEnding(member string) bool { - return r.root && r.tops[member] -} - -// topManagerKeys is the keys [teamRole.tops] holds, nil for every team but the -// root. -func topManagerKeys(file *teams.File, team teams.Team) map[string]bool { - if file == nil || !team.Root { - return nil - } - tops := map[string]bool{} +// topManager reports whether key manages an open top-level team now +// ([teams.File.TopManagers]), which is what [teamRole.top] says of a seat in +// the root. +func topManager(file *teams.File, key string) bool { for _, m := range file.TopManagers() { - tops[m.Key] = true + if m.Key == key { + return true + } } - return tops + return false } // teamWakes reports whether an entry starts this conversation's turn when it @@ -503,7 +499,7 @@ func topManagerKeys(file *teams.File, team teams.Team) map[string]bool { // member; a member's post to the manager, or a member's finished, failed or // asking event, for the manager. The watch suppresses a finished event when // the same turn already posted a reply, and the global manager is not woken by -// a top-level manager's turn ending ([teamEventWakesManagerOf]). +// a turn ending in the root ([teamEventWakesManagerOf]). func teamWakes(role teamRole, entry teams.Entry) bool { if !role.joinedAt.IsZero() && entry.At.Before(role.joinedAt) { return false @@ -525,7 +521,7 @@ func teamWakes(role teamRole, entry teams.Entry) bool { case teams.KindNote: return entry.To == teams.ToManager && strings.TrimSpace(entry.Text) != "" case teams.KindEvent: - return teamEventWakesManagerOf(role.quietEnding(entry.Member), entry.State, entry.Text) + return teamEventWakesManagerOf(role.root, entry.State, entry.Text) } return false } diff --git a/internal/session/teamevent.go b/internal/session/teamevent.go index 12fedb9e56..62c831e1b5 100644 --- a/internal/session/teamevent.go +++ b/internal/session/teamevent.go @@ -184,7 +184,7 @@ func (a *Agent) writeTeamEvent(event teamEvent) { if err != nil || !role.wakes { continue } - if teamEventWakesManagerOf(role.quietEnding(role.key), event.state, text) { + if teamEventWakesManagerOf(role.root, event.state, text) { // These wake the manager, so a manager nobody has open is opened // (team_wakewatch.go). a.rouseManager(profile, role, event.origin.provenance(role.key))