Skip to content

fix(adb): report the device state when a push cannot probe the path - #2354

Merged
morluto merged 1 commit into
morluto:mainfrom
huiq777:fix/adb-push-unknown-device-path
Oct 13, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
huiq777:fix/adb-push-unknown-device-path

Conversation

@huiq777

@huiq777 huiq777 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

push_adb_file tells the caller "the device path already exists" when the device is offline or unauthorized. With overwrite: true it goes on to push even though its existence probe established nothing.

No issue is linked: I found this while reading the push path, and it is an ordinary fix inside the existing ADB provider.

Problem and expected behavior

Before pushing, the provider runs adb shell test -e <device_path>. The outcome was classified like this:

if (existsProbe.ok) deviceExists = true;
else if (existsProbe.error instanceof AnalysisProtocolError) deviceExists = false;
else if (/* timeout, cancelled, resource */) return existsProbe;
else deviceExists = true; // authorization/refusal states surface on push instead
if (deviceExists && !input.overwrite) return err(/* already exists */);

Smallest trigger: the probe fails with error: device offline (or device unauthorized, or device '…' not found). runAdbCapture classifies those as AnalysisUnsupportedTargetError, which lands in the last branch.

  • With overwrite: false (the default) the comment's push never runs. The caller gets unreadable_output with "The device path already exists and overwrite was not requested", which is false and suggests retrying with overwrite: true.
  • With overwrite: true the push does run, after a probe that did not determine whether the path exists, and a success would report overwritten: true without having observed that.

Expected: existence is unknown, so the probe's own refusal is returned and nothing is pushed. This is what inspect_adb_device already returns for the same stderr.

Change and scope

The probe now has two understood outcomes and everything else is reported as is:

  • exit 0: the path exists;
  • a nonzero exit with no adb diagnosis (AnalysisProtocolError): test -e says the path is absent, unchanged;
  • any other failure: return the probe's error.

deviceExists is then simply existsProbe.ok. Timeout, cancellation and resource failures were already returned this way; the device-state refusals now join them, which removes four branches.

Not included: an unclassified nonzero probe exit that does carry stderr text is still read as "absent", as before. Tightening that to an empty-stderr exit 1 would be a separate decision.

Follow the contribution scope.
Scope decision: not applicable. This makes an existing mutation run in fewer cases.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the push operation's existence probe 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 push whose probe is refused by adb now returns unsupported_target with adb's diagnosis instead of the "already exists" unreadable_output.
  • Provider, bridge, target-format, or platform compatibility: ADB provider only.
  • Evidence, artifact, provenance, or reconstruction contract: overwritten is now only ever reported from an observed probe result.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): the push no longer runs when the probe could not establish whether the path exists.
  • 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.

push_adb_file already writes a file on the selected device; this PR only removes one case in which it did so.

Evidence and regression coverage

  • Tests added or updated: a table test in src/adb/AdbProvider.test.ts using the existing adb stub, for an offline and an unauthorized device without overwrite and an offline device with overwrite. Each expects unsupported_target carrying the device state, no "already exists" text, and exactly one adb device call (the probe), so no push ran.

  • Base reproduction or other evidence (executed): without the fix all three rows fail. The two without overwrite return unreadable_output; the one with overwrite records a push call after the failed probe.

  • User-visible CLI/MCP output (executed with REA_ADB_PATH pointing at a stand-in adb that answers every device command with error: device offline), for rea push-adb-file emulator-5554 payload.bin /data/local/tmp/payload.bin:

    Before, on 4dd44dd:

    {
      "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": {
        "operation": "push_adb_file",
        "reason": "The device path already exists and overwrite was not requested: /data/local/tmp/payload.bin"
      }
    }

    After:

    {
      "code": "unsupported_target",
      "message": "Unsupported target for push_adb_file at /data/local/tmp/payload.bin: error: device offline",
      "details": {
        "operation": "push_adb_file",
        "path": "/data/local/tmp/payload.bin",
        "reason": "error: device offline"
      }
    }
  • Remaining proof gaps: not run against a real device or a real adb binary.

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 to schemas. A caller that passed overwrite: true to a device adb refuses now gets the probe's refusal instead of the push's; both carry adb's diagnosis.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the device is written to in fewer cases than before.

