From 8557a1b448e76cddb73fda1e1485675180144006 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Mon, 16 Nov 2026 21:06:59 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Betty=20closes=20the=20loop?= =?UTF-8?q?=20on=20deep=20dives;=20research=20agents=20survive=20reconcile?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit research-1..N are added to the runtime only (not hive.yaml), and ReconcileAgents (config reload, reviewer autoscale) removes every agent not in the enabled config set, so the pool was emptied shortly after boot and each meeting research request failed with "no research agent available" while nothing was said in the meeting. - cmd/hive: the reconcile set carries the research pool's agents. - research.Pool: a dispatch that finds no agent re-registers them once; ErrNoAgents carries a sayable Reason; Status() for the settings page. - live: a persona deep dive that cannot start, errors, or runs past 5 minutes is answered with "I couldn't look that up: ." in the channel it was asked in; one progress note after 30 s; a spoken question's follow-up is spoken. - Settings, Meeting attendee: Research section with agents, availability and a "No research agent available" warning. Part of hivecommons/hive#18590 Signed-off-by: Andy Anderson --- ...xed-18590-betty-research-close-the-loop.md | 1 + src/cmd/hive/main.go | 5 +- src/cmd/hive/meetings_research.go | 94 ++++++++-- src/cmd/hive/meetings_research_test.go | 57 ++++++ src/cmd/hive/reviewer_autoscale.go | 2 +- src/docs/api-reference/knowledge.md | 8 +- src/docs/meetings.md | 4 +- src/pkg/dashboard/api_meetings_persona.go | 6 + src/pkg/dashboard/api_meetings_research.go | 85 +++++++++ .../dashboard/api_meetings_research_test.go | 41 +++++ .../static-src/js/meeting-attendee.js | 20 ++- src/pkg/dashboard/static/index.html | 20 ++- src/pkg/meetings/betty/betty.go | 35 +++- src/pkg/meetings/betty/voice.go | 16 ++ src/pkg/meetings/live/deepdive_test.go | 169 ++++++++++++++++++ src/pkg/meetings/live/runner.go | 24 +++ src/pkg/meetings/live/session.go | 99 +++++++++- src/pkg/meetings/live/types.go | 16 +- src/pkg/research/pool.go | 70 +++++++- src/pkg/research/pool_test.go | 49 ++++- 20 files changed, 782 insertions(+), 39 deletions(-) create mode 100644 changelog.d/fixed-18590-betty-research-close-the-loop.md create mode 100644 src/pkg/dashboard/api_meetings_research.go create mode 100644 src/pkg/dashboard/api_meetings_research_test.go create mode 100644 src/pkg/meetings/live/deepdive_test.go diff --git a/changelog.d/fixed-18590-betty-research-close-the-loop.md b/changelog.d/fixed-18590-betty-research-close-the-loop.md new file mode 100644 index 0000000000..991c97acf1 --- /dev/null +++ b/changelog.d/fixed-18590-betty-research-close-the-loop.md @@ -0,0 +1 @@ +- **Betty always closes the loop on a deep dive, and meeting research finds its agents again.** The research agents (`research-1..N`) live only in the runtime, so every config reload or reviewer autoscale step removed them and each later research request failed silently with "no research agent available"; they are now kept across reconciles, and a dispatch that finds none registers them again. When a deep dive cannot start, the agent reports an error, or it runs past 5 minutes, Betty says "I couldn't look that up: ." in the channel she was asked in (spoken for a spoken question); one running past 30 seconds gets one "still looking" note, and a spoken question's answer is spoken. Settings, Meeting attendee shows the research agents, how many are available, and a "No research agent available" warning. ([#18590](https://github.com/hivecommons/hive/issues/18590)) diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index c630962fde..ed7f538ac7 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -3590,6 +3590,9 @@ func (b *boot) bootDashboardAPIWith(deps bootDashboardAPIDeps) { rt = b.agentMgr } researchPool := wireMeetingsResearch(b.cfg, rt, b.logger) + if fn := meetingsResearchStatus(b.cfg, researchPool); fn != nil { + b.dashSrv.SetMeetingsResearchStatus(fn) + } if lr := wireMeetingsLive(b.cfg, mgr, store, b.knowledgeAPI, func() map[string]*beads.Store { return b.beadStores }, researchPool, b.logger, b.dashSrv.HiveStatusBrief); lr != nil { b.meetingsLive = lr b.cleanup.push(lr.Close) @@ -4004,7 +4007,7 @@ func (b *boot) bootWatchersWith(deps bootWatchersDeps) { if err := b.cfg.ExpandAgentReplicas(); err != nil { b.logger.Warn("failed to expand agent replicas after config reload", "error", err) } - addedAgents := b.agentMgr.ReconcileAgents(b.cfg.EnabledAgents()) + addedAgents := b.agentMgr.ReconcileAgents(withResearchAgents(b.cfg.EnabledAgents())) for _, added := range addedAgents { if ac, ok := b.cfg.Agents[added]; ok && !ac.OnDemand { deps.startAgent(b.ctx, b.agentMgr, added, b.logger) diff --git a/src/cmd/hive/meetings_research.go b/src/cmd/hive/meetings_research.go index 762b32a383..192534d3ed 100644 --- a/src/cmd/hive/meetings_research.go +++ b/src/cmd/hive/meetings_research.go @@ -3,9 +3,12 @@ package main import ( "errors" "log/slog" + "maps" "sort" + "sync/atomic" "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/dashboard" "github.com/hivecommons/hive/pkg/meetings/live" "github.com/hivecommons/hive/pkg/research" ) @@ -14,22 +17,53 @@ import ( // the research agents reuse (hivecommons/hive#18294). const meetingsResearchBaseAgent = "scanner" +// researchBaseName is the configured agent researchBase copies from, "" +// when there is none. +func researchBaseName(cfg *config.Config) string { + if cfg == nil || len(cfg.Agents) == 0 { + return "" + } + if _, ok := cfg.Agents[meetingsResearchBaseAgent]; ok { + return meetingsResearchBaseAgent + } + names := make([]string, 0, len(cfg.Agents)) + for n := range cfg.Agents { + names = append(names, n) + } + sort.Strings(names) + return names[0] +} + +// researchStatusSource is the slice of *research.Pool the settings page +// reads. +type researchStatusSource interface { + Status() research.Status +} + +// meetingsResearchStatus reports the pool for Settings, Meeting attendee, +// or nil when d is not a pool. +func meetingsResearchStatus(cfg *config.Config, d live.ResearchDispatcher) dashboard.MeetingsResearchStatusFunc { + src, ok := d.(researchStatusSource) + if !ok { + return nil + } + base := researchBase(cfg) + name := researchBaseName(cfg) + return func() dashboard.MeetingsResearchStatus { + st := src.Status() + return dashboard.MeetingsResearchStatus{Agents: st.Agents, Available: st.Available, BaseAgent: name, Backend: base.Backend, Model: base.Model} + } +} + // researchBase picks the backend and model for research-1..N: the scanner's // when it exists, else the first configured agent's by name. Only those two // fields are copied; research.AgentConfig forces the read-only rest. func researchBase(cfg *config.Config) config.AgentConfig { - if cfg == nil || len(cfg.Agents) == 0 { + name := researchBaseName(cfg) + if name == "" { return config.AgentConfig{} } - a, ok := cfg.Agents[meetingsResearchBaseAgent] - if !ok { - names := make([]string, 0, len(cfg.Agents)) - for n := range cfg.Agents { - names = append(names, n) - } - sort.Strings(names) - a = cfg.Agents[names[0]] - } + a := cfg.Agents[name] return config.AgentConfig{Backend: a.Backend, Model: a.Model} } @@ -53,13 +87,51 @@ func wireMeetingsResearch(cfg *config.Config, rt any, logger *slog.Logger) live. } return nil } - pool.Ensure(researchBase(cfg)) + base := researchBase(cfg) + pool.Ensure(base) + keepResearchAgents(pool.Agents(), research.AgentConfig(base)) if logger != nil { logger.Info("[meetings] research pool ready", "agents", pool.Agents()) } return pool } +// researchAgents is the research pool's agent set once it is wired. The +// agents are runtime-only (not in hive.yaml), so every ReconcileAgents call +// (config reload, reviewer autoscale) must carry them, or it removes them as +// "no longer configured" and every meeting research request then fails with +// "no research agent available" (hivecommons/hive#18590 finding 6). +var researchAgents atomic.Pointer[map[string]config.AgentConfig] + +// keepResearchAgents records the pool's agents for withResearchAgents. +func keepResearchAgents(names []string, cfg config.AgentConfig) { + set := make(map[string]config.AgentConfig, len(names)) + for _, n := range names { + set[n] = cfg + } + researchAgents.Store(&set) +} + +// withResearchAgents returns configs plus the research pool's agents (when +// the pool is wired and a name is not already configured), for +// ReconcileAgents. configs is not modified. +func withResearchAgents(configs map[string]config.AgentConfig) map[string]config.AgentConfig { + set := researchAgents.Load() + if set == nil || len(*set) == 0 { + return configs + } + out := maps.Clone(configs) + if out == nil { + out = make(map[string]config.AgentConfig, len(*set)) + } + for n, c := range *set { + if _, ok := out[n]; !ok { + out[n] = c + } + } + return out +} + // researchObserver is the slice of *research.Pool that reports progress. type researchObserver interface { Observe(fn func(research.Event)) (remove func()) diff --git a/src/cmd/hive/meetings_research_test.go b/src/cmd/hive/meetings_research_test.go index ec9dfaca30..a4fd794a23 100644 --- a/src/cmd/hive/meetings_research_test.go +++ b/src/cmd/hive/meetings_research_test.go @@ -85,6 +85,7 @@ func TestWireMeetingsResearch(t *testing.T) { if d := wireMeetingsResearch(on, struct{}{}, discardLogger()); d != nil { t.Fatal("an unsupported runtime must leave research unwired") } + t.Cleanup(func() { researchAgents.Store(nil) }) rt := &fakeResearchRuntime{added: map[string]config.AgentConfig{}} d := wireMeetingsResearch(on, rt, discardLogger()) if d == nil || len(rt.added) != 3 { @@ -126,6 +127,7 @@ func (s *fakeSpekForResearch) Lines() <-chan []byte { return s.lines } func (s *fakeSpekForResearch) Close(any) {} func TestRouteResearch(t *testing.T) { + t.Cleanup(func() { researchAgents.Store(nil) }) if remove := routeResearch(nil, nil); remove == nil { t.Fatal("always returns a func") } @@ -174,3 +176,58 @@ func newResearchTestRunner(t *testing.T, d live.ResearchDispatcher) *live.Runner t.Cleanup(lr.Close) return lr } + +// TestWithResearchAgentsSurvivesReconcile pins hivecommons/hive#18590 +// finding 6: the research agents are runtime-only, so the reconcile set +// must carry them or a config reload removes them. +func TestWithResearchAgentsSurvivesReconcile(t *testing.T) { + t.Cleanup(func() { researchAgents.Store(nil) }) + researchAgents.Store(nil) + cfgs := map[string]config.AgentConfig{"scanner": {Backend: "claude"}} + if got := withResearchAgents(cfgs); len(got) != 1 { + t.Fatalf("unwired pool adds nothing: %v", got) + } + on := &config.Config{Meetings: config.MeetingsConfig{Enabled: true, ResearchPoolSize: 2}, Agents: cfgs} + if wireMeetingsResearch(on, &fakeResearchRuntime{added: map[string]config.AgentConfig{}}, nil) == nil { + t.Fatal("pool not wired") + } + got := withResearchAgents(cfgs) + if len(got) != 3 || got["research-1"].Mode != research.Mode || got["research-2"].Role != research.Role || got["scanner"].Backend != "claude" { + t.Fatalf("reconcile set = %+v", got) + } + if len(cfgs) != 1 { + t.Fatal("the caller's map is not modified") + } + // A configured agent of the same name wins. + cfgs["research-1"] = config.AgentConfig{Backend: "copilot"} + if withResearchAgents(cfgs)["research-1"].Backend != "copilot" { + t.Fatal("hive.yaml wins over the pool's default") + } + if got := withResearchAgents(nil); len(got) != 2 { + t.Fatalf("nil configs = %v", got) + } +} + +func TestMeetingsResearchStatus(t *testing.T) { + if meetingsResearchStatus(nil, nil) != nil { + t.Fatal("no pool, no report") + } + t.Cleanup(func() { researchAgents.Store(nil) }) + cfg := &config.Config{Meetings: config.MeetingsConfig{Enabled: true, ResearchPoolSize: 2}, + Agents: map[string]config.AgentConfig{"scanner": {Backend: "claude", Model: "m1"}, "a": {Backend: "codex"}}} + d := wireMeetingsResearch(cfg, &fakeResearchRuntime{added: map[string]config.AgentConfig{}}, nil) + fn := meetingsResearchStatus(cfg, d) + if fn == nil { + t.Fatal("a pool reports") + } + st := fn() + if len(st.Agents) != 2 || st.Available != 2 || st.BaseAgent != "scanner" || st.Backend != "claude" || st.Model != "m1" { + t.Fatalf("status = %+v", st) + } + if got := researchBaseName(&config.Config{Agents: map[string]config.AgentConfig{"b": {}, "a": {}}}); got != "a" { + t.Fatalf("first by name, got %q", got) + } + if researchBaseName(nil) != "" { + t.Fatal("nil config") + } +} diff --git a/src/cmd/hive/reviewer_autoscale.go b/src/cmd/hive/reviewer_autoscale.go index b17ea24706..2c6bf139b0 100644 --- a/src/cmd/hive/reviewer_autoscale.go +++ b/src/cmd/hive/reviewer_autoscale.go @@ -191,7 +191,7 @@ func (r *reviewerAutoscaleRuntime) reconcile(ctx context.Context, cfg *config.Co } } enabled := cfg.EnabledAgents() - for _, added := range agentMgr.ReconcileAgents(enabled) { + for _, added := range agentMgr.ReconcileAgents(withResearchAgents(enabled)) { if ac, ok := cfg.Agents[added]; ok && !ac.OnDemand { if err := agentMgr.Start(ctx, added); err != nil { logger.Warn("reviewer autoscale: failed to start reviewer", "agent", added, "error", err) diff --git a/src/docs/api-reference/knowledge.md b/src/docs/api-reference/knowledge.md index 2119c50317..a417a420ce 100644 --- a/src/docs/api-reference/knowledge.md +++ b/src/docs/api-reference/knowledge.md @@ -114,10 +114,10 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `POST` | `/api/meetings/actions/{aid}/edit` | Owner or read-write | Change a pending or failed draft: `{type?, title?, body?, repo?}`; the repo must be a monitored one. 404 unknown, 409 already decided. Audited as `meeting_action_edit` | `pkg/dashboard/api_meetings_actions.go:72` | | `POST` | `/api/meetings/actions/{aid}/approve` | Owner or read-write | Create the draft (issue or RFC on GitHub, Spek session through the Inbox `spek_rfc` destination, knowledge note in the `meetings` vault) and report the result to the meeting. Returns the draft, `done` with `result_url` or `failed` with `error`. 409 when it is not pending or failed, or action requests are off. Audited as `meeting_action_approve` | `pkg/dashboard/api_meetings_actions.go:73` | | `POST` | `/api/meetings/actions/{aid}/reject` | Owner or read-write | Reject a pending or failed draft; nothing is created. Audited as `meeting_action_reject` | `pkg/dashboard/api_meetings_actions.go:74` | -| `GET` | `/api/meetings/persona` | Owner or read-write | Settings, Meeting attendee: `{effective, presets, overridden, voices, voice_types, restart_required, running, tts_configured, email}`. `effective` is the resolved persona (fields resolved as if on, `enabled` separately) with the rendered `intro` and `voice_on_address`; `presets` lists the built-in personas, the default first; `overridden` maps each `meetings.persona` key not taken from the preset or defaults to `config` or `env`; `voices` are the Kokoro voices with language, accent and voice type; `restart_required` is true when the saved persona differs from the one the hive booted with; `email` is the attendee address (`hive@`), the access list with registered calendar emails and proof status, the approval queue and the email-in switches (`available: false` until email-in is enabled). See [Meeting attendee settings](../meetings.md#meeting-attendee-settings) | `pkg/dashboard/api_meetings_persona.go:164` | -| `PUT` | `/api/meetings/persona` | Owner or read-write | Save `meetings.persona` to `hive.yaml`: `{enabled?, preset?, clear_overrides?, name?, display_name?, aliases?, pronouns?, language?, voice?, voice_type?, accent?, intro_template?, leave_phrases?, humor?, unprompted?: {per_10m?, min_gap_s?, per_meeting?, answer_wait_s?, min_confidence?, queue_depth?, stale_s?}, voice_on_address?}`. An absent field is unchanged, an empty one (or 0 for a cap) clears the override, a value equal to the preset's is stored as no override, and `clear_overrides` drops every field override first. Validated as if the persona were on; returns the GET body. 400 invalid. Audited as `meetings_persona`. An optional `email: {calendar_invites?, mail_in_files?}` sets `meetings.email.invites_enabled` / `files_enabled` (owner only, else 403; [#18395](https://github.com/hivecommons/hive/issues/18395)) | `pkg/dashboard/api_meetings_persona.go:165` | -| `POST` | `/api/meetings/persona/sample` | Owner or read-write | Speak a short line through the meetings TTS service (Kokoro `POST /v1/audio/speech`) and return the audio (`audio/mpeg`, at most 2 MiB, `Cache-Control: no-store`). Optional `{voice?, language?, display_name?, text?}` (unsaved form values; `text` at most 200 characters, default the persona's sample line in its language). 503 "TTS not configured" until `meetings.tts_url` is set, 400 invalid, 502 the TTS service failed | `pkg/dashboard/api_meetings_persona.go:166` | -| `GET` | `/api/meetings/persona/sample` | Owner or read-write | The same sample with `voice`, `language`, `display_name` and `text` as query parameters, for the dashboard's `