Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e7eefe
feat(apple): inspect IPS crash reports
mvanhorn Oct 23, 2026
c3554c6
fix(apple): keep IPS register literals exact
mvanhorn Oct 23, 2026
80ad2a0
fix(apple): budget IPS parsing and keep typed presence
mvanhorn Oct 23, 2026
a81b693
fix(apple): bound integer text expansion and reconcile coverage
gensokyo-dev Oct 24, 2026
130e457
chore: integrate main and shared IPS artifact ownership
gensokyo-dev Oct 24, 2026
c608dea
refactor(apple): retain image metadata at its owning row
gensokyo-dev Oct 24, 2026
54ebac6
refactor(apple): validate row capacity through reconciled coverage
gensokyo-dev Oct 24, 2026
135cab1
test(apple): verify resource recovery at the public error boundary
gensokyo-dev Oct 24, 2026
5898e4f
docs(apple): record complete IPS task and corpus measurements
gensokyo-dev Oct 24, 2026
02bacf7
chore: integrate current main for IPS final verification
gensokyo-dev Oct 24, 2026
2b92578
docs(apple): record integrated checks and stdio corpus evidence
gensokyo-dev Oct 24, 2026
7e931e2
chore: integrate PE imports and current native lifecycle fixes
gensokyo-dev Oct 24, 2026
45a5706
docs(apple): record PE integration and baseline cleanup controls
gensokyo-dev Oct 24, 2026
ab590a6
fix(native): bound IPS string decoding and preserve invalid identities
gensokyo-dev Oct 24, 2026
6fa8083
refactor(native): use exact optional IPS source evidence
gensokyo-dev Oct 24, 2026
93e5c43
docs(native): verify IPS escape capacity and complete-task costs
gensokyo-dev Oct 24, 2026
6d77f26
chore(native): integrate current main for IPS verification
gensokyo-dev Oct 24, 2026
c838cae
test(native): verify IPS through production stdio MCP
gensokyo-dev Oct 24, 2026
f6c270d
style(tests): format IPS advertised schema bindings
gensokyo-dev Oct 24, 2026
174c749
fix(native): preserve unresolved IPS references and recorded frame se…
gensokyo-dev Oct 24, 2026
a5cdb34
docs(native): record IPS reference review evidence
gensokyo-dev Oct 24, 2026
0a3dbf2
fix(apple-ips): enforce JSON and report consistency
gensokyo-dev Oct 24, 2026
38b5a3c
Merge commit '98ec00f4068bab894639d0d1d83ac0bfc428bcbf' into maintena…
gensokyo-dev Oct 24, 2026
98e1a61
docs(apple-ips): record final consistency verification
gensokyo-dev Oct 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(apple-ips): enforce JSON and report consistency
  • Loading branch information
gensokyo-dev committed Oct 24, 2026
commit 0a3dbf27df3efdaf8d053934951256280347fc2a
27 changes: 27 additions & 0 deletions docs/verification/apple-ips-2026-10-24.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,30 @@ this small warm-cache sample does not establish a general speed or memory
improvement. Processes are fresh; the OS file cache is warm. Caller input
creation, schemas/discovery, prompts, client parsing and MCP transport are not
included. The same 50 ms family-RSS limitations apply.

## JSON admission and output consistency follow-up

Three later review findings were reproduced with 19 failing controls before the
correction (49 other selected checks pass). Broad JavaScript trimming admitted
form-feed, vertical-tab, NBSP and BOM around JSON objects; those are not JSON
whitespace. The IPS adapter now passes the original body to the lossless parser,
and the complete-value boundary permits only space, tab, CR and LF after the
value. Twelve controls cover metadata suffixes and body prefixes/suffixes; a
positive control retains JSON whitespace around both objects. Caller bytes and
artifact identity stay unchanged.

The shared service no longer accepts a reported faulting-thread index without
an established retained owner or its corresponding reference mismatch. Unknown
or out-of-range recorded indexes remain available with partial coverage; an
unrelated mismatch cannot justify the unresolved lookup. The old empty service
fixture incorrectly asserted faulting thread zero and now records null. This is
output admission, not reinterpretation of provider source JSON.

