Skip to content

Commit 83e5962

Browse files
loganjLarry
andauthored
fix(desktop): keep explicit agent profiles bound to their exact key (#7131)
🤖 ## Summary In Buzz Desktop, clicking a message from stopped agent A could open running agent B—and B's controls—because both shared a persona (an agent definition). This now opens the author you clicked and only that agent's own controls, so you can inspect an old message without being redirected to a different running agent. An explicit public key—the identifier for one agent—now stays exact across message authors, members, DMs, deep links and Instances rows, including stopped, archived and relay-only agents. Local controls come only from a matching local record for that key. A relay-only A cannot borrow B's Start/Stop/Edit controls or configuration. Deliberately opening a **persona** is different: it can still select a representative that respects archived instances or offer Start when none remains. The change removes competing historical-persona redirects rather than adding another identity exception. ### Related issue Independent base: `main`; no stack parent or child among the replacements. Extracted from [#7114](#7114), retained as historical source (`98fe33ec`). [Behavior contract](https://github.com/block/buzz/blob/9c4b6523ceaef0f3d92906fcdb5d9a3b9ede7e17/docs/agent-profile-identity.md). Originating [Buzz discussion](buzz://message?channel=f7a9536a-1738-4bad-a888-b3ea25010ef1&id=7aa1f0ab23dce514bd8a0221441cf005bf428914621171472b79747c50820848) · channel `f7a9536a-1738-4bad-a888-b3ea25010ef1`. ### Testing Synthetic Playwright mock-bridge state. After screenshots exercise this independent profile extraction (`df6612b1`); no availability or cloud-marker implementation is included. #### Before: historical A redirects to running B Unchanged main product code (`bc006f67`) with the same updated historical-message fixture fails: clicking Earlier Parity Agent opens Current Parity Agent and its Stop control. ![01-before-historical-redirect](https://raw.githubusercontent.com/block/buzz/2acd989f6eae9e7bc1ce5ae5eeafcbc1704f605f/pr-7131--01-before-historical-redirect.png) #### After: historical A opens A The clicked author remains Earlier Parity Agent, with A's public key and its own Start control. The current sibling is not substituted. ![02-after-historical-exact](https://raw.githubusercontent.com/block/buzz/2acd989f6eae9e7bc1ce5ae5eeafcbc1704f605f/pr-7131--02-after-historical-exact.png) #### Exact relay-only A while local sibling B exists A's public key and owner-scoped profile are visible; no local Start/Stop/Edit/Add control or sibling definition is borrowed. ![03-exact-relay-with-local-sibling](https://raw.githubusercontent.com/block/buzz/2acd989f6eae9e7bc1ce5ae5eeafcbc1704f605f/pr-7131--03-exact-relay-with-local-sibling.png) #### Explicit persona navigation may select local B Deliberately opening the persona selects its local representative, with B's key and legitimate Stop/Restart/Edit controls. ![04-explicit-local-persona](https://raw.githubusercontent.com/block/buzz/2acd989f6eae9e7bc1ce5ae5eeafcbc1704f605f/pr-7131--04-explicit-local-persona.png) #### Explicit persona without an instance may offer Start This is a deliberately opened persona, not a relay-only key turned into a persona surface. ![05-explicit-persona-without-instance](https://raw.githubusercontent.com/block/buzz/2acd989f6eae9e7bc1ce5ae5eeafcbc1704f605f/pr-7131--05-explicit-persona-without-instance.png) [Original screenshot publication](#7131 (comment)); all five immutable image URLs and captions retained here. The final documentation-only commit does not change this UI. These are synthetic browser fixtures, not live runtime health evidence. To check manually, open an old message from stopped A while same-persona B is running; compare the displayed key and controls. Then open the persona itself and verify that representative selection still works. #### Evidence and limitations **5,793 desktop tests**, **56 profile/archive browser cases**, type/static/size checks and repository-wide `just ci` passed. The historical-message regression fails on unchanged main by opening B instead of A. [Published-head CI passed](https://github.com/block/buzz/actions/runs/33422207592). The [advisory security check](https://github.com/block/buzz/actions/runs/33422240973) timed out without a result; it is not a passing check. No availability, cloud-marker, discovery or mention-routing change is included. These screenshots do not establish remote delivery, agent execution or termination. #### Security authorization history (audit, not clearance) The [security gate](#7131 (comment)) remains visible and unresolved. Existing authorization-request comments were posted by `loganj`: [old-head request](#7131 (comment)) for `df6612b1db5a6f8d128cef955fd66a80b6828cb8` at 2026-08-31 17:55:11 UTC, then [current-head request](#7131 (comment)) for `9c4b6523ceaef0f3d92906fcdb5d9a3b9ede7e17` at 17:55:57 UTC. The existing [issue-comment workflow run](https://github.com/block/buzz/actions/runs/33422240973) ended cancelled after the previously reported timeout; it did not produce a completed security review. Latest exact-head Run/Post Codex jobs are skipped, not security approval. Historical comments remain available at their original links; consolidating their audit here does not withdraw authorization or clear the gate. An authorized security workflow owner must arrange the missing exact-range result. --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 434dafe commit 83e5962

13 files changed

Lines changed: 337 additions & 587 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default defineConfig({
2727
"**/search-scope-screenshots.spec.ts",
2828
"**/onboarding-docked-cta-screenshots.spec.ts",
2929
"**/identity-key-help.spec.ts",
30+
"**/exact-key-profile.spec.ts",
3031
"**/key-import-reveal.spec.ts",
3132
"**/navigation.spec.ts",
3233
"**/channels.spec.ts",

‎desktop/src/features/agents/AGENTS.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ with a TypeScript lookup table or an id comparison in a component.
200200
agent from Agents, a DM, or a channel must expose the same actions, tabs,
201201
fields, and profile-wide activity selection. Caller context may control the
202202
panel shell or return navigation, but must not filter or replace profile
203-
content.
203+
content. Explicit public-key targets are always exact, including stopped,
204+
archived, and relay-only identities. Only explicit persona navigation may
205+
select a representative or offer persona Start; a relay persona link cannot
206+
borrow a local sibling's management controls. See
207+
[the identity contract](../../../../docs/agent-profile-identity.md).
204208
14. **Thinking effort has two surfaces: a local-only WRITE control and a
205209
read-only two-facts DISPLAY.** The write control is `EffortPickerField`
206210
(`ui/EffortPickerField.tsx`), a self-contained section component mounted in
Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import {
5-
pickDirectProfileAgent,
6-
pickProfileAgent,
7-
} from "./pickProfileAgent.ts";
4+
import { pickProfileAgent } from "./pickProfileAgent.ts";
85

96
const NONE_ARCHIVED = () => false;
107

@@ -68,60 +65,3 @@ test("a fail-open predicate keeps every instance eligible while loading", () =>
6865
// Fail-open (all false) during the archive-snapshot window: normal ranking.
6966
assert.equal(pickProfileAgent([stopped, running], NONE_ARCHIVED), running);
7067
});
71-
72-
test("a direct-opened active instance is never redirected to a sibling", () => {
73-
// "Alpha Sibling" sorts before "Tyler Agent"; without the direct guard an
74-
// access edit on Tyler would target the sibling.
75-
const sibling = {
76-
name: "Alpha Sibling",
77-
pubkey: "a".repeat(64),
78-
status: "running",
79-
};
80-
const clicked = {
81-
name: "Tyler Agent",
82-
pubkey: "b".repeat(64),
83-
status: "running",
84-
};
85-
86-
assert.equal(
87-
pickDirectProfileAgent(clicked, [sibling, clicked], NONE_ARCHIVED),
88-
clicked,
89-
);
90-
});
91-
92-
test("a direct-opened inactive instance redirects to the active sibling", () => {
93-
const historical = {
94-
name: "Earlier Parity Agent",
95-
pubkey: "a".repeat(64),
96-
status: "stopped",
97-
};
98-
const current = {
99-
name: "Current Parity Agent",
100-
pubkey: "b".repeat(64),
101-
status: "running",
102-
};
103-
104-
assert.equal(
105-
pickDirectProfileAgent(historical, [historical, current], NONE_ARCHIVED),
106-
current,
107-
);
108-
});
109-
110-
test("a direct-opened inactive instance with no active sibling stays put", () => {
111-
const clicked = {
112-
name: "Only Instance",
113-
pubkey: "a".repeat(64),
114-
status: "stopped",
115-
};
116-
const otherStopped = {
117-
name: "Another Stopped",
118-
pubkey: "b".repeat(64),
119-
status: "stopped",
120-
};
121-
122-
assert.equal(
123-
pickDirectProfileAgent(clicked, [clicked, otherStopped], NONE_ARCHIVED),
124-
clicked,
125-
);
126-
assert.equal(pickDirectProfileAgent(clicked, [], NONE_ARCHIVED), clicked);
127-
});

‎desktop/src/features/agents/lib/pickProfileAgent.ts‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { ManagedAgent } from "@/shared/api/types";
55
* Pick the instance that represents a persona throughout the UI.
66
*
77
* A persona can have several historical agent instances. Keeping this rule in
8-
* one place prevents an avatar click on an older message from opening a
9-
* different detail surface than the card in the Agents library.
8+
* one place keeps persona navigation consistent. Explicit pubkey navigation
9+
* never uses this selector: older messages still name their exact author.
1010
*
1111
* Relay-archived instances are never eligible, so an archived record early in
1212
* file order can't hijack the persona target. Returns `undefined` when every
@@ -28,25 +28,3 @@ export function pickProfileAgent(
2828
return left.name.localeCompare(right.name);
2929
})[0];
3030
}
31-
32-
/**
33-
* Resolve which instance a profile panel opened for `directAgent` should
34-
* show, given every instance of the same persona.
35-
*
36-
* Access edits must target the exact instance the user clicked — resolving a
37-
* running sidebar member to an alphabetically-earlier sibling would let a
38-
* "tighten access" save widen the wrong agent. But when the clicked instance
39-
* is inactive and the persona has an active instance elsewhere (an avatar on
40-
* an old message from a retired instance), redirect to the active one so the
41-
* panel matches the Agents library. The `isArchived` predicate keeps that
42-
* redirect from ever landing on an archived sibling.
43-
*/
44-
export function pickDirectProfileAgent(
45-
directAgent: ManagedAgent,
46-
personaInstances: readonly ManagedAgent[],
47-
isArchived: (pubkey: string) => boolean,
48-
) {
49-
if (isManagedAgentActive(directAgent)) return directAgent;
50-
const canonical = pickProfileAgent(personaInstances, isArchived);
51-
return canonical && isManagedAgentActive(canonical) ? canonical : directAgent;
52-
}

