Compare commits

..
Author SHA1 Message Date
paseo-bot[bot] e03811554a fix(app): keep agent metadata after reload
The agent directory cache dropped metadata while keeping the cursor. Require metadata in cached snapshots so older rows trigger the existing agent directory refresh.
2026-11-29 02:00:22 +00:00
2 changed files with 45 additions and 1 deletions
@@ -7,7 +7,10 @@ import {
} from "@/stores/session-store";
import type { StreamItem } from "@/types/stream";
import { normalizeAgentSnapshot } from "@/utils/agent-snapshots";
import { createPluginWorkspaceSnapshot } from "@/plugins/client-state/snapshots";
import {
createPluginAgentSnapshot,
createPluginWorkspaceSnapshot,
} from "@/plugins/client-state/snapshots";
import { ReplicaCache } from ".";
import type { DirectoryCheckpoint } from "@/runtime/replica-cache";
import type { ReplicaHostRows, ReplicaRow, ReplicaRowChanges, ReplicaRowStore } from "./row-store";
@@ -158,6 +161,7 @@ function agent(id = "agent-1"): Agent {
persistence: null,
title: "Cached agent",
labels: {},
metadata: {},
},
SERVER_ID,
),
@@ -1433,3 +1437,40 @@ it("retains workspace metadata across replica-cache reload and invalidates pre-m
projects: checkpoint.projects,
});
});
it("restores agent metadata for plugins when the directory cache reopens", async () => {
const storage = new MemoryStorage();
const writer = createCache(storage);
const baseline = directory();
const metadata = { "plugin.waiting": { kind: "plan", at: "2026-07-18T08:02:00.000Z" } };
baseline.agents.set("agent-1", { ...agent(), metadata });
commitDirectory(writer, SERVER_ID, baseline);
await writer.flush();
const restored = await createCache(storage).readDirectory(SERVER_ID);
expect(
createPluginAgentSnapshot(restored.agents.get("agent-1")!, "workspace-1").metadata,
).toEqual(metadata);
expect(restored.checkpoint).toEqual(baseline.checkpoint);
});
it("discards the agent cursor when a pre-metadata agent row is restored", async () => {
const storage = new MemoryStorage();
const writer = createCache(storage);
const baseline = directory({
agents: { generation: "g", afterSeq: 12 },
projects: { generation: "g", afterSeq: 4 },
});
commitDirectory(writer, SERVER_ID, baseline);
await writer.flush();
const key = `${SERVER_ID}:agent:agent-1`;
const row = storage.rows.get(key)!;
const legacyPayload = JSON.parse(row.payload) as { snapshot: Record<string, unknown> };
delete legacyPayload.snapshot.metadata;
storage.rows.set(key, { ...row, payload: JSON.stringify(legacyPayload) });
const restored = await createCache(storage).readDirectory(SERVER_ID);
expect(restored.checkpoint).toEqual({ projects: baseline.checkpoint.projects });
expect(restored.agents.size).toBe(0);
});
@@ -257,6 +257,8 @@ const StoredAgentSnapshotSchema = z.strictObject({
lastError: z.string().optional(),
title: z.string().nullable(),
labels: z.record(z.string(), z.string()),
// Require metadata so older rows invalidate the agent cursor and refetch from the daemon.
metadata: z.record(z.string(), z.unknown() as z.ZodType<JsonValue>),
// Optional: clients without background_agents never received a background agent to cache.
background: z.boolean().optional(),
requiresAttention: z.boolean().optional(),
@@ -705,6 +707,7 @@ function serializeAgent(agent: Agent): StoredAgent {
...(agent.lastError ? { lastError: agent.lastError } : {}),
title: agent.title,
labels: agent.labels,
metadata: agent.metadata ?? {},
...(agent.background ? { background: true } : {}),
requiresAttention: agent.requiresAttention ?? false,
backgroundWork: agent.backgroundWork,