Skip to content

Commit 6d201b6

Browse files
klopez4212Terp
andcommitted
Count connected humans when ending desktop Huddles
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: klopez4212 <[email protected]>
1 parent deab478 commit 6d201b6

4 files changed

Lines changed: 124 additions & 11 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ this desktop. Keep Buzz and the Codex agent running here; the desktop microphone
3737
does not turn on. Other calls on another device do not seat an agent here.
3838
Leaving on every connected owner device closes the remote voice connection.
3939
When you leave a Huddle you started, desktop also ends it if you are its only
40-
human member and no additional device admission is visible. The ended card's
41-
View action keeps the transcript accessible. Other human members or known
40+
human connected to audio and no additional device admission is visible. The ended card's
41+
View action keeps the transcript accessible. Other connected humans or known
4242
additional devices keep the room open.
4343
If agent voice stops, the compact player and Huddle window show the reason;
4444
leave and rejoin to retry.

‎docs/huddles.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,12 @@ This is a client-only implementation. It uses the existing private ephemeral
222222
channel creation event (9007, TTL 3600), parent announcement (48100), authenticated
223223
`/huddle/{room}/audio` endpoint and v2 Opus wire format. The relay owns participant
224224
join/leave and disconnected-call teardown. On explicit desktop hangup, the client
225-
ends and archives a creator-owned room when fresh relay membership identifies the
226-
viewer as its sole human and the native audio roster has exactly one admission
227-
for that viewer. Known additional devices, other human members, unknown peers,
225+
ends and archives a creator-owned room when the native audio roster identifies
226+
the viewer as its sole human, with exactly one admission for that viewer. Fresh
227+
relay membership classifies bot roles; connected legacy agents are recognized by
228+
verified kind-30177 records from the viewer or room owners. Retained membership
229+
for a human who left audio does not count as attendance. Known additional devices,
230+
other connected humans, unknown peers,
228231
and unavailable membership evidence preserve the room. This is a snapshot check,
229232
not an atomic relay admission fence; concurrent joins still depend on relay cleanup.
230233
It retains room membership for transcript View. Non-creators rely on relay ending

‎src/features/huddle/ending.ts‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,50 @@ export async function endLastHumanHuddle(
5757
)
5858
)
5959
return;
60-
const humans = members.filter((tag) => tag[3] !== "bot");
61-
if (humans.length !== 1 || humans[0]?.[1] !== viewer) return;
6260
// A peer missing from membership evidence may be a newly admitted human.
6361
if (admissions.some((key) => !members.some((tag) => tag[1] === key))) return;
62+
// Membership retains history access; only audio admissions count as present.
63+
const candidates = [...new Set(admissions)].filter(
64+
(key) =>
65+
key !== viewer &&
66+
!members.some((tag) => tag[1] === key && tag[3] === "bot"),
67+
);
68+
if (candidates.length) {
69+
// Match legacy desktop's trust boundary, not self-declared profile hints.
70+
const authors = [
71+
...new Set([
72+
viewer,
73+
...members
74+
.filter((tag) => tag[3] === "owner")
75+
.flatMap((tag) => (tag[1] ? [tag[1]] : [])),
76+
]),
77+
];
78+
const agents = await session.snapshotRead(
79+
[
80+
{
81+
kinds: [30177],
82+
authors,
83+
"#d": candidates,
84+
limit: authors.length * candidates.length,
85+
consistency: "strong",
86+
},
87+
],
88+
{ signal },
89+
);
90+
if (!current()) return;
91+
if (
92+
candidates.some(
93+
(key) =>
94+
!agents.some(
95+
(event) =>
96+
event.kind === 30177 &&
97+
authors.includes(event.pubkey) &&
98+
exactLifecycleTag(event, "d") === key,
99+
),
100+
)
101+
)
102+
return;
103+
}
64104
const id = outbox.send(
65105
{
66106
kind: 48103,

‎src/features/huddle/service.test.ts‎

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,16 @@ describe("explicit last-human hangup", () => {
921921
type: "participants",
922922
participants: [destination.viewer, destination.viewer, botKey.pubkey],
923923
});
924-
if (reason === "another human")
925-
h.snapshotRead.mockResolvedValue(
926-
records([["p", keypair().pubkey, "", "member"]]),
927-
);
924+
if (reason === "another human") {
925+
const human = keypair().pubkey;
926+
h.snapshotRead
927+
.mockResolvedValueOnce(records([["p", human, "", "member"]]))
928+
.mockResolvedValue([]);
929+
h.receive({
930+
type: "participants",
931+
participants: [destination.viewer, botKey.pubkey, human],
932+
});
933+
}
928934
if (reason === "unknown peer")
929935
h.receive({
930936
type: "participants",
@@ -948,6 +954,70 @@ describe("explicit last-human hangup", () => {
948954
expect(h.archive).not.toHaveBeenCalled();
949955
await h.dispose();
950956
});
957+
958+
it.each([
959+
"departed human",
960+
"legacy agent",
961+
"untrusted claim",
962+
"failed lookup",
963+
])(
964+
"classifies audio attendance while retaining history: %s",
965+
async (scenario) => {
966+
const h = await connected();
967+
const other = keypair();
968+
const base = records([["p", other.pubkey, "", "member"]]);
969+
h.snapshotRead.mockResolvedValueOnce(base);
970+
// Both identities remain members. Only a live audio seat affects hangup.
971+
h.receive({
972+
type: "participants",
973+
participants: [destination.viewer, botKey.pubkey, other.pubkey],
974+
});
975+
if (scenario === "departed human")
976+
h.receive({
977+
type: "participants",
978+
participants: [destination.viewer, botKey.pubkey],
979+
});
980+
else if (scenario === "failed lookup")
981+
h.snapshotRead.mockRejectedValueOnce(
982+
new Error("Agent lookup unavailable"),
983+
);
984+
else
985+
h.snapshotRead.mockResolvedValueOnce([
986+
signed(scenario === "legacy agent" ? viewerKey : other, {
987+
kind: 30177,
988+
content: "{}",
989+
tags: [["d", other.pubkey]],
990+
}),
991+
]);
992+
await h.service.leave();
993+
const ended =
994+
scenario === "departed human" || scenario === "legacy agent";
995+
expect(h.publish).toHaveBeenCalledTimes(ended ? 1 : 0);
996+
expect(h.archive).toHaveBeenCalledTimes(ended ? 1 : 0);
997+
if (ended)
998+
expect(h.archive).toHaveBeenCalledWith(
999+
"archive",
1000+
room,
1001+
expect.any(AbortSignal),
1002+
expect.any(Function),
1003+
);
1004+
if (scenario !== "departed human")
1005+
expect(h.snapshotRead).toHaveBeenNthCalledWith(
1006+
2,
1007+
[
1008+
{
1009+
kinds: [30177],
1010+
authors: [destination.viewer],
1011+
"#d": [other.pubkey],
1012+
limit: 1,
1013+
consistency: "strong",
1014+
},
1015+
],
1016+
{ signal: expect.any(AbortSignal) },
1017+
);
1018+
await h.dispose();
1019+
},
1020+
);
9511021
it("does not end after switching communities during the fresh read", async () => {
9521022
const h = await connected();
9531023
const gate = deferred<ReturnType<typeof records>>();

0 commit comments

Comments
 (0)