Skip to content

Commit d2b7319

Browse files
kevin9327claudedavidmckayv
authored
Offer a conversation to be named only when the queue holds nothing for it (#587)
A pass offers at most twenty unnamed conversations. One the pass could not name keeps no summary and stays in that set, and offering it again while its settled work row stands does nothing but take a place. Enough of them ahead of a new conversation left the new one unoffered on every pass. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: David McKay <david@copilotkit.ai>
1 parent 76417f6 commit d2b7319

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
88

99
## Unreleased
1010

11+
### New conversations are still named once some older ones could not be
12+
13+
Every pass of the job that names conversations offered at most twenty of those still without a name.
14+
A conversation it had tried and could not name, for example because the model answered with no text
15+
or the conversation opened with only an attachment, keeps no name, so it stayed among those twenty
16+
and took a place on every pass, although offering it again did nothing. Once enough of them had built
17+
up, a new conversation could miss out on every pass and keep showing its plain name in the sidebar.
18+
A pass now skips any conversation that the job already holds work for, so new ones get a place. One
19+
it could not name is still tried again later, as before.
1120
### An offboarding one app refuses still records the apps that answered
1221

1322
Removing somebody withdraws each brokered account they connected. When the broker refused one of

server/src/channels/summary.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
* Offer then claim, like `work/culler.ts`. The offer is derived from the table rather than from an
88
* event, so a missed sweep costs two seconds where a missed event would cost the name entirely.
99
*/
10-
import { and, asc, eq, isNull, sql } from "drizzle-orm";
10+
import { and, asc, eq, isNull, notExists, sql } from "drizzle-orm";
1111
import { readFiring } from "../../../shared/routine-firing";
1212
import type { Database } from "../db/client";
1313
import {
1414
channelMemberships,
1515
channels,
1616
intelligenceChannelMappings,
17+
workItems,
1718
} from "../db/schema";
1819
import { DEFAULT_MAX_ATTEMPTS, type WorkQueue } from "../work/queue";
1920
import { CHANNEL_ACTIVITY_TOPIC, type ChannelActivityEvent } from "./events";
@@ -73,6 +74,25 @@ export async function offerChannelsAwaitingSummary(
7374
isNull(channels.summary),
7475
isNull(channels.deletedAt),
7576
sql`${channels.lastMessageAt} is not null`,
77+
/*
78+
* Not one the queue already holds a row for, pending or settled.
79+
*
80+
* Offering it again changes nothing, but it takes one of the `limit` places. A conversation
81+
* this cannot name keeps no summary and so never leaves the set above, and enough of them
82+
* ahead of a new conversation left the new one unoffered on every pass. Once its settled row
83+
* is forgotten it is offered again, as before.
84+
*/
85+
notExists(
86+
options.database
87+
.select({ key: workItems.key })
88+
.from(workItems)
89+
.where(
90+
and(
91+
eq(workItems.kind, CHANNEL_SUMMARY_KIND),
92+
eq(workItems.key, channels.id),
93+
),
94+
),
95+
),
7696
),
7797
)
7898
.limit(options.limit ?? 20);

server/tests/channel-summary.integration.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,46 @@ describe("offering conversations to be named", () => {
195195
.where(eq(workItems.key, channel.id));
196196
expect(rows).toHaveLength(1);
197197
});
198+
199+
/*
200+
* A pass offers at most `limit` conversations, twenty by default, and a conversation it could not
201+
* name keeps no summary, so it stays in the set the pass reads. Offering it again while its settled
202+
* work row stands does nothing, but it still used one of those places. Twenty such conversations
203+
* ahead of a new one left nothing for it, pass after pass.
204+
*/
205+
test("does not spend a place on a conversation whose settled work still stands", async () => {
206+
const owner = await createUser();
207+
const channel = await createUsedChannel(owner);
208+
await offer(channel.id);
209+
// Settled without a name, the way a model that answers with nothing leaves it.
210+
await summariseClaimedChannels(options({ title: titler(null) }));
211+
expect((await summaryOf(channel.id))?.summary).toBeNull();
212+
213+
const { offered } = await offerChannelsAwaitingSummary({
214+
database,
215+
queue,
216+
limit: 200,
217+
});
218+
219+
expect(offered).not.toContain(channel.id);
220+
});
221+
222+
test("offers it again once its settled work has been forgotten", async () => {
223+
const owner = await createUser();
224+
const channel = await createUsedChannel(owner);
225+
await offer(channel.id);
226+
await summariseClaimedChannels(options({ title: titler(null) }));
227+
// What `forgetSettledSummaries` does once the finished row is an hour old.
228+
await database.delete(workItems).where(eq(workItems.key, channel.id));
229+
230+
const { offered } = await offerChannelsAwaitingSummary({
231+
database,
232+
queue,
233+
limit: 200,
234+
});
235+
236+
expect(offered).toContain(channel.id);
237+
});
198238
});
199239

200240
/**

0 commit comments

Comments
 (0)