Classification is now a named discriminated schema: `classified` requires at
least one match and `unclassified` permits none. The source schema rejects both
contradictions. Production SDK/Ajv checks also test both contradictions and both
valid alternatives against the advertised JSON Schema; an actual stdio call
checks that non-JSON trailing whitespace returns a typed caller-input failure.
These are correctness changes. Prior CLI/performance results retain their exact
pins and are not a fresh measurement of the expanded classification schema or
agent catalog costs. No speed or token reduction is claimed for this follow-up.
64 changes: 63 additions & 1 deletion src/application/binaryDiagnostics/AppleIpsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const report: AppleIps = {
},
exception: null,
termination: null,
faulting_thread: 0,
faulting_thread: null,
threads: [],
images: [],
classification: { status: "unclassified", matches: [] },
Expand All @@ -52,6 +52,68 @@ const report: AppleIps = {
limitations: ["Opened Mach-O and dSYM UUID joins remain unobserved."],
};

it.each([0, 5])(
"rejects an unresolved faulting thread %s without its mismatch",
async (index) => {
const unresolved: AppleIps = { ...report, faulting_thread: index };
const service = new AppleIpsService({
identity,
inspect: () => Promise.resolve(ok(unresolved)),
});
const result = await service.inspect({ path: report.artifact.path });
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error._tag).toBe("AnalysisOutputError");
},
);

it.each(["body.faultingThread", "body.other"])(
"requires the matching reference diagnostic: %s",
async (path) => {
const unresolved: AppleIps = {
...report,
faulting_thread: 5,
coverage: {
...report.coverage,
status: "partial",
reason: "Unresolved reference",
type_mismatches: [
{ path, expected: "index into threads", observed: "out of range" },
],
},
};
const result = await new AppleIpsService({
identity,
inspect: () => Promise.resolve(ok(unresolved)),
}).inspect({ path: report.artifact.path });
expect(result.ok).toBe(path === "body.faultingThread");
},
);

it.each([
{ status: "classified", matches: [] },
{
status: "unclassified",
matches: [
{
rule: "watchdog",
fields: [{ name: "termination.code", value: "2343432205" }],
},
],
},
])(
"rejects contradictory provider classification $status",
async (classification) => {
const malformed = structuredClone(report);
Reflect.set(malformed, "classification", classification);
const result = await new AppleIpsService({
identity,
inspect: () => Promise.resolve(ok(malformed)),
}).inspect({ path: report.artifact.path });
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error._tag).toBe("AnalysisOutputError");
},
);

