Remove unused restorePersistedAgents function
This function was never called after implementing lazy-loading. Agents are now loaded on-demand via ensureAgentLoaded when the UI needs them, not eagerly at startup. Keeping the unused function was confusing - it suggested eager restoration was still the intended pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import type { ManagedAgent } from "./agent/agent-manager.js";
|
|||||||
import type { StoredAgentRecord } from "./agent/agent-registry.js";
|
import type { StoredAgentRecord } from "./agent/agent-registry.js";
|
||||||
import {
|
import {
|
||||||
attachAgentRegistryPersistence,
|
attachAgentRegistryPersistence,
|
||||||
restorePersistedAgents,
|
|
||||||
} from "./persistence-hooks.js";
|
} from "./persistence-hooks.js";
|
||||||
import type {
|
import type {
|
||||||
AgentPermissionRequest,
|
AgentPermissionRequest,
|
||||||
@@ -105,65 +104,6 @@ function createRecord(
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("persistence hooks", () => {
|
describe("persistence hooks", () => {
|
||||||
test("restorePersistedAgents resumes and creates agents", async () => {
|
|
||||||
const resumeAgent = vi.fn().mockResolvedValue(null);
|
|
||||||
const createAgent = vi.fn().mockResolvedValue(null);
|
|
||||||
const agentManager = {
|
|
||||||
resumeAgent,
|
|
||||||
createAgent,
|
|
||||||
};
|
|
||||||
const records: StoredAgentRecord[] = [
|
|
||||||
createRecord({
|
|
||||||
id: "claude-agent",
|
|
||||||
lastModeId: "plan",
|
|
||||||
}),
|
|
||||||
createRecord({
|
|
||||||
id: "codex-agent",
|
|
||||||
provider: "codex",
|
|
||||||
cwd: "/tmp/codex",
|
|
||||||
lastModeId: null,
|
|
||||||
config: { modeId: "auto", model: "gpt-4.1", extra: { codex: { policy: "auto" } } },
|
|
||||||
persistence: null,
|
|
||||||
}),
|
|
||||||
createRecord({
|
|
||||||
id: "unknown",
|
|
||||||
provider: "mystery" as any,
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
const registry = {
|
|
||||||
list: vi.fn().mockResolvedValue(records),
|
|
||||||
applySnapshot: vi.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
await restorePersistedAgents(
|
|
||||||
agentManager as any,
|
|
||||||
registry as any
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(resumeAgent).toHaveBeenCalledTimes(1);
|
|
||||||
expect(resumeAgent).toHaveBeenCalledWith(
|
|
||||||
records[0].persistence,
|
|
||||||
expect.objectContaining({
|
|
||||||
cwd: records[0].cwd,
|
|
||||||
modeId: records[0].lastModeId,
|
|
||||||
model: records[0].config?.model,
|
|
||||||
}),
|
|
||||||
records[0].id
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(createAgent).toHaveBeenCalledTimes(1);
|
|
||||||
expect(createAgent).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
provider: "codex",
|
|
||||||
cwd: "/tmp/codex",
|
|
||||||
modeId: "auto",
|
|
||||||
model: "gpt-4.1",
|
|
||||||
extra: { codex: { policy: "auto" } },
|
|
||||||
}),
|
|
||||||
"codex-agent"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("attachAgentRegistryPersistence forwards agent snapshots", async () => {
|
test("attachAgentRegistryPersistence forwards agent snapshots", async () => {
|
||||||
const applySnapshot = vi.fn().mockResolvedValue(undefined);
|
const applySnapshot = vi.fn().mockResolvedValue(undefined);
|
||||||
let subscriber: (event: any) => void = () => {
|
let subscriber: (event: any) => void = () => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { AgentManager } from "./agent/agent-manager.js";
|
import type { AgentManager } from "./agent/agent-manager.js";
|
||||||
import type {
|
import type {
|
||||||
AgentPersistenceHandle,
|
|
||||||
AgentProvider,
|
AgentProvider,
|
||||||
AgentSessionConfig,
|
AgentSessionConfig,
|
||||||
} from "./agent/agent-sdk-types.js";
|
} from "./agent/agent-sdk-types.js";
|
||||||
@@ -11,7 +10,10 @@ import type {
|
|||||||
|
|
||||||
type AgentRegistryPersistence = Pick<AgentRegistry, "applySnapshot" | "list">;
|
type AgentRegistryPersistence = Pick<AgentRegistry, "applySnapshot" | "list">;
|
||||||
type AgentManagerStateSource = Pick<AgentManager, "subscribe">;
|
type AgentManagerStateSource = Pick<AgentManager, "subscribe">;
|
||||||
type AgentManagerRestorer = Pick<AgentManager, "resumeAgent" | "createAgent">;
|
|
||||||
|
function isKnownProvider(provider: string): provider is AgentProvider {
|
||||||
|
return provider === "claude" || provider === "codex";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach AgentRegistry persistence to an AgentManager instance so every
|
* Attach AgentRegistry persistence to an AgentManager instance so every
|
||||||
@@ -33,83 +35,6 @@ export function attachAgentRegistryPersistence(
|
|||||||
return unsubscribe;
|
return unsubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore persisted agents from the AgentRegistry at server startup.
|
|
||||||
*/
|
|
||||||
export async function restorePersistedAgents(
|
|
||||||
agentManager: AgentManagerRestorer,
|
|
||||||
registry: AgentRegistryPersistence
|
|
||||||
): Promise<void> {
|
|
||||||
const records = await registry.list();
|
|
||||||
if (records.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let resumed = 0;
|
|
||||||
let created = 0;
|
|
||||||
|
|
||||||
for (const record of records) {
|
|
||||||
if (!isKnownProvider(record.provider)) {
|
|
||||||
console.warn(
|
|
||||||
`[Agents] Skipping persisted agent ${record.id} with unknown provider '${record.provider}'`
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handle = buildPersistenceHandle(record);
|
|
||||||
try {
|
|
||||||
if (handle) {
|
|
||||||
await agentManager.resumeAgent(
|
|
||||||
handle,
|
|
||||||
buildConfigOverrides(record),
|
|
||||||
record.id
|
|
||||||
);
|
|
||||||
resumed += 1;
|
|
||||||
} else {
|
|
||||||
await agentManager.createAgent(
|
|
||||||
buildSessionConfig(record),
|
|
||||||
record.id
|
|
||||||
);
|
|
||||||
created += 1;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`[Agents] Failed to restore agent ${record.id} from registry:`,
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`[Agents] Loaded ${records.length} persisted agent record(s); resumed ${resumed}, created ${created}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isKnownProvider(provider: string): provider is AgentProvider {
|
|
||||||
return provider === "claude" || provider === "codex";
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildPersistenceHandle(
|
|
||||||
record: StoredAgentRecord
|
|
||||||
): AgentPersistenceHandle | null {
|
|
||||||
if (!record.persistence) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const { provider, sessionId, nativeHandle, metadata } = record.persistence;
|
|
||||||
if (!isKnownProvider(provider)) {
|
|
||||||
console.warn(
|
|
||||||
`[Agents] Skipping persisted handle for ${record.id} with unknown provider '${provider}'`
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
provider,
|
|
||||||
sessionId,
|
|
||||||
nativeHandle,
|
|
||||||
metadata,
|
|
||||||
} satisfies AgentPersistenceHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildConfigOverrides(
|
export function buildConfigOverrides(
|
||||||
record: StoredAgentRecord
|
record: StoredAgentRecord
|
||||||
): Partial<AgentSessionConfig> {
|
): Partial<AgentSessionConfig> {
|
||||||
|
|||||||
Reference in New Issue
Block a user