From 81657ccedea257a7138c11908a4681dc5986eca3 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Mon, 30 Nov 2026 19:09:46 +0800 Subject: [PATCH] fix(analysis-view): return continuation for GPU pages at the byte limit (#15206) * fix(analysis-view): return continuation for GPU pages at the byte limit * test(analysis-view): admit GPU pagination requests through the schema * fix(analysis-view): reuse shared byte-bounded GPU pagination --- .../resource-constraint-constructor.json | 2 +- .../analysisView/gpuCodeObjectsView.test.ts | 82 +++++++++++++ src/domain/analysisView/gpuCodeObjectsView.ts | 112 ++++++++++-------- 3 files changed, 147 insertions(+), 49 deletions(-) diff --git a/scripts/verify/baselines/resource-constraint-constructor.json b/scripts/verify/baselines/resource-constraint-constructor.json index 77b2534e6da..bcece840c99 100644 --- a/scripts/verify/baselines/resource-constraint-constructor.json +++ b/scripts/verify/baselines/resource-constraint-constructor.json @@ -51,7 +51,7 @@ "src/desktop/BuildComputerController.ts": 2, "src/domain/analysisView/WebNetworkProjectionAccumulator.ts": 1, "src/domain/analysisView/analysisViewErrors.ts": 1, - "src/domain/analysisView/gpuCodeObjectsView.ts": 2, + "src/domain/analysisView/gpuCodeObjectsView.ts": 1, "src/domain/analysisView/nativeFunctionMatchingView.ts": 1, "src/domain/analysisView/recordedArrayView.ts": 2, "src/domain/analysisView/webSourceLocationView.ts": 1, diff --git a/src/domain/analysisView/gpuCodeObjectsView.test.ts b/src/domain/analysisView/gpuCodeObjectsView.test.ts index 4471ba416c8..d2af4a2c5e2 100644 --- a/src/domain/analysisView/gpuCodeObjectsView.test.ts +++ b/src/domain/analysisView/gpuCodeObjectsView.test.ts @@ -5,6 +5,7 @@ import { gpuCodeObjectsSchema } from "../gpu/gpuCodeObjects.js"; import type { AnalysisViewParent } from "./analysisViewParent.js"; import { gpuCodeObjectsItemsSchema, + gpuCodeObjectsViewRequestSchema, projectGpuCodeObjectsView, } from "./gpuCodeObjectsView.js"; @@ -106,3 +107,84 @@ it("preserves omitted AMD metadata columns instead of inventing null metadata", ]; expect(gpuCodeObjectsItemsSchema.parse(items)).toEqual(items); }); + +it("pages GPU rows at the byte allowance in filtered order", () => { + const location = { + container_id: null, + offset: 0, + size: 0, + section_index: null, + section_name: null, + }; + const source = gpuCodeObjectsSchema.parse({ + ...report(), + objects: ["first", "excluded", "second", "oversized"].map((id) => ({ + id, + parent_id: null, + kind: "ptx", + target: null, + payload_target: null, + cuda_target_header: null, + amd_target_metadata: null, + amd_pal_metadata: null, + target_consistency: "unexamined", + bundle_id: null, + compression: "none", + compression_id: null, + encoded_size: 0, + decoded_size: 0, + sha256: null, + raw_flags: null, + location, + metadata_location: location, + inspection: "inventory", + limitations: ["x".repeat(id === "oversized" ? 1_100_000 : 550_000)], + })), + }); + const input = parent(source); + const view = { + kind: "gpu-code-objects", + collection: "objects", + ids: ["second", "first"], + offset: 0, + limit: 2, + } as const; + const page = (request: unknown) => + projectGpuCodeObjectsView( + input, + gpuCodeObjectsViewRequestSchema.parse(request), + ); + const first = page(view); + expect(first).toMatchObject({ + ok: true, + value: { + items: [{ id: "first" }], + coverage: { examined: 1, total: 2, next_offset: 1 }, + }, + }); + if (!first.ok) throw first.error; + const second = page({ + ...view, + offset: first.value.coverage.next_offset!, + }); + expect(second).toMatchObject({ + ok: true, + value: { + items: [{ id: "second" }], + coverage: { examined: 1, total: 2, next_offset: null }, + }, + }); + + const oversized = { ...view, ids: ["oversized"] }; + expect(page(oversized)).toMatchObject({ + ok: false, + error: { _tag: "AnalysisResourceConstraintError" }, + }); + expect(page({ ...oversized, fields: ["id"] })).toMatchObject({ + ok: true, + value: { + items: [{ id: "oversized" }], + coverage: { examined: 1, total: 1, next_offset: null }, + }, + }); +}); diff --git a/src/domain/analysisView/gpuCodeObjectsView.ts b/src/domain/analysisView/gpuCodeObjectsView.ts index efa78bd6eb0..4adff8c797d 100644 --- a/src/domain/analysisView/gpuCodeObjectsView.ts +++ b/src/domain/analysisView/gpuCodeObjectsView.ts @@ -35,6 +35,10 @@ import type { JsonValue } from "../jsonValue.js"; import { jsonValueByteLength } from "../jsonValueByteLength.js"; import { AnalysisResourceConstraintError } from "../analysisErrorCore.js"; import { evidenceFileTarget } from "../evidence.js"; +import { + PLACEHOLDER_COVERAGE, + selectByteBoundedViewRows, +} from "./byteBoundedViewRows.js"; export const gpuCodeObjectsViewRequestSchema = z.discriminatedUnion( "collection", [ @@ -319,14 +323,12 @@ export const projectGpuCodeObjectsView = ( "target" in row ? row.target : byId.get(row.object_id)?.target; return target !== null && target !== undefined && targets.has(target); }; - const matches = rows.filter( - (row) => - (ids === undefined || ids.has(row.id)) && - (objectIds === undefined || - ("object_id" in row && objectIds.has(row.object_id))) && - (names === undefined || ("name" in row && names.has(row.name))) && - matchesTarget(row), - ); + const matches = (row: (typeof rows)[number]): boolean => + (ids === undefined || ids.has(row.id)) && + (objectIds === undefined || + ("object_id" in row && objectIds.has(row.object_id))) && + (names === undefined || ("name" in row && names.has(row.name))) && + matchesTarget(row); const defaults = view.collection === "kernels" ? new Set([ @@ -344,50 +346,64 @@ export const projectGpuCodeObjectsView = ( : undefined; const fields = view.fields === undefined ? defaults : new Set(view.fields); - const items = matches - .slice(view.offset, view.offset + view.limit) - .map((row) => { - const projected: Record = {}; - for (const [key, value] of Object.entries(row)) - if ( - key === "id" || - key === "object_id" || - key === "location" || - key === "metadata_location" || - key === "kind" || - key === "target" || - key === "payload_target" || - key === "target_consistency" || - key === "inspection" || - key === "sources" || - key === "representation" || - (view.collection === "targets" && - (key === "target" || - key === "confidence" || - key === "kernel_coverage")) || - fields === undefined || - fields.has(key) - ) - projected[key] = value; - return projected; - }); - if (jsonValueByteLength(items, 1024 * 1024) > 1024 * 1024) - return err( - new AnalysisResourceConstraintError( - "inspect_analysis_view", - "memory", - "GPU page exceeds the 1 MiB response budget; select fewer fields or rows", - { maximum_page_bytes: 1024 * 1024 }, - ANALYSIS_VIEW_PAGE_BUDGET_RECOVERY, - ), - ); - return ok({ + const envelope = { kind: "gpu-code-objects" as const, view, ...shared, source_coverage: report.coverage, - items: gpuCodeObjectsItemsSchema.parse(items), + items: [], ptx: null, - coverage: pageViewCoverage(view.offset, items.length, matches.length), + coverage: PLACEHOLDER_COVERAGE, + }; + const project = (row: (typeof rows)[number]) => { + const projected: Record = {}; + for (const [key, value] of Object.entries(row)) + if ( + key === "id" || + key === "object_id" || + key === "location" || + key === "metadata_location" || + key === "kind" || + key === "target" || + key === "payload_target" || + key === "target_consistency" || + key === "inspection" || + key === "sources" || + key === "representation" || + (view.collection === "targets" && + (key === "target" || + key === "confidence" || + key === "kernel_coverage")) || + fields === undefined || + fields.has(key) + ) + projected[key] = value; + return projected; + }; + const page = selectByteBoundedViewRows( + rows, + view, + { + matches: + ids === undefined && + objectIds === undefined && + names === undefined && + targets === undefined + ? undefined + : matches, + project, + }, + { + parentEvidenceId: parent.evidenceId, + envelope: envelope as unknown as JsonValue, + facet: `GPU ${view.collection}`, + }, + ); + if (!page.ok) return page; + const { rows: items, total } = page.value; + return ok({ + ...envelope, + items: gpuCodeObjectsItemsSchema.parse(items), + coverage: pageViewCoverage(view.offset, items.length, total), }); };