This touches the same two files as #2344 in different places; whichever lands second may need a trivial rebase, which I will do.

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

A push without overwrite read any unclassified failure of its existence
probe as an existing path, so an offline or unauthorized device was
reported as "the device path already exists". With overwrite it pushed
after a probe that had not established anything. The probe's own
refusal is now returned in both cases.

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.

@matbrgz

matbrgz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Review Finding & Error Type Invariant

In AdbProvider.ts#pushFile:

if (
  !existsProbe.ok &&
  !(existsProbe.error instanceof AnalysisProtocolError)
)
  return existsProbe;
const deviceExists = existsProbe.ok;
if (deviceExists && !input.overwrite)
  return err(
    new AnalysisOutputError(
      `Remote path ${input.device_path} already exists on device ${input.serial} and overwrite was not requested`,
    ),
  );

Finding: Error Typing on Target Collision

  • If existsProbe.ok is true and overwrite: false, returning AnalysisOutputError is semantically inaccurate.
  • Per REA error algebra (AGENTS.md and src/domain/analysisErrorCore.ts), a refusal due to a pre-existing destination without overwrite: true is an input constraint failure (AnalysisInputError or AnalysisResourceConstraintError), not an AnalysisOutputError (which designates malformed tool/subprocess output or serialization errors).
  • Returning AnalysisOutputError here misclassifies a normal safety precondition refusal as a provider output defect.

Suggested Fix

Wrap the refusal in AnalysisInputError or an explicit AnalysisResourceConstraintError with code destination_exists so callers can programmatically distinguish input conflicts from internal parsing failures.

@huiq777

huiq777 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@matbrgz The refusal you quote is not part of this change, and the snippet differs from the code. On main it reads:

new AnalysisOutputError(
  operation,
  `The device path already exists and overwrite was not requested: ${input.device_path}`,
)

This diff does not touch it; it only changes what happens when the existence probe itself is refused.

Two things on main depend on that error type today: the test "refuses a push onto an existing device path without overwrite" expects unreadable_output for it, and the provider's other destination refusal ("The output file already exists") uses AnalysisOutputError too. Retyping it would be a contract change across those refusals, so I have left it out of this fix. It may well be worth doing, as its own change.

@matbrgz

matbrgz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@huiq777 Thanks for the clarification! You are right that the downstream AnalysisOutputError refusal is pre-existing on main and kept intact here to preserve existing contract assertions across tests and the other destination refusal.

Looking strictly at the diff in this PR:
Replacing the fallback else deviceExists = true; with:

if (
  !existsProbe.ok &&
  !(existsProbe.error instanceof AnalysisProtocolError)
)
  return existsProbe;

cleanly fixes the false "already exists" assertion when the device is offline, unauthorized, or failing to communicate, and returns the actual probe error (unsupported_target) without running adb push. The regression tests in AdbProvider.test.ts verify both overwrite: true and overwrite: false when the probe cannot run.

The fix is focused, correct, and respects the scope of the problem.

@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; refused device probes now stop the push without changing the existing overwrite check.

Summary

push_adb_file now returns device-state errors from its existence probe instead of claiming the path exists or attempting a push.

  • ADB pushes stop when the device cannot answer the path check.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Probe device path"] --> B{"Probe result"}
  B -->|"Success"| C{"Overwrite requested?"}
  B -->|"AnalysisProtocolError"| D["Push; overwritten is false"]
  B -->|"Other error"| E["Return probe error; do not push"]
  C -->|"No"| F["Return already-exists error"]
  C -->|"Yes"| G["Push; overwritten is true"]
Loading

Reviews (1) · Last reviewed commit: "fix(adb): report the device state when a..." · Reviewed by Greptile

@morluto
morluto merged commit 2a61dea into morluto:main Oct 13, 2026
1 check passed
@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants