Skip to content

K2GO-372 fix(restore): ask before reading, and show one bar for the whole run - #523

Merged
luisguzman-adfa merged 5 commits into
mainfrom
fix/K2GO-372-restore-progress
Sep 2, 2026
Merged

luisguzman-adfa merged 5 commits into
mainfrom
fix/K2GO-372-restore-progress

Conversation

@luisguzman-adfa

Copy link
Copy Markdown
Collaborator

Restoring a backup asked the destructive question last and showed no progress at all.
Picking a file copied it into the cache and fully listed it — two complete reads of a
multi-gigabyte archive — and only then asked "replace your system?". Answering it meant
staying in front of a motionless screen for over three minutes on a 2.4 GB backup. The
ten minutes that followed reported nothing: an indeterminate spinner, indistinguishable
from a hang.

What changed

  • The confirm comes first. It needs the file's name, not its bytes. Every slow read
    now belongs to DeepOpService, so it is measured, it survives backgrounding, and the
    user can walk away as soon as they have answered.
  • The copy moved into the service and became the first of the run's three passes.
    ExtractProgress maps N passes onto one bar instead of two, so copy / check / restore
    share a single 0-100 rather than each filling it and sending it back to zero.
  • The pre-flight validation is deleted. It was a second place answering what
    TarExtractor already answers: identity, then the full listing, failing closed before
    writing anything. validate(), resolveTar() and listEntries() go with it.
  • The picked file is judged before it is copied. The identity manifest is the
    archive's first member, so a few KB of the SAF stream refuse a wrong-ABI or non-rootfs
    backup immediately. Gzip is detected from the magic bytes, since a SAF uri carries no
    filename to read an extension from.
  • The damage marker is planted at the first byte written, not at service start. The
    copy and the verify pass damage nothing, so an ungraceful exit during them no longer
    declares a false DAMAGED, and an archive the extractor rejects no longer leaves the
    system marked damaged.
  • The failure's reason reaches the screen instead of a generic "Restore failed".
  • Two fixes to the same screen: the status line uses the fixed-width ellipsis so it stops
    sliding as its dots grow, and the "this can take a while" card is hidden once the
    operation has finished.

Reduction

Before After
Places that validate 2 1
Full reads of a valid archive 4 3
Owners of the status label 2 1
Owners of the staged temp file 2 1
Inline Result-to-message chains 2 1 rule, 3 callers
Time to the confirm (2.4 GB) 3 m 15 s 3 s

No new flags and no new mutable state. The guard is planted lazily by reading the marker
itself (InstallGuard.isLive) rather than mirroring it in a boolean.

Verified on device

  • Confirm dialog: 3 s (2.4 GB) and 2 s (1.26 GB), against 3 m 15 s.
  • One monotone bar across all three passes: copy 31% -> 33% at the handoff -> check 42%,
    66% -> restore 78%, 87%. It never returns to zero.
  • Successful restore: temp deleted, marker absent, rootfs in place, server back up.
  • Wrong architecture: refused in 3 s (was 52 s) without copying, with the specific reason
    on screen; marker absent, rootfs untouched, environment lock released.
  • 18 unit tests green (4 new for the N-pass mapping), lint clean with all 33 locales
    translated.

Out of scope

Three pre-existing issues found while reviewing, each with its own ticket: the extractor
proceeds on an UNREADABLE validation verdict, and dismissing the confirm by tapping
outside dead-ends the screen.

…ve early

A restore streams the archive twice -- the safety listing pass the traversal
guard needs, then extraction -- and reported both as an indeterminate spinner.
On a 4.86 GB backup that is about five minutes with nothing to distinguish it
from a hang. The two-phase byte bar already existed for the rootfs install
(ADFA-5118); the restore simply never consumed it, setting -1 and implementing
only the no-op onProgress. It now maps both passes onto one 0-100 bar.

