Skip to content

fix(adb): keep the device's refusal when a package change exits nonzero - #2344

Merged
morluto merged 2 commits into
morluto:mainfrom
huiq777:fix/adb-install-failure-verdict
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
huiq777:fix/adb-install-failure-verdict

Conversation

@huiq777

@huiq777 huiq777 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

When a device refuses an install or uninstall, REA reports "unreadable output" and drops the device's reason. install_adb_package and uninstall_adb_package only keep the Failure [...] verdict when adb exits 0, which adb does not do for a refusal.

No issue is linked: I found this while reading how adb failures are classified, and it is an ordinary fix inside the existing ADB provider.

Problem and expected behavior

Smallest trigger: any refused package change, for example installing a package that is already present.

adb exits nonzero for a refusal. On AOSP android11-release:

runAdbCapture turns that nonzero exit into an AnalysisProtocolError, and both operations returned it before looking at the text:

if (!installed.ok) return installed;
const verdict = parsePackageChangeOutput(installed.value.stdout);

So parsePackageChangeOutput only ever saw zero-exit output. The existing tests cover that form (Failure [...] on stdout with exit 0), which is why this was not caught. docs/adb-device-analysis.md says installs "preserve the device's Failure [...] reason verbatim"; for a nonzero exit they did not.

Expected: the same unsupported_target refusal carrying the device's reason, whichever exit status adb used.

Change and scope

  • packageChangeFailureReason(output) in src/adb/AdbShellOutput.ts is now the one reader of the Failure [REASON] syntax. parsePackageChangeOutput uses it, with unchanged results.
  • packageChangeRefusal(...) in src/adb/AdbProvider.ts reads the verdict from a failed run's captured stdout and stderr. Install and uninstall call it before returning the run's error.
  • A nonzero exit without a Failure [...] verdict is left exactly as it was, so transport and protocol failures are not relabelled as device refusals. Device-state errors (offline, unauthorized, not found) are still classified earlier by runAdbCapture.

Not included: pull_adb_package's handling of a nonzero pm path, which open PR #1903 is already changing.

Follow the contribution scope.
Scope decision: not applicable. No new capability; this only changes how an existing operation reports a refusal.

Contract and boundary impact

  • Semantic owner and earliest changed stage: package-change output parsing in src/adb/AdbShellOutput.ts; the install and uninstall operations in src/adb/AdbProvider.ts.
  • Contribution scope fit and linked maintainer decision: fix within the existing ADB provider; not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. A refused install or uninstall that exits nonzero now returns unsupported_target with details.reason instead of unreadable_output with no details.
  • Provider, bridge, target-format, or platform compatibility: ADB provider only. Zero-exit behavior is unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged. The same adb commands run; only the interpretation of their failure output changes.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

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

The two operations already install and remove packages on the selected device; this PR does not change what they run.

Evidence and regression coverage

  • Tests added or updated: three cases in src/adb/AdbProvider.test.ts using the existing adb stub: a refused install reported on stderr with exit 1, a refused uninstall reported on stdout with exit 1, and a nonzero install with no verdict, which must stay unreadable_output.

  • Base reproduction or other evidence (executed): without the fix the first two cases fail with unreadable_output where unsupported_target is expected. The adb and Package Manager exit behavior is source-derived from the two AOSP android11-release files linked above; I did not check other releases.

  • User-visible CLI/MCP output (executed with REA_ADB_PATH pointing at a stand-in adb that reports refusals as above):

    Before, on fd95880, for both commands:

    {
      "code": "unreadable_output",
      "message": "Analysis returned an unreadable result. Run `rea doctor` and review the reported details; repeating the unchanged request is not expected to succeed.",
      "details": null
    }

    After, rea install-adb-package emulator-5554 app.apk:

    {
      "code": "unsupported_target",
      "message": "Unsupported target for install_adb_package at emulator-5554: INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install com.example without first uninstalling.",
      "details": {
        "operation": "install_adb_package",
        "path": "emulator-5554",
        "reason": "INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install com.example without first uninstalling."
      }
    }

    After, rea uninstall-adb-package emulator-5554 com.absent:

    {
      "code": "unsupported_target",
      "message": "Unsupported target for uninstall_adb_package at emulator-5554: not installed for 0",
      "details": {
        "operation": "uninstall_adb_package",
        "path": "emulator-5554",
        "reason": "not installed for 0"
      }
    }
  • Remaining proof gaps: not run against a real device or a real adb binary; the stand-in reproduces the stream and exit status that the AOSP sources describe.

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

macOS 15.6.1 arm64, Node 24.18.0, npm 11.16.0.

  • npm run test:local -- src/adb/AdbProvider.test.ts — 50 passed
  • npx vitest run src/adb — 5 files, 106 tests passed
  • npm run test:focused -- tests/boundary/cli/adbCli.test.ts tests/boundary/mcp/adbMcp.test.ts tests/boundary/mcp/adbStartMcp.test.ts tests/boundary/process/adbDirectoryListing.test.ts tests/boundary/providers/adb/adbBugreportPublication.test.ts — 5 files, 21 tests passed
  • npm run check — passed
  • npm run check:fast — passed

Not run: npm run check:pr, npm run docs:check (no contract or generated metadata changes), and no real-device lane.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only the error code and details of an already-failing call change.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the reason text comes from the device's own verdict and was already returned for zero-exit refusals; nothing new is read or executed.

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.

AI assistance (Claude Code, model Claude Opus 5.5) was used for investigation, implementation and running the tests locally.

🤖 Generated with Claude Code

Current adb exits 1 when the device refuses an install or uninstall and
prints the Failure [...] verdict to stderr or stdout. That run was
reported as unreadable output with no details, so the refusal reason
was only kept for the legacy zero-exit form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous coverage gap addressed.

Summary

The PR preserves the device's Failure [...] reason when an install or uninstall exits nonzero. The latest changes address the previous review's missing test coverage.

  • Refused installs and uninstalls keep the device’s reason when adb exits nonzero.

Reviews (2) · Last reviewed commit: "test(adb): assert retained package refus..." · Reviewed by Greptile

Comment thread src/adb/AdbProvider.test.ts Resolved
Address review findings at their producing boundaries and preserve directly affected consumers. Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request.
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

The refusal tests protected the message but omitted the public reason field. Both nonzero install and uninstall tests now assert the exact details.reason independently of the message, preserving the device verdict projection contract.

Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request. Commit: 355ff87

@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation area: providers Provider and capability discovery, including provider proposal triage P2: medium Medium priority issue labels Oct 13, 2026
@morluto
morluto merged commit 554ea76 into morluto:main Oct 13, 2026
35 checks passed
@morluto morluto added the area: build Build, CI, packaging, and publishing label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing area: providers Provider and capability discovery, including provider proposal triage area: runtime Process capture and runtime observation bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants