Skip to content

Build queue: a game that crashes, hangs or fills the storage never holds the next one (#348) - #555

Open
davdxpx wants to merge 6 commits into
igawa6:mainfrom
davdxpx:build-queue-failures
Open

davdxpx wants to merge 6 commits into
igawa6:mainfrom
davdxpx:build-queue-failures

Conversation

@davdxpx

@davdxpx davdxpx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What and why

A follow-up to #448 for #348. It sits on top of #448: its three commits show here until #448 is in, and the new one is the last commit, "a game that crashes, hangs or fills the storage never holds the next one".

It came from the question whether game 2 in the queue still builds when game 1 fails. For an error, such as a damaged file or a tool that exits with an error, it already did: the game is marked Build stopped with the reason and Retry or Resume, and the next game starts by itself. These cases could still hold the queue or end it.

1. A build that hangs

  • Before, a packer job whose tool stopped answering kept the queue waiting for good. The stall rule only fired for a packer that was not bound.
  • Now a running job with no change for 30 minutes is kept as paused and the :pack process is ended, since its tool does not answer the packer's own stop. The game is marked Build stopped, and Resume goes on from what it made so far.
  • The same applies to another game's job a build waits for, and to an import whose progress stands still. A stopped import's half-written files are deleted.

2. A packer that crashed and is not started again

  • Android does not start a service again after two crashes within a minute. The build now stops 5 minutes after the packer went, with Android's exit reason (ApplicationExitInfo) in the build log, instead of waiting 10 minutes for "no progress".

3. A native crash while importing

  • That game now stops at once, and the queue goes on after the first crash. Before, it ran again, crashed again, and two crashes within a minute ended Android's restarts of the build service until the app was opened.

4. An Error in a build

  • An OutOfMemoryError or a missing native method in a build ended the app's process. It is now that game's end only.

5. A full storage

  • A full disk while importing or in the packer is now OUT_OF_SPACE, so the card says to free up some space before Retry.
  • On dev-0.1.8 the import's ENOSPC no longer reached OUT_OF_SPACE after the text rework, because its message no longer carries the error. The 0.1.8 branch below maps it again.

6. Smaller ones

  • A game removed while the queue waits before it: the wait no longer goes on waiting for it.
  • After the app was killed or the phone restarted, the build log says how the last run ended (Android's reason and the step it was in) and which start of three this is.

For dev-0.1.8

The same commit with dev-0.1.8's texts, since Prepare and BuildService were reworded there: davdxpx:build-queue-0.1.8, one commit (1c1412a) on today's dev-0.1.8 (e13e4d8), without conflicts.

Code

  • New dev.peanuts.build.BuildWatch: the hang, packer-gone and full-storage rules and the words for Android's exit reasons. It is plain Java, so the JVM test covers it.
  • Prepare: the 30-minute watchdog (endPacker keeps the job paused and ends :pack), the packer-gone rule (Link.gone, packerEnd), the same watchdog for another game's job in waitForPacker, and OUT_OF_SPACE from the packer's error.
  • BuildService: the import watchdog (Importer.cancel), OUT_OF_SPACE for the import, catch (RuntimeException | Error), the log line for a run the app's end cut off, the stop at once after a native crash in the import, and waitTurn reads the next game each round.
  • BuildQueue: Item.cut marks a run the app's end cut off (not saved).
  • peanuts/docs/FAQ.md: what the queue does with a game that fails, crashes or hangs.
  • No upstream files.

Tested

  • peanuts/tests/test_build_queue.py: the new BuildWatchJvmTest, and BuildQueueJvmTest checks the cut mark.
  • The peanuts suite: no new failures.
  • check-min-api.py on the APK: nothing newer than API 33. check-publish.sh and upstream-update.sh --check.
  • A run on a Thor follows in a comment: a queue of three with a forced failure in the first game, kill -9 of the packer and of the app.

The packer (PackService, ":pack") runs one job, and a start that comes while it runs another is dropped. A build
whose Prepare started then waited for a job that never ran. Prepare now waits after its bind while the packer's
first message names another job that runs (the build before it, which stops within seconds of its Stop, or
upstream's own Prepare), and the card says what it waits for.

The packer tells every bound client of whatever job it runs. Prepare took any of those messages as its own job's
state, so another game's progress, or its "done", could end this build. Only messages of this run's job.json
count now.

A Resume of a paused job read the pause of the run before (job.json says "paused" until the packer takes the
job). A pause written before this start is passed over for 30 s; after that it counts, as before.

jobStarted() says whether this run started the packer on its job, for a Stop that pauses it (issue igawa6#348).
)

A second build was refused ("... is being built now"). It now goes into a build queue, kept in the app's own
storage (files/build-queue.tsv, dev.peanuts.build.BuildQueue, plain Java), and BuildService builds one game after
the other. The service is sticky: when Android ends the app's process it starts it again and the queue goes on
(else at the next start of the app); the game that was building runs again and every step resumes. A game whose
build ended the app three times is stopped, so one game cannot loop through the night.

- A game whose build fails or is stopped is marked (its card says why, with Dismiss) and the next one starts.
- Before each game the queue waits while upstream's PackPolicy says so (heat, battery; with the remembered Go on
  anyway), while a game of the app runs (memory on 8 GB phones, igawa6#124), while a build with mods runs and while a pack
  of the next game is being imported (Import pack, igawa6#44). A .nup that does not fit the free space, or less than
  0.5 GB where the pack is made, stops the game before anything is written.
- Stop and Cancel stop the game that builds; Cancel all and Stop all stop everything. A Stop in Prepare also pauses
  the packer's job, which went on in the background before. The packer's own Pause pauses the whole queue; Resume
  (the Up next card, or the job's own Resume on Home's Prepare card) goes on with that game.
- The notification says the game's place ("2 of 5") and has Cancel all; between two games it says what the queue
  waits for. Only the end of the queue alerts, once, with what is ready and what stopped.
- Library: a waiting game's cover says "Queued, 3 of 5"; the Building filter has Up next (each waiting game with
  Remove, Stop all, Resume when paused); the sheet says Add to queue and has Remove from queue; the bottom screen's
  card has the place, A for the build card, Y to remove. Build all... queues every game that needs a build (Build
  needed, stopped, or built by an earlier version of the app), after one question that names them.
- Import again, Prepare again (upstream's Prepare, one marked line in Ondevice.prepare: UPSTREAM-EDITS Round 58)
  and the control interface's build, reimport and prepare queue too; status.json has "queue", a library row can be
  "queued", job stop stops this game, job pause pauses the queue, and screens_off works while the queue waits.
- Each build card listener follows one build id, so the end of one game cannot land on the next game's card.

Tests: peanuts/tests/test_build_queue.py (BuildQueueJvmTest: order, the file, a cut-off run, a failure that does
not stop the queue, removing, Cancel all, the same game twice, the batch's places, a pause, a damaged file; and the
wiring).
FAQ: "Can I build several games one after the other?" (Add to queue, Build all..., Queued and Up next, the waits,
the storage check, Stop, Cancel all and Pause, what happens when Android ends the app), and the queue in the
notifications. CONTROL: build, reimport and prepare go into the queue, job stop and pause, the library row
state "queued", and status.json's "queue".
…lds the next one (igawa6#348)

A build that failed already stopped its game, and the queue went on with the next. These ends could still hold the
queue, or end it until the app was opened:

- A packer job that hangs (its tool prints nothing more while the packer's worker lives) was never stalled: the stall
  rule waited only for a packer that was not bound. Now a running job with no change for 30 minutes is kept as paused
  and the packer's process is ended (the tool does not answer the packer's own stop; a sticky restart runs only a job
  that is still running). The same for another game's job a build waits for, and for an import whose progress stands
  still. Every tool says how far it got at least every few seconds, and a heat or battery pause is a state of its own.
- When the packer's process ended (a native crash, Android ending it for memory), Android started it again, but not
  after a second crash within a minute: the build waited 10 minutes and said only that it stopped making progress. Now
  it stops 5 minutes after the packer went, with Android's record of why (ApplicationExitInfo) on the card.
- A run the app's process did not live through runs again, as before, now with what ended it in the build log. A
  native crash while importing stops that game at once: run again it crashed the same way, and a second crash within a
  minute ended Android's restarts of the service until the app was opened.
- An Error in a build (OutOfMemoryError, a missing native method) ended the app's process; now it is that game's end.
- A full disk while importing or in the packer is OUT_OF_SPACE, so the card offers Free up space.
- The wait before a game looks the next game up again each round: one removed meanwhile is not waited for.

dev.peanuts.build.BuildWatch holds the rules (plain Java). With the fake engine, files/test-hang-seconds shortens the
hang time for a test on a phone; other builds never read it.

Tests: peanuts/tests/test_build_queue.py (BuildWatchJvmTest: a hang, a packer that ended, a full disk, a process's
end and when it stops a game at once; BuildQueueJvmTest: a cut-off run is marked; and the wiring).
@igawa6

igawa6 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks, this closes real gaps in the queue. We reviewed the dev-0.1.8 version (build-queue-0.1.8, 1c1412a) for 0.1.8. The watchdog rules are sound, and Resume after a hang kill is safe: the killed :pack recovers the same way it already does after a low-memory kill (the split writes its marker first, shader results are kept one by one, and Resume resets the per-step start count). Tests: peanuts/tests 711 OK (the new test_watchdog, with BuildWatchJvmTest compiled and run), dm/tools/tests test_android_* 291 OK.

Please fix before we land it:

  1. A hung build with mods still holds the queue for good. waitTurn waits with no limit while a build with mods runs (BuildService.java:302), and the mods loop in Prepare.runModded0 (545-547) got neither new rule; a full disk there is still TOOL_STOPPED. Suggestion: move the watchdog and the packer-gone rule into one helper and call it from both loops.
  2. The import-hang card contradicts its button. The code is STALLED, so the card offers only Resume and adds "Tap Resume to go on from where it stopped", while its text says what it wrote was deleted and to tap Retry (BuildService.java:761, Library.java:1892 and 1952). Suggestion: the OTHER code, which gives Retry.
  3. The packer-gone stop leaves job.json "running" (Prepare.java:352-358). If Android brings the packer back after the 5-minute mark, its sticky restart runs the job with no Prepare following it: the next game waits behind it, the pack is never added to the library, and the card still says Build stopped. Suggestion: mark the job paused, as endPacker does.

Smaller:

  • Deep sleep counts. The 30 minutes use elapsedRealtime, which counts deep sleep. The wake locks end after 6 h (BuildService) and 7 h (PackService), so a longer build with the screen off can be killed the moment the phone wakes. uptimeMillis avoids that.
  • A stricter hang test: "no change and no CPU time used by :pack" (/proc/<pid>/stat).
  • endPacker:
    • It writes paused before the kill, so the packer can write running back in between.
    • Its reason is "user", so the panel says "You paused the build." A new reason would need adding to both reason lists in Prepare, or the build waits for ever.
  • onServiceConnected resets the packer-gone timer. A recreated bound service with no job falls back to the 10-minute rule, so rule 2 may rarely fire; worth a look on a device.
  • Full disk in the packer: "Free some space, then tap Retry" shows twice (PrepareText.java:77 and Library.java:1951).
  • The import's hang check runs before the return code, so a finished .part can be thrown away.
  • A native crash in the main process during the import step is blamed on the importer, and the .part it leaves is not deleted.
  • Logging an OutOfMemoryError's stack trace can throw again.
  • Not covered by the import watchdog: the keys and size probe, and a syscall that never returns.
  • Steps that print nothing for a while (patch_nso's load and spin search, the library hash check at the end of shaders, the frame rate variant's game data, cleanup at the start). None comes near 30 minutes on known timings, but none has been measured for The Legend of Zelda: Tears of the Kingdom or Xenoblade Chronicles X: Definitive Edition on the 8 GB plan.
  • Test coverage: the Prepare and BuildService checks only match strings; nothing drives the poll loop, endPacker, the packer-gone rule or the import watch thread.

The PR says a Thor run follows in a comment; that would help too. Once it's updated we'll run it on an AYN Thor:

  • a queue of three with a forced failure in the first game;
  • kill -9 of the packer (once and repeatedly) and SIGSTOP as a real hang;
  • kill -9 and kill -11 of the app during an import;
  • a full storage during the import and during the pack step;
  • a long Tears of the Kingdom or Xenoblade Chronicles X build with the screen off.

…and a stopped job stays stopped (igawa6#348)

The review of igawa6#555:

- A build with mods has the same watchdog as a build (one helper, Prepare.watch). Before, one that hung held the queue for good, since the queue waits while a build with mods runs. A full disk there is OUT_OF_SPACE too.
- Every watchdog stop keeps the job as paused, also for a packer that ended or stalled. A packer Android brought back later ran the job with no Prepare behind it: the next game waited, and the pack never reached the library.
- A hang ends the packer's processes first and saves "paused" again once they are gone, since the packer could save "running" in between. The job's reason is "hung" or "ended" (upstream's Job.reasonText has words for them), not "user", so the panel no longer says "You paused the build".
- A hang is no change and no CPU time used by the :pack processes (read from /proc, the forked ones too) for 30 minutes, or no change at all for 3 hours. A step that prints nothing for a while but works is no hang. The clock is uptime, so a phone that slept after the wake locks ended is no hang when it wakes.
- A packer that Android binds again no longer resets the time it went: a new service runs no job. Its last message and save, read in the poll after it went, still count as the old process's, and a packer that runs the job is never gone (a run on a Thor found two crashes within a minute stopped by the 10-minute stall rule, not the 5-minute one).
- An import that hangs gets Retry, not Resume, since what it wrote is deleted. Its watchdog covers the keys and the size probe too. A finished import is kept even when the watchdog asked it to stop. One that does not return 2 minutes after the stop is given up: the game is marked, its .part deleted, and the app's process ends, so the queue goes on when Android starts it again.
- A native crash during the import stops the game at once only when the tombstone says it was in the import's thread (or says nothing), and what the import wrote is deleted. A crash in another thread runs the game again.
- An OutOfMemoryError is logged by its name only, so the log cannot throw again.
- The card no longer says "Free some space, then tap Retry" twice.

Tests: BuildWatchJvmTest drives the watch over time, CPU time, a packer bound again, the order of a stop, /proc from a copy, the import's watch and a tombstone's crashed thread; test_build_queue.py checks the wiring.
davdxpx added a commit to davdxpx/peanuts-native that referenced this pull request Nov 24, 2026
…and a stopped job stays stopped (igawa6#348)

The review of igawa6#555:

- A build with mods has the same watchdog as a build (one helper, Prepare.watch). Before, one that hung held the queue for good, since the queue waits while a build with mods runs. A full disk there is OUT_OF_SPACE too.
- Every watchdog stop keeps the job as paused, also for a packer that ended or stalled. A packer Android brought back later ran the job with no Prepare behind it: the next game waited, and the pack never reached the library.
- A hang ends the packer's processes first and saves "paused" again once they are gone, since the packer could save "running" in between. The job's reason is "hung" or "ended" (upstream's Job.reasonText has words for them), not "user", so the panel no longer says "You paused the build".
- A hang is no change and no CPU time used by the :pack processes (read from /proc, the forked ones too) for 30 minutes, or no change at all for 3 hours. A step that prints nothing for a while but works is no hang. The clock is uptime, so a phone that slept after the wake locks ended is no hang when it wakes.
- A packer that Android binds again no longer resets the time it went: a new service runs no job. Its last message and save, read in the poll after it went, still count as the old process's, and a packer that runs the job is never gone (a run on a Thor found two crashes within a minute stopped by the 10-minute stall rule, not the 5-minute one).
- An import that hangs gets Retry, not Resume, since what it wrote is deleted. Its watchdog covers the keys and the size probe too. A finished import is kept even when the watchdog asked it to stop. One that does not return 2 minutes after the stop is given up: the game is marked, its .part deleted, and the app's process ends, so the queue goes on when Android starts it again.
- A native crash during the import stops the game at once only when the tombstone says it was in the import's thread (or says nothing), and what the import wrote is deleted. A crash in another thread runs the game again.
- An OutOfMemoryError is logged by its name only, so the log cannot throw again.
- The card no longer says "Free some space, then tap Retry" twice.

Tests: BuildWatchJvmTest drives the watch over time, CPU time, a packer bound again, the order of a stop, /proc from a copy, the import's watch and a tombstone's crashed thread; test_build_queue.py checks the wiring.
@davdxpx

davdxpx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@igawa6 Thanks for the review. The fixes are one more commit on each branch: e4fe072 on davdxpx:build-queue-0.1.8 (the version you reviewed) and 920a20c here on build-queue-failures.

The three to fix first

  1. A build with mods has the same watchdog as a build now. It is one helper, Prepare.watch, called from run0 and runModded0. A hang, a packer that ended or a stall ends the build with mods, so waitTurn waits no longer than that. A full disk there is OUT_OF_SPACE.
  2. An import that hangs is OTHER now, so its card offers Retry, which fits its text: what it wrote is deleted.
  3. Every stop keeps the job as paused, the packer-gone stop and the stall too. A packer Android brings back after the 5-minute mark finds a paused job and runs nothing. A job that ended meanwhile keeps its end.

The smaller ones

  • Deep sleep: every watchdog time is uptimeMillis now (the job's, the packer-gone time, the other job's, the import's).
  • The stricter test: a hang is no change and no CPU time used by the :pack processes for 30 minutes. The CPU time is utime + stime + cutime + cstime from /proc/<pid>/stat, with the forked workers found by their command line. Below 1 % of a core counts as idle, since the service's messages use a little. No change at all for 3 hours is still a hang, for a tool that spins. This also covers the steps that print nothing for a while: they use CPU time, so on any game they are no hang.
  • endPacker: paused, then every :pack process ended (the forked ones too), then paused again once they are gone, so a "running" the packer saved in between is undone. Its reason is a new one, hung (and ended for the packer-gone and stall stops). Both are in Prepare.stops, which is now the one list for both loops, and in Job.reasonText (a marked hook, UPSTREAM-EDITS Round 63), so the panel no longer says "You paused the build."
  • onServiceConnected no longer resets the packer-gone time. The rule looks at whether the job changed since the packer went, so a recreated service with no job is found after 5 minutes, and one that goes on with the job is not. A change read within 15 s of the end is still the old process's, and a packer that runs the job is never gone (the Thor run below found that case).
  • A full disk in the packer: the card adds no second sentence when the first line already says "Free some space".
  • The import's hang check comes after the return code, so a finished import is kept.
  • A native crash during the import: the tombstone (getTraceInputStream, tombstone.proto) names the crashed thread. The import's native calls run on a thread named peanuts-import now, and the importer's own threads take the name from it. Only a crash there, or one whose record names no thread, stops the game at once, and the .part it left is deleted. A crash in another thread runs the game again.
  • An OutOfMemoryError is logged by its name only, inside a try, so the log cannot throw again.
  • The import's watchdog covers the keys and the size probe too. An import that does not return 2 minutes after the stop (a call that never looks at it, or a syscall that never returns) is given up: the game is marked in the queue's file, its .part is deleted, and the app's process ends, so the queue goes on when Android starts the service again.
  • Tests: the decisions moved into BuildWatch, so BuildWatchJvmTest drives them: the watch over time with CPU readings and a packer bound again, the order of a stop with a packer that saves "running" between its steps, /proc from a copy, the import's watch on its own thread with a fake clock, and a tombstone's crashed thread. The Android side is still checked by its wiring in test_build_queue.py.

Checked: test_build_queue.py and the other tests that read these files (test_reimport and test_shader_upgrade fail the same way on a clean dev-0.1.8 on Windows), check-min-api.py on the APK, and check-publish.sh.

On an AYN Thor (fake engine, the hang time at 60 s by the fake engine's test file, real imports), a queue of four:

  • Game 1 with NX_FAKE_FAIL on its shader tool: Build stopped (tool_stopped), and game 2 started by itself.
  • Game 2: kill -9 of :pack in its shaders. Android started it again within 3 s, the job went on, and the game was ready.
  • Game 3: SIGSTOP of :pack in its shaders. About 60 s later its processes were ended, job.json said paused, reason hung ("no progress for 60 seconds"), the card said Build stopped, and game 4 started. Built again later, the job went on from where it stopped ("resumed, it was paused").
  • Game 4: kill -11 of the app's process in its Prepare. Android started the service again within 5 s. The log said crash_native, ..., in the thread id.test.peanuts (the tombstone's thread, so not the import's) and "start 2 of 3", and the game was ready.
  • Game 3 again: kill -11 of :pack twice within 12 s, and Android did not start it again. This first fell to the 10-minute stall rule, because the old process's last message, read in the poll after it went, counted as a change. That is fixed in the same commit. With the fix, the build stopped 5 minutes after the second crash with Android's reason (crash_native), and the job was kept as paused (ended).

Not run on the Thor: a full storage, an import that hangs (the importer has no test switch for it), and a long Tears of the Kingdom or Xenoblade X build. Thanks for the run you planned.

@igawa6

igawa6 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks for the quick and thorough follow-up. e4fe072 covers the three things we asked for before landing:

  • The build with mods has the same watchdog.
  • The import-hang card offers Retry.
  • Every stop keeps the job paused.

It covers the smaller points too: uptimeMillis, the CPU-time hang test, the hung and ended reasons, the order of the import's hang check, and the logging. The Thor run in your comment helps a lot.

How it lands. #448 is in 0.1.8, so this branch now conflicts with dev-0.1.9 in 11 files. The two commits on build-queue-0.1.8 (1c1412a and e4fe072) apply cleanly to dev-0.1.9, so we will land those, with you as the commit author. You do not need to rebase this branch.

Before it lands, we will run it on an AYN Thor:

  • a queue of three with a forced failure in the first game;
  • kill -9 of the packer, once and repeatedly, and SIGSTOP as a real hang;
  • kill -9 and kill -11 of the app during an import;
  • a full storage during the import and during the pack step (not in your run);
  • an import that does not return after the stop, which now ends the app's process: we want to see that the queue goes on cleanly when Android starts the service again;
  • a long Tears of the Kingdom build with the screen off on the 8 GB plan.

We will post the results here.

@igawa6 igawa6 added enhancement New feature or request app Peanuts app, launcher, settings, and user interface labels Nov 24, 2026
The build queue's three commits of igawa6#448 are in main already; this keeps
the two failure commits on top of 0.1.8's texts, the same as on
build-queue-0.1.8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Peanuts app, launcher, settings, and user interface enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants