Preserve registry creation timestamps
This commit is contained in:
@@ -17,12 +17,14 @@ export type { ManagedAgent };
|
|||||||
|
|
||||||
type ProjectionOptions = {
|
type ProjectionOptions = {
|
||||||
title?: string | null;
|
title?: string | null;
|
||||||
|
createdAt?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function toStoredAgentRecord(
|
export function toStoredAgentRecord(
|
||||||
agent: ManagedAgent,
|
agent: ManagedAgent,
|
||||||
options?: ProjectionOptions
|
options?: ProjectionOptions
|
||||||
): StoredAgentRecord {
|
): StoredAgentRecord {
|
||||||
|
const createdAt = options?.createdAt ?? agent.createdAt.toISOString();
|
||||||
const config = buildSerializableConfig(agent.config);
|
const config = buildSerializableConfig(agent.config);
|
||||||
const persistence = sanitizePersistenceHandle(agent.persistence);
|
const persistence = sanitizePersistenceHandle(agent.persistence);
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ export function toStoredAgentRecord(
|
|||||||
id: agent.id,
|
id: agent.id,
|
||||||
provider: agent.provider,
|
provider: agent.provider,
|
||||||
cwd: agent.cwd,
|
cwd: agent.cwd,
|
||||||
createdAt: agent.createdAt.toISOString(),
|
createdAt,
|
||||||
updatedAt: agent.updatedAt.toISOString(),
|
updatedAt: agent.updatedAt.toISOString(),
|
||||||
lastActivityAt: agent.updatedAt.toISOString(),
|
lastActivityAt: agent.updatedAt.toISOString(),
|
||||||
lastUserMessageAt: agent.lastUserMessageAt
|
lastUserMessageAt: agent.lastUserMessageAt
|
||||||
|
|||||||
@@ -126,6 +126,30 @@ describe("AgentRegistry", () => {
|
|||||||
expect(persisted.config?.extra?.claude).toMatchObject({ maxThinkingTokens: 1024 });
|
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 () => {
|
test("stores titles independently of snapshots", async () => {
|
||||||
await registry.applySnapshot(
|
await registry.applySnapshot(
|
||||||
createManagedAgent({
|
createManagedAgent({
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ export class AgentRegistry {
|
|||||||
const existing = this.cache.get(agent.id);
|
const existing = this.cache.get(agent.id);
|
||||||
const record = toStoredAgentRecord(agent, {
|
const record = toStoredAgentRecord(agent, {
|
||||||
title: existing?.title ?? null,
|
title: existing?.title ?? null,
|
||||||
|
createdAt: existing?.createdAt,
|
||||||
});
|
});
|
||||||
this.cache.set(agent.id, record);
|
this.cache.set(agent.id, record);
|
||||||
await this.flush();
|
await this.flush();
|
||||||
|
|||||||
Reference in New Issue
Block a user