Skip to content

fix(firmware): report a staging budget refusal as a resource constraint - #5962

Closed
XiaoBinGan wants to merge 5 commits into
morluto:mainfrom
XiaoBinGan:fix/firmware-staging-budget
Closed

XiaoBinGan wants to merge 5 commits into
morluto:mainfrom
XiaoBinGan:fix/firmware-staging-budget

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

inventoryFirmwareOutput refused an extraction that exceeded the caller-selected max_output_files or max_output_bytes staging budget with AnalysisOutputError, so an MCP caller received unreadable_output, category: "execution_failure" and rea doctor remediation for a deterministic allowance the caller can raise.

Fixes #5846

Problem and expected behavior

  • Smallest trigger: extract_firmware with max_output_files: 1 over the repository's synthetic Unblob producer, which stages rootfs/config (one directory and one regular file). The inventory counted two entries and threw Invalid analysis output for extract_firmware: Staging entry budget exceeded (1), projected as unreadable_output with doctor guidance.
  • Violated invariant: the firmware policy separates producer-report and staging allowances and documents caller-selected staging budgets; the error algebra classifies a bounded admission refusal as a resource constraint, and output errors describe failed output parsing. This refusal is a valid, deterministic budget decision.
  • Expected: keep refusing, identify the resource, report the exceeded allowance in limit details, and explain the actual recovery - raising that specific budget and rerunning with an absent output destination. details.reason keeps the observed text.

Change and scope

  • src/firmware/FirmwareFiles.ts: both staging overruns now throw AnalysisResourceConstraintError (entries: capacity, bytes: memory) with reported_limits.max_output_files / reported_limits.max_output_bytes, retryable: false, and a remediation that names the control, its supported maximum and the absent-destination retry.
  • src/firmware/FirmwareFiles.test.ts (new): covers both refusals and their projection, including the remediation text.
  • Not included: no change to the budgets themselves, to Unblob invocation, to the FirmwareCommand deadline path or to publication.

Contract and boundary impact

  • Semantic owner and earliest changed stage: firmware staging inventory enforcement.
  • Contribution scope fit and linked maintainer decision: not applicable - an ordinary fix inside an existing boundary.
  • CLI and MCP/tool-catalog contract: a staging-budget refusal now returns resource_constraint with reported_limits instead of unreadable_output; the input schema is unchanged.
  • Provider, bridge, target-format, or platform compatibility: none; the same function serves the provider and the command deadline path.
  • Evidence, artifact, provenance, or reconstruction contract: no extraction output is published when the budget is exceeded, as before.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged; no extra process is launched and workspace cleanup keeps its existing path.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added: src/firmware/FirmwareFiles.test.ts (2 cases).
  • Base reproduction: before the change both cases fail with Expected a resource constraint, received Error: Invalid analysis output for extract_firmware: Staging entry budget exceeded (1) and the byte equivalent; after the change they pass and project code: "resource_constraint" with details.reported_limits and the budget-specific remediation.
  • User-visible CLI/MCP output: the refusal now names max_output_files / max_output_bytes and the supported maximum instead of recommending rea doctor.
  • Remaining proof gaps: the tests stage a real directory tree but do not run Unblob; the original report exercised a mocked Linux admission on macOS, and no real Unblob or public CLI run is claimed.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run src/firmware tests/boundary/firmware - 46 passed, 40 skipped.
  • npm run format:check - all matched files use the correct format.
  • npm run verify:test-discovery - all 1903 test files discovered exactly once.
  • npm run typecheck - no diagnostic in the changed files (the remaining errors in this checkout are pre-existing protobuf-module resolution failures).
  • npm run lint - 0 errors, module boundaries checked.

Compatibility, safety, and release

  • Breaking changes or migration steps: callers that matched unreadable_output for a staging overrun now receive resource_constraint; both keep the same reason text.
  • Real Unblob coverage: none claimed.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @XiaoBinGan

  • 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.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Maintainer blocker verification

