fix(objdump): summarize command output by its size

Since the agent result budget, an over-budget inspect_with_objdump result
is replaced by its summary view, but that summary kept the complete
stdout and stderr. A whole-binary disassemble_all of a small C++ program
delivered 17.7 MB as its "summary", and over MCP exceeded the 10 MiB
stdio response limit, so the default call failed.

The summary now keeps every completion fact and reports available_counts
of stdout and stderr UTF-16 code units, as the GDB summary does for its
console streams; the retained parent keeps the complete output.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
gensokyo-devandgensokyo-dev authored and Ysopwnable committed 2026-11-27 00:30:09 +08:00
1 parent e99d0b2d86
commit 285af34aea
4 files changed
+66 -9

No files matched your search

@@ -43,6 +43,20 @@ export const gdbCommandSummarySchema = gdbCommandResultSchema
}),
});
/**
* Keep every completion fact and replace the opaque output text with its
* size: a whole-binary disassembly can be megabytes. The complete text stays
* in the retained parent.
*/
export const objdumpCommandSummarySchema = commandObservationSchema
.omit({ stdout: true, stderr: true })
.extend({
available_counts: z.strictObject({
stdout_utf16_units: z.number().int().nonnegative(),
stderr_utf16_units: z.number().int().nonnegative(),
}),
});
const readGdbCommandResult = createAnalysisViewResultReader(
gdbCommandResultSchema,
);
@@ -171,9 +185,16 @@ export const projectCommandObservationView = (
},
]),
);
const { stdout, stderr, ...facts } = report;
return ok({
...shared,
parent_operation: "inspect_with_objdump" as const,
summary: report,
summary: {
...facts,
available_counts: {
stdout_utf16_units: stdout.length,
stderr_utf16_units: stderr.length,
},
},
});
};
@@ -1,12 +1,14 @@
import { z } from "zod";
import { commandObservationSchema } from "../../commandObservation.js";
import { artifactSchema, summaryViewResultBase } from "../analysisViewBase.js";
import { commandSummaryContext } from "../commandObservationView.js";
import {
commandSummaryContext,
objdumpCommandSummarySchema,
} from "../commandObservationView.js";
export const objdumpSummaryViewResultSchema = z.strictObject({
...summaryViewResultBase,
...commandSummaryContext,
parent_operation: z.literal("inspect_with_objdump"),
artifact: artifactSchema.nullable(),
summary: commandObservationSchema,
summary: objdumpCommandSummarySchema,
});
@@ -165,8 +165,18 @@ it.each(kinds)(
expect(f.close).toHaveBeenCalledOnce();
expect(f.closeAll).toHaveBeenCalledOnce();
} else {
const { stdout, stderr, ...facts } = z
.object({ stdout: z.string(), stderr: z.string() })
.passthrough()
.parse(parent.normalized_result);
expect(selected.normalized_result).toMatchObject({
summary: parent.normalized_result,
summary: {
...facts,
available_counts: {
stdout_utf16_units: stdout.length,
stderr_utf16_units: stderr.length,
},
},
});
expect(f.runProvider).toHaveBeenCalledOnce();
expect(f.closeService).toHaveBeenCalledOnce();
@@ -1,3 +1,4 @@
import { z } from "zod";
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import pino from "pino";
@@ -203,12 +204,23 @@ it("keeps pathless objdump observations subjectless and preserves the default co
);
const parent = parseEvidence(full.structuredContent);
const summary = parseEvidence(selected.structuredContent);
const { stdout, stderr, ...facts } = z
.object({ stdout: z.string(), stderr: z.string() })
.passthrough()
.parse(parent.normalized_result);
expect(summary.normalized_result).toMatchObject({
parent_evidence_id: parent.evidence_id,
artifact: null,
source_parameters: { operation: "architectures" },
summary: parent.normalized_result,
summary: {
...facts,
available_counts: {
stdout_utf16_units: stdout.length,
stderr_utf16_units: stderr.length,
},
},
});
expect(summary.normalized_result).not.toHaveProperty("summary.stdout");
expect(summary.raw_result).toBeNull();
expect(summary.subject.identity.kind).toBe("unknown");
expect(ledger.get(parent.evidence_id)).toEqual(parent);
@@ -268,10 +280,12 @@ it("rejects malformed historical GDB facts and conflicting source commands", asy
});
it.each([true, false, null])(
"preserves opaque objdump capture and unknown/change facts (%s)",
"summarizes opaque objdump capture by its size and keeps unknown/change facts (%s)",
async (changed) => {
const report = {
stdout: "opaque output 🧪\n",
// A whole-binary disassembly can be megabytes; its summary reports only
// the output size.
stdout: "opaque output 🧪\n".repeat(64 * 1024),
stderr: "diagnostic",
exit_code: "ETIMEDOUT",
signal: "SIGTERM",
@@ -301,7 +315,17 @@ it.each([true, false, null])(
view: { kind: "summary" },
});
if (!selected.ok) throw selected.error;
expect(selected.value.normalized_result).toMatchObject({ summary: report });
const { stdout, stderr, ...facts } = report;
expect(selected.value.normalized_result).toMatchObject({
summary: {
...facts,
available_counts: {
stdout_utf16_units: stdout.length,
stderr_utf16_units: stderr.length,
},
},
});
expect(JSON.stringify(selected.value).length).toBeLessThan(8 * 1024);
if (changed !== null) {
const conflicting = createEvidence(
{