Skip to content
Merged
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
28 changes: 16 additions & 12 deletions docs/features/dashboard.md

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion docs/features/memory/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ each. A run in the proposal's namespace counts toward its trial when it names th
proposal ready for review. With `proposal_policy.mode="auto"`, `reject_after_fails` can
reject a proposal; automatic acceptance is refused. See [runs](../runs.md).

Each listed proposal names who proposed it: `actor` is the identity the server recorded
for the write, `human:<subject>` or `process:<subject>` from the writer's token, or a
pipeline's own actor (such as `process:session_contrast`) for a proposal the server wrote,
beside `agent`, the label the writing client sent. `memory_keys` (at most 500 keys that
together fit one 64 KiB parameter; a longer list is refused with a 422) lists only the
pending proposals under those keys; `limit` still applies, and `total` and `count_only`
count the matching rows. A key outside the caller's reach answers as a key with no
proposal. A `high` row lists no `content_sha256`: its hash comes with its value from
`memory.get_by_id`.

`memory.proposal_decide` requires an administrator. Acceptance also requires an
authenticated human whose subject, including linked aliases, differs from the proposer.
Service accounts and anonymous callers cannot approve. Acceptance supplies
Expand All @@ -350,7 +360,13 @@ read. Missing hashes or changed content leave that key undecided. The approved r
records the reviewer's identity and content hash. Pending review survives rejection,
metadata changes, tombstones and snapshot restoration; ordinary writes cannot activate it.
A pending row cannot be moved to another key. The **Proposals** tab of the **Review queue**
at `/admin/review_queue` supplies the displayed hashes when an administrator accepts.
at `/admin/review_queue?tab=proposals` lists each proposal with who proposed it. A
proposal's key opens its review, and `&key=<key>` in the address, the key percent-encoded,
opens the pending proposal under that key. The review shows the key, the proposer, the
agent, when the fact was first proposed and its graded runs above the complete text, and
holds both decisions: the tab supplies the displayed hash when an administrator accepts,
and a rejection can carry a reason. A rejection cannot be undone: the fact has to be
proposed again.
A decision names a key and decides its newest row, so the tab offers no decision for a key
that more than one listed proposal holds. Accepting a proposal that recorded a
contradiction while on trial stores it `conflicted`, and it waits on the **Conflicts** tab.
Expand Down
1 change: 1 addition & 0 deletions docs/guides/without-the-dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ are on `agent.account` and `agent.deployment`.
| Approve join requests | `grants.pending_for_me`, then `grants.approve namespace=… subject=… decision=approve` (or `reject`) | `agent.client.grants.pending_for_me()`, `agent.client.grants.approve(...)` |
| Members and grants | `grants.list`, `grants.create`, `grants.revoke` | `agent.grants.*` |
| Review queue (conflicts) | `conflicts.list`, `conflicts.resolve`, `learnings.review` | `agent.conflicts.list()`, `.resolve(...)` |
| Review queue (proposals) | `memory.proposals`, `memory.proposal_decide` ([proposals](../features/memory/writing.md#proposals)) | `agent.client.memory.proposals(...)`, `.proposal_decide(...)` |
| Review queue (definitions) | `memory.definitions.list` | `agent.client.memory.definitions_list()` |
| Activity, audit log | `profile.activity`, `audit.list`, `agents.connected`, `mentor.brief`, `memory.exposure_summary`, `memory.owner_report` | `agent.audit.list(...)`, `agent.profile.*` |
| Cost and budgets | `cost.summary`, `cost.budget_status` | `agent.cost.summary(...)` |
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/operations/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -1565,9 +1565,10 @@ List facts on trial (written with memory.set proposed=true) with the graded runs
| `namespace` | `str` | required | The namespace the op reads or writes. |
| `prefix` | `str` | `''` | Narrow the listing: a key prefix (`lesson_`), any-match tags. |
| `tags` | `list[str]` | *(computed)* | Only proposals carrying any of these tags; empty = no tag filter. |
| `memory_keys` | `list[str]` | *(computed)* | Only pending proposals under these keys, cut by `limit` like any listing; empty lists every proposal. |
| `only` | `Literal['', 'ready']` | `''` | `ready` keeps only proposals the policy thresholds would decide now (accept or reject); "" lists every proposal. |
| `limit` | `int` | `50` | At most this many proposals returned, newest first. |
| `count_only` | `bool` | `False` | Answer `total`, the exact number of pending proposals that match prefix and tags, and the namespace's `policy`, with no proposal or graded count read; default off. |
| `count_only` | `bool` | `False` | Answer `total`, the exact number of pending proposals that match prefix, tags and memory_keys, and the namespace's `policy`, with no proposal or graded count read; default off. |

| Output field | Type | Meaning |
| --- | --- | --- |
Expand Down
18 changes: 18 additions & 0 deletions frontend/e2e/list-tables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ const conflict = (i: number) => ({
content_sha256: "",
});

const proposal = (i: number) => ({
memory_key: `alerts/threshold/lane-${i}`,
memory_id: `proposal-${i}`,
content_sha256: String(i).repeat(64),
agent: "oncall-agent",
actor: i % 2 ? "human:alice@example.com" : "process:sa:release-bot",
value_preview: `page when lane ${i} p95 latency is over ${300 + i} ms`,
sensitivity: "",
created_at: ago(i * 45),
graded_passes: i,
graded_fails: 0,
ready: i ? "accept" : "",
});

const WORKERS = {
workers: {
embedding_worker: {
Expand Down Expand Up @@ -103,6 +117,9 @@ async function withRows(page: Page) {
},
}),
);
await page.route("**/v1/memory.proposals", (r) =>
r.fulfill({ json: { proposals: [0, 1, 2].map(proposal), total: 3 } }),
);
await page.route("**/v1/admin/workers.status", (r) => r.fulfill({ json: WORKERS }));
}

Expand All @@ -128,6 +145,7 @@ const TABLES: [string, string][] = [
["/admin/users", "Users"],
["/admin/activity", "Audit events"],
["/admin/review_queue", "Conflicts"],
["/admin/review_queue?tab=proposals", "Proposals"],
["/admin/health", "Workers"],
];

Expand Down
41 changes: 40 additions & 1 deletion frontend/src/api/review.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { collapseMemoryDuplicates, consolidateMemories, listMemoryDuplicates, listProposals } from "./review";
import {
collapseMemoryDuplicates,
consolidateMemories,
decideProposals,
listMemoryDuplicates,
listProposals,
} from "./review";

afterEach(() => {
vi.unstubAllGlobals();
Expand Down Expand Up @@ -29,4 +35,37 @@ describe("review requests", () => {
expect(sent.get("memory.dedup_list")).toMatchObject({ ...scope, limit: 50 });
expect(sent.get("memory.proposals")).toMatchObject({ ...scope, limit: 100 });
});

/** The bodies posted while `calls` runs, in order, without the `consumer` every call names. */
async function bodies(calls: () => Promise<unknown>): Promise<Record<string, unknown>[]> {
const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) => Response.json({}));
vi.stubGlobal("fetch", fetchMock);
await calls();
return fetchMock.mock.calls.map(([, init]) => {
const { consumer: _every, ...body } = JSON.parse(String(init?.body));
return body;
});
}

it("a keyed read sends the keys", async () => {
const [keyed, whole] = await bodies(async () => {
await listProposals(scope, { keys: ["deploy_window"] });
await listProposals(scope);
});
expect(keyed).toEqual({ ...scope, limit: 100, memory_keys: ["deploy_window"] });
expect(whole).toEqual({ ...scope, limit: 100 });
});

it("a rejection sends the hash it read and the reason", async () => {
const hash = { deploy_window: "a".repeat(64) };
const [rejected, bare, accepted] = await bodies(async () => {
await decideProposals(scope, ["deploy_window"], "reject", hash, "Out of date");
await decideProposals(scope, ["deploy_window"], "reject");
await decideProposals(scope, ["deploy_window"], "accept", hash, "never sent");
});
const decision = { ...scope, memory_keys: ["deploy_window"] };
expect(rejected).toEqual({ ...decision, decision: "reject", approved_sha256: hash, reason: "Out of date" });
expect(bare).toEqual({ ...decision, decision: "reject" });
expect(accepted).toEqual({ ...decision, decision: "accept", approved_sha256: hash });
});
});
23 changes: 19 additions & 4 deletions frontend/src/api/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export interface MemoryProposal {
memory_key: string;
memory_id: string;
agent: string;
/** Who proposed it (`human:<subject>`, `process:<subject>` or a pipeline's actor); absent
* from a server a release behind. */
actor?: string;
/** "" for a high row: its value is read by key. */
value_preview: string;
sensitivity: "" | "low" | "medium" | "high";
Expand All @@ -175,29 +178,41 @@ export interface MemoryProposal {
/** How many proposals the Review queue asks for, newest first. */
export const PROPOSAL_LIST_LIMIT = 100;

/** POST /v1/memory.proposals: the newest pending proposals, or with `keys` only those under
* these keys. A server a release behind lists every proposal and names `memory_keys` in
* `ignored_args`. */
export async function listProposals(
id: Scope,
opts: RequestOpts = {},
): Promise<{ proposals: MemoryProposal[]; total: number }> {
opts: RequestOpts & { keys?: string[] } = {},
): Promise<{ proposals: MemoryProposal[]; total: number; ignored_args?: string[] }> {
return post(
"/v1/memory.proposals",
{ org: id.org, namespace: id.namespace, limit: PROPOSAL_LIST_LIMIT },
{
org: id.org,
namespace: id.namespace,
limit: PROPOSAL_LIST_LIMIT,
...(opts.keys ? { memory_keys: opts.keys } : {}),
},
opts.signal,
);
}

/** POST /v1/memory.proposal_decide. `approvedSha256` names, per key, the hash served with
* the text the reviewer read, on either decision; `reason` is kept on a rejected fact. */
export async function decideProposals(
id: Scope,
keys: string[],
decision: "accept" | "reject",
approvedSha256: Record<string, string> = {},
reason = "",
): Promise<{ decided: number; results: { memory_key: string; decided: boolean; status: string; reason: string }[] }> {
return post("/v1/memory.proposal_decide", {
org: id.org,
namespace: id.namespace,
memory_keys: keys,
decision,
...(decision === "accept" ? { approved_sha256: approvedSha256 } : {}),
...(Object.keys(approvedSha256).length > 0 ? { approved_sha256: approvedSha256 } : {}),
...(decision === "reject" && reason ? { reason } : {}),
});
}

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/lib/state.namespace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ describe("writing the address", () => {
expect(history.length).toBe(before);
});

it("a switch drops a proposal's key", () => {
at("/admin/review_queue?namespace=team&tab=proposals&key=deploy_window");
useStore.getState().setIdentity({ ...team, namespace: "other" });
expect(address()).toBe("/admin/review_queue?namespace=other&tab=proposals");
});

it.each([
["tasks", "/tasks", "task"],
["knowledge", "/library", "doc"],
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/lib/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe("navigationHref keeps only the query keys the target view owns", () =>
expect(navigationHref("graph")).toBe("/graph?seed=a+b");
});

it("the Review queue keeps its tab and its key across a navigation to it", () => {
setLocation("/admin/review_queue?tab=proposals&key=deploy_window&seed=alpha");
expect(navigationHref("admin:review_queue")).toBe("/admin/review_queue?tab=proposals&key=deploy_window");
expect(navigationHref("memories")).toBe("/memories");
});

it("shortens links to the default Settings tab", () => {
setLocation("/?view=setup&tab=tokens");
expect(pathnameView()).toBe("setup");
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const VIEW_QUERY_KEYS: Partial<Record<View, readonly string[]>> = {
tasks: ["inbox", "task"],
// Settings carries its open tab (`?tab=memory|system`).
setup: ["tab"],
// The Review queue carries its open tab and the pending proposal open in it.
"admin:review_queue": ["tab", "key"],
"connected-accounts": ["kind"],
// The object open on a page rides its URL, so a deep link, a reload and Back reopen it:
// the memory in the drawer, the document in the preview, the thread in the replay.
Expand Down Expand Up @@ -219,9 +221,14 @@ function pushView(v: View, opts: NavOptions = {}, remember = true): void {
else history.pushState(state, "", want);
}

/** The current history entry's state; null where there is no history. */
function entryState(): unknown {
return typeof history === "undefined" ? null : history.state;
}

/** Whether the current history entry is the one the assistant's phone sheet pushed. */
export function sheetEntry(): boolean {
const st: unknown = typeof history === "undefined" ? null : history.state;
const st = entryState();
return !!st && typeof st === "object" && (st as Record<string, unknown>).loomSheet === true;
}

Expand All @@ -245,7 +252,7 @@ export function setViewParam(key: string, value: string | null, state: Record<st
/** The writer agent a `?memory=` link opens under: the one the entry remembers (a reload
* keeps history.state), else every agent ("*", as Runs opens a key it only knows by name). */
function linkedAgent(key: string): string {
const s: unknown = typeof history === "undefined" ? null : history.state;
const s = entryState();
const remembered = s && typeof s === "object" ? (s as Record<string, unknown>).loomInspect : null;
if (remembered && typeof remembered === "object") {
const r = remembered as Record<string, unknown>;
Expand All @@ -255,15 +262,15 @@ function linkedAgent(key: string): string {
}

// The URL keys that name an object of one namespace: a switch drops them.
const SWITCH_CLEARS = ["memory", "thread", "doc", "task", ...HANDOFF_QUERY_KEYS];
const SWITCH_CLEARS = ["memory", "thread", "doc", "task", "key", ...HANDOFF_QUERY_KEYS];
// A collection is the org's, not a namespace's: an entry made in another namespace keeps it,
// and only the person's own switch of namespace leaves it.
const PICK_CLEARS = [...SWITCH_CLEARS, "collection"];

/** The namespace the current history entry was made in: the app's stamp, else the one its
* address names (the entry a link opened, which boot rewrites and never stamps). */
function entryNamespace(): string | null {
const s: unknown = typeof history === "undefined" ? null : history.state;
const s = entryState();
const ns = s && typeof s === "object" ? (s as Record<string, unknown>).loomNamespace : null;
return typeof ns === "string" ? ns : urlParam(NAMESPACE_KEY);
}
Expand Down Expand Up @@ -297,7 +304,7 @@ export function addressPageNamespace(): void {
/** The entry state that makes the current entry `namespace`'s: stamped with it, and
* remembering no memory of the namespace it was made in. */
function stampFor(namespace: string | null): Record<string, unknown> {
const place = readPlace(typeof history === "undefined" ? null : history.state);
const place = readPlace(entryState());
return {
loomNamespace: namespace,
loomInspect: null,
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/views/Setup.title.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ describe("Settings", () => {
await waitFor(() => expect(screen.getByRole("tab", { name: "Tokens" })).toHaveAttribute("aria-selected", "true"));
});

it("drops a tab another page wrote to the address", async () => {
seed("team");
window.history.replaceState(null, "", "/settings?namespace=team&tab=proposals");
render(<Setup />);
expect(await screen.findByRole("tab", { name: "Tokens" }, WAIT)).toHaveAttribute("aria-selected", "true");
expect(window.location.search).toBe("?namespace=team");
});

it("announces a missing namespace from the alert itself, with no wrapper", async () => {
seed("");
render(<Setup />);
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/views/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export function Setup() {
// A link or browser history can change the tab without remounting Settings.
const navSeq = useStore((s) => s.navSeq);
useEffect(() => {
const sync = () => setTab(readTabParam());
const sync = () => {
// The Review queue owns `tab` too, and a navigation carries it between the two pages.
if (urlParam("tab") !== null && !isSettingsTab(urlParam("tab"))) setViewParam("tab", null);
setTab(readTabParam());
};
sync();
window.addEventListener("popstate", sync);
return () => window.removeEventListener("popstate", sync);
Expand Down
Loading
Loading