Skip to content

fix(ubi): bound smaller-grid probe memoization - #15087

Closed
ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/ubi-grid-cache-bounds
Closed

ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:fix/ubi-grid-cache-bounds

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #15069 at the same commit c5da2e434cfab84be89e1042342cbf60c6e85df2. The prior PR records the review history and validation for this commit.

Replaces #15008 at the same commit c5da2e434cfab84be89e1042342cbf60c6e85df2. The prior PR records the review history and validation for this commit.

Replaces #14989 at the same commit c5da2e434cfab84be89e1042342cbf60c6e85df2. The prior PR records the review history and validation for this commit.

Replaces #14963 at the same commit c5da2e434cfab84be89e1042342cbf60c6e85df2. The prior PR records the review history and validation for this commit.

Replaces #14818 at the same commit c5da2e434cfab84be89e1042342cbf60c6e85df2. The prior PR records the review history and validation for this commit.

Problem and fix

An accepted UBI image can grow smallerGridPositions with a boolean for every probed 512-byte offset. Moving the layout-volume blocks behind mostly erased dynamic-volume data makes smaller-grid discovery retain hundreds of thousands of entries; the existing EC-header cache cap does not cover this map. Both artifact inventory and extraction use this parser.

The same valid virtual images remain extractable before and after the fix:

Logical image Layout placement Retained grid results before After
128 MiB, 8 PEBs first 15 15
128 MiB, 8 PEBs last 196,617 65,536
256 MiB, 16 PEBs last 458,753 65,536

Cap this memoization at 65,536 results, matching the existing EC-cache scale. A miss still reads and classifies the position; reaching the cap neither skips probes nor changes input admission. A parser-level statistics callback, following the existing EC-cache observer, lets the regression measure retained state while checking successful geometry and volume facts. The guide documents the cache bound.

Addresses the unresolved grid-cache finding on merged #13333. No separate issue: the defect is directly reproduced in its existing parser, including an external Map-retention measurement against the unmodified source. Related UBI PR #14809 only shares fixture helpers.

The earlier baseline Knip prerequisite (removing the unused internal PeOverlayRange alias) has now landed independently in #14852, commit 412f92736e099899a6a4257ffd65ce926337ea0a. This branch merges that main revision; its effective diff now contains only the UBI parser, its cache regression, and the UBI guide. All three UBI file hashes, and the main parser used by the saved red reproduction, are unchanged.

Validation

AI-assisted work on Linux x64, Node 24.22.1, npm 11.21.3. The checks below were rerun after aligning with main 412f92736 on current commit c5da2e434cfab84be89e1042342cbf60c6e85df2. Its tree matches the validated tree; all 8457 typed-inventory source hashes remained unchanged through the merge-message commit hook. The resource regression serves bounded chunks for large logical images rather than allocating those images in memory.

  • Red: the unchanged production-parser probe accepted the layout-first and layout-last controls, but the latter retained 196,617 grid results. The final resource regression against the observer-only baseline failed both 128/256 MiB bounds (196,617 / 458,753); its front-layout control passed. The fixed source was restored and its full source hashes rechecked.
  • npm run test:focused -- src/domain/firmware/ubiImage.cache.test.ts src/domain/firmware/ubiImage.test.ts src/artifacts/UbiImageArtifactReader.test.ts src/artifacts/UbiImageArtifactReader.boundaries.test.ts tests/acceptance/ubiImageCli.test.ts tests/boundary/mcp/ubiImageMcp.test.ts — required artifact builds passed; 124 tests passed in six files, including compiled public CLI/MCP.
  • The regular check components passed: node scripts/run-exclusive.mjs artifacts node scripts/run-turbo.mjs run typecheck lint format:check knip metadata:check (six successful tasks), npm run verify:architecture-guards (3239 files), and npm run knip:production (99 advisory candidates). The full 8457-file typed-lint inventory passed in eight disjoint serial batches through node scripts/ci/static-check-report.mjs typed-lint, with identical rules/tsconfigs: zero errors, 6128 non-failing warnings, exact coverage and unchanged hashes verified. A monolithic npm run check is not claimed to have completed: the earlier revision's monolithic typed stage was interrupted with SIGINT near this environment's 8 GiB limit, so this aligned revision used the bounded full-inventory qualification directly.
  • npm run verify:test-discovery — all 4010 test/spec files discovered exactly once.
  • npm run docs:check — facts passed; 8 README consistency tests passed.
  • npm run deps:check and git diff --check — passed. The normal pre-commit hook ran for the merge-message amendment with no staged files; normal pre-push npm run check:fast passed. All validated source hashes remained unchanged.

