From d7a70f6efa376ee4adac97ea717bc7994d79a038 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Sun, 2 Aug 2026 13:47:24 +0800 Subject: [PATCH] fix(host): hand a raced plain-agent winner back from agentFor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The raced-collision catch mirrored only the subagent-owned half of ensureSession's `.catch`: a concurrent plain-agent publish winning the identity still fell through to `internal`, where ensureSession returns the winner. Mirror in full — classify a subagent-owned winner as `agent-busy`, return a clean plain-agent winner directly. --- packages/host/apiproxy/src/api-proxy.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/host/apiproxy/src/api-proxy.ts b/packages/host/apiproxy/src/api-proxy.ts index 0827762a8a..14f03b3773 100644 --- a/packages/host/apiproxy/src/api-proxy.ts +++ b/packages/host/apiproxy/src/api-proxy.ts @@ -1114,14 +1114,15 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro if (error instanceof SubagentSessionOwnership) { return { error: subagentOwnershipError(error.sessionId) } } - // A concurrent parent `enter()` can win the identity between the - // pre-resume published re-check and `ctx.agents.resume` publication; - // the ID-collision rejection falls through here. Re-classify that - // raced published winner into the stable ownership error, mirroring - // ensureSession's `.catch`. + // A concurrent publish can win the identity between the pre-resume + // re-check and `ctx.agents.resume` publication; the ID-collision + // rejection falls through here. Mirror ensureSession's `.catch` in + // full: classify a subagent-owned winner into the stable ownership + // error, and hand a clean plain-agent winner straight back. const live = ctx.agents.get(sessionId) - if (live !== undefined && hasSubagentOwner(live.session, live)) { - return { error: subagentOwnershipError(sessionId) } + if (live !== undefined) { + if (hasSubagentOwner(live.session, live)) return { error: subagentOwnershipError(sessionId) } + return { agent: live } } const attached = ctx.sessions.get(sessionId) if (attached !== undefined && hasSubagentOwner(attached, undefined)) {