Skip to content

Commit f55e6b6

Browse files
baxenclaude00claude
committed
fix(agents): address leftover review findings from the agents stack
- Startup: a conflicting or failed agents2 storage move is logged and skipped instead of throwing before React mounts, which left Buzz on "Opening Buzz" every launch. The source key stays for a later launch. - Runtimes: automatic failure and status replies from Claude Code and Codex tag the owner instead of the asker. A sibling asker was woken by the tag, so two agents failing alike woke each other without end. - Quiet lines: the collapsed scroll anchor moves from the toggle button to its entry, so revealing a linked message no longer takes the toggle out of the Tab order; the toggle gets the owner-level focus ring. - Session viewer: a Claude send shows as posted only once its result confirms it; failed and pending sends stay tool rows. Keyboard activation of a timing segment jumps to its record. /state no longer ships the unused raw transcript every poll. Co-authored-by: claude00 <fb8b76a01257932b8ca35060862c29bd09b2137638573731c2d5074fc02c5385@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Bradley Axen <[email protected]>
1 parent 6eacd13 commit f55e6b6

14 files changed

Lines changed: 165 additions & 26 deletions

‎scripts/export-claude-session.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ export function buildClaude(records) {
136136
} else if (
137137
block?.type === "tool_use" &&
138138
/(^|__)buzz__send$/.test(block.name) &&
139-
typeof block.input?.text === "string"
139+
typeof block.input?.text === "string" &&
140+
// A failed or unanswered send stays a tool row with its result: it is
141+
// what someone looking for a missing reply needs to see.
142+
results.has(block.id) &&
143+
results.get(block.id).is_error !== true
140144
) {
141145
entries.push(entry.sent(timestamp, block.input.text));
142146
} else if (block?.type === "tool_use") {

‎scripts/session-debug-client.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ $("timeline").addEventListener("focusin", (event) => {
403403
});
404404
$("timeline").addEventListener("focusout", hideTip);
405405
$("timeline").addEventListener("click", (event) => {
406-
const target = targetAt(event);
406+
// A keyboard click has no pointer position: use the button it activated.
407+
const target =
408+
event.detail === 0
409+
? event.target.closest("[data-seg],[data-mark],.idle-break")
410+
: targetAt(event);
407411
if (target) jumpTo(target);
408412
});
409413
// Minimap viewport: the conversation's on-screen time range as a band on the

‎scripts/session-debug.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ export async function createInspector({
152152
},
153153
);
154154
model.entries = snapshot.entries;
155-
model.raw = snapshot.raw;
156155
model.snapshotAt = until;
157156
}
158157
return { ...model, candidates };

‎scripts/session-model.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ export function sessionModel(
376376
},
377377
turns,
378378
timing: wallTiming(records, turns, provider),
379-
raw: records.map(publicRecord),
380379
limitations:
381380
provider === "codex"
382381
? "Recorded base instructions, dynamic tools, run settings, messages and usage. Native tool schemas and exact post-compaction inference requests are not recorded. Encrypted reasoning is omitted."