The identity check also ran after the listing, so a wrong-ABI backup was refused
only once a full decompression had been paid for. The manifest that answers it
is packed first by the backup writer, so reading it up front refuses the same
files in about a second.

The rule itself moves to deploy/domain/RootfsIdentity, pure and with the app ABI
passed in, because as written it could not be unit-tested -- it read the ABI from
android.os and its input had a private constructor. RootfsArchiveValidator keeps
one thin adapter, so the early check and the full validation cannot drift apart.

No new strings, no archive-format change, and the listing pass is untouched.
…hole run

The destructive confirm waited on a full copy plus a full validation listing of the
archive — over three minutes for a 2.4 GB backup — so the user had to stay and watch a
motionless screen to answer a question the file's contents do not affect. The confirm
comes first now, and every slow read belongs to DeepOpService, measured and behind the
foreground notification.

The pre-flight validation was a second place answering what TarExtractor already answers:
it checks identity, lists the archive and fails closed before writing anything. Deleting
it removes one full read of the archive and one of the two "Checking the file" labels;
validate(), resolveTar() and listEntries() go with it.

The copy becomes one of the run's three passes and shares the single bar (ExtractProgress
maps N passes now, not two) instead of filling it and sending it back to zero. The damage
marker is planted at the first byte written rather than at service start: the copy and the
verify pass damage nothing, and an archive the extractor rejects must not leave the system
marked damaged. The rejection's reason reaches the screen instead of a generic failure.

The status line uses the fixed-width ellipsis so it stops sliding as its dots grow, and the
"this can take a while" card is hidden once the op has finished, where it was asking the
user to wait for something that already happened.
…is the archive's

first member, so a few KB of the SAF stream refuse a wrong-ABI or non-rootfs backup in
about three seconds instead of after a multi-gigabyte copy (measured 52s -> 3s on a
1.26 GB archive). Gzip is detected from the magic bytes, since a SAF uri has no filename
to read an extension from. The Result-to-reason mapping, which TarExtractor spelled out
twice inline, moves to RootfsArchiveValidator.rejectionMessage for its three callers.
…eck for what it is

Second-pass review of the K2GO-372 change. Two one-line hardenings, and three notes so the
next reader does not undo something that was deliberate.

- The staged archive is deleted when the staging thread returns to a service that already
  reached a terminal. Unreachable while a restore is uncancellable, but the file is
  gigabytes and the branch left it in the cache.
- The staging copy ends only on -1; a zero-length read used to end it and silently truncate
  the copy.
- rejectBeforeCopy() stops sharing a name with RootfsArchiveValidator.identityRejection():
  one returns a message to show, the other a verdict.
- rejectionMessage() records that it also rejects CORRUPT, which the extractor's two inline
  chains did not — failing closed is the right direction and it is inert on today's callers
  — and that UNREADABLE deliberately does not reject there, a gap that predates it.
- TarExtractor says why its identity check is not a duplicate of the pre-copy one: it is the
  fail-closed gate every caller shares, and it judges the artifact actually about to be
  extracted.
…e the extract

The guard was only ever asked whether the expanded tree would fit, and only once the picked
archive had already been copied into the cache — so the copy itself, gigabytes of it, was
never covered. A device with room for neither filled up mid-copy and reported it as an
unreadable file.

SpaceEstimate.peakForRestore() names what a restore needs free at once: the staged copy plus
the tree it expands into, both on disk together until the extraction finishes. The service
asks it before copying, using the length the provider reports.

This is the same requirement asked earlier, not a stricter one: the old check wanted
free-after-copy >= expansion, this one wants free-before-copy >= copy + expansion, and the two
differ by exactly the copy. The check in runRestore stays as the authoritative gate, for when
the provider reports no length or the disk moves in between, and both now spell "it does not
fit" the same way.
@luisguzman-adfa
luisguzman-adfa merged commit 7d8474c into main Sep 2, 2026
3 checks passed
@luisguzman-adfa
luisguzman-adfa deleted the fix/K2GO-372-restore-progress branch September 2, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant