Skip to content

feat(analysis): make resource budgets recoverable across CLI and MCP - #9706

Merged
morluto merged 30 commits into
mainfrom
codex/recoverable-analysis-budgets
Nov 10, 2026
Merged

morluto merged 30 commits into
mainfrom
codex/recoverable-analysis-budgets

Conversation

@morluto

@morluto morluto commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Agents can change the budget that actually omitted or refused data, retry the same complete input, and retain exact exhaustion and coverage facts. Source-location tracing also gains compact retained delivery so a point answer does not require returning the entire map.

Related: #6176, #8434, #5808, #8978.

Problem and expected behavior

Several producers had fixed ceilings, duplicated allowances, or recovery that suggested changing an unrelated limit. Bun/SEA recognition could interpret unexamined data as absent; desktop seed checks could accept bytes the exported reader refused. A legitimate source-map result could exceed MCP delivery even after map admission succeeded.

The enforcing owner now accepts a bounded policy, preserves selected versus effective values, and explains the next action. Unexamined data stays unknown. Complete Evidence remains available when delivery is compact.

Change and scope

The implementation commits separate shared contracts, ASAR/Ghidra settings, artifact readers, JavaScript precision, source maps, historical captures, desktop views, live capture, managed/Go/Rust/Wasm/EVM/Android producers, and verification.

  • Add cohesive per-call artifact and producer policies; thread them through classification, acquisition, decoding, retention and extraction.
  • Preserve lower-budget cache re-admission, partial facts, cleanup ownership and exact failure causes. Unsupported increases no longer produce retry guidance.
  • Add source-location summaries, paged mapping metadata and explicit UTF-16 text selection over retained complete Evidence.
  • Align shipped seed admission and bounded SQLite views with emitted Python readers.
  • Preserve current main's desktop secret isolation/custom readers/gzip, Deno support, signed bundle validation and chunked I/O.

Scope decision: not applicable to new-provider approval. These are changes within existing workflows; no new target execution, attachment, injection, protection-recovery or network authority is introduced.

Contract and boundary impact

  • Owners: domain policies define bounds; each producer enforces its accepted policy before allocation/retention. CLI/MCP share those contracts.
  • CLI/MCP: additive artifact_limits, producer_limits, semantic/capture/view controls and curated runtime settings. Existing complete delivery remains the default.
  • Evidence: preserve omission, explicit selections, identity, unknown coverage and complete parents. Summary/view choices do not change source analysis identity.
  • Compatibility: existing defaults remain, except local source-map admission is calibrated from 4 to 8 MiB. Format/runtime/client and tighter inherited OS constraints remain independent.
  • Installation: setup forwards the added allowlisted launch settings through its existing approval/backup workflow. No unrelated software installation or upgrade.
  • Generated metadata: regenerated and checked; ignored catalogs, build outputs, downloaded artifacts and provider projects are excluded.

Expected effects within existing caller-selected workflows:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change files or configuration through existing extraction/export/setup operations.
  • Contact network services through existing explicitly selected capture/fetch operations.
  • Recover protected code or work around protections.

Evidence and regression coverage

Public CLI/MCP regressions cover lower → raise → lower admission on the same target, selected/effective provenance, both schema profiles, retained queries after source removal, malformed controls, unsupported increases, extraction output absence and cleanup. Desktop checks execute real SQLite workers and emitted Python helpers. Source regressions cover recognition uncertainty, escaping, surrogate boundaries and independent exhaustion causes.

Historical calibration records retain their measured runtime pins; they are not benchmarks of this main-integrated head. They support a narrow map-admission change and keeping other measured defaults, not universal optimality or a blanket speedup claim.

Validation performed

Integrated onto main 8dfc47b107afc0cf4b53322a10b94c666fe9e18b, excluding the original branch's unrelated documentation commits.

  • Focused compiled integration: 118 passed, 1 skipped across 11 CLI/MCP/provider files; additional affected JavaScript, desktop and parser owner suites passed.
  • npm run check:fast — typecheck/lint pass.
  • CI follow-up: corrected published oracle links; npm run docs:build passes. Triaged CodeQL alerts 710–716 and 718–723 as false positives for explicit local operator selections or the REA-owned LLDB journal path, with per-alert source rationale. Fresh observer → JavaScript harness → CLI smoke passed, including process-group cleanup.
  • npm run docs:generate and npm run docs:check — pass, including README consistency.
  • npm run test:python — 102 passed.
  • npm run verify:test-discovery — 3,343 files, each discovered once.
  • npm run verify:architecture-guards — pass across 2,696 source files.
  • Real Ghidra 12.1.4/JDK 21 lane rerun after integration — p-code/input/edge, payload and deadline recovery pass on one Program; target bytes unchanged, target not executed, cleanup verified.
  • Earlier real local Frida/LLDB budget checks and bounded public-artifact measurements are retained with their narrower scope.