‎src/bundled/claude-code/runtime.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,48 @@ it("replaces the spare when no agent runs where it was started", async () => {
559559
);
560560
expect(claudes()).toHaveLength(2);
561561
});
562+
563+
it("tells the owner, not the asking sibling, when a sibling's turn fails", async () => {
564+
const secret = schnorr.utils.randomSecretKey();
565+
const owner = bytesToHex(schnorr.getPublicKey(secret));
566+
const sibling = bytesToHex(
567+
schnorr.getPublicKey(schnorr.utils.randomSecretKey()),
568+
);
569+
const digest = createHash("sha256")
570+
.update(`nostr:agent-auth:${sibling}:`)
571+
.digest();
572+
const mention = message("2", "@Claude hi", {
573+
pubkey: sibling,
574+
tags: [
575+
["h", channel],
576+
["p", self],
577+
["auth", owner, "", bytesToHex(schnorr.sign(digest, secret))],
578+
],
579+
});
580+
const { runtime, published, claudes, agent } = setup();
581+
runtime.sync([{ pubkey: self, config: DEFAULT_CONFIG } as Agent]);
582+
await flush(10);
583+
const [spare] = claudes();
584+
if (!spare) throw new Error("no spare");
585+
spare.hold = true;
586+
await runtime.run({
587+
trigger: { type: "mention", event: mention },
588+
channelId: channel,
589+
agent: { ...agent, owner },
590+
config: DEFAULT_CONFIG,
591+
signal: new AbortController().signal,
592+
workingUntil: () => undefined,
593+
} as unknown as Delivery);
594+
await flush(10);
595+
expect(spare.prompts).toHaveLength(1);
596+
// Both share one login, so both hit the same limit: tagging the sibling
597+
// would wake it to fail and tag this agent back.
598+
spare.exit(1, "Error: usage limit\n");
599+
await flush(10);
600+
const report = published.find((event) => event.kind === 9);
601+
expect(report?.tags).toEqual([
602+
["h", channel],
603+
["e", mention.id, "", "reply"],
604+
["p", owner],
605+
]);
606+
});

‎src/bundled/claude-code/runtime.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ export class ClaudeRuntime {
305305
.finally(() => this.notify());
306306
}
307307

