mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 13:11:18 -05:00
21a5122a9a
* fix(native)!: bound read_bytes to 1 MiB per call read_bytes accepted any length up to Number.MAX_SAFE_INTEGER, both in the public contract and in the Ghidra bridge request, so one call could ask a provider to allocate and hex-encode an unbounded range before any delivery budget applied. Admit at most 1,048,576 bytes per call: about 2 MiB of hex, inside the 10 MiB maximum agent result budget and the MCP SDK's default 10 MiB stdio message buffer. The contract and the Ghidra request share one MAX_READ_BYTES_LENGTH, the schema describes the bound and how to read a longer range, and the refusal comes from input admission before the provider runs. Refs #8560 BREAKING CHANGE: read_bytes refuses length above 1048576 with invalid_request on length. Read longer ranges as consecutive calls that start at the previous address plus returned_bytes. * fix(native): derive the read_bytes ceiling from the maximum agent result budget The 1 MiB ceiling was a chosen number. Each byte returns as at least two hex characters and no result can exceed MAXIMUM_AGENT_RESULT_BUDGET_BYTES, so a read longer than half that maximum could never be delivered at any budget. Derive MAX_READ_BYTES_LENGTH from it (5,242,880 bytes), so it follows that ceiling instead of a separate constant. * fix(native): size the read_bytes ceiling to a complete MCP response MCP sends bytes_hex in both structuredContent and the text block, so a read of N bytes needs about 4N bytes of response. The ceiling was half the maximum agent budget, so a full read at it could not fit the default 10 MiB MCP response and failed after the provider finished. Derive it from MINIMUM_RESPONSE_BYTES, which every server delivers, less a 64 KiB Evidence envelope reserve, divided by four (2,605,056 bytes). The boundary test now delivers a complete read at the ceiling. The compact input schema drops field descriptions, so the consecutive-call advice now lives in the tool description and the length refusal message, from one READ_BYTES_CONTINUATION. * refactor(limits): own the minimum MCP response size in the domain limits nativeByteRead derives the read_bytes ceiling from the minimum MCP response, but imported it from config, which the pure-layer boundary forbids. Define MINIMUM_RESPONSE_BYTES with the other delivery limits in src/domain/analysisResourceLimits.ts; the config parser, the byte-read ceiling, the numeric-limit verifier and tests read it there. * test(ghidra): verify read_bytes at its admitted ceiling The real-Ghidra verifier still requested read_bytes with Number.MAX_SAFE_INTEGER and with a length past the new ceiling, so it stopped on input refusal. - The boundary probe reads MAX_READ_BYTES_LENGTH, which runs past the probe's mapped bytes, so it still checks an explicit incomplete read, and refuses a length one over the ceiling. - The large-result probe reads MAX_READ_BYTES_LENGTH through MCP and the CLI and checks it is delivered complete with the fixture's bytes. The annotation and dossier probes keep covering oversized delivery with a retained reference. * test(ghidra): compare the served annotation description with its owner The real-Ghidra boundary verifier compared annotate_native_function's served description with the bare contract text. Since the open-target prerequisite is appended by describeToolPrerequisite, the check failed before reaching the read_bytes probes. Compare with the description that owner produces from the contract and its availability. * test(ghidra): run verifier probes under the shared command owner The read_bytes and large-result verifier helpers launched the CLI, ps and the compiler through promisify(execFile), outside the verifier's command owner, so a failure or timeout could leave their children running. Pass the native-value verifier's commands owner through verifyGhidraBoundaries, verifyStartupCancellation and verifyGhidraLargeResults and run every command with commands.exec. Expected-refusal checks read the owner's VerifierCommandExitError output (snapshot.stdout.text).