Preserve registry creation timestamps

This commit is contained in:
Mohamed Boudra
2025-11-30 02:26:26 +00:00
parent f38287ff4c
commit cc34ea722a
3 changed files with 28 additions and 1 deletions

View File

@@ -17,12 +17,14 @@ export type { ManagedAgent };
type ProjectionOptions = {
title?: string | null;
createdAt?: string;
};
export function toStoredAgentRecord(
agent: ManagedAgent,
options?: ProjectionOptions
): StoredAgentRecord {
const createdAt = options?.createdAt ?? agent.createdAt.toISOString();
const config = buildSerializableConfig(agent.config);
const persistence = sanitizePersistenceHandle(agent.persistence);
@@ -30,7 +32,7 @@ export function toStoredAgentRecord(
id: agent.id,
provider: agent.provider,
cwd: agent.cwd,
createdAt: agent.createdAt.toISOString(),
createdAt,
updatedAt: agent.updatedAt.toISOString(),
lastActivityAt: agent.updatedAt.toISOString(),
lastUserMessageAt: agent.lastUserMessageAt

View File

@@ -126,6 +126,30 @@ describe("AgentRegistry", () => {
expect(persisted.config?.extra?.claude).toMatchObject({ maxThinkingTokens: 1024 });
});
test("applySnapshot preserves original createdAt timestamp", async () => {
const agentId = "agent-created-at";
const firstTimestamp = new Date("2025-01-01T00:00:00.000Z");
await registry.applySnapshot(
createManagedAgent({ id: agentId, createdAt: firstTimestamp })
);
const initialRecord = await registry.get(agentId);
expect(initialRecord?.createdAt).toBe(firstTimestamp.toISOString());
await registry.applySnapshot(
createManagedAgent({
id: agentId,
createdAt: new Date("2025-02-01T00:00:00.000Z"),
updatedAt: new Date("2025-02-01T00:00:00.000Z"),
lifecycle: "running",
})
);
const updatedRecord = await registry.get(agentId);
expect(updatedRecord?.createdAt).toBe(firstTimestamp.toISOString());
expect(updatedRecord?.lastStatus).toBe("running");
});
test("stores titles independently of snapshots", async () => {
await registry.applySnapshot(
createManagedAgent({

View File

@@ -109,6 +109,7 @@ export class AgentRegistry {
const existing = this.cache.get(agent.id);
const record = toStoredAgentRecord(agent, {
title: existing?.title ?? null,
createdAt: existing?.createdAt,
});
this.cache.set(agent.id, record);
await this.flush();