Repository navigation
fix(adb): preserve existing bugreport archives - #2221
Merged
Merged
Conversation
dakjdakd
marked this pull request as ready for review
October 12, 2026 15:27
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Record acquired archive facts before publishing, preserve the staging archive when the exclusive copy fails, and keep retained evidence out of automatic cleanup. Reuse the same observation through publication and digest failures. Add a real-filesystem ENOSPC regression covering error projection, existing evidence, subsequent collection and provider shutdown. Verified 96 focused tests, static checks and docs on macOS with simulated ADB; no real-device verification.
3 tasks done
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2220.
Collecting a bugreport into a directory that already contains a same-name ZIP could silently replace the earlier archive. This change isolates ADB's collection output and publishes the resulting ZIP exclusively, selecting a numeric suffix when a destination is occupied. Existing files retain their bytes, and a successful request still returns one newly created archive in the caller's chosen directory with its byte count and SHA-256 digest.
For example, if
bugreport test.zipandbugreport test (1).zipalready exist, the new collection is published asbugreport test (2).zip. The response names that final file inlocal_pathand preserves ADB's original completion path inadb_reported_path.Problem and expected behavior
The smallest trigger is a filename collision: the caller chooses an output directory, and
adb bugreportselects a ZIP name that is already present there. A collision can also appear while collection is running. Repeated collection does not guarantee a collision on every device, but the provider must preserve existing files whenever one occurs.The affected implementation passed the caller's directory directly to ADB and only inspected the reported file after ADB finished writing it. At that point, hashing the new archive could establish its current bytes but could not prevent or reveal the earlier file's destruction. The
output_directorycontract promises one new ZIP, and the request offers no permission to overwrite existing host evidence.The expected behavior is to preserve every occupied destination while acquiring a new archive. A preflight existence check would leave a race during a potentially long collection, so the preservation guarantee must be enforced by the final filesystem publication operation.
Change and scope
The correction lives in
AdbProvider.collectBugreport, shared by the CLI and MCP workflows:mkdtempand record its filesystem identity before starting ADB.adb bugreport. Parse the completion path and require it to identify a regular, non-symlink file directly in the owned staging directory. A report pointing elsewhere is a protocol refusal, rather than permission to acquire an arbitrary existing file.copyFile(..., COPYFILE_EXCL). Try the reported basename first; onEEXIST, select(1),(2), and subsequent suffixes before the original extension. Other publication failures remain output errors.close()or the next admitted operation.The existing package-directory cleanup owner has been generalized to cover both package pulls and bugreport staging, retaining the originating operation for each resource. Aggregate cleanup failures use the shared close operation and record the owning operations. This avoids introducing a second cleanup mechanism for the same filesystem responsibility.
Staging allocation failures return the tagged
Resulterror shape. Cleanup failures preserve the primary error rather than replacing it. If the archive has already been published, a digest cancellation retains its final path and producer path with an explicitly unknown digest. If hashing completed before cleanup failed, the error retains the completed acquisition, including its digest. The internal acquired-file partial-observation type accepts those completed bugreport facts.Contract and boundary impact
local_path, which can now include a collision suffix. No overwrite flag is introduced.bugreport; the directory is now an isolated staging destination. No Android configuration or archive format change is introduced. Host filename selection retains the original extension.adb_reported_pathretains the producer's exact reported value even though staging is subsequently removed. The archive's device-generated contents and existing limitations are unchanged. Internal partial observations now retain completed bugreport facts when later cleanup fails.Evidence and regression coverage
The new filesystem boundary regression executes on the Windows filesystem with simulated ADB output. The process replies model the archive write and ADB completion line; real filesystem operations perform publication and preservation checks. Targeted failure injection exercises staging allocation, digest cancellation, and cleanup failure.
The two collision scenarios verify that both the original basename and an already occupied first suffix keep their original bytes, while the new ZIP is published at the next available name with the expected bytes and digest. One creates the conflict before collection; the other creates it during collection. The affected implementation passed the caller directory to the fixture, so these assertions would expose its overwriting or incorrect artifact/digest selection. The affected base was reviewed in source; these new tests were executed on the fixed branch, not represented as a separate real-device or base-revision run.
The other regressions confirm that:
close()retry;The provider regression fixture now writes into the directory supplied to ADB and asserts the final artifact separately from the producer path.
Representative successful fields, when the original name and first suffix are occupied:
{ "local_path": "C:\\reports\\bugreport test (2).zip", "bytes": 15, "sha256": "<SHA-256 of the newly published archive>", "adb_reported_path": "C:\\reports\\.rea-bugreport-<unique>\\bugreport test.zip" }This is a field-level illustration of the existing successful result shape; the CLI/MCP Evidence wrapper, client identity, and device serial remain present in the complete response. A removed staging path remains source provenance rather than the location callers should open.
Validation performed
The final branch is based on
e4d3e1399d9cd4932653e7015a1bf8589e56029d. Local commands used the pinned Node 24.18.0 and npm 11.16.0 toolchain on Windows.npm run test:focused -- tests/boundary/providers/adb/adbBugreportPublication.test.ts src/adb/AdbProvider.test.ts— passed: 7 tests. This command completed against the rebased final implementation.npm run check— passed on the rebased final implementation: all 6 Turbo tasks completed successfully, including typecheck, lint, formatting, unused-code analysis, and metadata checks. Resolved module boundaries passed across 1,598 source files; architecture guards passed across 1,210 source files.npm run verify:test-discovery— passed: all 931 test files were discovered exactly once.git diff --check— passed.Compatibility, safety, and release
local_pathfield to locate it.dist/, generated skill bundle, provider projects, or local diagnostic artifacts are committed.Review checklist
Fixesabove.