fix(api-contract): report structured retained-facts allowance (#15256)

* fix(api-contract): report structured retained-facts allowance

* fix(limits): track contract retention as a pending resource policy

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
ShuaixinHuangandVincent Koc authored and GitHub committed 2026-12-01 00:23:06 +08:00
1 parent 061239a5de
commit 3f6260249c
7 files changed
+42 -11

No files matched your search

@@ -262,6 +262,13 @@
"reason": "Reuses ANALYSIS_VIEW_PAGE_ALLOWANCE declared by analysisViewErrors.ts for recorded-array view pages."
}
},
"src/domain/apiContract/contractFactAllowance.ts": {
"\"The API contract retained-facts allowance\"": {
"class": "pending",
"issue": 14237,
"reason": "The 32 MiB retained-facts budget is a producer resource policy for OpenAPI and GraphQL. It has no caller control yet; reply paging happens after the facts are materialized."
}
},
"src/domain/apiContract/GraphqlDocuments.ts": {
"`The GraphQL AST nesting allowance of ${String(GRAPHQL_CONTRACT_LIMITS.astDepth)} levels`": {
"class": "representation",
@@ -14,8 +14,6 @@
"src/cutter/CutterBridgeClient.ts": 1,
"src/desktop/AgentEnvComputer.ts": 1,
"src/desktop/BuildComputerController.ts": 2,
"src/domain/apiContract/GraphqlInventory.ts": 1,
"src/domain/apiContract/parseApiContract.ts": 1,
"src/hopper/HopperCallerReconciliation.ts": 1,
"src/il2cpp/Il2cppMetadataProvider.ts": 2,
"src/javascript/analysis/JavaScriptAnalysisTransfer.ts": 1,
+2 -4
View File
@@ -1,3 +1,4 @@
import { contractFactAllowance } from "./contractFactAllowance.js";
import type { ASTNode } from "graphql";
import { digestCanonicalValue } from "../canonicalDigest.js";
import { AnalysisResourceConstraintError } from "../analysisErrorCore.js";
@@ -71,10 +72,7 @@ export class GraphqlInventory {
"memory",
"GraphQL facts exceed the 32 MiB retained representation allowance.",
{ retained_fact_allowance: API_CONTRACT_FACT_BYTES },
{
remediationAction:
"Select smaller complete schema/operation documents; reply paging does not raise parser allowances.",
},
contractFactAllowance,
);
}
@@ -0,0 +1,13 @@
import { fixedAllowanceOptions } from "../fixedAllowanceRemediation.js";
import { API_CONTRACT_FACT_BYTES } from "./apiContract.js";
export const contractFactAllowance = fixedAllowanceOptions(
"The API contract retained-facts allowance",
"parser",
{
limit: API_CONTRACT_FACT_BYTES,
unit: "bytes",
narrowing:
"Select smaller complete contract documents. Page size does not raise the parser allowance; retain any partial observation returned with the refusal.",
},
);
@@ -7,6 +7,7 @@ import {
type ApiContractArtifact,
} from "./apiContract.js";
import { parseApiContractSteps } from "./parseApiContract.js";
import { projectAnalysisError } from "../analysisErrorProjection.js";
import { AnalysisCancelledError } from "../analysisErrorCore.js";
const artifact: ApiContractArtifact = {
@@ -321,6 +322,14 @@ it("bounds expanded identities and source pointers before building a giant row",
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected a retained-facts refusal");
expect(result.error._tag).toBe("AnalysisResourceConstraintError");
const projected = projectAnalysisError(result.error);
expect(projected.retryable).toBe(false);
expect(projected.details?.refusal).toMatchObject({
kind: "fixed_ceiling",
allowance: "The API contract retained-facts allowance",
limit: API_CONTRACT_FACT_BYTES,
unit: "bytes",
});
const partial = apiContractSchema.parse(result.error.partialObservation);
expect(partial.operations.map((row) => row.path)).toEqual(["/retained"]);
expect(partial.source_coverage).toMatchObject({
+2 -5
View File
@@ -1,3 +1,4 @@
import { contractFactAllowance } from "./contractFactAllowance.js";
import { Budget } from "../budget.js";
import { escapeJsonPointerToken } from "../jsonPointer.js";
import {
@@ -74,11 +75,7 @@ class ContractInventory {
"memory",
"API contract declarations exceed the retained-facts representation allowance.",
{ representation_bytes: API_CONTRACT_FACT_BYTES },
{
retryable: false,
remediationAction:
"Select a smaller complete API document; paging the reply does not increase the parser's retained-facts allowance.",
},
contractFactAllowance,
),
);
}
@@ -9,6 +9,7 @@ import { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
import { expect, it } from "vitest";
import { parseGraphqlContractSteps } from "./parseGraphqlContract.js";
import { API_CONTRACT_FACT_BYTES } from "./apiContract.js";
import { graphqlContractSchema } from "./graphqlContract.js";
import { projectAnalysisError } from "../analysisErrorProjection.js";
import type { GraphqlSourceDocument } from "./GraphqlDocuments.js";
@@ -296,6 +297,14 @@ it("retains a bounded prefix when expanded field facts exceed the shared allowan
);
if (result.ok) throw new Error("Expected fact capacity refusal");
expect(result.error._tag).toBe("AnalysisResourceConstraintError");
const projected = projectAnalysisError(result.error);
expect(projected.retryable).toBe(false);
expect(projected.details?.refusal).toMatchObject({
kind: "fixed_ceiling",
allowance: "The API contract retained-facts allowance",
limit: API_CONTRACT_FACT_BYTES,
unit: "bytes",
});
const report = graphqlContractSchema.parse(result.error.partialObservation);
expect(report.fields.length).toBeGreaterThan(1000);
expect(report.fields.length).toBeLessThan(18000);