fix(acp): one malformed session update no longer ends the session (#20015)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ede3f2d6ba
commit
559c4b1f21
8 files changed
+327
-66
No files matched your search
@@ -128,6 +128,8 @@ import { skillInvocationInput } from "./skill_invocation/input.ts";
|
||||
import { assertSimpleOutput } from "./simple/codex_output.ts";
|
||||
import { assertPiSimpleOutput } from "./simple/pi_output.ts";
|
||||
import { simpleInput } from "./simple/input.ts";
|
||||
import { malformedSessionUpdateInput } from "./malformed_session_update/input.ts";
|
||||
import { assertMalformedSessionUpdateOutput } from "./malformed_session_update/output.ts";
|
||||
import { assertSubagentOutput } from "./subagent/codex_output.ts";
|
||||
import { assertClaudeSubagentOutput } from "./subagent/claude_output.ts";
|
||||
import { subagentInput } from "./subagent/input.ts";
|
||||
@@ -594,6 +596,21 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "malformed_session_update",
|
||||
buildInput: malformedSessionUpdateInput,
|
||||
providers: [
|
||||
{
|
||||
driver: ProviderDriverKind.make("acpRegistry"),
|
||||
transcriptFile: new URL(
|
||||
"./malformed_session_update/registry_transcript.ndjson",
|
||||
import.meta.url,
|
||||
),
|
||||
modelSelection: ACP_REGISTRY_MODEL_SELECTION,
|
||||
assertOutput: assertMalformedSessionUpdateOutput,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "simple",
|
||||
buildInput: simpleInput,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { OrchestratorFixtureInput } from "../shared.ts";
|
||||
|
||||
export const MALFORMED_SESSION_UPDATE_PROMPT =
|
||||
"Respond with the following text: malformed update fixture ok";
|
||||
|
||||
/**
|
||||
* An agent sends a `usage_update` without the required `used` and `size`
|
||||
* mid-turn, the way clanka did (reported 2026-10-15). T3 drops that one
|
||||
* update and the turn completes with the text and usage that follow it.
|
||||
*/
|
||||
export function malformedSessionUpdateInput(): OrchestratorFixtureInput {
|
||||
return {
|
||||
steps: [{ type: "message", text: MALFORMED_SESSION_UPDATE_PROMPT }],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { assert } from "@effect/vitest";
|
||||
import type { ProviderReplayTranscript } from "@t3tools/contracts";
|
||||
|
||||
import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
|
||||
import {
|
||||
assertAssistantTextIncludes,
|
||||
assertBaseProjection,
|
||||
assertSemanticProjectionIntegrity,
|
||||
assertTurnItemTypes,
|
||||
assertUserMessagesInclude,
|
||||
projectionFor,
|
||||
} from "../shared.ts";
|
||||
import { MALFORMED_SESSION_UPDATE_PROMPT } from "./input.ts";
|
||||
|
||||
export function assertMalformedSessionUpdateOutput(
|
||||
result: OrchestratorV2ScenarioResult,
|
||||
transcript: ProviderReplayTranscript,
|
||||
) {
|
||||
assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] });
|
||||
const projection = projectionFor(result, transcript.scenario);
|
||||
assertSemanticProjectionIntegrity(projection);
|
||||
assertUserMessagesInclude(projection, [MALFORMED_SESSION_UPDATE_PROMPT]);
|
||||
assertTurnItemTypes(projection, ["user_message", "assistant_message"]);
|
||||
// The dropped update does not fail the turn.
|
||||
assert.notInclude(
|
||||
projection.turnItems.map((item) => item.type),
|
||||
"error",
|
||||
);
|
||||
assertAssistantTextIncludes(projection, "malformed update fixture ok");
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{"type":"transcript_start","provider":"acpRegistry","protocol":"acp.ndjson-jsonrpc","version":"1","scenario":"malformed_session_update","metadata":{"generatedBy":"protocol-semantic-fixture","nativeSessionId":"grok-replay-session-1"}}
|
||||
{"type":"expect_outbound","label":"initialize","frame":{"kind":"request","method":"initialize","params":{"protocolVersion":2,"info":"<any>","capabilities":"<any>","clientCapabilities":"<any>","clientInfo":"<any>"}}}
|
||||
{"type":"emit_inbound","label":"initialized","frame":{"kind":"response","method":"initialize","result":{"protocolVersion":1,"agentCapabilities":{"loadSession":true,"mcpCapabilities":{"http":true,"sse":true},"promptCapabilities":{"audio":false,"embeddedContext":true,"image":false}},"authMethods":[{"id":"replay","name":"Replay"}],"agentInfo":{"name":"grok-replay","version":"1"}}}}
|
||||
{"type":"expect_outbound","label":"session.new","frame":{"kind":"request","method":"session/new","params":{"cwd":"<workspace>","mcpServers":"<any>"}}}
|
||||
{"type":"emit_inbound","label":"session.created","frame":{"kind":"response","method":"session/new","result":{"sessionId":"grok-replay-session-1","models":{"currentModelId":"grok-build","availableModels":[{"modelId":"grok-build","name":"Grok Build"},{"modelId":"grok-composer-2.5-fast","name":"Grok Composer 2.5 Fast"}]}}}}
|
||||
{"type":"expect_outbound","label":"session.prompt","frame":{"kind":"request","method":"session/prompt","params":{"sessionId":"grok-replay-session-1","prompt":[{"type":"text","text":"<t3_code_instructions>\n<any>\n</t3_code_instructions>\n\n<user_request>\nRespond with the following text: malformed update fixture ok\n</user_request>"}]}}}
|
||||
{"type":"emit_inbound","label":"reasoning.1","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"agent_thought_chunk","content":{"type":"text","text":"I should "}}}}}
|
||||
{"type":"emit_inbound","label":"reasoning.2","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"agent_thought_chunk","content":{"type":"text","text":"answer exactly."}}}}}
|
||||
{"type":"emit_inbound","label":"usage.malformed","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"usage_update","cost":{"amount":0.01,"currency":"USD"}}}}}
|
||||
{"type":"emit_inbound","label":"assistant.1","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"malformed update "}}}}}
|
||||
{"type":"emit_inbound","label":"assistant.2","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"fixture ok"}}}}}
|
||||
{"type":"emit_inbound","label":"usage.valid","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"grok-replay-session-1","update":{"sessionUpdate":"usage_update","used":1200,"size":200000}}}}
|
||||
{"type":"emit_inbound","label":"prompt.completed","frame":{"kind":"response","method":"session/prompt","result":{"stopReason":"end_turn"}}}
|
||||
{"type":"runtime_exit","status":"success"}
|
||||
@@ -161,4 +161,33 @@ describe("effect-acp errors", () => {
|
||||
expect("detail" in protocolError).toBe(false);
|
||||
}),
|
||||
);
|
||||
|
||||
// The summary goes into logs, so it names where a payload broke its schema
|
||||
// and never copies a value, including a record key the agent chose.
|
||||
it.effect("summarizes schema issues by path without payload values", () =>
|
||||
Effect.gen(function* () {
|
||||
const secret = "acp-summary-secret";
|
||||
const cause = yield* Schema.decodeUnknownEffect(
|
||||
Schema.Struct({
|
||||
update: Schema.Struct({ used: Schema.Number, size: Schema.Number }),
|
||||
env: Schema.Record(Schema.String, Schema.Number),
|
||||
}),
|
||||
)({ update: { size: secret }, env: { [`${secret} key`]: secret } }, { errors: "all" }).pipe(
|
||||
Effect.flip,
|
||||
);
|
||||
const error = AcpError.AcpProtocolParseError.fromSchemaError(
|
||||
"decode-notification-payload",
|
||||
"session/update",
|
||||
cause,
|
||||
);
|
||||
|
||||
expect(error.issueSummary).toBe(
|
||||
"update.used missing, update.size wrong type, env.* wrong type",
|
||||
);
|
||||
expect(error.message).toBe(
|
||||
"ACP protocol operation 'decode-notification-payload' failed for method 'session/update': update.used missing, update.size wrong type, env.* wrong type.",
|
||||
);
|
||||
expect(error.message).not.toContain(secret);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as SchemaAST from "effect/SchemaAST";
|
||||
import type * as SchemaIssue from "effect/SchemaIssue";
|
||||
|
||||
import * as AcpSchema from "./_generated/schema.gen.ts";
|
||||
@@ -37,6 +38,74 @@ interface AcpSchemaIssueDiagnostics {
|
||||
readonly maximumPathDepth: number;
|
||||
}
|
||||
|
||||
const MAX_SUMMARY_ISSUES = 3;
|
||||
const MAX_SUMMARY_PATH_SEGMENTS = 8;
|
||||
|
||||
// Record keys come from the payload, so a key that is not a plain identifier
|
||||
// is shown as `*` rather than copied.
|
||||
const summaryPathSegment = (segment: PropertyKey): string =>
|
||||
typeof segment === "number" || /^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(String(segment))
|
||||
? String(segment)
|
||||
: "*";
|
||||
|
||||
const summaryPath = (path: ReadonlyArray<PropertyKey>): string => {
|
||||
if (path.length === 0) return "payload";
|
||||
const shown = path.slice(0, MAX_SUMMARY_PATH_SEGMENTS).map(summaryPathSegment).join(".");
|
||||
return path.length > MAX_SUMMARY_PATH_SEGMENTS ? `${shown}…` : shown;
|
||||
};
|
||||
|
||||
const summaryReason = (issue: SchemaIssue.Issue): string => {
|
||||
switch (issue._tag) {
|
||||
case "MissingKey":
|
||||
return "missing";
|
||||
case "UnexpectedKey":
|
||||
return "unexpected";
|
||||
case "InvalidType":
|
||||
return "wrong type";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
};
|
||||
|
||||
const isCatchAllMember = (issue: SchemaIssue.Issue) =>
|
||||
"ast" in issue && SchemaAST.resolveTitle(issue.ast) === "other";
|
||||
|
||||
/**
|
||||
* Names where a payload broke its schema, such as `update.used missing`,
|
||||
* without copying any value from it. ACP unions end in a member titled
|
||||
* "other" that admits custom and future variants; it fails only because the
|
||||
* discriminator names a known variant, so the known variant's issues are the
|
||||
* ones reported.
|
||||
*/
|
||||
const schemaIssueSummary = (root: SchemaIssue.Issue): string => {
|
||||
const entries = new Set<string>();
|
||||
const visit = (issue: SchemaIssue.Issue, path: ReadonlyArray<PropertyKey>): void => {
|
||||
switch (issue._tag) {
|
||||
case "Filter":
|
||||
case "Encoding":
|
||||
visit(issue.issue, path);
|
||||
return;
|
||||
case "Pointer":
|
||||
visit(issue.issue, [...path, ...issue.path]);
|
||||
return;
|
||||
case "Composite":
|
||||
case "AnyOf": {
|
||||
const known = issue.issues.filter((child) => !isCatchAllMember(child));
|
||||
const children = known.length > 0 ? known : issue.issues;
|
||||
if (children.length === 0) entries.add(`${summaryPath(path)} ${summaryReason(issue)}`);
|
||||
for (const child of children) visit(child, path);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
entries.add(`${summaryPath(path)} ${summaryReason(issue)}`);
|
||||
}
|
||||
};
|
||||
visit(root, []);
|
||||
const shown = [...entries].slice(0, MAX_SUMMARY_ISSUES);
|
||||
const hidden = entries.size - shown.length;
|
||||
return hidden > 0 ? `${shown.join(", ")} (+${hidden} more)` : shown.join(", ");
|
||||
};
|
||||
|
||||
const schemaIssueDiagnostics = (root: SchemaIssue.Issue): AcpSchemaIssueDiagnostics => {
|
||||
let issueCount = 0;
|
||||
let maximumPathDepth = 0;
|
||||
@@ -123,12 +192,15 @@ export class AcpProtocolParseError extends Schema.TaggedError<AcpProtocolParseEr
|
||||
issueCount: Schema.optionalKey(Schema.Number),
|
||||
issueKinds: Schema.optionalKey(Schema.Array(AcpSchemaIssueKind)),
|
||||
maximumPathDepth: Schema.optionalKey(Schema.Number),
|
||||
/** Where the payload broke its schema, e.g. `update.used missing`; never payload values. */
|
||||
issueSummary: Schema.optionalKey(Schema.String),
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message() {
|
||||
const method = this.method === undefined ? "" : ` for method '${this.method}'`;
|
||||
return `ACP protocol operation '${this.operation}' failed${method}.`;
|
||||
const summary = this.issueSummary === undefined ? "" : `: ${this.issueSummary}`;
|
||||
return `ACP protocol operation '${this.operation}' failed${method}${summary}.`;
|
||||
}
|
||||
|
||||
static fromSchemaError(
|
||||
@@ -140,6 +212,7 @@ export class AcpProtocolParseError extends Schema.TaggedError<AcpProtocolParseEr
|
||||
operation,
|
||||
method,
|
||||
...schemaIssueDiagnostics(cause.issue),
|
||||
issueSummary: schemaIssueSummary(cause.issue),
|
||||
cause,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import * as Effect from "effect/Effect";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Logger from "effect/Logger";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as References from "effect/References";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Sink from "effect/Sink";
|
||||
@@ -209,50 +211,116 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps invalid core notification values only in the schema cause", () =>
|
||||
// clanka once sent a usage_update without `used` and `size`. One bad update
|
||||
// must not end a session whose later updates are fine.
|
||||
it.effect("drops a session/update that fails to decode and keeps reading", () =>
|
||||
Effect.gen(function* () {
|
||||
const secret = "acp-core-notification-secret-sentinel";
|
||||
const { stdio, input } = yield* makeInMemoryStdio();
|
||||
const termination = yield* Deferred.make<AcpError.AcpError>();
|
||||
const events: Array<AcpProtocol.AcpProtocolLogEvent> = [];
|
||||
const warnings: Array<unknown> = [];
|
||||
let terminated = false;
|
||||
let transformCalls = 0;
|
||||
yield* AcpProtocol.makeAcpPatchedProtocol({
|
||||
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
|
||||
stdio,
|
||||
serverRequestMethods: new Set(),
|
||||
logIncoming: true,
|
||||
logger: (event) =>
|
||||
Effect.sync(() => {
|
||||
events.push(event);
|
||||
}),
|
||||
transformSessionUpdate: (notification) => {
|
||||
transformCalls += 1;
|
||||
return notification;
|
||||
},
|
||||
onTermination: (error) => Deferred.succeed(termination, error).pipe(Effect.asVoid),
|
||||
});
|
||||
|
||||
yield* Queue.offer(
|
||||
input,
|
||||
encoder.encode(
|
||||
`${encodeUnknownJsonString({
|
||||
jsonrpc: "2.0",
|
||||
method: "session/update",
|
||||
params: {
|
||||
sessionId: { secret },
|
||||
update: {
|
||||
sessionUpdate: "plan",
|
||||
entries: [],
|
||||
},
|
||||
},
|
||||
})}\n`,
|
||||
onTermination: () =>
|
||||
Effect.sync(() => {
|
||||
terminated = true;
|
||||
}),
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
Logger.layer([
|
||||
Logger.make(({ logLevel, fiber }) => {
|
||||
if (logLevel === "Warn")
|
||||
warnings.push(fiber.getRef(References.CurrentLogAnnotations));
|
||||
}),
|
||||
]),
|
||||
),
|
||||
);
|
||||
const received = yield* Deferred.make<AcpProtocol.AcpIncomingNotification>();
|
||||
yield* transport.incoming.pipe(
|
||||
Stream.runForEach((notification) => Deferred.succeed(received, notification)),
|
||||
Effect.forkScoped,
|
||||
);
|
||||
|
||||
const error = yield* Deferred.await(termination);
|
||||
assert.equal(transformCalls, 0);
|
||||
assert.instanceOf(error, AcpError.AcpProtocolParseError);
|
||||
const parseError = error as AcpError.AcpProtocolParseError;
|
||||
const { cause, ...directDiagnostics } = parseError;
|
||||
const send = (params: unknown) =>
|
||||
Queue.offer(
|
||||
input,
|
||||
encoder.encode(
|
||||
`${encodeUnknownJsonString({ jsonrpc: "2.0", method: "session/update", params })}\n`,
|
||||
),
|
||||
);
|
||||
const malformed = {
|
||||
sessionId: "session-1",
|
||||
update: { sessionUpdate: "usage_update", cost: { amount: 1, currency: secret } },
|
||||
};
|
||||
yield* send(malformed);
|
||||
yield* send(malformed);
|
||||
yield* send({
|
||||
sessionId: "session-1",
|
||||
update: { sessionUpdate: "usage_update", used: 10, size: 100 },
|
||||
});
|
||||
|
||||
const notification = yield* TestClock.withLive(
|
||||
Deferred.await(received).pipe(Effect.timeout("2 seconds")),
|
||||
);
|
||||
assert.equal(notification._tag, "SessionUpdate");
|
||||
assert.deepEqual(notification.params, {
|
||||
sessionId: "session-1",
|
||||
update: { sessionUpdate: "usage_update", used: 10, size: 100 },
|
||||
});
|
||||
assert.isFalse(terminated);
|
||||
assert.equal(transformCalls, 1);
|
||||
|
||||
const decodeFailed = events.find(({ stage }) => stage === "decode_failed");
|
||||
assert.deepInclude(decodeFailed?.payload as object, {
|
||||
operation: "decode-notification-payload",
|
||||
method: "session/update",
|
||||
issueSummary: "update.used missing",
|
||||
});
|
||||
// The repeated bad update is dropped again but warned about once.
|
||||
assert.lengthOf(
|
||||
events.filter(({ stage }) => stage === "decode_failed"),
|
||||
2,
|
||||
);
|
||||
assert.lengthOf(warnings, 1);
|
||||
assert.deepInclude(warnings[0] as object, {
|
||||
issueSummary: "update.used missing",
|
||||
});
|
||||
assert.notInclude(encodeUnknownJsonString({ decodeFailed, warnings }), secret);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps invalid core notification values only in the schema cause", () =>
|
||||
Effect.gen(function* () {
|
||||
const secret = "acp-core-notification-secret-sentinel";
|
||||
const cause = yield* Schema.decodeUnknownEffect(AcpSchema.SessionNotification)({
|
||||
sessionId: { secret },
|
||||
update: { sessionUpdate: "plan", entries: [] },
|
||||
}).pipe(Effect.flip);
|
||||
const parseError = AcpError.AcpProtocolParseError.fromSchemaError(
|
||||
"decode-notification-payload",
|
||||
"session/update",
|
||||
cause,
|
||||
);
|
||||
const { cause: directCause, ...directDiagnostics } = parseError;
|
||||
assert.equal(parseError.operation, "decode-notification-payload");
|
||||
assert.equal(parseError.method, "session/update");
|
||||
assert.isAbove(parseError.issueCount ?? 0, 0);
|
||||
assert.include(parseError.issueKinds ?? [], "Pointer");
|
||||
assert.isAbove(parseError.maximumPathDepth ?? 0, 0);
|
||||
assert.isTrue(Schema.isSchemaError(cause));
|
||||
assert.equal(parseError.issueSummary, "sessionId wrong type");
|
||||
assert.isTrue(Schema.isSchemaError(directCause));
|
||||
assert.notInclude(parseError.message, secret);
|
||||
assert.notInclude(encodeUnknownJsonString(directDiagnostics), secret);
|
||||
}),
|
||||
|
||||
@@ -166,6 +166,17 @@ const makeStrictNdJsonRpcParser = () => {
|
||||
};
|
||||
};
|
||||
const MAX_BUFFERED_RAW_NOTIFICATIONS = 32;
|
||||
|
||||
/** A decode failure's structural diagnostics, without its cause or any wire payload. */
|
||||
const decodeFailureDiagnostics = (error: AcpError.AcpProtocolParseError) => ({
|
||||
operation: error.operation,
|
||||
...(error.method === undefined ? {} : { method: error.method }),
|
||||
...(error.requestId === undefined ? {} : { requestId: error.requestId }),
|
||||
...(error.issueCount === undefined ? {} : { issueCount: error.issueCount }),
|
||||
...(error.issueKinds === undefined ? {} : { issueKinds: error.issueKinds }),
|
||||
...(error.maximumPathDepth === undefined ? {} : { maximumPathDepth: error.maximumPathDepth }),
|
||||
...(error.issueSummary === undefined ? {} : { issueSummary: error.issueSummary }),
|
||||
});
|
||||
// Outbound JSON-RPC notification: no `id`, so peers never treat it as a request.
|
||||
const encodeJsonRpcNotification = Schema.encodeUnknownExit(
|
||||
Schema.fromJsonString(
|
||||
@@ -223,6 +234,7 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
|
||||
outstandingAcknowledgements: new Set(),
|
||||
});
|
||||
const nextRequestId = yield* Ref.make(1);
|
||||
const warnedDecodeFailures = new Set<string>();
|
||||
const terminationHandled = yield* Ref.make(false);
|
||||
const terminationFailure = yield* Deferred.make<never, AcpError.AcpError>();
|
||||
const extPending = yield* Ref.make(new Map<string, AcpPendingRequest>());
|
||||
@@ -499,26 +511,49 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
|
||||
);
|
||||
};
|
||||
|
||||
// A notification has no reply to fail, so one the schema rejects is logged
|
||||
// and dropped. Ending the connection over it would kill a working session
|
||||
// because one update, possibly from a newer spec, did not parse. An agent
|
||||
// repeats a bad shape on every update, so each distinct failure is warned
|
||||
// about once per connection.
|
||||
const dropUndecodableNotification = (method: string) => (cause: Schema.SchemaError) => {
|
||||
const error = AcpError.AcpProtocolParseError.fromSchemaError(
|
||||
"decode-notification-payload",
|
||||
method,
|
||||
cause,
|
||||
);
|
||||
const diagnostics = decodeFailureDiagnostics(error);
|
||||
const key = `${method}\n${error.issueSummary}`;
|
||||
const firstOfItsKind = !warnedDecodeFailures.has(key);
|
||||
warnedDecodeFailures.add(key);
|
||||
return logProtocol({
|
||||
direction: "incoming",
|
||||
stage: "decode_failed",
|
||||
payload: diagnostics,
|
||||
}).pipe(
|
||||
Effect.andThen(
|
||||
firstOfItsKind
|
||||
? Effect.logWarning("Dropped an ACP notification that failed to decode").pipe(
|
||||
Effect.annotateLogs(diagnostics),
|
||||
)
|
||||
: Effect.void,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const handleRequestEncoded = (message: RpcMessage.RequestEncoded) => {
|
||||
if (message.id === "") {
|
||||
if (message.tag === CLIENT_METHODS.session_update) {
|
||||
return decodeSessionUpdate(message.payload).pipe(
|
||||
Effect.map(
|
||||
(params) =>
|
||||
({
|
||||
Effect.matchEffect({
|
||||
onFailure: dropUndecodableNotification(CLIENT_METHODS.session_update),
|
||||
onSuccess: (params) =>
|
||||
dispatchNotification({
|
||||
_tag: "SessionUpdate",
|
||||
method: CLIENT_METHODS.session_update,
|
||||
params: options.transformSessionUpdate?.(params) ?? params,
|
||||
}) satisfies AcpIncomingNotification,
|
||||
),
|
||||
Effect.mapError((cause) =>
|
||||
AcpError.AcpProtocolParseError.fromSchemaError(
|
||||
"decode-notification-payload",
|
||||
CLIENT_METHODS.session_update,
|
||||
cause,
|
||||
),
|
||||
),
|
||||
Effect.flatMap(dispatchNotification),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (
|
||||
@@ -527,22 +562,11 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
|
||||
) {
|
||||
const method = message.tag;
|
||||
return decodeElicitationComplete(message.payload).pipe(
|
||||
Effect.map(
|
||||
(params) =>
|
||||
({
|
||||
_tag: "ElicitationComplete",
|
||||
method,
|
||||
params,
|
||||
}) satisfies AcpIncomingNotification,
|
||||
),
|
||||
Effect.mapError((cause) =>
|
||||
AcpError.AcpProtocolParseError.fromSchemaError(
|
||||
"decode-notification-payload",
|
||||
method,
|
||||
cause,
|
||||
),
|
||||
),
|
||||
Effect.flatMap(dispatchNotification),
|
||||
Effect.matchEffect({
|
||||
onFailure: dropUndecodableNotification(method),
|
||||
onSuccess: (params) =>
|
||||
dispatchNotification({ _tag: "ElicitationComplete", method, params }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
return dispatchNotification({
|
||||
@@ -696,16 +720,7 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
|
||||
logProtocol({
|
||||
direction: "incoming",
|
||||
stage: "decode_failed",
|
||||
payload: {
|
||||
operation: error.operation,
|
||||
...(error.method === undefined ? {} : { method: error.method }),
|
||||
...(error.requestId === undefined ? {} : { requestId: error.requestId }),
|
||||
...(error.issueCount === undefined ? {} : { issueCount: error.issueCount }),
|
||||
...(error.issueKinds === undefined ? {} : { issueKinds: error.issueKinds }),
|
||||
...(error.maximumPathDepth === undefined
|
||||
? {}
|
||||
: { maximumPathDepth: error.maximumPathDepth }),
|
||||
},
|
||||
payload: decodeFailureDiagnostics(error),
|
||||
}),
|
||||
),
|
||||
Effect.flatMap((messages) =>
|
||||
|
||||
Reference in new issue
Block a user