Previously, four independent ubinize 2.1.5 controls passed against both original and fixed production-parser bundles; these were not rerun after this main alignment because both parser sources are byte-identical: dynamic/static volumes, non-default alignment, and NAND subpage geometry. Reassembly matched producer input bytes, including dynamic-volume padding. This is a parser/reassembly check, not an additional public CLI/MCP run.

Single-process resource observation

The same completed parser probe (front/tail layout on a 128 MiB virtual image) ran in one fresh Node process per revision. Before/after: wall time 0.940/0.918 s, CPU user+system 0.837/0.819 s, peak process-family RSS 61,640/54,980 KiB. The process had no child processes. These are single cold-process observations on a shared host, without warm samples or a general speed/RSS guarantee. No LLM calls occur in this probe; token impact was not measured. The regression independently verifies the deterministic retained-entry bound. The tail-layout case read 4,195,200 additional header bytes after the cap, while preserving its result.

Scope and limits

Existing read-only UBI parsing and extraction; maintainer scope decision not applicable. No new input allowance, runtime setting, provider, network/target-execution authority, package dependency or advertised schema. Artifact identity, CRC rules, cancellation and cleanup paths stay with their existing owners.

Local verification did not exercise real NAND dumps with OOB data, bad blocks or bit flips, Windows/macOS host workflows, or Fastmap. Hosted platform verification is reported separately below.

Hosted CI and automated review

The current aligned commit is c5da2e434cfab84be89e1042342cbf60c6e85df2. Its CI run 45939311205, attempt 1 completed successfully.

  • The selected built shard passed 121 tests in four files: UBI parser (82), cache bounds (3), artifact reader (9), and reader boundaries (27). The separate local run above also passed the three compiled CLI/MCP tests, for 124 total. Portable aggregation uses the same hosted shard rather than a second execution.
  • Hosted build, documentation and static checks passed. Regular lint checked 8457 files with zero errors; typed lint checked two changed files with zero errors. Full typed coverage is the local eight-batch qualification above.
  • The Linux x64 native package baseline passed, including package install/update, CLI, extracted-plugin MCP and cleanup verification. The Windows native-controls build also passed. The Windows capability/package lane was conditionally skipped; Linux arm64 and Darwin arm64 baselines did not run on this narrower three-file diff.

The previous commit bb8f01a5f63547390ff71604b07b2fffa68a2ae4 completed CI run 45923144747 successfully, including Windows capability tests (1124 passed / 73 skipped), Windows package verification (59 tests), and Linux x64/arm64 and Darwin arm64 native package baselines. Those are historical selected-platform checks, not current-head platform runs or UBI regression coverage on every host.

Greptile inspected the current c5da2e4 commit and reported no actionable issue. Automated review is source-inspection evidence, not a test run or human readiness declaration. The prior Codex review could not complete because the repository's code-review usage limit was reached; no completed current-head Codex review is claimed.

Under CONTRIBUTING, readiness records the initial review and later pushes do not invalidate it. The existing human-owned declaration below is preserved unchanged. This CI update was prepared by the coding agent and does not attest to an additional human review.

Author readiness

Human owner: @ShuaixinHuang

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T07:31:24.307464Z c5da2e4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

security Security Review

This PR appears safe to merge from a security standpoint.

What was checked
  • Capping the smaller-grid memoization never skips a probe: an uncached position is still read and classified, so the cap cannot make the parser accept an image it previously rejected.
  • The cached verdict depends only on the image bytes at that offset and geometry fields fixed for the whole parse, so uncapped re-reads return the same result.
  • The new onSmallerGridCacheStats callback reports only a retained-entry count, runs even when parsing fails, and is consumed only by tests, so nothing sensitive leaves the parser.
  • The cap trades memory for at most a constant factor of extra bounded reads with cancellation yields intact, so it introduces no new hang or unbounded CPU use.
  • In this clone the PR commit exists only on the PR head (the fix commit plus an alignment merge), matching its claim to supersede the earlier PRs; GitHub-side supersession could not be verified locally.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Bounds retained smaller-grid probe answers at 65,536 without stopping further checks.

  • UBI parsing keeps its smaller-grid probe cache within a fixed bound.
  • The UBI guide now explains the cache limit and producer-check scope.

Reviews (1) · Last reviewed commit: "chore: align UBI cache fix with main" · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant