perf(firmware/desktop): fuse range-snapshot SHA-256 in FirmwareFiles and eliminate owned JSON deep-clones (#13505)

perf(firmware/desktop): fuse range-snapshot SHA-256 in FirmwareFiles and eliminate owned JSON deep-clones (#13504)
This commit is contained in:
morluto authored and GitHub committed 2026-11-22 12:57:20 -05:00
1 parent 5262268826
commit 18a197fb3c
4 files changed
+24 -11

No files matched your search

+7 -3
View File
@@ -7,7 +7,7 @@ import { z } from "zod";
import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js";
import { Deadline } from "../domain/deadline.js";
import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
import { ownedJsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
import { isCanonicalBase64 } from "../domain/stringPatterns.js";
import { StructuredContentMcpClient } from "../providers/StructuredContentMcpClient.js";
import { validateMcpHttpResponse } from "../providers/Utf8McpResponse.js";
@@ -455,10 +455,14 @@ export class AgentEnvComputer implements ControlledComputer {
{ name, arguments: args },
{ timeout: REQUEST_TIMEOUT_MS, signal },
);
const structured = jsonObjectSchema.safeParse(result.structuredContent);
const structured = ownedJsonObjectSchema.safeParse(
result.structuredContent,
);
return {
isError: result.isError === true,
content: result.content.map((block) => jsonObjectSchema.parse(block)),
content: result.content.map((block) =>
ownedJsonObjectSchema.parse(block),
),
structured: structured.success ? structured.data : null,
};
}
+3 -3
View File
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
import { z } from "zod";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import { ownedJsonValueSchema } from "../domain/jsonValue.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import { AnalysisCleanupRelease } from "../domain/analysisCleanupRelease.js";
import { readBoundedControlLines } from "../process/BoundedControlLines.js";
@@ -91,7 +91,7 @@ export class SolveCleanupError extends ProviderCleanupError {
...diagnostics,
...(report === undefined
? {}
: { solve_report: jsonValueSchema.parse(report) }),
: { solve_report: ownedJsonValueSchema.parse(report) }),
},
{
operation,
@@ -112,7 +112,7 @@ export class SolveCancelledError extends AnalysisCancelledError {
) {
super(operation, {
cause: reason,
diagnostics: { solve_report: jsonValueSchema.parse(report) },
diagnostics: { solve_report: ownedJsonValueSchema.parse(report) },
});
}
}
+12 -3
View File
@@ -174,21 +174,31 @@ export class FirmwareFileAccess {
},
]);
let inputPath = fullPath;
let selectionSha256 = sha256;
if (selected !== undefined) {
inputPath = join(root, "selected.bin");
await withArtifactRegularFile(
selectionSha256 = await withArtifactRegularFile(
fullPath,
this.resources,
signal,
async ({ handle }) => {
const selectionHash = createHash("sha256");
const hasher = new Transform({
transform(chunk: Buffer, _encoding, callback) {
selectionHash.update(chunk);
callback(null, chunk);
},
});
await pipeline(
readArtifactFileChunks(handle, {
start: offset,
end: offset + length - 1,
signal,
}),
hasher,
createWriteStream(inputPath, { flags: "wx", mode: 0o600 }),
);
return selectionHash.digest("hex");
},
);
await chmod(inputPath, 0o400);
@@ -200,8 +210,7 @@ export class FirmwareFileAccess {
selection: {
offset,
length,
sha256:
selected === undefined ? sha256 : await this.#hash(inputPath, signal),
sha256: selectionSha256,
},
};
}
+2 -2
View File
@@ -30,7 +30,7 @@ import {
import { classifyProviderFailure } from "../providers/classifyProviderFailure.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import { ownedJsonValueSchema } from "../domain/jsonValue.js";
import { err, ok, type Result } from "../domain/result.js";
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
import type { ProviderProcessSupervisor } from "../process/ProviderProcess.js";
@@ -756,7 +756,7 @@ const completedFirmwareObservation = (
): FirmwarePartialObservation => ({
kind: "firmware",
result: execution.result,
provenance: jsonValueSchema.parse({
provenance: ownedJsonValueSchema.parse({
raw_result: execution.rawResult,
provider: execution.provider,
subject: execution.subject,