CI follow-up: restored reader/screen-judge documentation and repository receipt links; full verify:docs:routes passes across 404 pages. Updated real mitmproxy fixture calls for explicit projection depth and corrected the Ghidra live-budget snapshot regression. Focused CLI/MCP snapshot suites pass (49 passed, 2 skipped); Python tests (102) and docs checks pass. Removed a source-location projector dependency cycle and refreshed stale profile/control assertions. Real Python file-only verifier coverage now proves no computer execution is needed, replacing an inherited whole-renderer checksum. Additional source/view/precision tests pass; model suites pass (154), evidence-bundle suite passes (50), and reverse-tools coverage passes (800 passed, 29 platform skips locally). Typecheck/lint pass. Further CI fixes preserve selected directory/file/unknown alias kinds in desktop exports and remove the duplicate alias helper (55 tests passed). Windows conformance now uses the current cleanup guard and bounded readback API (21 lifecycle tests passed locally). Provider fixture/control and live-dossier assertions were corrected with focused checks; no production guards or CI rules were weakened. Completed JavaScript CodeQL triage: alerts 215, 504, 703, 724–726 and 729 are false positives for explicit local executable/path selections or provider-owned request files; all related source flows were checked and per-alert rationale recorded. Latest CI follow-up preserves raw capture-path provenance in environment-build (7 public CLI tests pass, byte-identical bundles), restores Windows/POSIX endpoint refusal parity with retained cleanup retry (27 focused tests pass), and checks emitted desktop alias metadata structurally (112 related tests pass). Artifact-limit CLI recovery tests pass (4). GitHub checks are rerunning on head 6ecbcd6bc8.

The complete check:pr gate was not run. Windows, Linux-only native lanes, full AgentEnv execution and real-provider combinations beyond the listed qualifications remain unverified. Admission/heap requests are not whole-process-family memory guarantees.

Author readiness

Human owner: @morluto (PR author)

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

@morluto
morluto marked this pull request as ready for review November 9, 2026 22:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-10T10:15:13.943766Z 1e1a274 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.

Comment thread bridge/native/rea_lldb_tracer.py Dismissed
# Conflicts:
#	scripts/verify-windows-native.mjs
#	src/application/desktop/DesktopApplicationExport.test.ts
#	src/cli/environmentCommands.ts
#	src/domain/desktop/appExport.ts
#	src/domain/desktop/appExportPython.ts
#	src/domain/desktop/appTaskReaders.test.ts
#	tests/acceptance/modelArtifactCli.test.ts
#	tests/boundary/cli/environmentBuildCli.test.ts
#	tests/boundary/filesystem/evidenceBundleFiles.test.ts
#	tests/boundary/providers/desktopExportPython.test.ts
#	tests/boundary/providers/ida/calleeLookupBatch.test.ts
@morluto
morluto merged commit cb4e5cf into main Nov 10, 2026
8 checks passed
@morluto
morluto deleted the codex/recoverable-analysis-budgets branch November 10, 2026 10:11
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 10, 2026
main's morluto#9706 adds the native_value_flow_projection semantic to every
Ghidra profile, so this branch's raw digests move: repin the x86, x86_64,
ARM, ARM64, m68k and M-profile pins, and set the new semantic aside in the
pre-base_address snapshot compatibility check like the other later
revisions. The bridge keeps main's decompiler payload and value-flow
limits beside this branch's entry-context registers.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 10, 2026
main's morluto#9706 replaces the fixed 16 MiB reverse-command output cap with the
caller's max_output_bytes and reserves that allowance per call. The
version probe runs inside the call before the command, so it now uses
the call's reserved allowance instead of the removed constant, and a
probe whose output that allowance cut identifies no tool, as a banner cut
by its record budget already did. The Rizin description and guide keep
main's output-admission text beside the probe sentence; the test imports
drop the removed REVERSE_COMMAND_OUTPUT_LIMITATION.
RishTheFish21 added a commit to RishTheFish21/rea that referenced this pull request Nov 10, 2026
Main's morluto#9706 makes this MCP test create two Evidence records instead of three, so the automatic unknown counts drop from 6 to 4 (two per record). The raw profile digests changed again and are repinned; the profile assertion keeps both main's native_value_flow_projection and this PR's indirect_branch_inventory.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 11, 2026
…dgets

