fix(coding-agent): prevented race condition in concurrent createAgentSession calls

- Export AgentRegistry from the SDK to allow passing a private registry instance.
- Provide a dedicated AgentRegistry per in-process client in the benchmark runner.
This commit is contained in:
can1357
2026-07-30 06:03:32 +02:00
parent 00fedcf6ac
commit a6001c04a3
3 changed files with 11 additions and 0 deletions
@@ -9,6 +9,7 @@ import type { AgentEvent, AgentMessage, ResolvedThinkingLevel, ThinkingLevel } f
import type { Model, ToolExample } from "@oh-my-pi/pi-ai";
import type { AgentSession, AgentSessionEvent, AuthStorage, SessionStats } from "@oh-my-pi/pi-coding-agent";
import {
AgentRegistry,
type CreateAgentSessionResult,
createAgentSession,
discoverAuthStorage,
@@ -97,6 +98,11 @@ export class InProcessClient {
authStorage: shared?.authStorage,
modelRegistry: shared?.modelRegistry,
sessionManager: SessionManager.inMemory(this.#options.cwd),
// Benchmark tasks run many top-level sessions concurrently in one
// process. The global registry admits only one "Main" per process
// generation (later registrations replace earlier refs, which then
// fail session initialization), so each client gets its own registry.
agentRegistry: new AgentRegistry(),
systemPrompt: this.#options.appendSystemPrompt
? (defaultPrompt: string[]) => [...defaultPrompt, this.#options.appendSystemPrompt!]
: undefined,