mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
fix: Restore icon and appearance when rolling back an agent config revision (#19244)
> [!NOTE] > Opened by Prospector's automated issue-fix pipeline. A maintainer reviews and decides; nothing here merges on its own. ## Thinking Path - Issue #19081 reports a defect in paperclipai/paperclip. - Root cause, as the fixing agent read it: configPatchFromSnapshot built the rollback patch without icon or appearance, so a rollback kept the agent's newer values and recorded that mixed state as the new revision. - This pull request: Restore icon and appearance when rolling back an agent config revision ## What Changed - `server/src/lib/agent-records.ts`: configPatchFromSnapshot now adds icon (string or null) and appearance (only if agentAppearanceSchema.safeParse succeeds). It leaves each field out when the snapshot value is missing or invalid, so older revisions don't clear the agent's current values. ## Verification - Reproducing test(s), added in this PR: `server/src/__tests__/agent-config-snapshot-patch.test.ts`, `server/src/__tests__/agent-persona-persistence.test.ts` - They fail on the base commit and pass with the fix, each twice in a fresh sandbox. - 3 independent attempts wrote 3 reproductions; this fix passes every one of them. - The repository's compile command passes with the fix applied. - 1 existing test file(s) near the change passed. - The full test suite passes except for the 13 file(s) that already fail on the base commit. ## Risks - Written by an automated pipeline, not a person: review it as you would an outside contribution. - Risk tier of the touched paths: 2. ## Model Used - codex:gpt-6.1-sol, opus, sonnet (Anthropic Claude, via Claude Code; OpenAI, via the Codex CLI), writing and checking the change in an isolated sandbox. - opus (Anthropic Claude, via Claude Code), reviewing it independently. ## Linked Issues Fixes #19081 A search of paperclipai/paperclip's open and closed pull requests found no other pull request that names #19081. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with 'Fixes: #' / 'Closes #' / 'Refs #' OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub '#NNN' / 'github.com/paperclipai/paperclip' URLs) - [ ] My branch name describes the change (e.g. 'docs/...', 'fix/...') and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge <!-- prospector:issue-fix v1 issue=19081 base=6452e964a363 report=e4e8f7064467f854 --> Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
5ea18a811a
commit
0733a01c8d
3 files changed
+80
-1
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { randomAgentAppearance } from "@paperclipai/shared";
|
||||
import { configPatchFromSnapshot } from "../lib/agent-records.js";
|
||||
|
||||
const baseSnapshot = {
|
||||
name: "Agent",
|
||||
role: "engineer",
|
||||
adapterType: "process",
|
||||
budgetMonthlyCents: 0,
|
||||
};
|
||||
|
||||
describe("configPatchFromSnapshot", () => {
|
||||
it("restores icon and appearance from the snapshot", () => {
|
||||
const appearance = randomAgentAppearance();
|
||||
const patch = configPatchFromSnapshot({ ...baseSnapshot, icon: "bot", appearance });
|
||||
expect(patch.icon).toBe("bot");
|
||||
expect(patch.appearance).toEqual(appearance);
|
||||
});
|
||||
|
||||
it("restores a null icon", () => {
|
||||
expect(configPatchFromSnapshot({ ...baseSnapshot, icon: null }).icon).toBeNull();
|
||||
});
|
||||
|
||||
it("leaves icon and appearance out when the snapshot lacks valid values", () => {
|
||||
const patch = configPatchFromSnapshot({ ...baseSnapshot, icon: 5, appearance: { bad: true } });
|
||||
expect(patch).not.toHaveProperty("icon");
|
||||
expect(patch).not.toHaveProperty("appearance");
|
||||
const legacy = configPatchFromSnapshot(baseSnapshot);
|
||||
expect(legacy).not.toHaveProperty("icon");
|
||||
expect(legacy).not.toHaveProperty("appearance");
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { agents, companies, createDb } from "@paperclipai/db";
|
||||
import { agentConfigRevisions, agents, companies, createDb } from "@paperclipai/db";
|
||||
import { agentAppearanceSchema, appearanceForPalette, legacyAgentAppearance } from "@paperclipai/shared";
|
||||
import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
||||
import { agentService } from "../services/agents.js";
|
||||
@@ -38,6 +38,49 @@ describe("persisted agent personas", () => {
|
||||
const [row] = await db.select().from(agents).where(eq(agents.id, original.id));
|
||||
expect(row.appearance).toEqual(appearance);
|
||||
});
|
||||
it("restores the revision's icon and appearance on rollback and records them in the rollback revision", async () => {
|
||||
const service = agentService(db);
|
||||
const appearance = appearanceForPalette("arctic-blue");
|
||||
const newerAppearance = appearanceForPalette("cherry-pop");
|
||||
const original = await createAgentLifecycle(db).requestHire(companyId, { name: "Restored persona", role: "engineer", adapterType: "process", icon: "bot", appearance });
|
||||
await service.update(original.id, { title: "First" }, { recordRevision: { source: "test" } });
|
||||
const [revision] = await service.listConfigRevisions(original.id);
|
||||
await service.update(original.id, { title: "Second", icon: "brain", appearance: newerAppearance });
|
||||
const restored = await service.rollbackConfigRevision(original.id, revision.id, {});
|
||||
expect(restored).toMatchObject({ title: "First", icon: "bot", appearance });
|
||||
const [row] = await db.select().from(agents).where(eq(agents.id, original.id));
|
||||
expect(row).toMatchObject({ icon: "bot", appearance });
|
||||
const [rollbackRevision] = await service.listConfigRevisions(original.id);
|
||||
expect(rollbackRevision.source).toBe("rollback");
|
||||
expect(rollbackRevision.changedKeys).toEqual(expect.arrayContaining(["icon", "appearance"]));
|
||||
expect(rollbackRevision.afterConfig).toMatchObject({ title: "First", icon: "bot", appearance });
|
||||
});
|
||||
it("clears the icon when the rolled back revision recorded no icon", async () => {
|
||||
const service = agentService(db);
|
||||
const original = await createAgentLifecycle(db).requestHire(companyId, { name: "Iconless persona", role: "engineer", adapterType: "process", icon: null });
|
||||
await service.update(original.id, { title: "First" }, { recordRevision: { source: "test" } });
|
||||
const [revision] = await service.listConfigRevisions(original.id);
|
||||
await service.update(original.id, { icon: "brain" });
|
||||
const restored = await service.rollbackConfigRevision(original.id, revision.id, {});
|
||||
expect(restored?.icon).toBeNull();
|
||||
});
|
||||
it.each([
|
||||
["missing", (config: Record<string, unknown>) => {
|
||||
const { icon: _icon, appearance: _appearance, ...rest } = config;
|
||||
return rest;
|
||||
}],
|
||||
["invalid", (config: Record<string, unknown>) => ({ ...config, icon: 42, appearance: { paletteId: "not-a-palette" } })],
|
||||
])("keeps the current icon and appearance when the revision's values are %s", async (kind, rewrite) => {
|
||||
const service = agentService(db);
|
||||
const newerAppearance = appearanceForPalette("cherry-pop");
|
||||
const original = await createAgentLifecycle(db).requestHire(companyId, { name: `Older revision ${kind}`, role: "engineer", adapterType: "process", icon: "bot", appearance: appearanceForPalette("arctic-blue") });
|
||||
await service.update(original.id, { title: "First" }, { recordRevision: { source: "test" } });
|
||||
const [revision] = await service.listConfigRevisions(original.id);
|
||||
await db.update(agentConfigRevisions).set({ afterConfig: rewrite(revision.afterConfig) }).where(eq(agentConfigRevisions.id, revision.id));
|
||||
await service.update(original.id, { title: "Second", icon: "brain", appearance: newerAppearance });
|
||||
const restored = await service.rollbackConfigRevision(original.id, revision.id, {});
|
||||
expect(restored).toMatchObject({ title: "First", icon: "brain", appearance: newerAppearance });
|
||||
});
|
||||
it("backfills legacy IDs with exactly the same persisted identity as the runtime fallback", async () => {
|
||||
const ids = Array.from({ length: 20 }, () => randomUUID());
|
||||
await db.insert(agents).values(ids.map((id, i) => ({ id, companyId, name: `Legacy ${i}`, role: "engineer", appearance: null, icon: "bot" })));
|
||||
|
||||
@@ -260,10 +260,14 @@ export function configPatchFromSnapshot(snapshot: unknown): Partial<typeof agent
|
||||
throw unprocessable("Invalid revision snapshot: runtimeConfig");
|
||||
}
|
||||
|
||||
const appearance = agentAppearanceSchema.safeParse(snapshot.appearance);
|
||||
|
||||
return {
|
||||
name: snapshot.name,
|
||||
role: snapshot.role,
|
||||
title: typeof snapshot.title === "string" || snapshot.title === null ? snapshot.title : null,
|
||||
...(typeof snapshot.icon === "string" || snapshot.icon === null ? { icon: snapshot.icon } : {}),
|
||||
...(appearance.success ? { appearance: appearance.data } : {}),
|
||||
reportsTo:
|
||||
typeof snapshot.reportsTo === "string" || snapshot.reportsTo === null ? snapshot.reportsTo : null,
|
||||
capabilities:
|
||||
|
||||
Reference in new issue
Block a user