[GH-ISSUE #4776] [Feature] Filter Android class searches before native bridge serialization #2484

Closed
opened 2026-10-17 21:05:29 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @N0zoM1z0 on GitHub (Oct 17, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/4776

Before submitting

  • Searched open/closed issues and related Android analysis work.
  • Reviewed contribution scope; this is existing static APK analysis.
  • Only public targets, portable paths and non-sensitive measurements are included.

Area / current limitation

Android static analysis efficiency. search_android_classes retrieves every top-level class-name page from the native bridge and filters in TypeScript. The bridge already owns a cached classFqns inventory. Focused searches still transfer, parse and retain unrelated rows.

Use case and observed evidence

Production stdio MCP on official NewPipe 0.29.1, SHA-256 18447bfb1e06d113edc88df93f471827280de06f6f3d4dc42f56f28b9c1bab79: query MainActivity returns two matching rows from 7096 top-level rows, but transfers two complete internal pages (~380 KB). Existing MCP summary reduces the public reply to ~7.4 KB; it does not avoid producer transfer/decoding.

A separate production shared-service diagnostic retained ~383 KB Evidence for that focused query. CLI uses the same complete Evidence workflow; an actual CLI before/after measurement is still proposed, not claimed here. In one clean diagnostic, warm search was 202 ms: session work ~48 ms, provider admission ~127 ms, target/Evidence work ~28 ms. Do not treat the whole latency as removable search cost.

Measured source: 9c56d09c05356c74a7000e4c558ac293639ea33f. Current e5ee3ac658cd10ba23700e1757c86ce0a4520406 changes only Apktool identity since that audit, not this JADX path. JDK21/JADX headless0.7.1, Linux x86-64, one CPU, 768 MiB JVM heap, 4 GiB family hard limit; successful runs verified cleanup and zero OOM events. ApiDemos6.0.18 supplied the smaller comparison. Offline token counts are estimates, not actual model usage.

Desired outcome and success criteria

Push case-sensitive substring selection into REA's metadata bridge using the existing cached class-name inventory. CLI/MCP should preserve query, matches and order, duplicate-name counts, total top-level rows, complete/unknown semantics, and artifact/engine Evidence. Empty query must still return the complete inventory. Keep complete producer replies retained and the full inventory accessible, with explicit examined scope and matching-page coverage. Avoid adding another retained class index or a public tool.

Target interaction / scope

Read the caller-selected APK through the existing owned immutable JADX session; same process/workspace lifetime. Never install or execute the APK, attach a device, mutate original bytes, or fork the upstream JAR. No new provider/target-execution authority; additional maintainer capability decision is not applicable to this existing read-only optimization.

Possible direction / alternatives

Change the REA-owned bridge's class-page contract to filter before serialization, then validate query/total/offset consistency and matching rows at the adapter boundary. Existing snapshot/configuration freshness checks stay authoritative. Existing package/search summaries are useful and should be retained. A second generic index/cache or a new agent orchestration surface is not justified by these measurements.

Verification planned

Fresh-main isolated branch; real public CLI/MCP completed focused/miss/full-inventory tasks on both APKs, independent full-inventory filtering oracle, duplicate and malformed-page regressions, cold/warm wall/CPU/family memory and whole-task schema/request/reply token estimates. Include broad/empty queries to detect regressions; preserve cancellation/cleanup and invalidation tests. No speedup or token-reduction claim until equivalent workflows finish.

References

Originally created by @N0zoM1z0 on GitHub (Oct 17, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/4776 ### Before submitting - [x] Searched open/closed issues and related Android analysis work. - [x] Reviewed contribution scope; this is existing static APK analysis. - [x] Only public targets, portable paths and non-sensitive measurements are included. ### Area / current limitation Android static analysis efficiency. `search_android_classes` retrieves every top-level class-name page from the native bridge and filters in TypeScript. The bridge already owns a cached `classFqns` inventory. Focused searches still transfer, parse and retain unrelated rows. ### Use case and observed evidence Production stdio MCP on official [NewPipe 0.29.1](https://github.com/TeamNewPipe/NewPipe/releases/tag/v0.29.1), SHA-256 `18447bfb1e06d113edc88df93f471827280de06f6f3d4dc42f56f28b9c1bab79`: query `MainActivity` returns two matching rows from 7096 top-level rows, but transfers two complete internal pages (~380 KB). Existing MCP summary reduces the public reply to ~7.4 KB; it does not avoid producer transfer/decoding. A separate production shared-service diagnostic retained ~383 KB Evidence for that focused query. CLI uses the same complete Evidence workflow; an actual CLI before/after measurement is still proposed, not claimed here. In one clean diagnostic, warm search was 202 ms: session work ~48 ms, provider admission ~127 ms, target/Evidence work ~28 ms. Do not treat the whole latency as removable search cost. Measured source: `9c56d09c05356c74a7000e4c558ac293639ea33f`. Current `e5ee3ac658cd10ba23700e1757c86ce0a4520406` changes only Apktool identity since that audit, not this JADX path. JDK21/JADX headless0.7.1, Linux x86-64, one CPU, 768 MiB JVM heap, 4 GiB family hard limit; successful runs verified cleanup and zero OOM events. ApiDemos6.0.18 supplied the smaller comparison. Offline token counts are estimates, not actual model usage. ### Desired outcome and success criteria Push case-sensitive substring selection into REA's metadata bridge using the existing cached class-name inventory. CLI/MCP should preserve query, matches and order, duplicate-name counts, total top-level rows, complete/unknown semantics, and artifact/engine Evidence. Empty query must still return the complete inventory. Keep complete producer replies retained and the full inventory accessible, with explicit examined scope and matching-page coverage. Avoid adding another retained class index or a public tool. ### Target interaction / scope Read the caller-selected APK through the existing owned immutable JADX session; same process/workspace lifetime. Never install or execute the APK, attach a device, mutate original bytes, or fork the upstream JAR. No new provider/target-execution authority; additional maintainer capability decision is not applicable to this existing read-only optimization. ### Possible direction / alternatives Change the REA-owned bridge's class-page contract to filter before serialization, then validate query/total/offset consistency and matching rows at the adapter boundary. Existing snapshot/configuration freshness checks stay authoritative. Existing package/search summaries are useful and should be retained. A second generic index/cache or a new agent orchestration surface is not justified by these measurements. ### Verification planned Fresh-main isolated branch; real public CLI/MCP completed focused/miss/full-inventory tasks on both APKs, independent full-inventory filtering oracle, duplicate and malformed-page regressions, cold/warm wall/CPU/family memory and whole-task schema/request/reply token estimates. Include broad/empty queries to detect regressions; preserve cancellation/cleanup and invalidation tests. No speedup or token-reduction claim until equivalent workflows finish. ### References - [Producer pagination](https://github.com/morluto/rea/blob/e5ee3ac658cd10ba23700e1757c86ce0a4520406/bridge/android/ReaJadxBridge.java#L214) - [Current adapter-side filtering](https://github.com/morluto/rea/blob/e5ee3ac658cd10ba23700e1757c86ce0a4520406/src/android/JadxAnalysis.ts#L148) - Related correctness foundation: #4768 / #4771. Repeated Apktool locale decoding is a separate follow-up with selection/resource/partial-result contracts to settle.
bsakaguchi 2026-10-17 21:05:29 +00:00
Author
Owner

@N0zoM1z0 commented on GitHub (Oct 17, 2026):

Implemented in #4791 (ready for review), commit 4249918555bd0c0ec69de36b346c3e03159ea5a7.

Real production CLI/MCP before/after on official NewPipe0.29.1 and ApiDemos6.0.18 preserves normalized matches, order, duplicate counts and full-inventory results. Focused default CLI output drops383,302→3,649 and134,960→3,549 bytes (offline cl100k token estimates80,140→991 and29,259→959; actual model usage unmeasured). Seven warm MCP queries improve1,015–1,116→760–793ms /1,059–1,202→997–1,010ms across two fresh sessions per APK/revision. MCP already has summaries; no material MCP token reduction or stable cold-start/whole-task CPU/memory improvement established.

75 focused tests and the full real Android lane passed, including CLI/MCP parity, complete/native inventory oracle, literal/Unicode/NUL/isolated-surrogate selectors, cross-DEX references, cancellation and failure recovery. Full npm run check and npm run docs:check passed. Performance remained serial/oneCPU/4GiB family cap; full static checking used the newly authorized8GiB cap and peaked4,156MiB. Included runs verified cleanup and zero OOM events. Detailed scope, counts, resource measurements and unverified platforms are in the PR.

Selection reuses the existing inventory and filters before native serialization; no second index or result cache. Complete selected producer replies remain available, and empty query still inventories all top-level names. CI/review pending; not yet merged.

<!-- gh-comment-id:6234028054 --> @N0zoM1z0 commented on GitHub (Oct 17, 2026): Implemented in #4791 (ready for review), commit `4249918555bd0c0ec69de36b346c3e03159ea5a7`. Real production CLI/MCP before/after on official NewPipe0.29.1 and ApiDemos6.0.18 preserves normalized matches, order, duplicate counts and full-inventory results. Focused default CLI output drops383,302→3,649 and134,960→3,549 bytes (offline cl100k token estimates80,140→991 and29,259→959; actual model usage unmeasured). Seven warm MCP queries improve1,015–1,116→760–793ms /1,059–1,202→997–1,010ms across two fresh sessions per APK/revision. MCP already has summaries; no material MCP token reduction or stable cold-start/whole-task CPU/memory improvement established. 75 focused tests and the full real Android lane passed, including CLI/MCP parity, complete/native inventory oracle, literal/Unicode/NUL/isolated-surrogate selectors, cross-DEX references, cancellation and failure recovery. Full `npm run check` and `npm run docs:check` passed. Performance remained serial/oneCPU/4GiB family cap; full static checking used the newly authorized8GiB cap and peaked4,156MiB. Included runs verified cleanup and zero OOM events. Detailed scope, counts, resource measurements and unverified platforms are in the PR. Selection reuses the existing inventory and filters before native serialization; no second index or result cache. Complete selected producer replies remain available, and empty query still inventories all top-level names. CI/review pending; not yet merged.
Author
Owner

@N0zoM1z0 commented on GitHub (Oct 17, 2026):

Resolved by #4791, merged as 2d84c800bc51dc865fcabdd3e28cda3d2f4413e7.

Merged as 2d84c800bc51dc865fcabdd3e28cda3d2f4413e7. Verified again in a separate checkout of that actual commit (including intervening main Electron/ELF/README changes): runtime rebuild plus 78 focused tests passed (190.0 s wall/186.1 s CPU/2,813 MiB family peak, 8 GiB cap); real NewPipe production MCP orientation/broad/full-inventory workflow passed (34.4 s/32.1 s/1,698 MiB); real ApiDemos default CLI output passed against the pinned baseline (14.5 s/14.1 s/839 MiB). Native smoke runs kept the original 4 GiB/one-CPU/768 MiB JVM settings. Original APK hashes unchanged, all runs verified owned cleanup and zero OOM events. Both requested co-author trailers are present on the squash commit.

PR-head CI: all 41 enabled checks passed; exact-head Greptile 5/5, both review findings fixed/resolved. CLI token savings are offline estimates; no actual model usage, startup speedup or general whole-task CPU/memory benefit claimed. Separate Apktool repeated resource decoding proposal remains #4777.

<!-- gh-comment-id:6234455588 --> @N0zoM1z0 commented on GitHub (Oct 17, 2026): Resolved by #4791, merged as `2d84c800bc51dc865fcabdd3e28cda3d2f4413e7`. Merged as `2d84c800bc51dc865fcabdd3e28cda3d2f4413e7`. Verified again in a separate checkout of that actual commit (including intervening main Electron/ELF/README changes): runtime rebuild plus 78 focused tests passed (190.0 s wall/186.1 s CPU/2,813 MiB family peak, 8 GiB cap); real NewPipe production MCP orientation/broad/full-inventory workflow passed (34.4 s/32.1 s/1,698 MiB); real ApiDemos default CLI output passed against the pinned baseline (14.5 s/14.1 s/839 MiB). Native smoke runs kept the original 4 GiB/one-CPU/768 MiB JVM settings. Original APK hashes unchanged, all runs verified owned cleanup and zero OOM events. Both requested co-author trailers are present on the squash commit. PR-head CI: all 41 enabled checks passed; exact-head Greptile 5/5, both review findings fixed/resolved. CLI token savings are offline estimates; no actual model usage, startup speedup or general whole-task CPU/memory benefit claimed. Separate Apktool repeated resource decoding proposal remains #4777.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2484
No description provided.