‎desktop/src/features/profile/lib/resolveCanonicalManagedAgent.test.mjs‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ test("a persona target with a live sibling resolves to the live instance", () =>
2626
directManagedAgent: undefined,
2727
isArchived: (pubkey) => pubkey === ARCHIVED_PK,
2828
personaInstances: [archived, live],
29-
preferDirectManagedAgent: false,
30-
preserveRequestedInstance: false,
3129
pubkey: undefined,
3230
});
3331

@@ -42,8 +40,6 @@ test("a persona target with all instances archived resolves to undefined", () =>
4240
directManagedAgent: undefined,
4341
isArchived: () => true,
4442
personaInstances: [first, second],
45-
preferDirectManagedAgent: false,
46-
preserveRequestedInstance: false,
4743
pubkey: undefined,
4844
});
4945

@@ -58,8 +54,6 @@ test("an explicit archived pubkey stays exact even when a live sibling exists",
5854
directManagedAgent: archivedDirect,
5955
isArchived: (pubkey) => pubkey === ARCHIVED_PK,
6056
personaInstances: [archivedDirect, live],
61-
preferDirectManagedAgent: false,
62-
preserveRequestedInstance: false,
6357
pubkey: ARCHIVED_PK,
6458
});
6559

@@ -75,48 +69,42 @@ test("an explicit archived pubkey with no managed record resolves to undefined s
7569
directManagedAgent: undefined,
7670
isArchived: (pubkey) => pubkey === HISTORICAL_PK,
7771
personaInstances: [],
78-
preferDirectManagedAgent: false,
79-
preserveRequestedInstance: false,
8072
pubkey: HISTORICAL_PK,
8173
});
8274

