Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/operations/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ List memory keys under this identity, optionally filtered.
| `tags` | `list[str]` | *(computed)* | Only rows carrying any one of these tags, in any case; empty = no tag filter. |
| `tags_every` | `bool` | `False` | Require every one of `tags` instead of any one; default off. |
| `contains` | `str \| None` | `None` | Only rows whose value or key holds this text, any case (a high row by its key only) — the keyword filter of a browse page's search box, which must find every row that names a word (a ranked search returns its top k and misses the rest). |
| `pinned_only` | `bool` | `False` | Only pinned rows. |
| `fields` | `list[str]` | *(computed)* | Whitelist of entry field names; every entry carries only those plus `memory_key` and `sensitivity`. |
| `known_version` | `int \| str \| None` | `None` | The `namespace_version` a previous answer carried. |

Expand Down
12 changes: 9 additions & 3 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ export async function listMemories(
tags?: string[];
// Only rows this agent wrote; every agent's rows when unset.
agent?: string;
// Only pinned rows.
pinnedOnly?: boolean;
} & RequestOpts = {},
): Promise<MemoryListResponse> {
// Without an agent the Memories view shows every agent's rows, so it sends `agent=*` to
Expand All @@ -482,6 +484,7 @@ export async function listMemories(
...(opts.fields ? { fields: opts.fields } : {}),
...(opts.previewChars ? { preview_chars: opts.previewChars } : {}),
...(opts.contains ? { contains: opts.contains } : {}),
...(opts.pinnedOnly ? { pinned_only: true } : {}),
// Tags as typed; the server matches them in any case. Two or more must all match (a
// build that predates `tags_every` matches any one, and the page then requires every tag
// itself).
Expand Down Expand Up @@ -1036,9 +1039,12 @@ export async function countConflicts(
return r.total ?? 0;
}

/** The conflicted memory keys of a namespace, for the cards' chips
* — the same operation with `keys_only`, one FINAL read of the key columns and no value
* column. */
/** The most keys one `keys_only` read returns: the server's cap. */
export const CONFLICT_KEYS_CAP = 5000;

/** The conflicted memory keys of a namespace, newest version first, for the cards' chips
* and the Conflicted list — the same operation with `keys_only`, one FINAL read of the key
* columns and no value column. At most `CONFLICT_KEYS_CAP` keys. */
export async function conflictKeys(id: Pick<Identity, "org" | "namespace">, opts: RequestOpts = {}): Promise<string[]> {
const r = await post<{ keys?: string[] | null }>(
"/v1/conflicts.list",
Expand Down
119 changes: 113 additions & 6 deletions frontend/src/views/Recent.lists.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ const entry = (memory_key: string, over: Partial<MemoryListEntry> = {}): MemoryL
...over,
});

// A memory.bulk_get answer for each key asked.
const detail = (over: Partial<MemoryDetail> = {}): MemoryDetail => ({
found: true,
value: "a conflicted value",
memory_type: "semantic",
confidence: 1,
version: 1,
pinned: false,
created_at: "2026-09-18T09:00:00Z",
agent: "support-bot",
...over,
});
function bulkAnswers() {
vi.mocked(bulkGetMemories).mockImplementation(async (_id, keys) => ({
results: Object.fromEntries(keys.map((k) => [k, detail()])),
missing: [],
}));
}

const ROWS = [
entry("a/pinned", { pinned: true }),
entry("b/verified", { verification: "human", verified_by: "human:o@example.com", agent: "support-bot" }),
Expand All @@ -47,7 +66,7 @@ vi.mock("../api", async (importOriginal) => {
isAuthDisabled: () => false,
};
});
import { getMemory, listMemories, pinMemory } from "../api";
import { bulkGetMemories, conflictKeys, getMemory, listMemories, pinMemory } from "../api";

const owner: WhoAmI = {
authenticated: true,
Expand Down Expand Up @@ -242,7 +261,7 @@ describe("Memories list chrome", () => {
async (_id, limit = 50): Promise<MemoryListResponse> =>
limit === 1000
? {
entries: Array.from({ length: 1000 }, (_, i) => entry(`p${i}`, { pinned: i < 60 })),
entries: Array.from({ length: 1000 }, (_, i) => entry(`p${i}`, i < 60 ? { verification: "human" } : {})),
total: 5000,
today: 0,
truncated: true,
Expand All @@ -251,9 +270,9 @@ describe("Memories list chrome", () => {
);
render(<Recent />);
await screen.findByText("d/plain");
await pick("Status", "pinned");
await pick("Status", "verified");
await waitFor(() => expect(toolbar()).toHaveTextContent("60 matches"));
// 60 pinned among the newest rows read: not "the newest 60".
// 60 verified among the newest rows read: not "the newest 60".
const pager = screen.getByRole("navigation", { name: "Memories pages" });
expect(pager).toHaveTextContent("1–50 of 60");
expect(pager).not.toHaveTextContent("newest");
Expand All @@ -265,7 +284,9 @@ describe("Memories list chrome", () => {
async (_id, limit = 50): Promise<MemoryListResponse> =>
limit === 1000
? {
entries: Array.from({ length: 100 }, (_, i) => entry(`t${i}`, { tags: ["api"], pinned: i < 60 })),
entries: Array.from({ length: 100 }, (_, i) =>
entry(`t${i}`, { tags: ["api"], ...(i < 60 ? { verification: "human" as const } : {}) }),
),
total: 340,
today: 0,
truncated: true,
Expand All @@ -276,7 +297,7 @@ describe("Memories list chrome", () => {
await screen.findByText("d/plain");
await userEvent.type(screen.getByLabelText("Search memories"), "tag:api");
await waitFor(() => expect(toolbar()).toHaveTextContent("340 matches"));
await pick("Status", "pinned");
await pick("Status", "verified");
await waitFor(() => expect(toolbar()).toHaveTextContent("60 matches"));
expect(screen.getByRole("navigation", { name: "Memories pages" })).not.toHaveTextContent("newest");
});
Expand Down Expand Up @@ -391,6 +412,7 @@ describe("Memories list chrome", () => {
});

it("filters by status: pinned, conflicted, verified", async () => {
bulkAnswers();
render(<Recent />);
await screen.findByText("d/plain");
// No chip row under the toolbar.
Expand Down Expand Up @@ -529,3 +551,88 @@ describe("Memories list chrome", () => {
expect(screen.getByText("request id req-f")).toBeInTheDocument();
});
});

describe("Memories status filters over the whole namespace", () => {
beforeEach(() => {
vi.clearAllMocks();
localStorage.clear();
resetNamespaceRoleCache();
vi.mocked(listMemories).mockResolvedValue({ entries: ROWS, total: 1234, today: 2, truncated: false });
useStore.setState({
authed: true,
whoami: owner,
myNamespaces: [row],
identity: { org: "dev", namespace: "team", agent: "loom-ui" },
view: "memories",
inspectedMemoryKey: null,
});
});
afterEach(() => {
cleanup();
useStore.setState({ whoami: null, myNamespaces: null, identity: null });
});

it("asks the server for pinned rows and counts them from its total", async () => {
vi.mocked(listMemories).mockImplementation(
async (_id, _limit, opts): Promise<MemoryListResponse> =>
opts?.pinnedOnly
? {
entries: Array.from({ length: 1000 }, (_, i) => entry(`pin${i}`, { pinned: true })),
total: 1500,
today: 0,
truncated: true,
}
: { entries: ROWS, total: 1234, today: 2, truncated: false },
);
render(<Recent />);
await screen.findByText("d/plain");
await pick("Status", "pinned");
expect(await screen.findByText("pin0")).toBeInTheDocument();
expect(vi.mocked(listMemories).mock.calls.at(-1)?.[2]).toMatchObject({ pinnedOnly: true });
await waitFor(() => expect(toolbar()).toHaveTextContent("1,500 matches"));
expect(
screen.getByText("Showing the newest matches. Add a tag or a search word to narrow them."),
).toBeInTheDocument();
});

it("keeps the pinned rows among those read when the server does not know pinned_only", async () => {
vi.mocked(listMemories).mockResolvedValue({
entries: ROWS,
total: 1234,
today: 2,
truncated: true,
ignored_args: ["pinned_only"],
});
render(<Recent />);
await screen.findByText("d/plain");
await pick("Status", "pinned");
await waitFor(() => expect(shown()).toEqual(["a/pinned"]));
expect(toolbar()).toHaveTextContent("1 match");
expect(screen.getByText("Showing the pinned memories among the newest ones read.")).toBeInTheDocument();
});

it("lists a conflicted key that is not among the newest rows, reading the rows in batches of 1,000", async () => {
const keys = ["z/old-conflict", ...Array.from({ length: 1499 }, (_, i) => `conflict${i}`)];
vi.mocked(conflictKeys).mockResolvedValue(keys);
bulkAnswers();
render(<Recent />);
await screen.findByText("d/plain");
await pick("Status", "conflicted");
expect(await screen.findByText("z/old-conflict")).toBeInTheDocument();
await waitFor(() => expect(toolbar()).toHaveTextContent("1,500 matches"));
expect(vi.mocked(bulkGetMemories).mock.calls.map((c) => c[1].length)).toEqual([1000, 500]);
// The list read beside them is one row, for the namespace version.
expect(vi.mocked(listMemories).mock.calls.at(-1)?.[1]).toBe(1);
expect(screen.queryByText(/conflicted keys\./)).toBeNull();
});

it("says how many conflicted keys it covers when the read reaches the server's cap", async () => {
vi.mocked(conflictKeys).mockResolvedValue(Array.from({ length: 5000 }, (_, i) => `conflict${i}`));
bulkAnswers();
render(<Recent />);
await screen.findByText("d/plain");
await pick("Status", "conflicted");
expect(await screen.findByText("Showing the memories of the newest 5,000 conflicted keys.")).toBeInTheDocument();
expect(vi.mocked(bulkGetMemories)).toHaveBeenCalledTimes(5);
});
});
40 changes: 27 additions & 13 deletions frontend/src/views/Recent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
deleteMemory,
restoreMemory,
conflictKeys as fetchConflictKeys,
CONFLICT_KEYS_CAP,
isAuthDisabled,
type MemoryListEntry,
} from "../api";
Expand Down Expand Up @@ -65,8 +66,8 @@ const MembersDialog = lazy(() => import("../flows/MembersDialog").then((m) => ({
// DOM, same scroll, same find-in-page once it settles.
const FIRST_SCREEN_CARDS = 12; // A screen shows eight or nine

/** What the Status select shows. Every status but Live and Recently
* deleted reads the newest 1,000 and keeps the matching rows: none has a server filter. */
/** What the Status select shows. Pinned is a server filter; Conflicted reads every
* conflicted row by key; Verified reads the newest 1,000 and keeps the matching rows. */
type Status = "live" | "pinned" | "conflicted" | "verified" | "deleted";
const STATUSES: ReadonlyArray<{ value: Status; label: string }> = [
{ value: "live", label: "Live" },
Expand Down Expand Up @@ -199,8 +200,9 @@ function MemoryList() {
// A filter covers the whole namespace, not the page on screen. A tag or agent filter is
// asked of the server, which returns the rows carrying every tag, in any case (a server a
// release behind matches any one tag exactly, and the list then requires every tag
// itself). Pinned, Conflicted and Verified have no server filter: the list reads the
// newest 1,000 and keeps the matching ones. What is typed is debounced, so `tag:…` sends
// itself). Pinned is asked of the server too, and Conflicted reads the conflicted rows by
// key; Verified reads the newest 1,000 and keeps the matching ones (a server a release
// behind lists Pinned the same way). What is typed is debounced, so `tag:…` sends
// one read, not one per key; a chip applies at once.
const typedNow = useSameFilter(filterOf(parsed));
const [typed, setTyped] = useState(typedNow);
Expand Down Expand Up @@ -274,6 +276,7 @@ function MemoryList() {
loadError,
truncated,
serverMatches,
statusServed,
newKeys,
bulkValues,
refreshing,
Expand Down Expand Up @@ -633,11 +636,15 @@ function MemoryList() {
? // What a search covers: the newest rows holding the word, when there are more.
`${matches(flatList.length)}${keywordTotal > keywordKeys.size ? ` · the newest ${keywordKeys.size.toLocaleString()} of ${keywordTotal.toLocaleString()} holding "${keywordFor}"` : ""}${ranking ? " · finding related…" : ""}`
: showDeleted || listFiltered
? // A tag or agent filter is matched on the server, whose total is exact; a status
// is kept here among the rows read.
? // A tag or agent filter, and Pinned, are matched on the server, whose total is
// exact; another status counts the rows kept here.
matches(
// Of the filter it read: not of a typed tag still on its way.
!showDeleted && listFilter.status === "live" && serverMatches !== null && filterRead && !filterPending
!showDeleted &&
(listFilter.status === "live" || statusServed) &&
serverMatches !== null &&
filterRead &&
!filterPending
? serverMatches
: flatList.length,
)
Expand Down Expand Up @@ -925,9 +932,11 @@ function MemoryList() {

{truncated && (
<p className="mb-3 text-xs text-text-muted">
{listFilter.tags.length > 0 || listFilter.agent
? "Showing the newest matches. Add a tag or a search word to narrow them."
: `Showing the ${filterNames.toLowerCase()} memories among the newest ones read.`}
{listFilter.status === "conflicted" && statusServed
? `Showing the memories of the newest ${CONFLICT_KEYS_CAP.toLocaleString()} conflicted keys.`
: listFilter.tags.length > 0 || listFilter.agent || statusServed
? "Showing the newest matches. Add a tag or a search word to narrow them."
: `Showing the ${filterNames.toLowerCase()} memories among the newest ones read.`}
</p>
)}
{/* Where a page change takes the reader: a heading a screen reader announces. */}
Expand Down Expand Up @@ -1033,9 +1042,14 @@ function MemoryList() {
pageSize={pageSize}
shown={(listFiltered && filterRead) || (!listFiltered && browsedCurrent) ? pageList.length : 0}
total={listFiltered ? (filterRead ? listTotal : undefined) : browsedTotal}
// A tag or agent read the server cut short holds its newest matches, not every one.
// A status is kept among the rows read, which the note under the toolbar says.
capped={truncated && listFilter.status === "live" && (listFilter.tags.length > 0 || listFilter.agent !== "")}
// A tag, agent or Pinned read the server cut short holds its newest matches, not
// every one. Another status is kept among the rows read, which the note under the
// toolbar says.
capped={
truncated &&
((listFilter.status === "live" && (listFilter.tags.length > 0 || listFilter.agent !== "")) ||
(listFilter.status === "pinned" && statusServed))
}
onPage={setPage}
onPageSize={(n) => {
setPageSize(n);
Expand Down
Loading
Loading