Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Backend hotfix: the confidential sets are built once per read, not once per person per agent (#4504) (#3543)

0xken15f93d91287151
diff --git a/backend/src/superTabs/confidential.ts b/backend/src/superTabs/confidential.ts
index 2c91e8493..db148272b 100644
--- a/backend/src/superTabs/confidential.ts
+++ b/backend/src/superTabs/confidential.ts
@@ -2,7 +2,7 @@ import type { Prisma } from '@prisma/client'
import { SuperTabError, type Agent, type SuperTabState } from './model.js'
import { RETRYABLE_SWARM_CODES } from './retry.js'
import { loadActive, reassemble } from './parts/index.js'
-import { confidentialSession, sessionKey, type OtherRegistrations } from './projects.js'
+import { confidentialSession, confidentialSets, sessionKey, type OtherRegistrations } from './projects.js'
import { bindSession, sessionRecordId } from './sessionScope.js'
type Transaction = Prisma.TransactionClient
@@ -44,7 +44,9 @@ export async function confidentialSessions(tx: Transaction, agentIds: string[],
busyClosed(tabId)
continue
}
- for (const target of state.agents) if (pending.includes(target.id) && confidentialSession(state, target)) found.add(target.id)
+ // One build of the sets for all of them, not one per agent (task #4504).
+ const sets = confidentialSets(state)
+ for (const target of state.agents) if (pending.includes(target.id) && confidentialSession(state, target, sets)) found.add(target.id)
}
return found
}
@@ -66,7 +68,8 @@ export async function otherRegistrations(tx: Transaction, state: SuperTabState,
}
for (const [tabId, targets] of unmarked) {
const there = reassemble(await loadActive(tx, tabId, { agentIds: targets.map(t => t.id) }))
- for (const target of there.agents) if (targets.some(t => t.id === target.id) && confidentialSession(there, target)) confidential.add(sessionKey(target.machineId, target.harnessId))
+ const sets = confidentialSets(there)
+ for (const target of there.agents) if (targets.some(t => t.id === target.id) && confidentialSession(there, target, sets)) confidential.add(sessionKey(target.machineId, target.harnessId))
}
return { registered, confidential }
}
diff --git a/backend/src/superTabs/projects.ts b/backend/src/superTabs/projects.ts
index 6736b0cfb..c8cc220c6 100644
--- a/backend/src/superTabs/projects.ts
+++ b/backend/src/superTabs/projects.ts
@@ -475,16 +475,18 @@ export function canReadAgent(state: SuperTabState, actor: Actor, target: Agent):
/** A session that reads people's private messages: its project's Lead (the Product Manager each person chats with privately),
* or any agent in a private conversation, so a replaced Lead's earlier screen stays closed too. */
-export const confidentialSession = (state: SuperTabState, target: Agent): boolean => {
- const { leaders, privateMembers } = confidentialSets(state)
- return leaders.has(target.id) || privateMembers.has(target.id)
-}
+export const confidentialSession = (state: SuperTabState, target: Agent, sets: ConfidentialSets = confidentialSets(state)): boolean =>
+ sets.leaders.has(target.id) || sets.privateMembers.has(target.id)
+
+/** confidentialSets' answer. A caller that asks about many agents or readers of one state builds it once and passes it down
+ * (task #4504: the host roster rebuilt it for each person on each agent, agents x people passes over the conversations). */
+export interface ConfidentialSets { leaders: ReadonlySet<string>; privateMembers: ReadonlySet<string> }
/** Who confidentialSession holds confidential, for every agent at once: the Leads of a project's Lead conversation, and every
* member of a private conversation (one with an audience). One pass over the conversations: asking per agent scanned them
* per project and agent on every command (markConfidential), 13.5 M of ledProject's callbacks and 1.6 M of the private
* member check's in the 2026-11-02 prod profiles. Built per call, never kept on the state, since a command changes it. */
-export function confidentialSets(state: SuperTabState): { leaders: ReadonlySet<string>; privateMembers: ReadonlySet<string> } {
+export function confidentialSets(state: SuperTabState): ConfidentialSets {
const leadChats = new Set(projectsOf(state).map(p => p.leadConversationId))
const leaders = new Set<string>(), privateMembers = new Set<string>()
for (const c of state.conversations) {
@@ -495,8 +497,8 @@ export function confidentialSets(state: SuperTabState): { leaders: ReadonlySet<s
}
/** Whether an agent's session is confidential: marked, or a Lead or private member now, here or (`elsewhere`) in another Swarm. */
-export const isConfidential = (state: SuperTabState, target: Agent, elsewhere = false): boolean =>
- !!target.confidential || elsewhere || confidentialSession(state, target)
+export const isConfidential = (state: SuperTabState, target: Agent, elsewhere = false, sets?: ConfidentialSets): boolean =>
+ !!target.confidential || elsewhere || confidentialSession(state, target, sets)
/** A native session's identity across Swarms: its machine and harness. */
export const sessionKey = (machineId: string, harnessId: string) => `${machineId}\n${harnessId}`
@@ -535,16 +537,16 @@ export function markConfidential(state: SuperTabState): void {
* the exception, view only (Ken, 2026-10-28): every reader of its project watches it, the private chats it is in included.
* It stays marked, so a former Lead, another Swarm and an ordinary share still find it closed. `elsewhere`: the session is
* confidential in another Swarm (confidential.ts), whose chats are not this Swarm's to read. */
-export const watchClosed = (state: SuperTabState, target: Agent, elsewhere = false): boolean =>
- elsewhere || (isConfidential(state, target) && !ledProject(state, target.id))
+export const watchClosed = (state: SuperTabState, target: Agent, elsewhere = false, sets?: ConfidentialSets): boolean =>
+ elsewhere || (isConfidential(state, target, false, sets) && !ledProject(state, target.id))
/** Who may watch an agent's terminal: observe it or hold a share of it. Reading or typing in it on request is closed by
* `isConfidential` alone (terminal.ts mayDrive). Any other agent: every reader of its project, as before. */
-export function canWatchAgent(state: SuperTabState, actor: Actor, target: Agent, elsewhere = false): boolean {
+export function canWatchAgent(state: SuperTabState, actor: Actor, target: Agent, elsewhere = false, sets?: ConfidentialSets): boolean {
if (!canReadAgent(state, actor, target)) return false
- const team = teamSessionAccess(state, actor, target, elsewhere)
+ const team = teamSessionAccess(state, actor, target, elsewhere, sets)
if (team) return team !== 'none'
- return !watchClosed(state, target, elsewhere) || ownSession(actor, target)
+ return !watchClosed(state, target, elsewhere, sets) || ownSession(actor, target)
}
/** Whether [pool] is a Harness Team account: a Mac's (it names its Mac) or a machine used only for agents (its reading came
@@ -588,11 +590,11 @@ export function wordsOf(source: unknown): 'author' | 'none' | 'unknown' | { agen
* Other members watch it as they watch any confidential session (watchClosed). Null for every other session, and for
* agents, which keep their own rules (mayDrive).
*/
-export function teamSessionAccess(state: SuperTabState, actor: Actor, target: Agent, elsewhere = false): 'watch' | 'none' | 'member' | null {
- if (!onTeamAccount(state, target) || actor.kind !== 'person' || !isConfidential(state, target, elsewhere)) return null
+export function teamSessionAccess(state: SuperTabState, actor: Actor, target: Agent, elsewhere = false, sets?: ConfidentialSets): 'watch' | 'none' | 'member' | null {
+ if (!onTeamAccount(state, target) || actor.kind !== 'person' || !isConfidential(state, target, elsewhere, sets)) return null
if (ownsProject(state, actor.userId, projectOf(state, agentProjectId(state, target)))) return 'watch'
if (actor.userId === target.machineOwnerId) return 'none'
- return watchClosed(state, target, elsewhere) ? 'none' : 'member'
+ return watchClosed(state, target, elsewhere, sets) ? 'none' : 'member'
}
/** Who could watch an agent's terminal before a commit and cannot after it (canWatchAgent, by the session the observer relay
@@ -602,12 +604,10 @@ export function teamSessionAccess(state: SuperTabState, actor: Actor, target: Ag
export function watchersLost(before: SuperTabState, after: SuperTabState): Array<{ agentId: string; personIds: string[] }> {
const session = (a: Agent) => `${a.machineId}\n${a.harnessId}\n${a.machineOwnerId}`
const now = new Map(after.agents.map(a => [session(a), a]))
- // canWatchAgent per person, with whether the agent is closed read once per state.
- const watchers = (state: SuperTabState, target: Agent) => {
- const closed = watchClosed(state, target)
- return state.people.map(p => ({ kind: 'person' as const, userId: p.id, email: p.email }))
- .filter(actor => canWatchAgent(state, actor, target))
- }
+ // canWatchAgent per person, with the confidential sets built once per state, not once per person per agent (task #4504).
+ const sets = new Map<SuperTabState, ConfidentialSets>([[before, confidentialSets(before)], [after, confidentialSets(after)]])
+ const watchers = (state: SuperTabState, target: Agent) => state.people.map(p => ({ kind: 'person' as const, userId: p.id, email: p.email }))
+ .filter(actor => canWatchAgent(state, actor, target, false, sets.get(state)))
return before.agents.flatMap(target => {
const was = watchers(before, target)
if (!was.length) return []
diff --git a/backend/src/superTabs/read/hostRows.ts b/backend/src/superTabs/read/hostRows.ts
index 2d7451426..6cfee226f 100644
--- a/backend/src/superTabs/read/hostRows.ts
+++ b/backend/src/superTabs/read/hostRows.ts
@@ -9,7 +9,7 @@ import { activeWork, agent, isLeads, SuperTabError, conversation, type Agent, ty
import { buddyChatOf, isSwarmBuddy, isSwarmBuddyChat } from '../buddies.js'
import { buddyEngineChat } from '../buddyEngine.js'
import { hostLocalGrid, machineContribution, machineLimitReached, machineRoom, type MachineCleanup } from '../machines.js'
-import { agentProjectId, agentSetRole, canWatchAgent, isConfidential, groupProject, ledProject, projectsOf, skillModeOf, startProject, skillSetOf, watchClosed } from '../projects.js'
+import { agentProjectId, agentSetRole, canWatchAgent, confidentialSets, isConfidential, groupProject, ledProject, projectsOf, skillModeOf, startProject, skillSetOf, watchClosed, type ConfidentialSets } from '../projects.js'
import type { HostAgentRow, HostPool, HostRosterRow, HostTabRows } from './contract.js'
import { hostEtag } from './hostEtag.js'
import { coordinatorNameOf, FIRST_INSTRUCTIONS, instructionsHash, roleNameOf } from '../instructions.js'
@@ -56,9 +56,11 @@ async function roster(tabId: string, state: SuperTabState, machineId: string, us
for (const team of missing.slice(0, machineRoom(state, user.sub, { team: true }))) {
rows.push({ tabId, joinTeam: { machineId: team.machineId, name: mac!.name, maxAgents: mac!.maxAgents } })
}
+ // Once per read: each row asks it for each person (task #4504). The state is this read's own, so nothing changes it meanwhile.
+ const sets = confidentialSets(state)
for (const target of state.agents.filter(a => a.machineId === machineId && a.machineOwnerId === user.sub)) {
try { agent(state, target.id); await lookups.agentGrant(target) } catch (error) { if (error instanceof SuperTabError) continue; throw error }
- rows.push(agentRow(tabId, state, machineId, user, lastChangedAt, lookups, target))
+ rows.push(agentRow(tabId, state, machineId, user, lastChangedAt, lookups, target, sets))
}
for (const { agentId: id, harnessId } of (state.closingSessions ?? []).filter(c => c.machineId === machineId && c.machineOwnerId === user.sub)) {
rows.push({ tabId, agent: { id, harnessId, machineId }, closeSession: true, active: false })
@@ -68,7 +70,8 @@ async function roster(tabId: string, state: SuperTabState, machineId: string, us
return rows
}
-function agentRow(tabId: string, state: SuperTabState, machineId: string, user: AuthUser, lastChangedAt: number | null, lookups: HostLookups, target: Agent): HostAgentRow {
+function agentRow(tabId: string, state: SuperTabState, machineId: string, user: AuthUser, lastChangedAt: number | null, lookups: HostLookups, target: Agent,
+ sets: ConfidentialSets): HostAgentRow {
const closed = lookups.confidential.has(target.id)
const waiting = state.conversations.find(c => activeWork(c) && c.assignment!.agentId === target.id &&
c.assignment!.execution.machineId === machineId && ['needs_human', 'blocked'].includes(c.assignment!.status))?.assignment
@@ -115,12 +118,12 @@ function agentRow(tabId: string, state: SuperTabState, machineId: string, user:
ledConversationId: ledProject(state, target.id)?.leadConversationId ?? null,
...(isSwarmBuddy(target) && !target.buddySession ? { buddyConversationId: buddyChat?.id ?? buddyEngineChat(state, target) } : {}),
stopRequested: target.workDecision === 'stop' && !state.conversations.some(c => activeWork(c) && c.assignment?.agentId === target.id),
- observers: lookups.people.filter(p => p.id !== user.sub && canWatchAgent(state, { kind: 'person', userId: p.id, email: p.email }, target, closed))
+ observers: lookups.people.filter(p => p.id !== user.sub && canWatchAgent(state, { kind: 'person', userId: p.id, email: p.email }, target, closed, sets))
.map(p => ({ email: p.email, userId: p.id })),
// The host refuses every share of a confidential session, ordinary ones too, and remembers it (cli observers.ts).
- confidential: isConfidential(state, target, closed),
+ confidential: isConfidential(state, target, closed, sets),
// But for this Swarm's current Lead: its listed observers watch it while this row is in force (Ken, 2026-10-28).
- membersWatch: isConfidential(state, target, closed) && !watchClosed(state, target, closed),
+ membersWatch: isConfidential(state, target, closed, sets) && !watchClosed(state, target, closed, sets),
// Which of its person's Buddies' chats it is in (task #3818).
...isSwarmBuddy(target) || (target.buddySession && target.buddyOf) ? { buddyChatId: buddyChat?.id ?? null } : {},
}
diff --git a/backend/src/superTabs/read/hostRowsConfidential.test.ts b/backend/src/superTabs/read/hostRowsConfidential.test.ts
new file mode 100644
index 000000000..0e0de0833
--- /dev/null
+++ b/backend/src/superTabs/read/hostRowsConfidential.test.ts
@@ -0,0 +1,126 @@
+import { describe, expect, it } from 'vitest'
+import type { AuthUser } from '../../lib/ssoAuth.js'
+import type { Actor, Conversation, SuperTabState } from '../model.js'
+import { canWatchAgent, isConfidential, watchClosed, watchersLost } from '../projects.js'
+import { hostTab, type HostLookups } from './hostRows.js'
+import { owner, swarm } from './fixture.test-support.js'
+
+// Task #4504 (Ken's prod scan, 11-07 16:20 VN): the host roster asked canWatchAgent for each person on each agent, and every
+// call built confidentialSets with a pass over all the Swarm's conversations, so a read cost agents x people x conversations
+// (1.6 s of self time per 30 s profile at 16h, and growing with tab data). A read now builds the sets once.
+
+const user = { sub: owner.userId, email: owner.email } as AuthUser
+const personId = (i: number) => `2000000000000000000${String(i).padStart(5, '0')}`
+
+/** A Swarm of [people] people, [agents] agents on the owner's machine `host` and [conversations] conversations, with every kind
+ * of confidential session: the Lead, members of private conversations, a marked one, a Team account's, and a private project
+ * only some people read. */
+function seeded({ people, agents, conversations }: { people: number; agents: number; conversations: number }) {
+ const s = swarm()
+ const persons = Array.from({ length: people }, (_, i) => ({ kind: 'person' as const, userId: personId(i), email: `p${i}@example.com` }))
+ for (const person of persons) s.join(person)
+ const secret = s.run({ type: 'project.create', name: 'Secret', visibility: 'private', brief: '' }).projectId as string
+ s.run({ type: 'project.sharing', projectId: secret, visibility: 'private', memberIds: persons.filter((_, i) => i % 3 === 0).map(p => p.userId) })
+ const web = s.group('Web'), hidden = s.group('Hidden', secret)
+ const ids = [s.add('lead-harness', 'lead', true, owner, 'host', owner.userId)]
+ for (let i = 1; i < agents; i++) ids.push(s.add(`h${i}`, i % 4 === 0 ? hidden : web, false, owner, 'host', owner.userId))
+ s.edit(state => {
+ const template = state.conversations.find(c => c.id === web)!
+ for (let i = state.conversations.length; i < conversations; i++) {
+ const members = [ids[(i * 7) % ids.length]!, ids[(i * 11) % ids.length]!]
+ const row: Conversation = { ...structuredClone(template), id: `bulk-${i}`, number: 1000 + i, title: `Task ${i}`, agentIds: members, assignment: null }
+ // Every tenth one private, with an audience of two people.
+ if (i % 10 === 0) row.audience = { people: [persons[i % people]!, persons[(i + 1) % people]!].map(p => ({ id: p.userId, generation: 'g' })) }
+ state.conversations.push(row)
+ }
+ state.agents.find(a => a.id === ids[2 % ids.length])!.confidential = true
+ state.agents.find(a => a.id === ids[3 % ids.length])!.teamAccount = true
+ })
+ const lookups = (confidential: string[] = []): HostLookups => ({
+ people: [{ id: owner.userId, email: owner.email }, ...persons.map(p => ({ id: p.userId, email: p.email }))],
+ confidential: new Set(confidential), agentGrant: async () => {}, teams: [], githubApp: false,
+ })
+ return { state: s.state, persons, ids, lookups }
+}
+
+/** How often a read looks at whether a conversation is private: once per conversation for one build of the sets. */
+function countingAudienceReads(state: SuperTabState): { state: SuperTabState; reads: () => number } {
+ let reads = 0
+ const conversations = state.conversations.map(c => new Proxy(c, {
+ get: (target, key, receiver) => { if (key === 'audience') reads++; return Reflect.get(target, key, receiver) },
+ }))
+ return { state: { ...state, conversations }, reads: () => reads }
+}
+
+describe('the host roster\'s confidential sets (task #4504)', () => {
+ it('are built once per read: the passes over conversations do not grow with agents or people', async () => {
+ const passes = async (people: number, agents: number) => {
+ const { state, lookups } = seeded({ people, agents, conversations: 200 })
+ const counted = countingAudienceReads(state)
+ await hostTab('tab', counted.state, 'host', user, null, lookups())
+ return counted.reads() / counted.state.conversations.length
+ }
+ const small = await passes(1, 2)
+ expect(small).toBeLessThanOrEqual(1)
+ expect(await passes(20, 2)).toBe(small)
+ expect(await passes(1, 20)).toBe(small)
+ expect(await passes(20, 20)).toBe(small)
+ })
+
+ it('give every reader exactly the answers each check gave on its own', async () => {
+ const { state, ids, lookups } = seeded({ people: 12, agents: 16, conversations: 120 })
+ const elsewhere = [ids[5]!]
+ const rows = (await hostTab('tab', state, 'host', user, null, lookups(elsewhere))).roster.flatMap(r => 'agent' in r && 'observers' in r ? [r] : [])
+ expect(rows.length).toBe(ids.length)
+ const people = lookups().people
+ for (const row of rows) {
+ const target = state.agents.find(a => a.id === row.agent.id)!
+ const closed = elsewhere.includes(target.id)
+ expect(row.observers, target.id).toEqual(people.filter(p => p.id !== user.sub
+ && canWatchAgent(state, { kind: 'person', userId: p.id, email: p.email }, target, closed)).map(p => ({ email: p.email, userId: p.id })))
+ expect(row.confidential, target.id).toBe(isConfidential(state, target, closed))
+ expect(row.membersWatch, target.id).toBe(isConfidential(state, target, closed) && !watchClosed(state, target, closed))
+ }
+ // The seeded store holds both answers, so the comparison means something.
+ expect(rows.some(r => r.confidential) && rows.some(r => !r.confidential)).toBe(true)
+ expect(rows.some(r => r.observers.length > 0) && rows.some(r => r.observers.length < people.length - 1)).toBe(true)
+ })
+})
+
+describe('who loses the watch of an agent after a commit (task #4504)', () => {
+ /** watchersLost as it read before: canWatchAgent for each person on each agent, each building its own sets. */
+ function naiveLost(before: SuperTabState, after: SuperTabState) {
+ const session = (a: SuperTabState['agents'][number]) => `${a.machineId}\n${a.harnessId}\n${a.machineOwnerId}`
+ const now = new Map(after.agents.map(a => [session(a), a]))
+ const watchers = (state: SuperTabState, target: SuperTabState['agents'][number]) =>
+ state.people.map((p): Actor => ({ kind: 'person', userId: p.id, email: p.email })).filter(actor => canWatchAgent(state, actor, target))
+ return before.agents.flatMap(target => {
+ const was = watchers(before, target)
+ if (!was.length) return []
+ const still = now.get(session(target))
+ const is = new Set(still ? watchers(after, still).map(a => (a as Extract<Actor, { kind: 'person' }>).userId) : [])
+ const personIds = was.map(a => (a as Extract<Actor, { kind: 'person' }>).userId).filter(id => !is.has(id))
+ return personIds.length ? [{ agentId: target.id, personIds }] : []
+ })
+ }
+
+ it('gives the same answer, with one pass over each state\'s conversations however many agents and people', () => {
+ const { state: before, ids } = seeded({ people: 12, agents: 16, conversations: 120 })
+ const after = structuredClone(before)
+ // A worker joins a private conversation, which makes it confidential: its readers lose its screen.
+ after.conversations.find(c => c.audience)!.agentIds.push(ids[6]!)
+ after.agents.find(a => a.id === ids[7])!.confidential = true
+ expect(watchersLost(before, after)).toEqual(naiveLost(before, after))
+ expect(watchersLost(before, after).length).toBeGreaterThan(0)
+
+ const passes = (people: number, agents: number) => {
+ const { state } = seeded({ people, agents, conversations: 200 })
+ const a = countingAudienceReads(state), b = countingAudienceReads(structuredClone(state))
+ watchersLost(a.state, b.state)
+ return (a.reads() + b.reads()) / (2 * a.state.conversations.length)
+ }
+ const small = passes(1, 2)
+ expect(small).toBeLessThanOrEqual(1)
+ expect(passes(20, 20)).toBe(small)
+ })
+})
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index bebe5854e..bdee956f4 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -53,7 +53,7 @@ import { retryTransient } from './retry.js'
import { recordReload } from './retryStats.js'
import { buddyChatId, isSwarmBuddyChat, shownBefore, swarmBuddyChatId, type ChosenBuddyName } from './buddies.js'
import { cleanPullRequestLinks } from './cards.js'
-import { accountOf, wordsOf, buddyInstructionsProject, canReadAgent, canReadGroup, groupRepositoryUrl, canWatchAgent, groupProject, ledProject, onTeamAccount, ownerAccount, ownsProject, admitPerson, projectOf, projectsOf, agentProjectId, readConversation, readProject, skillModeOf, startProject, type ProjectVisibility, sessionKey, GITHUB_SEEN, type GitHubSeen, type RepositoryCreation, repositoryCreator, type SwarmProject } from './projects.js'
+import { accountOf, wordsOf, buddyInstructionsProject, canReadAgent, canReadGroup, groupRepositoryUrl, canWatchAgent, confidentialSets, groupProject, ledProject, onTeamAccount, ownerAccount, ownsProject, admitPerson, projectOf, projectsOf, agentProjectId, readConversation, readProject, skillModeOf, startProject, type ProjectVisibility, sessionKey, GITHUB_SEEN, type GitHubSeen, type RepositoryCreation, repositoryCreator, type SwarmProject } from './projects.js'
import { taskProcess } from './process.js'
import { bindSession, makeProjectPrivate } from './sessionScope.js'
import { SESSION_ENDED_KIND, sessionContext, sessionReadsRow, type ContextRow } from './buddySessions.js'
@@ -4675,11 +4675,13 @@ export class SuperTabStore {
// Confidential in another Swarm closes it here too; in this one, its current Lead stays open to readers (projects.ts watchClosed).
const elsewhere = await confidentialSessions(this.db, targets.flatMap(t => t ? [t.id] : []), tabId, this.cachedState, busyListing)
const allowed: T[] = []
+ // Once for every share, not once per share (task #4504).
+ const sets = confidentialSets(state)
for (const [i, share] of shares.entries()) {
const target = targets[i]
if (!target) continue
try { agent(state, target.id) } catch (error) { if (error instanceof SuperTabError) continue; throw error }
- if (canWatchAgent(state, { kind: 'person', userId: user.sub, email: user.email }, target, elsewhere.has(target.id))
+ if (canWatchAgent(state, { kind: 'person', userId: user.sub, email: user.email }, target, elsewhere.has(target.id), sets)
&& await granted(target)) allowed.push(share)
}
return allowed