Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-18590-betty-research-close-the-loop.md
Original file line number Diff line number Diff line change
@@ -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: <reason>." 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))
5 changes: 4 additions & 1 deletion src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
94 changes: 83 additions & 11 deletions src/cmd/hive/meetings_research.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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}
}

Expand All @@ -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())
Expand Down
57 changes: 57 additions & 0 deletions src/cmd/hive/meetings_research_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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}, AgentRuntimeConfig: config.AgentRuntimeConfig{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},
AgentRuntimeConfig: config.AgentRuntimeConfig{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{AgentRuntimeConfig: config.AgentRuntimeConfig{Agents: map[string]config.AgentConfig{"b": {}, "a": {}}}}); got != "a" {
t.Fatalf("first by name, got %q", got)
}
if researchBaseName(nil) != "" {
t.Fatal("nil config")
}
}
2 changes: 1 addition & 1 deletion src/cmd/hive/reviewer_autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/docs/api-reference/knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@<dashboard host>`), 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 `<audio>` element (the dashboard CSP has no `media-src`, so audio must come from the dashboard origin) | `pkg/dashboard/api_meetings_persona.go:169` |
| `GET` | `/api/meetings/persona` | Owner or read-write | Settings, Meeting attendee: `{effective, presets, overridden, voices, voice_types, restart_required, running, tts_configured, email, research}`. `research` is the research agent pool Betty's deep dives go to: `{wired, agents, available, base_agent, backend, model, pool_size, warning}`, with `warning` set when no agent can take a request. `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@<dashboard host>`), 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:166` |
| `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:167` |
| `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:168` |
| `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 `<audio>` element (the dashboard CSP has no `media-src`, so audio must come from the dashboard origin) | `pkg/dashboard/api_meetings_persona.go:171` |
| `POST` | `/api/meetings/invites` | Hub relay signature | Calendar invites hive-mx received for `hive@<host>` ([#18395](https://github.com/hivecommons/hive/issues/18395)), relayed by the hub with `X-Hive-Relay-Timestamp`, `X-Hive-Relay-Signature-256` and `X-Hive-Relay-Delivery` (5-minute skew, replay-protected). An invite is scheduled at once when the sender is its organizer, passed DMARC alignment and is on the calendar email allowlist, otherwise it awaits approval; a change or CANCEL for a meeting already on the calendar applies only when authenticated as its organizer. `200 {results[]}`; `409` invites or meetings off; `422` nothing schedulable; `401` bad relay signature. See [Inviting Betty by email](../meetings.md#inviting-betty-by-email) | `pkg/dashboard/api_meetings_email.go:62` |
| `POST` | `/api/meetings/calendar-emails/proof` | Hub relay signature | A proof mail: the address whose pending code is in the subject is proven when the mail came from it and passed DMARC alignment. `200 {proven, email}`; `422` unknown code (shown, sender masked, in the owner's `recent_proof_attempts`), or an expired code, another sender or no DMARC alignment for that address (the reason and SPF/DKIM/alignment summary are recorded on the address as `last_failure`) | `pkg/dashboard/api_meetings_email.go:63` |
| `GET` | `/api/meetings/calendar-emails` | Any role | The signed-in user's calendar emails (`email`, `proven`, `proven_at`, pending `code` and `code_expires_at`, `last_error`, `last_failure` with the refused proof's `reason` (`not_aligned`, `from_mismatch`, `expired`), `at`, the parsed From `from` on a mismatch, SPF/DKIM/alignment results and plain-language `message`, `active`), the hive's `address` and the `invites_enabled` / `files_enabled` switches; the owner also gets `recent_proof_attempts` (unknown-code proof mails, sender masked); `?all=1` adds the whole `allowlist` for the owner (no codes) | `pkg/dashboard/api_meetings_email.go:64` |
Expand Down
Loading
Loading