Skip to content

Commit 35dd228

Browse files
saphidclaude
andcommitted
fix(server): an empty peer answer still marks the link as failing
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 069cde3 commit 35dd228

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎apps/server/src/peer/PeerMcpClient.test.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ it.effect("keeps a link healthy when the peer refuses a call", () =>
141141
it.effect("renews a missing peer session once and reuses its replacement", () =>
142142
Effect.gen(function* () {
143143
const sessionHeaders: Array<string | undefined> = [];
144-
const statuses = [200, 202, 404, 200, 202, 200, 200];
144+
const statuses = [200, 202, 404, 200, 202, 200, 200, 200];
145+
const outcomes: Array<string | null> = [];
145146
const http = HttpClient.make((request) =>
146147
Effect.sync(() => {
147148
const index = sessionHeaders.length;
@@ -151,13 +152,15 @@ it.effect("renews a missing peer session once and reuses its replacement", () =>
151152
return HttpClientResponse.fromWeb(
152153
request,
153154
new Response(
154-
index >= 5
155-
? JSON.stringify({
156-
result: {
157-
content: [{ type: "text", text: '{"modes":"approval-required/plan"}' }],
158-
},
159-
})
160-
: "",
155+
index === 7
156+
? "{}"
157+
: index >= 5
158+
? JSON.stringify({
159+
result: {
160+
content: [{ type: "text", text: '{"modes":"approval-required/plan"}' }],
161+
},
162+
})
163+
: "",
161164
{
162165
status,
163166
headers:
@@ -193,7 +196,7 @@ it.effect("renews a missing peer session once and reuses its replacement", () =>
193196
url: "https://peer.example",
194197
token: "fixture",
195198
}),
196-
recordOutcome: () => Effect.void,
199+
recordOutcome: (_, outcome) => Effect.sync(() => outcomes.push(outcome.error)),
197200
}),
198201
),
199202
),
@@ -211,6 +214,17 @@ it.effect("renews a missing peer session once and reuses its replacement", () =>
211214
}),
212215
).toEqual({ modes: "approval-required/plan" });
213216
}
217+
// An answer with neither a result nor an error is the link's problem, not the call's.
218+
const empty = yield* client
219+
.call({
220+
environmentId: box.environmentId,
221+
tool: "probe",
222+
arguments: {},
223+
limits: { runtimeMode: "approval-required", interactionMode: "plan" },
224+
success: Result,
225+
})
226+
.pipe(Effect.flip);
227+
expect(outcomes).toEqual([null, null, empty.message]);
214228
expect(sessionHeaders).toEqual([
215229
undefined,
216230
"old",
@@ -219,6 +233,7 @@ it.effect("renews a missing peer session once and reuses its replacement", () =>
219233
"renewed",
220234
"renewed",
221235
"renewed",
236+
"renewed",
222237
]);
223238
}).pipe(Effect.scoped),
224239
);

‎apps/server/src/peer/PeerMcpClient.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,17 @@ const make = Effect.gen(function* () {
211211
}),
212212
),
213213
);
214-
if (body.error !== undefined || body.result === undefined) {
214+
if (body.error !== undefined) {
215215
return Result.fail(
216-
new OrchestratorMcpFailure({
217-
code: "invalid_request",
218-
message: body.error?.message ?? "The linked environment returned no result.",
219-
}),
216+
new OrchestratorMcpFailure({ code: "invalid_request", message: body.error.message }),
220217
);
221218
}
219+
if (body.result === undefined) {
220+
return yield* new OrchestratorMcpFailure({
221+
code: "invalid_request",
222+
message: "The linked environment returned no result.",
223+
});
224+
}
222225
const text = body.result.content.map((part) => part.text ?? "").join("");
223226
if (body.result.isError === true) {
224227
// A refusal keeps the peer's own code, so the agent sees why it was refused.

0 commit comments

Comments
 (0)