fix: live sub-agent observability — dispatch cards, steer artifacts, sidebar panel
The pi-style ack protocol (previous commit) left the client describing the
old world: artifact cards read the ack string as a result ("could not be
displayed"), the only job poller rendered on input-available parts that no
longer exist (so wake turns landed invisibly until re-navigation), steers
rendered as learner bubbles with no SVG anywhere, and server-persisted
assistant messages carried empty SDK ids (duplicate React keys).
- persistTurn (turn-service): fill empty message ids at the canonical write
— server-only messages (last turn's, wake turns') now key uniquely;
client-authored ids untouched.
- chat.tsx: ONE central /api/jobs poll (fast while jobs run, slow discovery
cadence, off for job-less sessions) drives every job surface, re-syncs
once when a job settles (the record already holds the steer + wake
response at flip time), and adopts server-side wake turns via the same
turnInFlight machinery as returning mid-turn. Steers branch to the
artifact card — never a bubble. Composer no longer gates on jobs.
- /api/jobs now reports turnInFlight alongside the job list.
- dispatch-card: the tool-call box — live activity by toolCallId while
running, quiet "delivered"/"failed" one-liner after; the ack is visible
observability, the artifact lives in the steer.
- steer-card: renders the delivered artifact by kind (research brief /
sanitized SVG / sandboxed demo iframe) from the data-subagent-artifact
part; result renderers extracted and exported from the artifact cards.
- sub-agents-panel: right-sidebar section above the plan tree listing
running sub-agents (kind, elapsed, live activity) — vanishes when idle.
- tests: dispatch/steer/panel render tests re-target the new protocol;
persistTurn id-hygiene suite. 229/229 green, build green.
Out-of-lane touches for master review: chat.tsx + components/** (cleared
this wave), app/api/jobs/route.ts, src/server/turn-service.ts, contracts
protocol doc §2. Live-verified on :3003 (full loop, SSR DOM checked).
This commit is contained in:
@@ -42,6 +42,7 @@ import { createTeacherAgent } from "../src/agent/teacher-agent.ts";
|
||||
import { createTeacherTools } from "../src/agent/tools.ts";
|
||||
import { handleChatRequest } from "../src/server/chat-handler.ts";
|
||||
import { deliverJobResult, setTurnRunner } from "../src/server/jobs.ts";
|
||||
import { persistTurn, withMessageIds } from "../src/server/turn-service.ts";
|
||||
import { chatStore } from "../src/store/chats.ts";
|
||||
import { jobStore } from "../src/store/jobs.ts";
|
||||
import { createJobRunner, researchModelOverride } from "../src/agent/subagents/runner.ts";
|
||||
@@ -657,3 +658,32 @@ describe("wake pipeline (src/server/jobs.ts)", () => {
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
// ─── persist id hygiene (the duplicate-empty-key bug) ────────────────────────
|
||||
|
||||
describe("persistTurn id hygiene", () => {
|
||||
it("withMessageIds fills EMPTY ids (server-only synthesized messages) and preserves existing ones", () => {
|
||||
const filled = withMessageIds([
|
||||
{ id: "", role: "assistant", parts: [{ type: "text", text: "wake turn" }] },
|
||||
{ id: "client-id", role: "user", parts: [{ type: "text", text: "hi" }] },
|
||||
]);
|
||||
assert.notEqual(filled[0]!.id, "", "empty id replaced");
|
||||
assert.match(filled[0]!.id, /^msg_/);
|
||||
assert.equal(filled[1]!.id, "client-id", "client-authored id untouched");
|
||||
assert.notEqual(filled[0]!.id, filled[1]!.id);
|
||||
});
|
||||
|
||||
it("persistTurn saves every message with a unique non-empty id (wake turns never re-POSTed)", () => {
|
||||
const chat = chatStore.createChat("Test: persist ids");
|
||||
trackChat(chat.id);
|
||||
persistTurn(chatStore, chat.id, [
|
||||
{ id: "", role: "user", parts: [{ type: "text", text: "q" }] },
|
||||
{ id: "", role: "assistant", parts: [{ type: "text", text: "a1" }] },
|
||||
{ id: "", role: "assistant", parts: [{ type: "text", text: "a2" }] },
|
||||
], false);
|
||||
const record = chatStore.getChat(chat.id);
|
||||
const ids = record!.messages.map((m) => m.id);
|
||||
assert.ok(ids.every((id) => id && id.length > 0), "no empty ids survive persist");
|
||||
assert.equal(new Set(ids).size, ids.length, "ids unique — React keys safe");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user