it.each(["288", "309 "])(
"rejects unsupported crash kind %s from a custom provider",
async (bugType) => {
Expand Down
11 changes: 11 additions & 0 deletions src/application/binaryDiagnostics/AppleIpsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ const validReport = (
report.coverage.images !== report.images.length
)
return false;
const faultingThread = report.faulting_thread;
const mismatches = report.coverage.type_mismatches;
if (
faultingThread !== null &&
(report.threads[faultingThread]?.index !== faultingThread ||
mismatches.some(
({ path }) => path === `body.threads[${String(faultingThread)}]`,
)) &&
!mismatches.some(({ path }) => path === "body.faultingThread")
)
return false;
let frames = 0;
let registers = 0;
for (const thread of report.threads) {
Expand Down
19 changes: 19 additions & 0 deletions src/domain/native/appleIps.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import { expect, it } from "vitest";
import { appleIpsSchema, inspectAppleIpsInputSchema } from "./appleIps.js";

it.each([
["classified", 0, false],
["classified", 1, true],
["unclassified", 0, true],
["unclassified", 1, false],
] as const)(
"advertises classification %s with %s matches consistently",
(status, count, accepted) => {
const matches = Array.from({ length: count }, () => ({
rule: "watchdog",
fields: [{ name: "termination.code", value: "2343432205" }],
}));
expect(
appleIpsSchema.shape.classification.safeParse({ status, matches })
.success,
).toBe(accepted);
},
);

it("rejects extra caller arguments and admits an empty crash inventory", () => {
expect(
inspectAppleIpsInputSchema.safeParse({
Expand Down
14 changes: 10 additions & 4 deletions src/domain/native/appleIps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,16 @@ export const appleIpsSchema = z.strictObject({
faulting_thread: uint.nullable(),
threads: z.array(threadSchema),
images: z.array(imageSchema),
classification: z.strictObject({
status: z.enum(["classified", "unclassified"]),
matches: z.array(classificationMatchSchema),
}),
classification: z.discriminatedUnion("status", [
z.strictObject({
status: z.literal("classified"),
matches: z.array(classificationMatchSchema).min(1),
}),
z.strictObject({
status: z.literal("unclassified"),
matches: z.array(classificationMatchSchema).max(0),
}),
]),
coverage: coverageSchema,
unlisted_body_keys: z.array(z.string().min(1)),
limitations: z.array(z.string().min(1)),
Expand Down
3 changes: 1 addition & 2 deletions src/native/apple/AppleIpsJsonShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ export const consumeJson = (
const parsed = parseLosslessJson(text, 0, shape, {
maxDepth: MAX_IPS_JSON_DEPTH,
});
const trailing = text.slice(parsed.end).trim();
if (trailing.length > 0)
if (!/^[\u0020\u0009\u000a\u000d]*$/u.test(text.slice(parsed.end)))
throw new AppleIpsFormatFailure(
"malformed",
`${label} has trailing JSON text after the first complete value`,
Expand Down
34 changes: 34 additions & 0 deletions src/native/apple/AppleIpsParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ const artifact = (bytes: Buffer) => ({
bytes: bytes.length,
});

it.each(
["\f", "\v", "\u00a0", "\ufeff"].flatMap((character) =>
["metadata suffix", "body prefix", "body suffix"].map((position) => ({
character,
position,
})),
),
)(
"rejects non-JSON whitespace at $position: $character",
({ character, position }) => {
const metadata = appleIpsMetadataLine();
const body = '{"threads":[],"usedImages":[]}';
const bytes = Buffer.from(
position === "metadata suffix"
? `${metadata}${character}\n${body}`
: position === "body prefix"
? `${metadata}\n${character}${body}`
: `${metadata}\n${body}${character}`,
);
expect(() => parseAppleIps(bytes, artifact(bytes), input)).toThrow(
AppleIpsFormatFailure,
);
},
);

it("accepts only JSON whitespace around each object", () => {
const bytes = Buffer.from(
` \t${appleIpsMetadataLine()} \t\r\n \t\r\n{"threads":[],"usedImages":[]} \t\r\n`,
);
expect(parseAppleIps(bytes, artifact(bytes), input).coverage.status).toBe(
"complete",
);
});

it.each([
"not-a-uuid",
"Z".repeat(32),
Expand Down
2 changes: 1 addition & 1 deletion src/native/apple/AppleIpsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const crashText = (bytes: Buffer): { metadata: string; body: string } => {
"IPS crash report must start with a metadata JSON object on the first line",
);
const lineEnd = text.startsWith("\r\n", newline) ? newline + 2 : newline + 1;
return { metadata: text.slice(0, newline), body: text.slice(lineEnd).trim() };
return { metadata: text.slice(0, newline), body: text.slice(lineEnd) };
};

const metadataOf = (text: string, read: FieldReader): AppleIps["metadata"] => {
Expand Down
26 changes: 26 additions & 0 deletions tests/boundary/mcp/appleIpsMcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ it("advertises and validates IPS facts and failures through production stdio MCP
},
};
expect(ajv.validate(outputSchema, unsupported)).toBe(false);
const match = {
rule: "watchdog",
fields: [{ name: "termination.code", value: "2343432205" }],
};
for (const [status, matches, accepted] of [
["classified", [], false],
["classified", [match], true],
["unclassified", [match], false],
["unclassified", [], true],
] as const) {
expect(
ajv.validate(outputSchema, {
...evidence,
normalized_result: { ...report, classification: { status, matches } },
}),
).toBe(accepted);
}

const whitespacePath = join(root, "non-json-whitespace.ips");
await writeFile(
whitespacePath,
Buffer.concat([appleIpsBytes(), Buffer.from("\f")]),
);
const whitespace = await call("inspect_apple_ips", { path: whitespacePath });
expect(whitespace.isError).toBe(true);
expect(parseMcpToolError(whitespace).error.code).toBe("invalid_request");

const malformedPath = join(root, "malformed-uuid.ips");
await writeFile(malformedPath, appleIpsBytes({ uuid: "malformed/report" }));
Expand Down