Skip to content

Commit 2fe1b02

Browse files
committed
fix(ui): never settle a slug tie from an incomplete search
A truncated candidate set is an unfinished search, not a tie: an unexamined page could hold the same short-id prefix under the same slug. Settling there would be the guess the bounded search exists to avoid, so keep the chooser.
1 parent 5366385 commit 2fe1b02

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎ui/src/pages/chat/route-loader.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,15 @@ function sessionReferenceMatches(
197197
// which one was meant, so it settles the tie and keeps generated links durable at their
198198
// normal length. It can only narrow: a hint that matches nothing (a stale or hand-edited
199199
// name) leaves the original candidates for the chooser rather than dropping the session.
200+
//
201+
// A truncated set is not a tie, it is an unfinished search. Another page could hold the
202+
// same prefix under the same slug, so settling here would be the guess the bounded search
203+
// exists to avoid.
200204
function narrowBySlugHint(
201205
resolution: SessionReferenceResolution,
202206
slugHint: string | undefined,
203207
): SessionReferenceResolution {
204-
if (resolution.kind !== "ambiguous" || !slugHint) {
208+
if (resolution.kind !== "ambiguous" || resolution.truncated || !slugHint) {
205209
return resolution;
206210
}
207211
const matched = resolution.sessions.filter(

‎ui/src/pages/chat/route-resolution.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,26 @@ describe("gateway-backed session route resolution", () => {
434434
}
435435
});
436436

437+
it("does not settle a slug tie while the bounded search is incomplete", async () => {
438+
// Only one loaded row carries the slug, but pagination stopped early: an unexamined
439+
// page could hold the same prefix under the same name, so the chooser has to stand.
440+
const storedRow = row({
441+
key: "agent:roboclaw:thread:12345678-0aaa-4000-8000-000000000001",
442+
displayName: "Deploy monitor",
443+
});
444+
const { context } = contextFor(({ offset = 0 }) =>
445+
result(offset === 0 ? [storedRow] : [], { hasMore: true, nextOffset: offset + 20, offset }),
446+
);
447+
const loaded = await loadChatRoute(
448+
context,
449+
{ pathname: "/chat/roboclaw/deploy-monitor-12345678", search: "", hash: "" },
450+
"chat",
451+
new AbortController().signal,
452+
);
453+
454+
expect(loaded).toMatchObject({ kind: "ambiguous", shortId: "12345678", truncated: true });
455+
});
456+
437457
it("prefers an exact literal key over slug matches", async () => {
438458
const literal = row({
439459
key: "agent:roboclaw:default-mode-with-rare-surprises",

0 commit comments

Comments
 (0)