Skip to content

Commit 7beedfe

Browse files
committed
fix(gateway): route detached announce by instance
1 parent 07ab482 commit 7beedfe

2 files changed

Lines changed: 13 additions & 23 deletions

File tree

‎src/agents/subagents/announce/subagent-announce-delivery.runtime.test.ts‎

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { afterEach, describe, expect, it, vi } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22
import { WRITE_SCOPE } from "../../../gateway/method-scopes.js";
33
import { createGatewayMethodRegistry } from "../../../gateway/methods/registry.js";
4-
import { createGatewayInstanceRuntime } from "../../../gateway/server-instance-runtime.js";
54
import type {
65
GatewayRequestContext,
76
GatewayRequestHandlers,
87
} from "../../../gateway/server-methods/types.js";
98
import { dispatchSubagentAnnounceAgent } from "./subagent-announce-delivery.runtime.js";
109

11-
function createContext(): GatewayRequestContext {
10+
function createContext(handlers: GatewayRequestHandlers): GatewayRequestContext {
1211
return {
1312
deps: {},
1413
getRuntimeConfig: () => ({}),
14+
getGatewayMethodRegistry: () => createRegistry(handlers),
1515
logGateway: {
1616
warn: vi.fn(),
1717
error: vi.fn(),
@@ -34,38 +34,28 @@ function createRegistry(handlers: GatewayRequestHandlers) {
3434
}
3535

3636
describe("subagent announce Gateway instance dispatch", () => {
37-
let closeRuntime: (() => void) | undefined;
38-
39-
afterEach(() => {
40-
closeRuntime?.();
41-
closeRuntime = undefined;
42-
});
43-
44-
it("delivers a detached announce after the originating request scope has ended", async () => {
45-
const context = createContext();
37+
it("delivers a detached announce through its explicit instance resolver", async () => {
38+
const context = createContext({
39+
agent: ({ respond }) => respond(true, { raw: true }),
40+
});
4641
const idempotencyKey = "detached-subagent-announce";
4742
context.dedupe.set(`agent:${idempotencyKey}`, {
4843
ts: Date.now(),
4944
ok: true,
5045
payload: { runId: "announce-run", status: "ok", summary: "delivered" },
5146
});
52-
const runtime = createGatewayInstanceRuntime({
53-
getContext: () => context,
54-
getMethodRegistry: () =>
55-
createRegistry({
56-
agent: ({ respond }) => respond(true, { raw: true }),
57-
}),
58-
isDispatchAvailable: () => true,
59-
});
60-
closeRuntime = runtime.close;
6147

6248
await expect(
6349
dispatchSubagentAnnounceAgent(
6450
{
6551
message: "Process one completed child result.",
6652
idempotencyKey,
6753
},
68-
{ expectFinal: true, forceSyntheticClient: true },
54+
{
55+
expectFinal: true,
56+
forceSyntheticClient: true,
57+
resolveGatewayContext: () => context,
58+
},
6959
),
7060
).resolves.toEqual({ runId: "announce-run", status: "ok", summary: "delivered" });
7161
});

‎src/agents/subagents/announce/subagent-announce.runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* IO without changing the announce logic itself.
66
*/
77
import { loadSessionEntry } from "../../../config/sessions/session-accessor.js";
8-
export { dispatchGatewayLifecycleMethod as dispatchGatewayMethodInProcess } from "../../../gateway/server-recovery-runtime-context.js";
8+
export { dispatchGatewayMethodInProcess } from "../../../gateway/server-plugin-in-process-dispatch.js";
99
export { getRuntimeConfig } from "../../../config/config.js";
1010
export {
1111
resolveAgentIdFromSessionKey,

0 commit comments

Comments
 (0)