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/added-18742-customers-agent-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Customers: agents and the meeting persona are told who the work is for (#18742).** When a kick is about an issue whose human author, assignee or claimer is a customer, the prompt gains a `# Customer context` block: their GitHub login, the tags that are on, up to three goals a person confirmed, and a count. It is capped at 1,024 bytes and never holds an email address, an id, notes or the satisfaction assessment; goals the hive inferred and nobody confirmed stay out. Goals are text people typed, so each is scanned by `ioscan` and dropped whole if it holds an address, an id or a recognised attack, and the rest sit in a fenced `untrusted-customer-data` block with a fresh nonce, marked as data. The meeting persona gets a people retriever: when a question names a customer, it can describe them from a name, tags and confirmed goals, and never says notes or the satisfaction assessment aloud. Agents still cannot query the customers store; they only receive this slice. `src/docs/security-model.md` describes the boundary.
46 changes: 46 additions & 0 deletions src/cmd/hive/customerswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"errors"
"fmt"
"log/slog"
"sync/atomic"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/customers"
"github.com/hivecommons/hive/pkg/customers/gql"
"github.com/hivecommons/hive/pkg/dashboard"
"github.com/hivecommons/hive/pkg/meetings/betty"
"github.com/hivecommons/hive/pkg/scheduler"
)

