From 3f6260249cdba6e665264308e48bc9d5daaeb049 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Tue, 1 Dec 2026 00:23:06 +0800 Subject: [PATCH] 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 --- scripts/verify/fixed-ceiling-registry.json | 7 +++++++ scripts/verify/untyped-budget-refusal-baseline.json | 2 -- src/domain/apiContract/GraphqlInventory.ts | 6 ++---- src/domain/apiContract/contractFactAllowance.ts | 13 +++++++++++++ src/domain/apiContract/parseApiContract.test.ts | 9 +++++++++ src/domain/apiContract/parseApiContract.ts | 7 ++----- src/domain/apiContract/parseGraphqlContract.test.ts | 9 +++++++++ 7 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/domain/apiContract/contractFactAllowance.ts diff --git a/scripts/verify/fixed-ceiling-registry.json b/scripts/verify/fixed-ceiling-registry.json index 7eb3f9915fc..baa881b3df3 100644 --- a/scripts/verify/fixed-ceiling-registry.json +++ b/scripts/verify/fixed-ceiling-registry.json @@ -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", diff --git a/scripts/verify/untyped-budget-refusal-baseline.json b/scripts/verify/untyped-budget-refusal-baseline.json index 13f98744521..afc349773f8 100644 --- a/scripts/verify/untyped-budget-refusal-baseline.json +++ b/scripts/verify/untyped-budget-refusal-baseline.json @@ -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, diff --git a/src/domain/apiContract/GraphqlInventory.ts b/src/domain/apiContract/GraphqlInventory.ts index 3279986929f..9b33635a610 100644 --- a/src/domain/apiContract/GraphqlInventory.ts +++ b/src/domain/apiContract/GraphqlInventory.ts @@ -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, ); } diff --git a/src/domain/apiContract/contractFactAllowance.ts b/src/domain/apiContract/contractFactAllowance.ts new file mode 100644 index 00000000000..0e4e04689a9 --- /dev/null +++ b/src/domain/apiContract/contractFactAllowance.ts @@ -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.", + }, +); diff --git a/src/domain/apiContract/parseApiContract.test.ts b/src/domain/apiContract/parseApiContract.test.ts index 839d54d3c1e..e7267f4740f 100644 --- a/src/domain/apiContract/parseApiContract.test.ts +++ b/src/domain/apiContract/parseApiContract.test.ts @@ -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({ diff --git a/src/domain/apiContract/parseApiContract.ts b/src/domain/apiContract/parseApiContract.ts index 81768a7c110..3855b3f92b7 100644 --- a/src/domain/apiContract/parseApiContract.ts +++ b/src/domain/apiContract/parseApiContract.ts @@ -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, ), ); } diff --git a/src/domain/apiContract/parseGraphqlContract.test.ts b/src/domain/apiContract/parseGraphqlContract.test.ts index 98e5fe24af2..dbd20684f24 100644 --- a/src/domain/apiContract/parseGraphqlContract.test.ts +++ b/src/domain/apiContract/parseGraphqlContract.test.ts @@ -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);