Skip to content

Commit 34a9c0c

Browse files
fix(spaces): Never archive a Space when its last subscriber leaves
Leave and unsubscribe on a Space Conversation act on the Lead, its root. When the person was the last subscriber, that archived the Lead's whole tree, which is every Conversation in the Space. Only a Space archive ends a Space now. Also drop stale startConversation and root wording.
1 parent 8a46cc2 commit 34a9c0c

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

‎packages/junior-evals/evals/agent/lead.eval.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("Lead", () => {
9292
space: expect.objectContaining({ name: "Eval work" }),
9393
}),
9494
);
95-
expect(toolCallsOf("startConversation", conversation)).toEqual([]);
95+
expect(toolCallsOf("startAgent", conversation)).toEqual([]);
9696
});
9797

9898
// Only a member of a Space moves work into it. The case measures whether
@@ -114,7 +114,7 @@ describe("Lead", () => {
114114
expect(completedToolCalls("moveConversationToSpace", conversation)).toEqual(
115115
[],
116116
);
117-
expect(toolCallsOf("startConversation", conversation)).toEqual([]);
117+
expect(toolCallsOf("startAgent", conversation)).toEqual([]);
118118
expect(toolCallsOf("messageAgent", conversation)).toEqual([]);
119119
await expect(conversation).toSatisfyJudge(
120120
RubricJudge,
@@ -150,6 +150,6 @@ describe("Lead", () => {
150150
expect(completedToolCalls("moveConversationToSpace", conversation)).toEqual(
151151
[],
152152
);
153-
expect(toolCallsOf("startConversation", conversation)).toEqual([]);
153+
expect(toolCallsOf("startAgent", conversation)).toEqual([]);
154154
});
155155
});

‎packages/junior/src/api/conversations/list.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ function conversationCodeRepositoryFilter(
158158
}
159159

160160
/**
161-
* Keep the Lead's children in one Space with the status that the viewer may find. A
162-
* private Space shows its roots only to its members.
161+
* Keep the Lead's children in one Space with the status that the viewer may
162+
* find. A private Space shows its work only to its members.
163163
*/
164164
function conversationSpaceFilter(
165165
spaceId: string,

‎packages/junior/src/api/conversations/subscription.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,23 @@ export async function leaveConversation(
253253
/**
254254
* Archive the tree for everyone when no Participant still has it in their
255255
* feed. Returns the archive time, or null when a subscriber remains. Runs
256-
* under the root's row lock.
256+
* under the root's row lock. A Lead's tree is its whole Space, which only
257+
* a Space archive ends, so it never archives here.
257258
*/
258259
async function archiveWithoutSubscribers(
259260
db: JuniorDatabase,
260261
rootConversationId: string,
261262
): Promise<string | null> {
263+
const [lead] = await db
264+
.select({ id: juniorConversations.conversationId })
265+
.from(juniorConversations)
266+
.where(
267+
and(
268+
eq(juniorConversations.conversationId, rootConversationId),
269+
eq(juniorConversations.kind, "lead"),
270+
),
271+
);
272+
if (lead) return null;
262273
if (await hasSubscriber(db, rootConversationId)) return null;
263274
const archivedAt = new Date();
264275
// Archive the root and each descendant that is not archived, so an

‎packages/junior/src/chat/conversations/search.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ export async function searchConversations(
222222
.where(eq(requesterRoot.conversationId, requesterRootId)),
223223
),
224224
// The Conversations of a private Space share one audience, the members.
225-
// A private Space's roots have their own Destinations, so only this
226-
// match reaches them.
225+
// Space work can have other Destinations than the requester's root, so
226+
// only this match reaches all of it.
227227
eq(
228228
rootSpaceIdSql(roots),
229229
db

‎packages/junior/tests/integration/api/spaces.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,18 @@ describe("Spaces API", () => {
386386
expect(
387387
(await spaceFeed(ana, space.id)).map((row) => row.conversationId),
388388
).toEqual([inSpace]);
389+
390+
// Leave by the last subscriber never archives the Space's work.
391+
const left = await request(
392+
ana,
393+
"POST",
394+
`/conversations/${encodeURIComponent(inSpace)}/leave`,
395+
);
396+
expect(left.status).toBe(200);
397+
expect(await left.json()).toEqual({ archivedAt: null });
398+
expect(
399+
(await spaceFeed(ana, space.id)).map((row) => row.conversationId),
400+
).toEqual([inSpace]);
389401
});
390402

391403
it("finds and moves Conversations into, between, and out of Spaces with the agent tools", async () => {

0 commit comments

Comments
 (0)