Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Counts include settings exposure as separate rows; they are not feature quality
| Catalog lists, search and detail through the BookOrbit integration | ✅ (v0.11.3-rc.17) Cached catalog adapter. [android/koreader/orbit.koplugin/ko/cache.lua:24](../android/koreader/orbit.koplugin/ko/cache.lua#L24) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Catalog cache and facet queries. [xteink/orbify/CatalogRefresh.inc:31](../xteink/orbify/CatalogRefresh.inc#L31) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Catalog cache and facet queries. [xteink/orbify/CatalogRefresh.inc:31](../xteink/orbify/CatalogRefresh.inc#L31) | 🟡 Online catalog; no BookSync offline cache; **hardware: cache uses PSRAM; X3 flash cuts**. [xteink/tailnet/tailnet_build.py:292](../xteink/tailnet/tailnet_build.py#L292) |
| Group every catalog list by series or author | ✅ (v0.11.3-rc.17) Series/author chips and grouped rows. [android/koreader/orbit.koplugin/ko/grouping.lua:40](../android/koreader/orbit.koplugin/ko/grouping.lua#L40) | ❌ Facet lists exist; no group-every-list control; **deliberately deferred: ROADMAP Next 6a**. [xteink/overlay/patches/v2.0/0054-orbify-bulk-catalog.patch:6](../xteink/overlay/patches/v2.0/0054-orbify-bulk-catalog.patch#L6) | ❌ Facet lists exist; no group-every-list control; **deliberately deferred: ROADMAP Next 6a**. [xteink/overlay/patches/v2.0/0054-orbify-bulk-catalog.patch:6](../xteink/overlay/patches/v2.0/0054-orbify-bulk-catalog.patch#L6) | ❌ No grouping control; **hardware: current cached implementation excluded on X3; ROADMAP Next 6a**. [xteink/tailnet/tailnet_build.py:292](../xteink/tailnet/tailnet_build.py#L292) |
| Offline catalog pages and retained book details | ✅ (v0.11.3-rc.17) SQLite cache via companion; local window queries. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/CacheStore.kt:15](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/CacheStore.kt#L15) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Ranked SD rows serve every refreshed list window without Wi-Fi, independent of source page size. [xteink/orbify/CacheStore.cpp:396](../xteink/orbify/CacheStore.cpp#L396) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Ranked SD rows serve every refreshed list window without Wi-Fi, independent of source page size. [xteink/orbify/CacheStore.cpp:396](../xteink/orbify/CacheStore.cpp#L396) | ❌ Online catalog; no refreshed SD windows; **hardware: X3 flash gate; no PSRAM**. [xteink/tailnet/tailnet_build.py:292](../xteink/tailnet/tailnet_build.py#L292) |
| Explicit resumable Full refresh; monotone percentage | ✅ (v0.11.3-rc.17) Refresh tap always refreshes normally; hold offers Full refresh; companion owns queued/active progress and completion stamps without timer-only failure; explicit resumes show immediate startup feedback, missing acknowledgements warn once, and liveness queries back off; Full refresh joins an active incremental bulk run and displays its progress. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt:60](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt#L60) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path. [xteink/orbify/RefreshRunner.cpp:32](../xteink/orbify/RefreshRunner.cpp#L32) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path. [xteink/orbify/RefreshRunner.cpp:32](../xteink/orbify/RefreshRunner.cpp#L32) | ❌ X3 flash gate; no PSRAM; **hardware: X3 flash gate and no PSRAM exclude the bulk catalog worker and its progress counts; Home sync keeps its finish-time stamp; Android companion acknowledgement and startup-repair recovery do not apply to firmware**. [xteink/tailnet/tailnet_build.py:295](../xteink/tailnet/tailnet_build.py#L295) |
| Explicit resumable Full refresh; monotone percentage | ✅ (v0.11.3-rc.17) Refresh tap always refreshes normally; hold offers Full refresh; companion owns queued/active progress and completion stamps without timer-only failure; explicit resumes show immediate startup feedback, missing acknowledgements warn once, and liveness queries back off; Full refresh joins an active incremental bulk run and displays its progress. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt:60](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt#L60) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path; flash-safe internal worker stack; two unfinished attempts stop automatic resume, keeping books, settings and the published catalog; explicit Full refresh retries. [xteink/orbify/RefreshRunner.cpp:32](../xteink/orbify/RefreshRunner.cpp#L32) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path; flash-safe internal worker stack; two unfinished attempts stop automatic resume, keeping books, settings and the published catalog; explicit Full refresh retries. [xteink/orbify/RefreshRunner.cpp:32](../xteink/orbify/RefreshRunner.cpp#L32) | ❌ X3 flash gate; no PSRAM; **hardware: X3 flash gate and no PSRAM exclude the bulk catalog worker and its progress counts; Home sync keeps its finish-time stamp; Android companion acknowledgement and startup-repair recovery do not apply to firmware**. [xteink/tailnet/tailnet_build.py:295](../xteink/tailnet/tailnet_build.py#L295) |
| Bulk manifest, derived lists and batched state reconciliation | ✅ (v0.11.3-rc.17) Bulk catalog plan. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/BulkWork.kt:10](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/BulkWork.kt#L10) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Bulk catalog derived author/series lists. [xteink/orbify/BulkCatalog.cpp:22](../xteink/orbify/BulkCatalog.cpp#L22) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Bulk catalog derived author/series lists. [xteink/orbify/BulkCatalog.cpp:22](../xteink/orbify/BulkCatalog.cpp#L22) | ❌ X3 flash gate; no PSRAM; **hardware: X3 flash gate; no PSRAM**. [xteink/tailnet/tailnet_build.py:295](../xteink/tailnet/tailnet_build.py#L295) |
| Refresh continues away from the catalog; foreground remains usable | ✅ (v0.11.3-rc.17) Companion worker. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt:17](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt#L17) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Separate refresh task. [xteink/orbify/RefreshRunner.cpp:38](../xteink/orbify/RefreshRunner.cpp#L38) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Separate refresh task. [xteink/orbify/RefreshRunner.cpp:38](../xteink/orbify/RefreshRunner.cpp#L38) | ❌ X3 flash gate; no PSRAM; **hardware: X3 flash gate; no PSRAM**. [xteink/tailnet/tailnet_build.py:295](../xteink/tailnet/tailnet_build.py#L295) |
| Saved pages retained indefinitely; silent incremental refresh | ✅ (v0.11.3-rc.17) Companion reconciliation. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt:60](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt#L60), [android/koreader/orbit.koplugin/ko/cache.lua:24](../android/koreader/orbit.koplugin/ko/cache.lua#L24) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Opening does not evict/revalidate; worker incremental requests. [xteink/orbify/CacheStore.cpp:496](../xteink/orbify/CacheStore.cpp#L496), [xteink/orbify/RefreshRunner.cpp:36](../xteink/orbify/RefreshRunner.cpp#L36) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Opening does not evict/revalidate; worker incremental requests. [xteink/orbify/CacheStore.cpp:496](../xteink/orbify/CacheStore.cpp#L496), [xteink/orbify/RefreshRunner.cpp:36](../xteink/orbify/RefreshRunner.cpp#L36) | ❌ X3 flash gate; no PSRAM; **hardware: X3 flash gate; no PSRAM**. [xteink/tailnet/tailnet_build.py:292](../xteink/tailnet/tailnet_build.py#L292) |
Expand Down
6 changes: 5 additions & 1 deletion docs/design/emulated-release-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ series-card cover fetch and no lent connection, so it runs the three that apply
| Scenario | Rows | Readers |
|---|---|---|
| `sync_through_proxy` | foundation | all |
| `mirror_urls` | X5 | X4s |
| `mirror_urls` | X5, flash-safe refresh task stack | X4s |
| `full_refresh_crash_breaker` | two unclean worker boots, durable quarantine, retained books/settings | X4s |
| `full_refresh_sd_card_recovery` | remove the single persisted request, boot without retrying | X4s |
| `full_refresh_early_boot_breaker` | two setup crashes, disable suspect catalog before cache reads | X4s |
| `full_refresh_large_catalog` | 3,000-book full catalog with modeled flash-stack constraint | X4 Pro |
| `copy_refresh_sleep_sync` | X6 | all |
| `copy_refresh_tight_heap` | X6, shared-session heap floors | X4s |
| `heap_floor_waits` | X3 | X4s |
Expand Down
105 changes: 105 additions & 0 deletions docs/design/full-refresh-crash-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Full refresh crash recovery (0.11)

Bug fix for X4 Pro and X4 Classic on main. Android owns its refresh in the
companion; X3 has no bulk catalog worker or PSRAM, so neither uses this task.

## Cause and evidence

The reported firmware is `xteink-v2.0.0.562+bookorbit.1-rc3`. There is no device
log. We can prove an unsafe call path and its boot-loop mechanism; we cannot
identify the exact instruction that panicked on that reader without its log.

`RefreshRunner.cpp` allocated the `orb_catalog` task's 16 KB stack with
`MALLOC_CAP_SPIRAM`. Its `OrbifyBulk::refresh` network callback reaches the
catalog HTTP transport and Tailnet resolver. `TailnetResolver.cpp` calls
`tailnet_ensure_peer`; `Tailnet.cpp` calls `rememberServer` (changed server) or
`storePin` (unknown peer), which synchronously call NVS writes/commit on the
requesting task. These flash operations require an internal stack. ESP-IDF's
`components/spi_flash/cache_utils.c`, `esp_task_stack_is_sane_cache_disabled`,
asserts that the stack pointer is in internal DRAM before disabling the cache.
Ordinary visible-view Refresh uses the main task and avoids this worker-stack
mistake. Full refresh does not run the copy replacement queue; its only
`CopyRefresh` call reads the small library-version token.

[Espressif's external-RAM constraints](https://docs.espressif.com/projects/esp-idf/en/release-v5.5/esp32s3/api-guides/external-ram.html)
explain why PSRAM is inaccessible with the flash cache disabled. The fix uses
an internal stack with the matching task creation/deletion APIs. JSON and numeric
catalog indexes retain their separate PSRAM allocator. Failure to allocate the
stack retains the request and backs off; it does not fall back to an unsafe stack.

The ordinary SDL simulator omits Tailscale and flash-cache restrictions. A baseline
3,000-book run completed (533 requests, 187,801 bytes peak catalog PSRAM), so it
did not reproduce heap exhaustion. The added simulator model runs the synchronous
resolver flash-write constraint at the bulk transport callback. Restoring the old
external stack makes that run fail with exit 87; the internal stack passes. This
is a modeled hardware constraint, not an ESP32 CPU emulation or proof of the
maintainer's specific panic. The large-catalog emulated regression exercises the
actual worker, HTTP parsing and SD adapter with 3,000 books.

## Persistent state and breaker

`/.crosspoint/orbify/mirror.request` survives resets until Full refresh finishes.
The global worker sees it on every boot, without opening the catalog. Bulk staging
markers under `/.crosspoint/orbify-catalog/bulk/` resume the incomplete generation.
A deterministic panic was therefore retried indefinitely; a cold power cycle did
not clear it. Neither NVS nor a book's `.part` file is needed for this loop.

The generic `ResumedWork` guard writes `refresh.inflight` durably before entering
the job and clears it only on ordinary return (success, offline, low heap or
cancellation). Its temporary marker is also checked after a reset during rename;
malformed markers fail closed. After two runs never return, the next boot blocks
a third. `mirror.request.crashed` blocks automatic incremental work across later
boots too. The request and bulk stage marker (including `.bak`/`.tmp`) are removed.
Published catalog generations, books, reading state and settings remain. Only an
explicit Full refresh or credential change clears the breaker; explicit refresh
starts a fresh staging generation. A storage failure that prevents recording an
attempt prevents starting the job.

A second marker, `refresh-boot.inflight`, brackets setup while refresh state is
pending. After two incomplete setups the recovery hook runs immediately after SD
mount, before settings/catalog/activity restoration. It also quarantines the bulk
`active` pointer as `active.crashed` and removes its backup, preventing the suspect
catalog from being decoded on that boot. The generation bytes remain on SD.

Host tests cover marker writes/renames, cold-boot instances, corrupt markers and
normal pauses. The emulated release scenario injects two abrupt process exits,
boots twice with the same fault still enabled, checks no network job runs and
verifies retained bytes, then retries through the real X4 Pro Home hold gesture.

## Recover the already installed firmware

1. Power the reader off/reset it as needed, then remove the SD card. In a card
reader, enable showing hidden files. From the **SD root**, delete only
`/.crosspoint/orbify/mirror.request`.
2. Reinsert the card and restart. This removes the automatic Full refresh request;
keep using ordinary Refresh and avoid Full refresh until installing a tested fix.
Do not delete `/.crosspoint`, `bookorbit.json`, `wifi.json`, books or reading
state, and do not erase NVS. The bulk stage files alone do not schedule work.
If it still fails while restoring the catalog, rename only the metadata folder
`/.crosspoint/orbify-catalog` to `/.crosspoint/orbify-catalog.recovery` on the card
and restart. This hides all bulk pointers/backups together and preserves their
bytes for inspection. Books and settings live elsewhere and remain intact.
3. Once booting, OTA can install a subsequently published fixed firmware through
the normal update screen/channel. This change publishes no firmware. A test
artifact is not offered by OTA; install a matching X4 Pro test image through
SD firmware update or the maintainer-operated USB sideload workflow.

There is no verified button-only way to cancel the persisted request in .562, and
no guaranteed interval in which Settings/OTA can be reached before the crash.
Booting without the SD card prevents this SD-backed request from running, but is
not a repair of the card and cannot supply the SD staging required for updates.
The existing **Down + Power** power-button-wake chord opens the SD `.bin` firmware
picker, but .562 still calls the global refresh scheduler in that mode. Do not
rely on that chord alone to outrun the worker: remove the request on the card first.
Afterward, a matching `.bin` already on the card can be selected there; USB is not
required when an SD card reader is available.

Upstream recovery evidence at CrossInk commit
`87e2e1984481e8a3d996f12b34b50a383f9013b8`:
`src/main.cpp:1830-1837` selects Down on the S3 readers and requires a power-button
wake; `src/main.cpp:2128-2131` chooses `SdFirmwareUpdateActivity`;
`src/activities/settings/SdFirmwareUpdateActivity.cpp:26-30` opens the root picker
restricted to firmware. BookSync's patch 0053 adds the unconditional global
`OrbifyMirror::service()` call to `loop()`, explaining why recovery mode does not
cancel the request. These line references are for the unpatched pin; the overlay
moves the resulting source lines.
4 changes: 2 additions & 2 deletions shared/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
},
"x4_pro": {
"status": "supported",
"note": "Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path",
"note": "Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path; flash-safe internal worker stack; two unfinished attempts stop automatic resume, keeping books, settings and the published catalog; explicit Full refresh retries",
"reason": null,
"evidence": [
{
Expand All @@ -221,7 +221,7 @@
},
"x4": {
"status": "supported",
"note": "Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path",
"note": "Refreshed SD lists serve browser windows offline; live list, book and cover counts; finish-time BookSync stamp; runs in firmware without an Android companion or companion acknowledgement path; flash-safe internal worker stack; two unfinished attempts stop automatic resume, keeping books, settings and the published catalog; explicit Full refresh retries",
"reason": null,
"evidence": [
{
Expand Down
8 changes: 8 additions & 0 deletions xteink/orbify/BulkCatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <esp_heap_caps.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#ifdef SIMULATOR
#include <orbify_sim_flash.h>
#endif
#include <atomic>
#include <cstddef>
#include <cstdio>
Expand Down Expand Up @@ -166,6 +169,11 @@ bool refresh(bool fresh,bool (*cancelled)(),const std::function<void(unsigned)>&
const auto start=millis();
const bool ok=catalog.refresh(owner(),[&](const std::string& path,JsonDocument& out){
if(!OrbifyHeap::roomForRequest("Full refresh"))return false;
#ifdef SIMULATOR
// The simulator omits Tailscale. Inject its synchronous resolver-side
// rememberServer/storePin NVS write, with ESP-IDF's cache-disabled stack rule.
orbify_sim_flash::write();
#endif
fetching.store(xTaskGetCurrentTaskHandle());
const bool result=BookOrbitCatalogClient::fetchBulk(path+(path.find("/manifest?")!=std::string::npos?"&deviceId="+orbify::bulk::encode(BookOrbitSyncClient::deviceId()):""),out);
fetching.store(nullptr);return result;
Expand Down
Loading
Loading