const (
Expand Down Expand Up @@ -164,3 +167,46 @@ func (c *customersDashboard) Graph(ctx context.Context, v dashboard.CustomersVie
func (c *customersDashboard) AnswerHint(v dashboard.CustomersViewer, hintID string, same bool) (dashboard.CustomerResult, error) {
return customerResult(c.svc.AnswerHint(customersViewer(v), hintID, same))
}

// meetingsPeople holds the people directory the meeting persona reads. The
// persona is built before customers are wired, so it asks at call time.
var meetingsPeople atomic.Pointer[customersPeopleDirectory]

func meetingsPeopleDirectory() betty.PeopleDirectory {
if d := meetingsPeople.Load(); d != nil {
return d
}
return nil
}

// customersPeopleDirectory answers the persona's "who is this?" from the
// customers service. The persona speaks in a room, so the directory hands
// over only what customers.PeopleBriefs allows: a name, tags and confirmed
// goals.
type customersPeopleDirectory struct{ svc *customers.Service }

// Find implements betty.PeopleDirectory.
func (d *customersPeopleDirectory) Find(terms []string, limit int) []betty.PersonBrief {
var out []betty.PersonBrief
for _, b := range d.svc.PeopleBriefs(terms, limit) {
out = append(out, betty.PersonBrief{Name: b.Name, Tags: b.Tags, Goals: b.Goals})
}
return out
}

// installCustomersAgentContext hands the customers service to the two
// places agents and the persona read it: the kick prompt and the persona's
// retrievers. Neither can query the store; they receive a bounded slice.
func installCustomersAgentContext(c *customersDashboard, setKickLookup func(scheduler.CustomerContextLookup)) {
if c == nil {
meetingsPeople.Store(nil)
if setKickLookup != nil {
setKickLookup(nil)
}
return
}
meetingsPeople.Store(&customersPeopleDirectory{svc: c.svc})
if setKickLookup != nil {
setKickLookup(c.svc.KickContext)
}
}
56 changes: 56 additions & 0 deletions src/cmd/hive/customerswire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/customers"
"github.com/hivecommons/hive/pkg/dashboard"
"github.com/hivecommons/hive/pkg/meetings/betty"
"github.com/hivecommons/hive/pkg/scheduler"
)

func wireTestCustomers(t *testing.T) *customersDashboard {
Expand Down Expand Up @@ -217,3 +219,57 @@ func TestCustomersAdapterGraph(t *testing.T) {
t.Fatalf("Graph without an engine = %v", err)
}
}

// TestCustomersAgentContextWiring: with customers wired, the kick lookup and
// the persona's directory return the bounded slice; unwired they return
// nothing.
func TestCustomersAgentContextWiring(t *testing.T) {
c := wireTestCustomers(t)
owner := dashboard.CustomersViewer{User: "olivia", Full: true, Owner: true}
ada, err := c.Add(owner, dashboard.CustomerAddRequest{Name: "Ada Lovelace", Identities: []dashboard.CustomerIdentityInput{{Kind: "github", Value: "adal"}, {Kind: "email", Value: "ada@example.com"}}})
if err != nil {
t.Fatal(err)
}
for _, e := range []dashboard.CustomerEditRequest{
{Op: "goal_add", Text: "Ship the engine"},
{Op: "notes", Notes: "private note"},
{Op: "satisfaction_set", Level: "at_risk"},
} {
if _, err := c.Edit(owner, ada.ID, e); err != nil {
t.Fatal(err)
}
}

var lookup scheduler.CustomerContextLookup
installCustomersAgentContext(c, func(fn scheduler.CustomerContextLookup) { lookup = fn })
t.Cleanup(func() { installCustomersAgentContext(nil, func(scheduler.CustomerContextLookup) {}) })
block := lookup([]string{"adal"})
if !strings.HasPrefix(block, customers.KickContextHeader) || !strings.Contains(block, "@adal: Ship the engine") || len(block) > customers.KickContextCap {
t.Fatalf("kick block = %q", block)
}
for _, leak := range []string{"ada@example.com", "private note", "at_risk", ada.ID} {
if strings.Contains(block, leak) {
t.Fatalf("the kick block leaks %q", leak)
}
}
dir := meetingsPeopleDirectory()
if dir == nil {
t.Fatal("no people directory for the persona")
}
got := dir.Find([]string{"lovelace"}, 3)
if len(got) != 1 || got[0].Name != "Ada Lovelace" || len(got[0].Goals) != 1 {
t.Fatalf("persona directory = %+v", got)
}
// The persona retriever sees it through the package-level holder.
hits := betty.PeopleRetriever{Directory: meetingsPeopleDirectory}.Retrieve(context.Background(), "who is lovelace", []string{"lovelace"}, 3)
if len(hits) != 1 || strings.Contains(hits[0].Text, "private note") || strings.Contains(hits[0].Text, "at_risk") {
t.Fatalf("persona snippets = %+v", hits)
}

// Off: nothing is wired and the kick lookup is removed.
var removed = true
installCustomersAgentContext(nil, func(fn scheduler.CustomerContextLookup) { removed = fn == nil })
if !removed || meetingsPeopleDirectory() != nil {
t.Fatal("unwiring left the lookup or the directory in place")
}
}
3 changes: 3 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,9 @@ func (b *boot) bootDashboardAPIWith(deps bootDashboardAPIDeps) {
b.cleanup.push(stop)
b.customers = svc
b.dashSrv.SetCustomersService(svc)
if b.sched != nil {
installCustomersAgentContext(svc, b.sched.SetCustomerContextLookup)
}
}
// #8380: chain GitHub comments/labels behind the relay yank on takeover.
ghClientFn := func() *github.Client { return b.ghClient }
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/meetingswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ func meetingPersonaFactory(cfg *config.Config, persona config.ResolvedMeetingsPe
if beadStores != nil {
retrievers = append(retrievers, betty.BeadRetriever{Stores: beadStores})
}
// Customers the question names (#18742): read at call time, so it is
// empty while customers are off or not yet wired.
retrievers = append(retrievers, betty.PeopleRetriever{Directory: meetingsPeopleDirectory})
client := &http.Client{}
// Web answers (opt-in through searxng_url): SearXNG and the keyless
// direct sources, behind a guard that keeps questions about this hive,
Expand Down
28 changes: 27 additions & 1 deletion src/docs/design/customers.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,33 @@ query it.
and no person ids. Scanned and fenced as untrusted. The pattern is the
maintainer-notes block (`src/pkg/scheduler/kick_maintainer_notes.go`).
- A people retriever for the meeting persona
(`src/pkg/meetings/betty/retrieve.go`).
(`src/pkg/meetings/betty/retrieve_people.go`).

What crosses into a prompt is built in one place, `customers.RenderKickContext`
and `customers.PeopleBriefs`, and the scheduler and the meetings package see
only the finished text or a small struct, never the customers package:

- Only customers; a suggested person is never included. A login is matched on
the exact GitHub identity.
- Only a login, the active tags, up to three goals a person confirmed, and a
count. Never an email, an id, notes or the satisfaction assessment. A goal the
hive inferred and nobody confirmed stays out.
- A goal is text a person typed, so `SafeGoal` scans it with `ioscan`, removes
control characters, and drops the whole goal if it holds anything that looks
like an address or one of this store's ids, or if `ioscan` finds anything.
What remains sits inside one `<untrusted-customer-data nonce="...">` fence
with a fresh nonce, and any fence marker in the text is rewritten.
- The kick block is at most 1,024 bytes, people lines first, and a line that
does not fit is left out rather than cut. The scheduler appends it only when
it starts with the block header, and asks about at most 20 logins.
- The persona's snippet is a name, tags and confirmed goals, nothing else. The
persona speaks in a room that can hold people who are not users, so notes and
the satisfaction assessment have no field to travel in. Betty fences snippets
as data in its own prompt as well.

Retrieval by name here is not identity resolution: a word in a question is
matched against the words of a customer's name or their login to find a profile
to describe, and nothing is linked or created.

**Personal data of people who never signed up.** A hive sees issue authors,
meeting attendees and mail senders who never created an account on it. The
Expand Down
13 changes: 13 additions & 0 deletions src/docs/security-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ envelope before it reaches spektacular or an agent prompt
scanned for them. Session state is pruned and logs are scrubbed
([security.md](security.md)).

Customer profiles follow the same rule. An agent cannot read the customers
store. When a kick is about an issue whose author, assignee or claimer is a
customer, the hive adds one short block to the prompt: their GitHub login, the
tags that are on, and the goals a person confirmed. The block is capped at 1,024
bytes. It never holds an email address, an id, notes or the satisfaction
assessment. A goal is text a person typed, so it is scanned by `ioscan` first. A
goal that holds an address, an id or a recognised attack is dropped whole. The
rest sit inside a fence with a random nonce, marked as data and not as
instructions. The meeting persona gets the same slice for a customer a question
names: a name, tags and confirmed goals. It never says notes or the satisfaction
assessment aloud, because a room can hold people who are not the hive's users.
Goals the hive inferred stay out until a person confirms them.

Untrusted recordings transcribed by the built-in whisper provider are decoded
and transcribed outside the hive process, in the `hive-whisper` sandbox: a
separate `hive-transcribe` uid with no home, shell or supplementary groups,
Expand Down
Loading
Loading