WP-096: Google TV package storage and download reliability
Status: ✅ Done (2026-11-28). Executed on the TCL 65Q77K
(EC-014, every
step passed); fork PR barefootbetters/scummvm#23,
merged 2026-11-28 (b757d503bb). D1–D4 answered 2026-11-28 · pre-flight
READY 2026-11-28 (pre-flight-WP-096-2026-11-28) ·
execution prompt session-WP-096-2026-11-28.
Numbering: WP-086 is the Hotspot Magnet research (✅), and WP-095 is held
by the open wizard’s-skull PR, so this takes WP-096 and EC-014 (EC-011 has
never been used) (wp-lifecycle §Supersession check).
Phase: 5 (polish & distribution).
Depends on: WP-085 (its installer, merged into the fork in
barefootbetters/scummvm#13;
WP-085’s one open item, an import route without a computer, isn’t needed here);
the ISO-free feasibility study
(the sizes this WP plans for).
Unblocks: delivering licensed game-data packages to beta testers’ TVs.
That also needs a host and access scheme, a separate WP (§Out of scope).
Companion EC: EC-014.
Pre-flight required: Yes. It changes the fork outside
engines/terraglyph/ (the Android advanced mode) and changes network download
code.
Targets generation(s): none directly. No engine code changes. The
installer is game-agnostic, and Showdown (Gen 1) sets the sizes it must
handle.
Estimated effort: 3–4 days, including the TCL runs.
Goal
Make the WP-085 package installer safe on a storage-constrained Google TV. It should know before it starts whether a package fits, refuse cleanly when it doesn’t, resume an interrupted download instead of starting over, confirm that what it installed is what the package held, and never lose an installed version or a save along the way. The installer is extended, not replaced.
Background
- What WP-085 built (
backends/platform/android/advanced/, test builds only per WP-085 D4): a manifest (format 1: id, version, size, SHA-256, HTTPS URL), a download topackages/.staging/, size and SHA-256 checks, a data-only extract, a rename intopackages/<id>/<version>/, an update beside the old version, and removal that keeps saves. Its rules are in the manifest doc. - What the feasibility study measured for Showdown, Aug 2001
(§G):
- installed size 556,351,281 B (530.6 MiB);
- zip download 419,557,579 B (400.1 MiB);
- peak during install ~931 MiB (zip plus extract);
- peak during an update ~1.46 GiB (old version, zip and new version).
A TV needs far more free space than the game’s final size.
- The gaps the study found in
PackageStore.javaatbfeaa1c7ba(§H):- No free-space check: there’s no
StatFs,getUsableSpaceorgetAllocatableBytescall before the download or the extract. - No resume.
fetch()callscleanStaging()first (:176) and deletes the zip infinally(:209), so any interruption restarts a ~400 MiB download from byte 0. - Integrity is checked for the zip (SHA-256) and, implicitly, per entry
(
ZipInputStream’s CRC-32). Nothing is recorded that would let an installed folder be checked again later.
- No free-space check: there’s no
- What already holds and must keep holding:
- An interrupted update leaves the old version playable (WP-085 Milestone 4).
- Removal keeps saves, which live in
<base>/saves, outsidepackages/.
- The manifest parser ignores unknown fields. It reads every field with
optString/optLong(PackageManifest.java), so a new optional field stays compatible with format 1 and older test builds.
Scope
In scope
All of it lives in the advanced mode (test builds). The release build stays free of it, as WP-085 D4 requires.
1. Storage preflight
- Before downloading, the app computes the required space as **package size
- The installed size comes from a new optional manifest field,
installedSize(the sum of the zip’s uncompressed entry sizes). If it’s absent, the app checks the download size before downloading. Once the zip is verified, it reads the zip’s central directory for the exact extracted size and checks again before extracting. - An update needs space for the zip and the new version only. The installed old version is already on disk and isn’t counted as free.
- If the space isn’t there, the app refuses before writing anything. It shows the bytes needed, the bytes free and the shortfall, and logs the same line (D1).
- Running out of space mid-download or mid-extract (
ENOSPCas anIOException) deletes that package’s staging files. Any installed version stays where it is, and the log names the cause.
2. Interrupted-download recovery
- A network failure or a killed app keeps the partial download as
<id>-<version>.zip.part, with a sidecar recording the URL, the bytes written and the server’sETag/Last-Modified. - A refusal still deletes the partial download: wrong size, wrong SHA-256,
a data-only rule, or any
RefusedException. - A retry of the same id and version continues the download. The app
re-hashes the bytes it already has, then sends
Range: bytes=<n>-withIf-Range. A206appends. A200, a changed validator or a416restarts from 0. The final size and SHA-256 checks are unchanged, so a bad resume can never install. cleanStaging()keeps the.partand sidecar for the id and version being fetched, and deletes everything else in.staging/.
3. Installation integrity
- After extracting, the app writes
packages/<id>/<version>.files.jsonwith each entry’s path, size and CRC-32 from the zip. It sits outside the game folder, so ScummVM’s detection never sees it. - The advanced mode gains a Verify action per installed package. It
re-reads every file, compares size and CRC-32 with
.files.json, and reports pass, or each missing or changed file.
4. Preservation
- A refusal, an interruption or a failure at any step never deletes or alters an installed version, its library entry or any save.
- Documented in the manifest doc:
installedSize, the space rule, resume and Verify.
5. Interrupted installation recovery (a power cut or a killed app during extraction)
WP-085 already covers part of this at bfeaa1c7ba:
- extraction runs inside
.staging/and is renamed into place only when complete; installed.jsonis written atomically (temp file and rename), and only inapplyPending()after that rename;cleanOrphans()deletes any version folder thatinstalled.jsonandpending.jsondon’t name.
So a partly extracted game is never recorded as installed today. What’s
missing is durability across a power cut: no file or directory is
fsynced before those renames, so file data that hasn’t reached the disk may
be lost behind a completed rename. (The staging sweep already runs on every
advanced-mode start: PackagesActivity.onCreate calls cleanStaging() and
cleanOrphans() (:59-60). The draft said otherwise; the pre-flight corrected
it. That sweep deletes everything in .staging/, so as it stands it would also
delete a resumable .part.)
- Every extracted file is
fsynced (FileOutputStream.getFD().sync()) before the staging folder is renamed into place. The writteninstalled.json/pending.jsontemp file is synced before its rename. - The existing start-up sweep (
PackagesActivity.onCreate→cleanStaging(),cleanOrphans()) still runs first on every advanced-mode start. It now deletes every.dextraction folder and temp file in.staging/but keeps the.partdownloads and sidecars that item 9 keeps. Each deletion is logged. - A package is marked installed (
installed.json) only after its folder is complete, synced and renamed. An interrupted extraction leaves the previous version recorded, playable and untouched, along with every save. - After an interruption, installing the same package again starts cleanly: the download resumes or is reused if complete and verified, and the extract starts over.
Out of scope
- The production host and access scheme for licensed packages (Cloudflare R2, presigned URLs vs. a Worker gate). This belongs in its own WP once the question in the study’s §L.3 is answered. The downloader already takes any HTTPS URL.
- Hosting Showdown or any licensed data anywhere. It’s tested here only through the size of a synthetic package (D2).
- Freeing space for the user (offering to remove other games or clear caches). D1 records it as a later option.
- Package building (a per-title file list and a packaging script). That’s
step 2 of the study’s next steps, a
tools/WP of its own. - The release build, Google Play and any store UI. WP-084 owns them.
- Engine detection changes (
Scooby.exe, the Feb 2001 Showdown). Those belong to an engine WP. - Manifest format 2. Everything here fits format 1 as optional fields.
Decisions for Jeff
All four were answered on 2026-11-28, when Jeff relayed a review that approved each recommendation and added safeguards to D3 and D4.
| # | Decision | Recommendation | Answer (2026-11-28) |
|---|---|---|---|
| D1 | What happens when a package doesn’t fit. (a) Refuse, showing needed, free and shortfall; (b) also offer to remove other installed packages to make room | (a) for v1. Choosing which game to delete is a product decision, and test builds don’t need it yet | (a), “Approve” |
| D2 | A large test package. (a) A synthetic ~420 MB zip of random data, on the public tv-test-packages release (no rights question, and it matches Showdown’s real size); (b) BASS only (69 MB, too small to stress space or resume); (c) a real Showdown package on a private host |
(a). (c) waits for the host-and-access WP | (a), “Approve” |
| D3 | Headroom added to the required space. (a) A fixed 64 MiB; (b) 5% of the installed size; (c) none | (a). It covers filesystem overhead and the sidecars, and is easy to read in a refusal message | (a) “for initial testing”. The 64 MiB must be checked against what the TCL actually does, not assumed to be enough everywhere (exit criterion 11) |
| D4 | Testing a full disk on Jeff’s TCL. (a) Fill internal storage with a temporary filler file over adb until the package no longer fits, then delete it; (b) test only through a debug-build override of the free-space figure |
(a) for the real ENOSPC path, with (b) as well for the quick refusal checks. The filler is deleted in the same step, and the TV’s free space is recorded before and after |
(a) and (b), “Approve with safeguards”. The safeguards are in §Filler safeguards |
Filler safeguards (D4)
- One test folder only. Filler files go in
/sdcard/wp096-filler/. Nothing is written anywhere else, and the cleanup deletes only that folder. - Never a full device. Each filler is sized to leave a stated floor
free: the package’s shortfall target, and never less than 256 MiB of
real free space, so the system and other apps keep running. The size is
computed from a fresh
df /datareading just before the filler is written. - Automatic cleanup, failure included. Fillers are created and removed
by one script,
tools/Invoke-TvFiller.ps1(PowerShell). Itstry/finallydeletes/sdcard/wp096-filler/however the step ends: a pass, a failure, anadberror or Ctrl+C. Each filler step starts and ends withdf /data, and the end reading must be within 1 MiB of the start. - No orphans between sessions. EC-014’s pre-flight removes any
/sdcard/wp096-filler/left from a previous run before anything else.
Engineering calls (Claude’s, for pre-flight review)
getAllocatableBytesovergetUsableSpaceon API 26+. It counts the cache Android can clear on demand. That matches what an install can really get on a TV whose free space is mostly cache. The TCL runs Android 14.- CRC-32, not SHA-256, for Verify. The zip already carries a CRC-32 for every entry, so it costs no extra manifest data. The zip-level SHA-256 still guards the download itself.
- The resume validator comes from the server’s response, not the manifest.
If-Rangewith the storedETagorLast-Modifiedstops a changed object from being appended to an old partial file. The final SHA-256 check is the backstop either way. - Hosts that ignore
Range(they answer200) just restart. The pre-flight found GitHub Releases honours it: a302to a signedrelease-assets.githubusercontent.comURL answers206withContent-Rangeand a stableETag. - Two code facts the pre-flight found (fork
6b5b02c53b):open()refuses every status but200(PackageStore.java:155), so it must accept206for a range request.- The redirect target is signed and short-lived, so a resume always
re-requests the manifest URL and follows the redirect afresh. It never
stores the redirected URL. The JVM harness checks that
HttpURLConnectionkeeps theRangeheader across the redirect.
Dependencies
- A fork worktree off a freshly fetched
origin/scooby-engine(wp-lifecycle;tools/New-ForkWorktree.ps1). - The Android toolchain and the libpng build from the
smart-TV guide. The TV is driven through
Windows
adb. - The TCL 65Q77K.
- Test packages on
barefootbetters/tv-test-packages:- the existing BASS 1.2 and 1.2.1;
- the D2 synthetic package and a manifest that lists it with and without
installedSize.
New release assets are created only on Jeff’s go, as in WP-085.
Execution
- Pre-flight:
pre-flight-WP-096-<date>.md, with D1–D4 answered and the GitHub ReleasesRangebehaviour recorded. - Implement in the order of the scope sections: 1 (preflight), 2 (resume), 3 (integrity), 5 (interrupted install), and 4 (the preservation checks, mostly tests). One commit per section on the fork branch.
- Exercise the pure-Java parts on a desktop JVM, as WP-085 did for
zip-slip: the space arithmetic, the resume decision table, the
.files.jsoncomparison. - Run EC-014 on the TCL, write §Result, and open the fork PR.
Exit criteria
- D1–D4 answered (2026-11-28); pre-flight READY (2026-11-28).
- With too little space (a filler file, per D4), installing the synthetic
package is refused before any byte reaches
.staging/. The refusal shows needed, free and shortfall, and the free-space figure before and after the attempt is unchanged (logged). - With exactly enough room for the download but not the extract, and no
installedSizein the manifest, the post-download check refuses before extracting and the staging files are gone (logged). - A real
ENOSPCmid-extract leaves an installed older version of the same id playable, and.staging/empty (logged). - A download killed at about 30% (
am force-stop) and retried sendsRange, gets206, transfers only the remainder, and installs with a matching SHA-256. The log shows the resume offset and the bytes fetched (logged). - A host or object that answers
200to aRangerequest restarts from 0 and still installs. A partial download whose validator changed restarts from 0 too (logged; local test or JVM harness). - Verify passes on a fresh install. After one byte of an installed file
is changed through
run-as, Verify names that file (logged). - In each of criteria 2–7 and 12, existing saves and library entries are
byte-identical before and after (
run-aslistings, as in WP-085 Milestone 4). - The release APK still has no advanced-mode code (the WP-085 D4
apkanalyzerand dex string checks, returning 0). - The manifest doc documents
installedSize, the space rule, resume, Verify and the interrupted-install recovery. The fork PR is open with the section commits, and §Result is written. - The headroom is measured, not assumed (D3). For BASS and the
synthetic package, the real free-space drop on the TCL is recorded at
three points: after the download, at the extract’s peak, and after
install (
df /dataandgetAllocatableBytes). §Result states each package’s overshoot over package size + installed size, and whether 64 MiB covered it. If it didn’t, the headroom is raised to the measured overshoot rounded up, and the change is noted. - Interrupted installation recovery. The app is killed mid-extract
(
kill -9of the app process) during an update of the synthetic package, and separatelyadb rebootis run mid-extract. In each case, after restart:- the previous version is still installed, recorded in
installed.json, launches and passes Verify; - every save and library entry is byte-identical to snapshot S;
- the log shows the staging sweep removing the incomplete extraction;
installed.jsonnever names the interrupted version;- retrying the update completes and passes Verify.
One physical power cut at the wall mid-extract is run as well, with Jeff pulling the plug when the run sheet says to. Jeff chose it at pre-flight, 2026-11-28: it’s the only test of the
fsyncstep, becausekill -9andadb rebootboth leave the kernel to flush the page cache (logged). - the previous version is still installed, recorded in
Deliverables
- Fork branch and PR (Java only, under
backends/platform/android/advanced/, plus any manifest-merge or Gradle line it needs). No game data. - The updated manifest doc;
pre-flight-WP-096-<date>.md; EC-014 filled in; §Result, with the measured headroom (criterion 11). tools/Invoke-TvFiller.ps1, the D4 filler script with guaranteed cleanup (this repo).- On Jeff’s go: the synthetic test package and its manifests on
tv-test-packages. - Never committed: game data, captures showing the TV’s address or the app’s id (they stay local, as in WP-085), signing keys.
Result
✅ Done, 2026-11-28. All 12 exit criteria hold on the TCL 65Q77K (Android 14). The captures are in EC-014.
What landed:
- Fork PR barefootbetters/scummvm#23, merged into
scooby-engine2026-11-28 (b757d503bb): four commits onwp-096-tv-package-reliability(off6b5b02c53b), one per scope section:6c260eb0e0, space preflight;791e70d424, resume;79b2298822, file lists and Verify;7891d25887, power-cut durability.
Java only, all under
backends/platform/android/advanced/. The base has since gained engine-only commits, which don’t overlap. - The manifest doc now covers
installedSize, the space check, resume, Verify and interrupted installs. tools/Invoke-TvFiller.ps1, the D4 filler.- Release
packages-2026-11-28ontv-test-packages: the synthetic zip (419,431,397 B, random data) and two manifests, one withinstalledSizeand one without.
Evidence by criterion (store-log lines unless noted):
| # | Evidence |
|---|---|
| 2 | Filler leaving 600 MiB: REFUSED … needs 864.0 MB (905970878 bytes), 99.9 MB (104751104 bytes) free, short by 764.1 MB; .staging/ absent and df 614,296 KiB before and after. The override gave the same refusal at 500 MB |
| 3 | No installedSize, filler leaving 1,150 MiB: the download was verified, then REFUSED … 249.9 MB … free, short by 214.1 MB … (to extract 400.0 MB); .staging/ empty |
| 4 | Update 1.0 → 1.1 with a filler leaving 500 MiB: FAILED wp096-synth 1.1: out of space (ENOSPC) while extracting; deleting its staging files; .staging/ empty; 1.0 recorded and Verify PASS; BASS launched |
| 5 | Force-stopped at 31.3%; Range: bytes=131432229- → HTTP 206 … -> APPEND; fetched 287,999,168 B; SHA-256 matched; installed |
| 6 | On the TV: codeload.github.com answered 200 → RESTART_WITH_BODY, installed; an edited validator → RESTART_NEW_REQUEST, full 419,431,397 B fetched, installed. Also in the JVM harness (32 passed, 0 failed) |
| 7 | Verify … PASS, 6 of 6; after dd changed one byte: FAILED; changed wp096-synthetic/data3.bin (CRC-32 eb6fb321, expected 02d35efb) |
| 8 | Each step’s before and after snapshots match for saves, library, installed.json and package files (see the note below) |
| 9 | Release APK 17a9bec1…: 0 advanced classes, 0 TestFeatures, 0 PackagesActivity, 0 TVPKG_MANIFEST_URL, 0 debug-free-bytes |
| 10 | Manifest doc updated; fork PR #23 opened (merged 2026-11-28); this section |
| 11 | The headroom table below |
| 12 | kill -9, adb reboot and Jeff’s power cut, each mid-extract during an update: Staging sweep: deleting packages/.staging/wp096-synth-1.1.d (an incomplete extraction); installed.json named 1.0; Verify PASS; snapshots identical; BASS launched; each retry installed 1.1 and passed Verify |
Measured headroom (criterion 11). These are drops in
getAllocatableBytes from before the install. The once-a-second df /data
poll agrees.
| Package | Zip + installed | After download | Extract’s end (peak) | After install | Overshoot | 64 MiB enough |
|---|---|---|---|---|---|---|
| BASS 1.2 | 142,239,592 | 69,382,144 | 142,266,368 | 72,888,320 | 26,776 B | yes |
| synthetic 1.0 | 838,862,014 | 419,483,648 | 838,889,472 | 419,454,976 | 27,458 B | yes |
The overshoot is ext4 block rounding and metadata, under 30 KB. 64 MiB stays (D3): it’s far more than the TCL needs.
Extract time with fsync. Extracting the 400 MB synthetic package with
every file synced took 7.1 to 29.1 s across the run (7,146 to 29,072 ms).
Most runs were about 8 s; the slow ones came while the TV was busy. A build
without the syncs took 10.6 and 11.3 s, so syncing costs little or nothing
here.
Findings:
- Android frees cache when storage runs low. The first out-of-space try
(filler leaving 700 MiB) didn’t run out: by the tap, about 258 MB of cache
had been cleared and 1.1 fit. Leaving 500 MiB produced the
ENOSPC. - So the filler’s 1 MiB drift check is noisy. It printed FAIL for all three Step 3 fillers, with free space ending higher than it started (+258,484, +3,132 and +5,976 KiB). That’s the freed cache, not a leak; a leak would show less free space. The script now says this when the drift is positive; the D4 rule is unchanged. For the same reason the TV ended the run 290,924 KiB freer than the pre-flight baseline.
getAllocatableBytes=getUsableSpace− 500 MiB on this TV, exactly, in every reading. The app sees 500 MiB less thandf./dataalso keeps a 144 MiB ext4 reserve for the system (resgid=1065).- GitHub’s asset host ignores
If-Range. Given a validator that doesn’t match, it still answers206with its realETag. The app’s own validator comparison restarts anyway (engineering call 3 holds). - One
fallocateof 16.8 GB fails on the TCL withInvalid argument. The filler now uses 1 GiB files. - The out-of-space failure message was wrong (“a partial download is kept”). It’s fixed in the resume commit: the screen now says what the store really kept.
- A power cut can shorten a verified download. The
.partisn’t synced after the download, so Jeff’s cut left 377,638,912 of 419,431,397 B. The resume measures the file, not the sidecar, and re-hashes it, so it fetched the missing 41,792,485 B and the SHA-256 check passed. Follow-up 1 now syncs the.partwhen its download completes. - The first power cut missed. The extract takes about 8 s and the run sheet hadn’t warned Jeff. It still showed a just-finished install survives a cut (Verify PASS). The second cut landed 6 s into the extract.
- The library key order changes; the entries don’t. Saves stayed
byte-identical through the whole run.
scummvm.inisometimes writes[showdown-win]’spathandtitle_movies_seenin the other order, launches included. My reading is that ScummVM’s config domains are hash maps, so the order isn’t stable. The keys and values never changed, and each step’s before and after snapshots match exactly.
Follow-ups (not done here):
Sync theDone 2026-11-28 in fork PR barefootbetters/scummvm#25, merged 2026-11-28 (.partonce its download completes.6e87dd1788).download()syncs the.partafter its last byte, before the sidecar update and the SHA-256 check. On the TCL the sync took 390 ms for a fresh 400 MB download and 1,456 ms for a resumed one; both verified, installed and passed Verify. Power cut, 2026-11-28: Jeff pulled the plug 1–4 s after the download synced, during the extract. After boot the.partwas the full 419,431,397 B (before the fix, the same cut left 377,638,912 B). The retry loggedReusing the complete download … not fetching it again, verified and installed. The installed files’ SHA-256s equal the zip’s, and saves and library were identical. That cut also showedstore.logisn’t synced: it lost its last lines and kept a zero-filled tail. Fixed with follow-up 2: each log line is now synced, and the log view drops zero bytes left by an earlier cut.Delete aDone 2026-11-28 in fork PR barefootbetters/scummvm#28, merged 2026-11-28 (.partthat’s never retried (for example, after a few days or when the manifest no longer lists that version).d5a7ade9b6), along with syncingstore.log.- Start-up sweep: deletes a
.partwith no sidecar, a sidecar with no.part, and any.partunchanged for 7 days. - Manifest load: also deletes any
.partthe manifest doesn’t list, or whose entry changed so it can’t be resumed. - Each deletion takes its sidecar and is logged with the reason.
- On the TCL: one planted case per rule was deleted by the expected
sweep, with the expected log line, while a real 30% partial of the
synthetic 1.1 survived both sweeps, resumed with
206, installed and passed Verify.
- Start-up sweep: deletes a
Reinstall WP-085’sDone 2026-11-28 on the TCL, through the app’s own Remove (keep saves) and install frombass-cdso Verify can check it (it has no file list).packages-2026-11-26/manifest-update.json.- Before, Verify reported
no file list. After, it reportsVerify bass-cd 1.2.1: PASS, 5 of 5 files match. - The reinstalled files are byte-identical to the old ones (SHA-256), and
the
SKY-VMsaves are unchanged. - Re-adding brings
[sky]back without the three settings ScummVM writes on launch (FM_medium_quality,FM_high_quality,fullscreen). The first launch wrote them back, and the entry then matched the original exactly. No code change was needed.
- Before, Verify reported
Make longer extract windows possible for a power-cut test (a test-only delay), if it’s run again.Done 2026-11-28 in fork PR barefootbetters/scummvm#33.- How: a number of milliseconds in
files/packages/debug-extract-delay-ms(throughrun-as) makes the extract pause that long after each file is written and synced, up to 60 s per file. The store log, the “Extracting…” status and the diagnostics show it. - Example: 5000 gives the 6-file synthetic package about 30 s of extract instead of 8.
- Tested: in the desktop JVM harness (33 passed: a 1,500 ms delay on three files took 4,502 ms, with the same files and CRC-32s). The release APK doesn’t contain it.
- On the TCL, 2026-11-30, with 5000 ms: the diagnostics and the
“Extracting…” status showed the delay. The six files appeared 5–8 s
apart, and the log said
Extracted 6 file(s) … in 38445 ms (each file synced; test delay 5000 ms after each). It verified 6 of 6, and deleting the file turned the delay off.
- How: a number of milliseconds in
- Out of scope for this WP and still open: the production host and access scheme for licensed packages, a free-up-space UI (D1 b), and the package-building script.
Notes
- Evidence discipline. Every device claim cites a capture from the run; Jeff’s live confirmations are quoted as his (DECISIONS, the 2026-11-21 fabrication lesson).
- Sizes to design for (from the study): a ~400 MiB download, a ~531 MiB install, ~931 MiB free to install, and ~1.46 GiB free to update. Two Gen 1 games installed take ~1.02 GiB.
- Generation discipline. No generation claim is made. Gen 2/3 packages will keep their disc-root layout (study §E), which this installer already allows.