Skip to content

Commit 6fb3303

Browse files
steipeteampagent
andauthored
1 parent 0f1d652 commit 6fb3303

3 files changed

Lines changed: 30 additions & 31 deletions

File tree

‎ui/src/e2e/session-owner-first.e2e.test.ts‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ suite.define(() => {
6363
sessions: sharedRoster.sessions.slice(0, 1),
6464
};
6565
const gateway = await installMockGateway(page, {
66-
deferredMethods: ["sessions.list"],
66+
deferredMethods: ["sessions.list", "sessions.list"],
6767
presenceUsers: [{ self: true, id: "profile-ada", name: "Ada" }],
6868
sessionKey: "agent:main:ada",
6969
methodResponses: {
@@ -79,23 +79,20 @@ suite.define(() => {
7979
try {
8080
await page.goto(`${suite.server?.baseUrl ?? ""}chat`);
8181
await expect
82-
.poll(async () =>
83-
(await gateway.getRequests("sessions.list")).some(
84-
(request) =>
85-
(request.params as { ownerId?: unknown } | undefined)?.ownerId === "profile-ada",
86-
),
87-
)
88-
.toBe(true);
89-
await gateway.deferNext("sessions.list", { agentId: "main", limit: 60 });
82+
.poll(async () => (await gateway.getRequests("sessions.list")).length)
83+
.toBeGreaterThanOrEqual(2);
84+
expect(
85+
(await gateway.getRequests("sessions.list")).some(
86+
(request) =>
87+
(request.params as { ownerId?: unknown } | undefined)?.ownerId === "profile-ada",
88+
),
89+
).toBe(true);
9090
await gateway.resolveDeferred("sessions.list", ownerRoster);
9191

9292
const adaRow = page.locator('[data-session-key="agent:main:ada"]');
9393
const bobRow = page.locator('[data-session-key="agent:main:bob"]');
9494
await adaRow.waitFor();
9595
await expect.poll(() => bobRow.count()).toBe(0);
96-
await expect
97-
.poll(async () => (await gateway.getRequests("sessions.list")).length)
98-
.toBeGreaterThanOrEqual(2);
9996
await captureSidebar(page, "owner-first-roster.png");
10097

10198
await gateway.resolveDeferred("sessions.list", sharedRoster);

‎ui/src/lib/sessions/connection-hydration.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ describe("session connection hydration", () => {
191191
expect.objectContaining({ ownerId: "operator", limit: 60 }),
192192
),
193193
);
194-
expect(request.mock.calls.filter(([method]) => method === "sessions.list")).toHaveLength(1);
195-
const queuedRefresh = sessions.refresh({ agentId: "other", search: "queued", force: true });
196-
197-
ownerList.resolve(ownerResult);
198-
await waitForFast(() => expect(sessions.state.result).toBe(ownerResult));
199194
await waitForFast(() =>
200195
expect(request.mock.calls.filter(([method]) => method === "sessions.list")).toHaveLength(2),
201196
);
202-
expect(sessions.state.loading).toBe(false);
197+
expect(sessions.state.result).toBeNull();
203198
expect(request.mock.calls.at(-1)?.[1]).toEqual(
204199
expect.objectContaining({ agentId: "main", limit: 60 }),
205200
);
206201
expect(request.mock.calls.at(-1)?.[1]).not.toHaveProperty("ownerId");
202+
const queuedRefresh = sessions.refresh({ agentId: "other", search: "queued", force: true });
203+
204+
ownerList.resolve(ownerResult);
205+
await waitForFast(() => expect(sessions.state.result).toBe(ownerResult));
206+
expect(sessions.state.loading).toBe(false);
207207

208208
sharedList.resolve(sharedResult);
209209
await waitForFast(() =>

‎ui/src/lib/sessions/session-roster-refresh.ts‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function createSessionRosterRefresh(host: SessionRosterRefreshHost) {
231231
}
232232
};
233233

234-
const load = async (options: SessionRosterLoadOptions) => {
234+
const load = async (options: SessionRosterLoadOptions, publishAfter?: Promise<void>) => {
235235
const scope = host.connection.capture();
236236
if (!scope) {
237237
return;
@@ -265,7 +265,9 @@ export function createSessionRosterRefresh(host: SessionRosterRefreshHost) {
265265
);
266266
}
267267
try {
268-
const result = await requestSessionList(scope.client, requestOptions);
268+
const request = requestSessionList(scope.client, requestOptions);
269+
await Promise.allSettled([request, publishAfter]);
270+
const result = await request;
269271
if (!host.connection.isCurrent(scope)) {
270272
return;
271273
}
@@ -386,10 +388,10 @@ export function createSessionRosterRefresh(host: SessionRosterRefreshHost) {
386388
return { ...lastListOptions, force: true };
387389
};
388390

389-
const refreshPlan = (options: SessionRefreshOptions): SessionRosterLoadOptions[] => {
391+
const refreshPlan = (options: SessionRefreshOptions) => {
390392
const ownerId = host.snapshot().selfUser?.id.trim();
391393
if (!ownerId || options.append === true || !isPrimarySessionListQuery(options)) {
392-
return [options];
394+
return { initial: options, shared: undefined };
393395
}
394396
const sharedLimit = Math.max(
395397
OWNER_FIRST_SESSION_LIST_LIMIT,
@@ -399,19 +401,19 @@ export function createSessionRosterRefresh(host: SessionRosterRefreshHost) {
399401
);
400402
// Keep owner-first and shared loads atomic in the existing refresh queue.
401403
// Only the shared phase advances canonical membership and durable options.
402-
return [
403-
{
404+
return {
405+
initial: {
404406
...options,
405407
ownerId,
406408
limit: OWNER_FIRST_SESSION_LIST_LIMIT,
407409
provisional: true,
408410
},
409-
{
411+
shared: {
410412
...options,
411413
limit: sharedLimit,
412414
mergeExisting: true,
413415
},
414-
];
416+
};
415417
};
416418

417419
const drainRefreshQueue = async (options: SessionRefreshOptions) => {
@@ -421,11 +423,11 @@ export function createSessionRosterRefresh(host: SessionRosterRefreshHost) {
421423
}
422424
let next: SessionRefreshOptions | null = options;
423425
while (next) {
424-
for (const loadOptions of refreshPlan(next)) {
425-
await load(loadOptions);
426-
if (!host.connection.isCurrent(scope)) {
427-
return;
428-
}
426+
const { initial, shared } = refreshPlan(next);
427+
const initialLoad = load(initial);
428+
await (shared ? load(shared, initialLoad) : initialLoad);
429+
if (!host.connection.isCurrent(scope)) {
430+
return;
429431
}
430432
next = takeNextQueuedRefresh();
431433
}

0 commit comments

Comments
 (0)