fix(decompile): retain inventory limitations and selection (#8466)

* fix(decompile): retain inventory limitations with the latest selection

The manifest and decompile index dropped procedure-inventory
limitations, so a directory separated from its Evidence response could
not explain why functions were selected or omitted. Keep those
limitations on the manifest and in a latest_run index record that also
names the filter and counts that produced them. Older runs remain
represented only by their retained function records.

Fixes #8355

* test(decompile): surface export errors and check function caveats

Address review findings on the inventory-limitation regression:

- Throw the typed export error instead of returning from a failed Result.
- Assert historical function records keep their own pseudocode caveats
  and do not receive the latest inventory warnings.
This commit is contained in:
2SinceJuly authored and GitHub committed 2026-11-05 17:04:55 +08:00
1 parent 1f14d648fa
commit fc20aebb94
6 files changed
+176

No files matched your search

+5
View File
@@ -236,6 +236,11 @@ the index retains the complete selected names, addresses, provider facts and
caveats. Failure details retain at most 32 rows within 2,048 JSON-encoded
UTF-8 bytes; names may be omitted to keep complete addresses and reasons. The
index retains every failure and its complete observed name.
The manifest reports the procedure-inventory limitations of the current call in
`inventory_limitations`. `decompile-index.json`'s `latest_run` records that
call's filters, selected and excluded counts, and inventory limitations; older
runs remain represented only by their retained function records, so a later
inventory warning is not presented as the history of every file.
Each function's `decompile-index.json` record, whatever its status, keeps the
complete limitations of the observations it used.
When available, `provider_source` records the source of that attempt's
@@ -138,6 +138,7 @@ const harness = (options?: {
Record<string, "error" | "timeout" | "empty" | "null">
>;
readonly info?: "ok" | "unavailable" | "error";
readonly listLimitations?: readonly string[];
readonly listProfile?: typeof profile;
readonly subject?: boolean;
readonly mismatch?: string;
@@ -173,6 +174,9 @@ const harness = (options?: {
{
analysisProfile: options?.listProfile ?? profile,
...(options?.subject === false ? {} : { subject }),
...(options?.listLimitations === undefined
? {}
: { limitations: options.listLimitations }),
},
),
),
@@ -379,6 +383,89 @@ describe("decompile_all manifest", () => {
});
});
describe("decompile_all inventory limitations", () => {
const directory = useOutputDirectory();
const readIndex = async (root: string) =>
decompileDirectoryIndexSchema.parse(
JSON.parse(
await readFile(join(root, DECOMPILE_DIRECTORY_INDEX_NAME), "utf8"),
),
);
it("keeps the latest selection's limitations without attaching them to historical files", async () => {
const created = await run(
harness({ listLimitations: ["first inventory limitation"] }).tools,
directory(),
{ name: "Foo::", limit: 1 },
);
expect(created.ok).toBe(true);
if (!created.ok) throw created.error;
expect(created.value).toMatchObject({
inventory_limitations: ["first inventory limitation"],
counts: { selected: 2, excluded: 1, requested: 1, remaining: 1 },
});
const firstIndex = await readIndex(directory());
expect(firstIndex.latest_run).toEqual({
resume: false,
selected: 2,
excluded: 1,
selection: {
name: "Foo::",
namespace: null,
address_start: null,
address_end: null,
limit: 1,
},
inventory_limitations: ["first inventory limitation"],
});
expect(firstIndex.limitations).toEqual([]);
expect(firstIndex.functions).toHaveLength(1);
expect(firstIndex.functions[0]?.limitations).toContain(
"terminal call may cut the body",
);
expect(firstIndex.functions[0]?.limitations).not.toContain(
"first inventory limitation",
);
const resumed = await run(
harness({ listLimitations: ["second inventory limitation"] }).tools,
directory(),
{ resume: true, name: "Bar::" },
);
expect(resumed.ok).toBe(true);
if (!resumed.ok) throw resumed.error;
expect(resumed.value).toMatchObject({
inventory_limitations: ["second inventory limitation"],
counts: { selected: 1, excluded: 2, requested: 1, remaining: 0 },
});
const resumedIndex = await readIndex(directory());
expect(resumedIndex.latest_run).toMatchObject({
resume: true,
selected: 1,
excluded: 2,
selection: { name: "Bar::" },
inventory_limitations: ["second inventory limitation"],
});
expect(
resumedIndex.functions.map((record) => record.address).sort(),
).toEqual(["0x1000", "0x3000"]);
expect(
resumedIndex.functions.every((record) =>
record.limitations?.includes("terminal call may cut the body"),
),
).toBe(true);
expect(
resumedIndex.functions.every(
(record) =>
!record.limitations?.includes("first inventory limitation") &&
!record.limitations?.includes("second inventory limitation"),
),
).toBe(true);
expect(resumedIndex.limitations).toEqual([]);
});
});
describe("decompile_all external functions", () => {
const directory = useOutputDirectory();
@@ -119,6 +119,7 @@ export const decompileAll = async (
input,
bounds.value,
);
const inventoryLimitations = loaded.value.limitations;
const opened = await DecompileExport.open({
placement: placement.value,
identity: loaded.value.identity,
@@ -164,6 +165,19 @@ export const decompileAll = async (
indexed = await session.writeIndex({
layoutStatus: layoutStatus(input.layout),
limitations,
latestRun: {
resume: input.resume,
selected: selection.procedures.length,
excluded: selection.excluded,
selection: {
name: input.name ?? null,
namespace: input.namespace ?? null,
address_start: input.address_start ?? null,
address_end: input.address_end ?? null,
limit: input.limit ?? null,
},
inventoryLimitations,
},
});
} finally {
closed = await session.close();
@@ -220,6 +234,7 @@ export const decompileAll = async (
excluded: selection.excluded,
state,
limitations,
inventoryLimitations,
}),
);
return manifest.success
@@ -258,6 +273,7 @@ const loadProcedures = async (
readonly procedures: readonly SelectedProcedure[];
readonly identity: ExportIdentity;
readonly unaddressed: number;
readonly limitations: readonly string[];
},
AnalysisError
>
@@ -287,6 +303,7 @@ const loadProcedures = async (
})),
identity: identity.value,
unaddressed: parsed.data.length - addressed.length,
limitations: observed.value.limitations,
});
};
@@ -999,6 +1016,7 @@ const manifestOf = (input: {
readonly excluded: number;
readonly state: PublishState;
readonly limitations: readonly string[];
readonly inventoryLimitations: readonly string[];
}) => {
const requested =
input.state.written + input.state.failed + input.state.external;
@@ -1026,6 +1044,7 @@ const manifestOf = (input: {
provider: input.identity.provider,
analysis_profile_digest: input.identity.analysisProfileDigest,
target_sha256: input.identity.targetSha256,
inventory_limitations: [...input.inventoryLimitations],
limitations: [...input.limitations],
resume: input.input.resume,
};
@@ -205,6 +205,19 @@ export class DecompileExport {
async writeIndex(input: {
readonly layoutStatus: "address" | "debug_layout_unavailable";
readonly limitations: readonly string[];
readonly latestRun: {
readonly resume: boolean;
readonly selected: number;
readonly excluded: number;
readonly selection: {
readonly name: string | null;
readonly namespace: string | null;
readonly address_start: string | null;
readonly address_end: string | null;
readonly limit: number | null;
};
readonly inventoryLimitations: readonly string[];
};
}): Promise<Result<void, AnalysisError>> {
// Appends update this owner only after journal sync; resume parses once.
// Reuse those committed facts instead of re-reading and reinterpreting them.
@@ -215,6 +228,13 @@ export class DecompileExport {
analysis_profile_digest: this.identity.analysisProfileDigest,
layout: this.identity.layout,
layout_status: input.layoutStatus,
latest_run: {
resume: input.latestRun.resume,
selected: input.latestRun.selected,
excluded: input.latestRun.excluded,
selection: input.latestRun.selection,
inventory_limitations: [...input.latestRun.inventoryLimitations],
},
limitations: [...input.limitations],
functions: [...this.records.values()].sort((left, right) =>
compareProcedureAddresses(left.address, right.address),
+32
View File
@@ -201,6 +201,11 @@ export const decompileDirectoryManifestSchema = z
.describe(
"SHA-256 of the analyzed target, or null when the observation has no file subject.",
),
inventory_limitations: z
.array(z.string())
.describe(
"Limitations reported by this call's procedure inventory. They describe the selection that produced this run, not every historical function record in the directory.",
),
limitations: z
.array(z.string())
.describe("Limits of this export. Pseudocode is not included."),
@@ -318,6 +323,28 @@ export const decompileJournalLineSchema = z.discriminatedUnion("kind", [
decompileJournalFunctionSchema,
]);
/** One caller selection, retained to distinguish the latest run from older records. */
const decompileSelectionSchema = z.strictObject({
name: z.string().nullable(),
namespace: z.string().nullable(),
address_start: z.string().nullable(),
address_end: z.string().nullable(),
limit: z.number().int().min(1).nullable(),
});
/**
* Facts owned by the run that last rewrote this index. Inventory limitations
* and filters describe that run; older runs remain represented only by their
* retained function records.
*/
const decompileLatestRunSchema = z.strictObject({
resume: z.boolean(),
selected: countSchema("Functions matching this run's filter."),
excluded: countSchema("Inventory functions excluded by this run's filter."),
selection: decompileSelectionSchema,
inventory_limitations: z.array(z.string()),
});
/** Index rewritten from the journal at the end of a call. */
export const decompileDirectoryIndexSchema = z.strictObject({
version: z.literal(DECOMPILE_DIRECTORY_VERSION),
@@ -326,6 +353,11 @@ export const decompileDirectoryIndexSchema = z.strictObject({
analysis_profile_digest: digestSchema.nullable(),
layout: layoutSchema,
layout_status: z.enum(["address", "debug_layout_unavailable"]),
latest_run: decompileLatestRunSchema
.optional()
.describe(
"Selection and inventory limitations owned by the run that last rewrote this index. Absent in indexes written before this field existed.",
),
limitations: z.array(z.string()),
functions: z.array(decompileDirectoryFunctionSchema),
});
@@ -277,6 +277,19 @@ describe("decompile journal ownership", () => {
await opened.value.writeIndex({
layoutStatus: "address",
limitations: [],
latestRun: {
resume: false,
selected: 1,
excluded: 0,
selection: {
name: null,
namespace: null,
address_start: null,
address_end: null,
limit: null,
},
inventoryLimitations: [],
},
})
).ok,
).toBe(true);