Both staging refusals use schema-owned maxima and one remediation owner: below the cap callers may increase the selected budget up to the supported maximum; at the cap the message recommends a smaller firmware range/image and a fresh absent output destination. It no longer recommends an impossible increase above the schema ceiling.

Regular-file sizes measure retained staging capacity, not observed process memory. The byte-budget refusal therefore reports capacity, matching entry-budget refusal, with non-retryability and the actual configured limit. Four focused FirmwareFiles tests and npm run check:fast passed on Node 24.18.0/npm 11.16.0, including serialized resource classification and cap-specific recovery guidance. No real Unblob extraction or public CLI was executed in this pass.

Current follow-up evidence

Merged main 82e4e032 to resolve the actual firmware contract conflict, retaining main's staging semantics and the schema-owned capacity/remediation fix. The combined tree passed 4 FirmwareFiles tests, 11 report-file boundary tests and check:fast; the 36 firmware integration cases were skipped by host configuration. No real extraction/provider result is claimed. The fork push was a verified fast-forward; this update establishes local combined-tree checks, not completed hosted CI.

inventoryFirmwareOutput threw AnalysisOutputError when the caller-selected
max_output_files or max_output_bytes staging budget was exceeded, so an
MCP caller saw unreadable_output with doctor guidance for a deterministic
allowance the caller can raise.

Report both refusals as resource constraints that keep the observed reason,
name the exceeded control in details.reported_limits, stay non-retryable,
and explain how to raise that specific budget for a rerun.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T06:41:38.548864Z 746a64c New commits
ℹ️ 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 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

Firmware staging overruns now return resource_constraint, the selected allowance, and budget-specific recovery guidance.

  • Firmware extraction names the staging budget when it stops.

Reviews (5) · Last reviewed commit: "chore: integrate firmware staging-budget..." · Reviewed by Greptile

Comment thread src/firmware/FirmwareFiles.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0a5874367

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/firmware/FirmwareFiles.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 997a55297d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/firmware/FirmwareFiles.ts Resolved