main's morluto#9706 adds native_value_flow_projection to the shared analysis
semantics, which changes the profiles of images without a section overlap.
With that one revision removed, the previous pins hold (79 of 79).
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 11, 2026
main's morluto#9706 adds native_value_flow_projection to the shared analysis
semantics, which changes the profiles that targets outside the M-profile
lane keep. With that one revision removed, the previous pins hold (57 of 57).
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 11, 2026
main's morluto#9706 adds native_value_flow_projection to the shared analysis
semantics, which moves 10 integration pins: ARM 2, raw 6 and RISC-V 2.
With that one revision removed, the previous pins hold (169 of 171; the
other two are the raw pins already taken from Change 2's repin).
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
General provenance only knew a literal require, so a bundled Electron
external held in one binding and destructured from another
(`const s=n(K);const{BrowserWindow}=s`) lost its windows and IPC. The
Electron binding origin now follows stable lexical aliases, and stops at
a rebindable binding that direct eval may have changed.

Fixes #4490
Supersedes #6993

Squashed from #6993 and rebased onto main. Rebase adaptation: the walk
uses the caller-selectable precision.alias_selections budget (the fixed
SEMANTIC_ALIAS_SELECTION_LIMIT it used was removed by #9706) and records
alias-selections when it stops there; a test pins that an over-budget
chain is not claimed and the limit is reported.

Co-Authored-By: gensokyo-dev <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
General provenance only knew a literal require, so a bundled Electron
external held in one binding and destructured from another
(`const s=n(K);const{BrowserWindow}=s`) lost its windows and IPC. The
Electron binding origin now follows stable lexical aliases, and stops at
a rebindable binding that direct eval may have changed.

Fixes #4490
Supersedes #6993

Squashed from #6993 and rebased onto main. Rebase adaptation: the walk
uses the caller-selectable precision.alias_selections budget (the fixed
SEMANTIC_ALIAS_SELECTION_LIMIT it used was removed by #9706) and records
alias-selections when it stops there; a test pins that an over-budget
chain is not claimed and the limit is reported.

Co-Authored-By: gensokyo-dev <[email protected]>
@morluto morluto added area: cli CLI adapter and one-shot commands enhancement New feature or request labels Nov 22, 2026
morluto added a commit that referenced this pull request Nov 24, 2026
…ce (#8464)

* fix(ghidra)!: load ESP-IDF flash code in Ghidra's default address space

ESP-IDF's linker script reserves the addresses of .flash.text with the
NOBITS section .flash_rodata_dummy. Ghidra 12.1.4's ELF loader gives the
default address space to the later section, so .flash.text lands in an
overlay that its DWARF import, call-frame processing and default-space
references do not reach. Flash functions lose their DWARF signatures,
locals and no-return flags, each gets a one-byte shadow function in the
reservation, and pseudocode runs past calls such as esp_restart().

The ELF reader now records allocated ranges that an executable section
shares with another section, through one section-table visitor that the
RISC-V ISA reader also uses. When a NOBITS section starts with one
executable section and covers it, the RISC-V lanes commit both sections
to the analysis profile. ReaGhidraPrepareElfLoad.java then gives the code
the default address space before auto-analysis and keeps the reservation
as an uninitialized overlay; bytes, file offsets, symbols, functions and
entry points are kept. The session reports the outcome, and any memory
map that differs from the committed plan is refused. Images without such
an overlap keep their analysis profiles byte for byte.

BREAKING CHANGE: RISC-V images with this layout, such as ESP-IDF
ESP32-C6, H2 and H21 builds, report flash code at its ELF address
(0x42...) instead of .flash.text:0x42..., and their analysis profiles
change. RISC-V images with any other section overlap that involves
executable code are now refused with the overlapping sections named.
These include ESP-IDF v5.5.2 ESP32-C5 and C61 builds, whose second
reservation, .ext_ram.dummy, also covers .flash.text. See
docs/ghidra-riscv.md.

* fix(ghidra): bound the overlap sweep and check the load preparation

Domain:
- Find section overlaps with one sort and sweep that stops at the second
  overlap involving executable code, and read the ISA and the overlap in
  one section-table pass.
- Record the two sections that cause a refusal as witnesses. The Ghidra
  lane owns the refusal text and names them with their ranges.

Ghidra lane:
- Check the preparation report before the first lazily started analysis
  call, as for the calling-convention report.
- The pre-analysis script removes the code's overlay entry points, checks
  that no symbol or reference remains in the old overlay range, and reports
  the counts of the result. Its report echoes the blocks it left, which the
  client compares with the committed sections. A failed move refuses and
  rethrows. Reservation labels mark no entry points.
- Session limitations no longer state a planned move after a canonical
  outcome.

Verification:
- The ESP fixture defines ESP-IDF's absolute text bounds and the
  reservation's label. The lane checks their addresses, the entry points,
  file-offset uniqueness and snapshot replay, a reservation-first build,
  a pre-analysis refusal through analyzeHeadless and a truncated
  double-float section table.
- Boundary tests cover the refusal witnesses, a 10,000-section table and
  an ELF64 table.

* fix(ghidra): retarget references into the moved ESP-IDF flash code

The move takes the references from the code's range but not the
references into it. Besides the entry points, Ghidra 12.1.4's loader
records one data reference from the .flash.text section header to the
code, which the new post-condition refused in the RISC-V lane. Retarget
plain memory references and entry points into the old range to the moved
code; any other kind stays behind and is refused.

Removing the reservation block keeps the references into its range, so
the pinned symbols' entry points need no re-add.

* fix(ghidra): move labels past the ESP-IDF flash code's end with it

Ghidra 12.1.4 places a section-relative symbol at the section's end, such
as ESP-IDF's _etext, in the code's overlay space one byte past the block.
The move covers the block only, so the label stayed in the overlay and
ended up in the reservation. Everything in the code's overlay space now
follows the code: references are retargeted, labels outside the block are
created again in the default space, and the post-condition checks the
whole space. The script refuses when another block shares that space.

The ESP fixture defines _etext, and the lane checks its address.

* fix(ghidra): check prepared blocks by coordinates and address spaces

The client compared the pre-script's echoed block names with the ELF
section names, although section names are display only: an unnamed
section's empty name never matches the name Ghidra gives its block, so
that preparation was refused. It also accepted any reported address
spaces. The check now compares addresses, sizes and the code's file
offset, and requires moved code to go from an overlay into the
program's default space while its reservation leaves it, and canonical
code to stay there. An unnamed section is labelled by its index.

The docs and the pre-script now state that a failure during the move
may be refused without its reason, and that an entry mark on a
reservation label stays at its default-space address. The docs give
the llvm-objcopy route for the refused C5 and C61 builds. The lane
checks that no other block maps any of the code's file bytes, and the
overlap tests add the C5 and C61 section shape.

* fix(ghidra): bound the sections the overlap check keeps

The overlap check kept one record per allocated, non-empty section, and
only the file size limited their number. NOBITS headers take no file
bytes, so a crafted 1 GB ELF32 table holds about 27 million of them.
The check now keeps at most 65,280 (SHN_LORESERVE, from which ELF
counts sections through section zero) and reports the overlap as
unavailable beyond that, which the RISC-V lanes refuse as they refuse
a table that cannot be read.

* fix(ghidra): check RISC-V handshake reports before any analysis call

A RISC-V session that committed neither a calling-convention policy nor
a load preparation started its bridge lazily on the first query other
than `health`. An `elf_load_preparation` or calling-convention report
that the profile did not commit was then never checked, and the query
returned its result. Every RISC-V session now starts through the
checked handshake, so such a report closes the session before any
analysis call, whatever the first query is. A double-float session that
reports a preparation, and one that reports a calling-convention
policy, are now tested with `list_procedures`; both fail without the
fix.

Admission, profile parameters and profile digests do not change. If
Ghidra exits during the first query of a double-float session, the
error now tells the caller to reopen the session, as other checked
sessions do.

* fix(ghidra): skip analysis after a refused ELF load preparation

A refused memory map only wrote the refusal, so headless Ghidra still
ran seeds, auto-analysis and post-script analysis on a program that REA
then discarded. The preparation now turns off headless auto-analysis when
it refuses; later pre-scripts and the bridge still run, so the session
reports the reason.

The swap also renamed the reservation's overlay space to the section's
raw name, so a reservation named like another address space, such as
the RISC-V default space ram, or containing characters Ghidra rejects,
failed after the move. The space now takes the name Ghidra's memory map
derives for an overlay block: ':' and whitespace become '_', and a name
in use gains .1, .2 and so on.

verify:ghidra:riscv drops -noanalysis from the refusal run and checks
that Ghidra analyzed nothing, and a seventh fixture names the
reservation ram and checks that it moves into the overlay space ram.1.

* test(ghidra): read the load preparation report before Ghidra's log suffix

* test(ghidra): pin unchanged RISC-V profiles at main's revisions

main's byte-search (#8840), data-type (#8602) and reference revisions change every
Ghidra profile. With those revisions reversed, the old pins hold.

* fix(ghidra): name the moved RISC-V guide in load-layout diagnostics

The overlap refusal, the load-layout limitation and the bridge comments
named docs/ghidra-riscv.md, which main moved to docs/providers/.

* test(ghidra): check load-preparation facts instead of sentences

The refusal, report-check and handshake tests compared whole messages.
They now check the sections, coordinates, spaces and counts each message
must state, and the handshake compares the session's limitations with
ghidraRiscvLoadPreparationLimitations. Rewording the messages passes;
dropping a count fails.

* fix(ghidra): give the ESP-IDF load preparation unused temporary names

The preparation created its temporary blocks as <name>.rea, so a disjoint
section already named that refused an otherwise admitted image. It now
takes the first unused <name>.rea[.N]. verify:ghidra:riscv gains an
esp-edge-names fixture with such a section.

* fix(ghidra): keep both final block names free during the ESP-IDF swap

The code's temporary block could take the removed reservation's name,
such as a reservation named <code>.rea, and the reservation's rename
back then collided. The picker now skips both final names.
verify:ghidra:riscv's esp-edge-names fixture names its reservation
.flash.text.rea beside a disjoint .flash.text.rea.1.

* test(ghidra): repin the overlap-free RISC-V digests for main's #8340

main's #8340 bumps call_relationship_coverage from v5 to v7, which changes
every Ghidra profile digest. With the revision reverted in place, the old
pins hold (79 of 79).

* test(ghidra): repin unchanged RISC-V digests for main's value-flow budgets

main's #9706 adds native_value_flow_projection to the shared analysis
semantics, which changes the profiles of images without a section overlap.
With that one revision removed, the previous pins hold (79 of 79).

* fix(ghidra): inspect RISC-V PIE section overlaps and refuse an unverified PIE reservation

Main admits RISC-V PIE, but this lane requires a section-overlap read
that the resolver made only for ET_EXEC, so every PIE was refused. A PIE's
section addresses are fixed offsets from its load base, so overlaps do not
depend on the base: read them for ET_DYN too. The NOBITS reservation
preparation is verified for ET_EXEC only, so a PIE that needs it is
refused. Main's producer identity now digests the bridge sources, so the
test that compared profile digests with main's is replaced by checking
that images without an overlap commit no load preparation.

* fix(ghidra): find an ESP-IDF reservation that Ghidra 12.2 marks executable

Ghidra 12.2 gives each section block the permissions of the first PT_LOAD
that contains its address, so a NOBITS reservation that shares the code's
addresses comes out executable and the preparation refused every ESP-IDF
image. Tell the reservation from the code by its missing bytes alone; the
displaced reservation is still made non-executable. The PIE refusal test
now uses the ELF64 lane, which admits PIE.

* fix(verify): read the ESP-IDF fixtures' identity where main's #11416 moved it

Evidence subjects and snapshot targets now carry their digest under
identity, as the rest of the RISC-V verifier reads it.

* docs(ghidra): describe the ESP-IDF load layout as verified on Ghidra 12.2

The real RISC-V lane now passes on Ghidra 12.2, whose ELF loader still puts
the code in an overlay when its reservation follows it. Name 12.2 where the
lane exercised that behaviour, and note that 12.2 can mark the reservation
executable. Measurements of Ghidra APIs the lane did not re-check keep
their 12.1.4 attribution.

* docs(domain): align RISC-V section-overlap JSDoc with ET_DYN inspection

---------

Co-authored-by: morluto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants