Skip to content

fix(android): bound inline search Evidence with retained inventory provenance - #1890

Merged
morluto merged 1 commit into
morluto:mainfrom
akushonkamen:fix/1850-android-search-inventory
Oct 11, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
akushonkamen:fix/1850-android-search-inventory

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Summary

Focused and zero-match search_android_classes responses embedded every examined class name: a single-match search on a 7,096-class APK returned a 382,435-byte tool response because the complete raw provider inventory rode inside the inline Evidence. When the server session retains Evidence, the complete raw-call record is now written to the retained store and the tool response delivers a bounded summary Evidence that keeps the pagination audit, the unchanged normalized matches and truthful coverage metadata, and links the retained complete inventory by Evidence ID (Fixes #1850).

Problem and expected behavior

Smallest trigger: load a 7,096-class APK through the jadx bridge and call search_android_classes with a query matching exactly one class. Prior behavior: the response's inline raw_result contained every list_classes page with all 7,096 class names, because the raw provider call record was captured whole and serialized into every tool response. The violated invariant: a bounded, focused search response should not grow with the size of the unfiltered inventory, and a single match must not cost the full class list on the wire. Expected behavior: the inline Evidence carries the pagination audit (total, offset, limit, per-page items_omitted), an inventory_elided marker, the unchanged normalized matches and coverage: complete / total_classes, and evidence_links + complete_evidence_id pointing at the retained complete record; sessions without retention keep the complete inline delivery, so CLI JSON output is unchanged and no provenance is discarded.

Change and scope

Root cause chain: src/android/JadxSession.ts records each list_classes page's complete MCP envelope into #observedCalls (src/android/JadxSession.ts:220-221); those calls ride into the execution as rawResult through createAnalysisExecution (src/android/JadxSession.ts:145-152); src/application/android/AndroidAnalysisService.ts embeds them into the Evidence (src/application/android/AndroidAnalysisService.ts:44-55); and src/server/contractToolHandler.ts serializes the complete Evidence into every tool response (src/server/contractToolHandler.ts:66-71). The normalized result (src/domain/android/JadxAnalysis.ts:175) is itself bounded; only the raw-call record is not.

Fix: new src/application/android/AndroidSearchEvidenceSummary.ts, applied on the search_android_classes registration path in src/server/registerAndroidTools.ts. When the session retains Evidence, the complete Evidence (with the full raw-call inventory) is recorded first via recordEvidence, then a summary Evidence is delivered with items_omitted counts replacing the full per-page name lists. Sessions without retention skip summarization entirely, preserving the previous complete inline behavior for CLI consumers. Intentionally not included: no change to the normalized search contract, no change to non-search Android tools, and no budgeting for retention-free sessions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the MCP tool-response boundary in src/server/registerAndroidTools.ts, after the normalized result and raw-call record exist and before serialization.
  • CLI and MCP/tool-catalog contract: the advertised search_android_classes schema is unchanged and the normalized result is byte-identical; the inline raw_result for retaining sessions now elides inventory items behind items_omitted counts plus complete_evidence_id, which is an output-size bound, not a shape change to the advertised contract.
  • Provider, bridge, target-format, or platform compatibility: none; the jadx bridge protocol is untouched (the fixture updates only extend the test protocol fixture to paginate at the same limits as the real bridge).
  • Evidence, artifact, provenance, or reconstruction contract: no provenance is discarded — the complete raw-call record is retained and addressable by Evidence ID through evidence_links; observed vs. elided content remains distinguishable via inventory_elided and items_omitted.
  • Process execution, authorization, cleanup, or containment impact: none; no new process, engine, or target acquisition.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none; no catalog, package, or installation contract changes and no generated outputs committed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/process/androidSearchEvidenceBudget.test.ts drives a real 7,096-class jadx protocol fixture through the MCP server and asserts (1) with a retaining session: the single-match and zero-match inline raw_result contain no class names, stay under 32 KiB, carry items_omitted, and link a retained complete record whose raw calls hold all 7,096 names; (2) without a retaining session: the complete inventory stays inline.
  • Base reproduction or other evidence: with the src/ change removed (test and fixtures in place) on the rebased base, the retaining-session case fails exactly on the inline-raw assertion — the single-match response contains the full 7,096-name inventory, i.e. the issue symptom.
  • User-visible CLI/MCP output: MCP responses for retaining sessions shrink from ~382 KB to a bounded summary for focused/zero-match searches; complete CLI JSON output is unchanged.
  • Remaining proof gaps: no real-device or real-APK lane was run; the fixture reproduces the real bridge's pagination envelope at the same 4,096 page limit.

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

Rebased onto origin/main (fa9a7e5e, which touches src/domain/evidence.ts), artifacts refreshed with npm run test:prepare, then:

  • npx vitest run --project process-boundary tests/boundary/process/androidSearchEvidenceBudget.test.ts with the src/ fix removed — 1 failed / 1 passed; the failure is the bounded-Evidence assertion with the full 7,096-name inventory present in a single-match response (base reproduction).
  • Same command with the fix restored — Test Files 1 passed, Tests 2 passed.
  • npx vitest run tests/boundary/android/ tests/boundary/process/ src/server/ src/domain/android/ src/contracts/android/ — 36 files passed, 237 passed + 2 skipped, 0 failed.
  • npx vitest run src/android/ src/server/ — 2 files passed, 12 passed. (Note: npx vitest run src/android/ alone exits 1 with "No test files found"; src/android/ has no test files in this repository.)
  • npx vitest run tests/acceptance/tools/localToolContracts.test.ts tests/boundary/mcp/ — 97 files (95 passed + 2 skipped), 370 passed + 3 skipped, 0 failed.
  • npx tsc --noEmit — exit 0.
  • npx oxlint — 0 errors (the max-params(5) warning on registerAndroidTools is pre-existing at origin/main); npx oxfmt --check src/ tests/ — clean.
  • Real Hopper/Ghidra, browser, or OS lanes: not exercised; the change is covered by the jadx protocol fixture suites above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Retaining-session MCP consumers that parsed the full inventory out of the inline raw record should read the retained complete record via evidence_links/complete_evidence_id; CLI output (no retention) is byte-identical in shape.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; Android jadx bridge fixture only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: bounds a response-size amplification (one focused query cost the entire class inventory on the wire); no new network, process, or authority surface.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

🤖 Generated with AI assistance (disclosure voluntary per repo policy)

…ovenance

Focused and zero-match search_android_classes responses embedded every
examined class name: JadxSession records each raw list_classes page into
observed calls, those calls ride into Evidence raw_result on the
registration path, and the complete inline Evidence is serialized into
every tool response (issue morluto#1850: 382,435 bytes for one match).

When the server session retains Evidence, record the complete raw-call
record first, then deliver a summary Evidence that keeps the pagination
audit (totals, offsets, page sizes, elided item counts), the unchanged
normalized matches and truthful coverage metadata, and links the
retained complete inventory by Evidence ID. Sessions without retention
keep the complete inline delivery, so complete CLI JSON output is
unchanged and no provenance is discarded.

🤖 Generated with AI assistance (disclosure voluntary per repo policy)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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 ⚠️ Failed 2026-10-11T16:01:20.045268Z 5a6c0e8 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.

@morluto
morluto merged commit 7a0140b into morluto:main Oct 11, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

This keeps focused Android searches readable without dropping evidence, @akushonkamen. In retained sessions, the inline response carries pagination and omission facts plus a link to the complete stored inventory; sessions without retention still receive full inline Evidence. Thanks for preserving provenance and the existing CLI behavior.

@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
@akushonkamen
akushonkamen deleted the fix/1850-android-search-inventory branch October 25, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Focused Android class searches embed the complete provider inventory

2 participants