@CassieFox23 CassieFox23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: Main still reports a staging-budget refusal as unreadable_output with rea doctor advice (issue #5846). This PR turns it into a resource constraint that names the budget and its supported maximum. CI is green on this head, and my open points are small.

Findings

Should fix

  • The body does not keep the repo template as written. Please restore the template text. What changed:
    • The "Follow the contribution scope" paragraph is gone. That drops the CONTRIBUTING.md link and the rules about new providers.
    • In "Expected effects", this line is gone: Unchecked items do not establish absence; leave uncertainties visible.
    • "(if applicable)" is gone from the "Target selection, authority..." label.
    • The part in brackets after the "Generated metadata" label is gone. The template says CI builds the catalogs and skills/, and to edit authored instructions in .agents/skills/reverse-engineer-anything/.
    • "Tests added or updated" now reads "Tests added". The change is that "Base reproduction or other evidence" is now "Base reproduction". "User-visible CLI/MCP output (if applicable)" lost its "(if applicable)".
    • "Real Hopper/Ghidra, browser, or OS coverage" now reads "Real Unblob coverage".
    • Two sections follow "Before merge". They are not in the template. One is Maintainer blocker verification. The other is Current follow-up evidence.
    • All other headings and labels are present.

Worth a look

  • The body lists the new error code under "Breaking changes or migration steps". It says "callers that matched unreadable_output for a staging overrun now receive resource_constraint". But the title is fix(firmware): with no !. docs/releasing.md says what a PR must do before it adds !. It must identify a previously valid call that fails or changes meaning. Is a changed error code for the same refusal in that class? This is a question for the maintainers. I am not saying it is.
  • The tests call inventoryFirmwareOutput directly. Issue #5846 was found through the MCP extract_firmware call. I read the two call sites. FirmwareProvider.ts line 495 is followed by a catch at line 573. That catch calls firmwareFailure (the matching try is at line 344). And firmwareFailure returns any AnalysisError unchanged. The polling loop in FirmwareCommand.ts (line 246) ends in the same function. So I expect the new error to reach the caller, but no test pins that path. The body says as much ("no real Unblob or public CLI run is claimed"). One test through firmwareFixture, like the issue's reproduction, would cover it.
  • The body has a section called "Current follow-up evidence". It says "Merged main 82e4e03" and reports local checks on that tree. The branch has since moved. The head commit is 746a64c, by XiaoBinGan. It merges c106cf2. Then 82e4e03 is the second parent of an earlier merge, 98b6997 (git log, merges). CI on the head is green, so this is only a stale note, but the body's local-check numbers no longer describe the head tree.
  • The body says "2 cases" under "Tests added" and "Four focused FirmwareFiles tests" under the follow-up. The file has four (two budget cases and an it.each over both maximums).
  • Lines 190 to 195 of docs/firmware-analysis.md give the staging budgets. They say the budgets are polled and rechecked. They do not say what an overrun returns. One sentence naming resource_constraint and the two reported_limits keys would help callers. The PR does not touch this file.

Looks good

  • Main (ecd997e) still has the bug. inventoryFirmwareOutput on main throws AnalysisOutputError for both budgets, at lines 335 and 359.
  • The fix is small: 3 files and 152 changed lines by the compare API (main...head), 100 of them tests.
  • Both refusals now throw AnalysisResourceConstraintError with capacity, reported_limits and retryable: false (lines 357 to 369 and 390 to 402).
  • The remediation uses the schema's own maximums. firmwareAnalysis.ts lines 13 and 14 define them and the two .max() calls (lines 48 and 57) use them, so the limit and the advice can't drift apart. At the maximum it says to pick a smaller range instead of "raise it", and a test covers both maximums.
  • The bot findings on earlier heads are answered. Greptile left a note on advice above the schema ceiling (4336830317). Codex left one too (4336836324). A third note, from Codex (4342026078), is on memory versus capacity. I did not repeat them. The Codex summary comment says no unresolved findings on this head. An earlier head (e0a5874) was approved by hiteshnatha, with no comment.
  • CI ran on this head and passed: CI required, Portable tests, all eight test shards, Static checks, Docs Generation and Build package (run 39912714461). The other lanes (native, browser, web and the like) show as skipped.
  • No other open PR fixes #5846 (search on the number found only this one).

Not run

  • No checkout, no build, no tests, no formatter.
  • I did not run Unblob or send an extract_firmware call.
  • I did not read the full FirmwareCommand.ts supervisor loop. I read lines 236 to 262 and 335 to 400.

Thanks, XiaoBinGan, for the fix and for the maximum-budget wording. Thanks, coygeek, for the clear report in #5846.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • Head / base: 746a64c / c106cf2 (merge base); main was ecd997e

🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@XiaoBinGan XiaoBinGan closed this Oct 24, 2026
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the classification this PR carries is now on main, and #5846 is closed as completed (2026-10-24T06:12Z).

main already returns a nonretryable resource_constraint with resource: "capacity", the selected budget in reported_limits, and a firmwareStagingLimit owner in src/firmware/FirmwareFiles.ts. Two of my four tests fail there only because they assert this PR's own wording, not a missing behaviour.

One real gap survives, and I have moved it to a focused PR instead of keeping this branch: at the schema ceiling the remediation still says "Increase max_output_files within its schema maximum", which is not an available recovery. That is the only delta left, it is small, and it belongs in its own change rather than inside a stale 900-commit-behind branch.

Thanks @CassieFox23 for the detailed review — every body-template point was correct, and the "Worth a look" notes about the ceiling wording and the missing extract_firmware path test are what led me to split that gap out. Sorry the branch went stale under the review; that is on the delivery channel, not on the review.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Firmware staging-budget refusal returns unreadable_output and doctor guidance

4 participants