308-
/** Says in the thread that a turn failed, so nobody waits on it. */
308+
/** Says in the thread that a turn failed, so nobody waits on it. Tells the
309+
* owner even when a sibling asked: tagging the sibling would wake it, and two
310+
* agents failing alike would wake each other without end. */
309311
private report(
310312
agent: AgentHandle,
311313
channel: string,
@@ -319,7 +321,7 @@ export class ClaudeRuntime {
319321
tags: [
320322
["h", channel],
321323
["e", threadReference(event)?.rootId ?? event.id, "", "reply"],
322-
["p", event.pubkey],
324+
["p", agent.owner],
323325
],
324326
})
325327
.catch((failure) =>

‎src/bundled/codex/runtime.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ it("ignores non-owner messages without spawning", async () => {
922922
expect(f.spawn).not.toHaveBeenCalled();
923923
expect(f.publish).not.toHaveBeenCalled();
924924
});
925-
it("answers another agent its owner attested", async () => {
925+
it("answers another agent its owner attested, telling the owner of failures", async () => {
926926
const f = fixture();
927927
const secret = schnorr.utils.randomSecretKey();
928928
const owner = bytesToHex(schnorr.getPublicKey(secret));
@@ -944,6 +944,12 @@ it("answers another agent its owner attested", async () => {
944944
}
945945
await f.runtime.run({ ...ask, agent: { ...ask.agent, owner } });
946946
await vi.waitFor(() => expect(f.starts()).toHaveLength(1));
947+
// A failure tells the owner: tagging the sibling would wake it to fail too.
948+
f.complete(0, "");
949+
await vi.waitFor(() => expect(f.publish).toHaveBeenCalledTimes(1));
950+
const failure = f.publish.mock.calls[0]?.[0] as { tags: string[][] };
951+
expect(failure.tags).toContainEqual(["p", owner]);
952+
expect(failure.tags).not.toContainEqual(["p", sibling]);
947953
});
948954
it("publishes unexpected exit and empty-completion failures instead of silently losing work", async () => {
949955
const f = fixture();

‎src/bundled/codex/runtime.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,16 @@ export class CodexRuntime {
471471
snapshot.session.read(filters, { signal }),
472472
);
473473
}
474+
// Tags the owner even when a sibling asked: tagging the sibling would wake
475+
// it, and two agents failing alike would wake each other without end.
474476
private publish(request: Request, content: string) {
475477
return request.agent.publish({
476478
kind: 9,
477479
content,
478480
tags: [
479481
["h", request.conversation.channelId],
480482
["e", rootOf(request.event), "", "reply"],
481-
["p", request.event.pubkey],
483+
["p", request.agent.owner],
482484
],
483485
});
484486
}

‎src/features/agents/migrate-storage.test.ts‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, it } from "vitest";
1+
import { expect, it, vi } from "vitest";
22
import { migrateAgentStorage } from "./migrate-storage";
33
import { readRecords, readTeams, STORAGE_KEY, TEAMS_KEY } from "./store";
44
import { memoryStorage } from "./test-fakes";
@@ -30,28 +30,40 @@ it("moves settings and teams byte for byte, then restarts without resurrecting o
3030
});
3131

3232
it("preserves the source on write failure and resumes an interrupted copy", () => {
33+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
3334
const storage = memoryStorage();
3435
storage.setItem("buzz.agents2.v1", "exact bytes");
35-
expect(() =>
36-
migrateAgentStorage({
37-
...storage,
38-
setItem: () => {
39-
throw new Error("full");
40-
},
41-
}),
42-
).toThrow("full");
36+
migrateAgentStorage({
37+
...storage,
38+
setItem: () => {
39+
throw new Error("full");
40+
},
41+
});
42+
expect(error).toHaveBeenCalledWith(
43+
"Cannot migrate buzz.agents2.v1",
44+
expect.objectContaining({ message: "full" }),
45+
);
4346
expect(storage.getItem("buzz.agents2.v1")).toBe("exact bytes");
47+
expect(storage.getItem(STORAGE_KEY)).toBeNull();
48+
error.mockRestore();
4449
storage.setItem(STORAGE_KEY, "exact bytes");
4550
migrateAgentStorage(storage);
4651
expect(storage.getItem("buzz.agents2.v1")).toBeNull();
4752
expect(storage.getItem(STORAGE_KEY)).toBe("exact bytes");
4853
});
4954

50-
it("refuses to overwrite conflicting settings", () => {
55+
it("refuses to overwrite conflicting settings without stopping startup", () => {
56+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
5157
const storage = memoryStorage();
5258
storage.setItem("buzz.agents2.v1", "old");
5359
storage.setItem(STORAGE_KEY, "new");
54-
expect(() => migrateAgentStorage(storage)).toThrow("different data");
60+
storage.setItem("buzz.agents2.teams.v1", "teams");
61+
migrateAgentStorage(storage);
62+
expect(error).toHaveBeenCalledWith(
63+
expect.stringContaining("already contains different data"),
64+
);
5565
expect(storage.getItem("buzz.agents2.v1")).toBe("old");
5666
expect(storage.getItem(STORAGE_KEY)).toBe("new");
67+
expect(storage.getItem(TEAMS_KEY)).toBe("teams");
68+
error.mockRestore();
5769
});

‎src/features/agents/migrate-storage.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ export function migrateAgentStorage(storage: Storage) {
1111
if (old === null) continue;
1212
const current = storage.getItem(key);
1313
// An interrupted copy can resume; conflicting data needs recovery, never
14-
// an implicit overwrite or merge of independently edited settings.
15-
if (current !== null && current !== old)
16-
throw new Error(
14+
// an implicit overwrite or merge of independently edited settings. Either
15+
// failure leaves the source for a later launch and must not stop startup:
16+
// this runs before the app can render any error.
17+
if (current !== null && current !== old) {
18+
console.error(
1719
`Cannot migrate ${oldKey}: ${key} already contains different data`,
1820
);
19-
if (current === null) storage.setItem(key, old);
20-
storage.removeItem(oldKey);
21+
continue;
22+
}
23+
try {
24+
if (current === null) storage.setItem(key, old);
25+
storage.removeItem(oldKey);
26+
} catch (error) {
27+
console.error(`Cannot migrate ${oldKey}`, error);
28+
}
2129
}
2230
}

0 commit comments

Comments
 (0)