8375
assert.equal(resolved, undefined);
8476
});
8577

86-
test("a preserved requested instance pins the exact record over canonicalization", () => {
78+
test("an explicit stopped instance pins the exact record over canonicalization", () => {
8779
const requested = agent({ pubkey: HISTORICAL_PK, status: "stopped" });
8880
const live = agent({ pubkey: LIVE_PK, status: "running" });
8981

9082
const resolved = resolveCanonicalManagedAgent({
9183
directManagedAgent: requested,
9284
isArchived: NONE_ARCHIVED,
9385
personaInstances: [requested, live],
94-
preferDirectManagedAgent: false,
95-
preserveRequestedInstance: true,
9686
pubkey: HISTORICAL_PK,
9787
});
9888

9989
assert.equal(resolved, requested);
10090
});
10191

102-
test("a non-archived historical pubkey canonicalizes to the live persona instance", () => {
103-
// Rule 5: #5788 canonicalization is retained for non-archived navigation.
92+
test("a non-archived historical pubkey stays exact, like archived and active keys", () => {
93+
// History is authored by a key, not its current persona representative.
10494
const requested = agent({ pubkey: HISTORICAL_PK, status: "stopped" });
10595
const live = agent({ pubkey: LIVE_PK, status: "running" });
10696

10797
const resolved = resolveCanonicalManagedAgent({
10898
directManagedAgent: requested,
10999
isArchived: NONE_ARCHIVED,
110100
personaInstances: [requested, live],
111-
preferDirectManagedAgent: false,
112-
preserveRequestedInstance: false,
113101
pubkey: HISTORICAL_PK,
114102
});
115103

116-
assert.equal(resolved, live);
104+
assert.equal(resolved, requested);
117105
});
118106

119-
test("preferDirectManagedAgent keeps a directly opened active instance exact", () => {
107+
test("explicit navigation keeps a directly opened active instance exact", () => {
120108
// The panel's own default: an access edit must target the clicked instance,
121109
// not an alphabetically-earlier active sibling.
122110
const sibling = agent({ name: "Alpha", pubkey: LIVE_PK, status: "running" });
@@ -130,28 +118,37 @@ test("preferDirectManagedAgent keeps a directly opened active instance exact", (
130118
directManagedAgent: clicked,
131119
isArchived: NONE_ARCHIVED,
132120
personaInstances: [sibling, clicked],
133-
preferDirectManagedAgent: true,
134-
preserveRequestedInstance: false,
135121
pubkey: HISTORICAL_PK,
136122
});
137123

138124
assert.equal(resolved, clicked);
139125
});
140126

141-
test("an explicit archived pubkey stays exact even with preferDirectManagedAgent", () => {
142-
// Rule 2 wins over the direct-preference redirect: a deliberately opened
143-
// archived instance must not be redirected away from its unarchive control.
127+
test("an explicit archived pubkey stays exact with a running sibling", () => {
128+
// Archive state does not change what identity an explicit target names.
144129
const archivedDirect = agent({ pubkey: ARCHIVED_PK, status: "stopped" });
145130
const live = agent({ pubkey: LIVE_PK, status: "running" });
146131

147132
const resolved = resolveCanonicalManagedAgent({
148133
directManagedAgent: archivedDirect,
149134
isArchived: (pubkey) => pubkey === ARCHIVED_PK,
150135
personaInstances: [archivedDirect, live],
151-
preferDirectManagedAgent: true,
152-
preserveRequestedInstance: false,
153136
pubkey: ARCHIVED_PK,
154137
});
155138

156139
assert.equal(resolved, archivedDirect);
157140
});
141+
142+
for (const instances of [[], [agent({ status: "running" })]]) {
143+
test(`relay-only A never resolves to local sibling B (${instances.length} siblings)`, () => {
144+
assert.equal(
145+
resolveCanonicalManagedAgent({
146+
directManagedAgent: undefined,
147+
isArchived: NONE_ARCHIVED,
148+
personaInstances: instances,
149+
pubkey: HISTORICAL_PK,
150+
}),
151+
undefined,
152+
);
153+
});
154+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import assert from "node:assert/strict";
2+
import { after, afterEach, before, test } from "node:test";
3+
import { JSDOM } from "jsdom";
4+
5+
const dom = new JSDOM("<!doctype html><html><body></body></html>", {
6+
url: "http://localhost",
7+
});
8+
let renderHook;
9+
let cleanup;
10+
let createElement;
11+
let QueryClient;
12+
let QueryClientProvider;
13+
let useCanonicalManagedAgentProfile;
14+
const clients = [];
15+
const A = "a".repeat(64);
16+
const B = "b".repeat(64);
17+
const sibling = {
18+
pubkey: B,
19+
personaId: "shared-persona",
20+
status: "running",
21+
name: "Local B",
22+
};
23+
24+
before(async () => {
25+
Object.assign(globalThis, {
26+
window: dom.window,
27+
document: dom.window.document,
28+
IS_REACT_ACT_ENVIRONMENT: true,
29+
});
30+
({ renderHook, cleanup } = await import("@testing-library/react"));
31+
({ createElement } = await import("react"));
32+
({ QueryClient, QueryClientProvider } = await import(
33+
"@tanstack/react-query"
34+
));
35+
({ useCanonicalManagedAgentProfile } = await import(
36+
"./useCanonicalManagedAgentProfile.ts"
37+
));
38+
});
39+
afterEach(() => {
40+
cleanup();
41+
for (const client of clients.splice(0)) client.clear();
42+
});
43+
after(() => dom.window.close());
44+
45+
function wrapper() {
46+
const client = new QueryClient({
47+
defaultOptions: { queries: { retry: false, gcTime: 0 } },
48+
});
49+
client.setQueryData(["identity"], { pubkey: "c".repeat(64) });
50+
client.setQueryData(["archivedIdentities"], { archived: [] });
51+
clients.push(client);
52+
return ({ children }) =>
53+
createElement(QueryClientProvider, { client }, children);
54+
}
55+
56+
for (const managedAgents of [[], [sibling]]) {
57+
test(`explicit remote A cannot borrow persona P or its ${managedAgents.length} local instances`, () => {
58+
const { result, rerender } = renderHook(
59+
(props) => useCanonicalManagedAgentProfile(props),
60+
{
61+
wrapper: wrapper(),
62+
initialProps: { managedAgents, personaId: "shared-persona", pubkey: A },
63+
},
64+
);
65+
assert.equal(result.current.managedAgent, undefined);
66+
assert.equal(result.current.linkedPersonaId, undefined);
67+
assert.deepEqual(result.current.instanceBuckets, {
68+
live: [],
69+
archived: [],
70+
});
71+
// Only deliberately navigating to the persona may choose B or offer Start.
72+
rerender({ managedAgents, personaId: "shared-persona", pubkey: undefined });
73+
assert.equal(result.current.linkedPersonaId, "shared-persona");
74+
assert.equal(result.current.managedAgent, managedAgents[0]);
75+
// Returning to the explicit key cannot retain the persona representative.
76+
rerender({ managedAgents, personaId: "shared-persona", pubkey: A });
77+
assert.equal(result.current.managedAgent, undefined);
78+
assert.equal(result.current.linkedPersonaId, undefined);
79+
});
80+
}
81+
82+
test("explicit local instance uses only its own definition link, with normalized key matching", () => {
83+
const { result } = renderHook(
84+
() =>
85+
useCanonicalManagedAgentProfile({
86+
managedAgents: [sibling],
87+
personaId: "unrelated-persona",
88+
pubkey: B.toUpperCase(),
89+
}),
90+
{ wrapper: wrapper() },
91+
);
92+
assert.equal(result.current.managedAgent, sibling);
93+
assert.equal(result.current.linkedPersonaId, sibling.personaId);
94+
});

0 commit comments

Comments
 (0)