Skip to content

fix(tvos): persist server configuration and sessions - #63

Merged
Quixomatic merged 6 commits into
Quixomatic:mainfrom
SHRIVES93:fix/tvos-session-persistence
Oct 13, 2026
Merged

Quixomatic merged 6 commits into
Quixomatic:mainfrom
SHRIVES93:fix/tvos-session-persistence

Conversation

@SHRIVES93

@SHRIVES93 SHRIVES93 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Fix Apple TV returning to server setup after restarting Airwave. AsyncStorage stores tvOS values in purgeable caches, and failed hydration could route to onboarding with incomplete state.

Store six small session/onboarding values in an allowlisted UserDefaults Expo module, migrate surviving values, acknowledge writes, and offer Retry on storage errors. Logout retains the server; Change Server clears it; current-session 401s require login while transient failures retain state. Other platforms retain their storage backends.

Fixes #64. Separate commits contain the fix and session regressions/CI. Remote navigation is separate in #65.

Validation

  • All physical Apple TV session persistence/recovery acceptance tests pass, confirmed by the contributor.
  • 28 automated session tests, Swift storage checks, and native app typecheck pass on this branch.
  • tvOS Release build and simulator lifecycle/recovery checks passed.
  • Required pnpm check-types was run after a full locked install. It reports errors in unchanged desktop, server, web, site, and tv-tauri code, including Electrobun declarations and missing generated files. CI awaits upstream approval.

A new native binary is required; already-purged settings cannot be recovered. Exact App Store v1.3 source remains unverified. No version, dependency, secrets, or signing changes.

@vercel

vercel Bot commented Oct 11, 2026

Copy link
Copy Markdown

@SHRIVES93 is attempting to deploy a commit to the quixomatic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@SHRIVES93
SHRIVES93 force-pushed the fix/tvos-session-persistence branch from a772043 to f29e839 Compare October 11, 2026 04:01
@SHRIVES93 SHRIVES93 changed the title fix(tvos): persist server configuration outside purgeable caches fix(tvos): preserve sessions and restore remote swipe navigation Oct 11, 2026
@SHRIVES93
SHRIVES93 marked this pull request as ready for review October 11, 2026 04:16
AsyncStorage 2.2.0 stores tvOS values in NSCachesDirectory, where the OS can
remove saved settings. Failed hydration also previously mounted the entry
route with incomplete state and sent configured users back to onboarding.

- Store the six small session/onboarding values in an allowlisted UserDefaults
  Expo module; acknowledge writes and migrate surviving cache values with
  deletion markers. Preserve the keychain-free tvOS workaround and other
  platforms' existing storage backends.
- Gate routing on successful hydration and provide remote/touch Retry on
  storage failure. Surface failed saves, logout, and server changes.
- Clear both credential interfaces on logout while retaining the server.
  Invalidate only the current bearer on 401 and serialize token updates so
  stale responses cannot erase a new login; retain state on transient failures.
- Document migration, storage limits, and the required native binary update.

Validation: native storage and session regressions pass. The user confirms
all physical Apple TV session persistence and recovery acceptance tests pass.
The persistence fix needs regressions that distinguish missing settings from
failed hydration and verify saved state across fresh application processes.

- Add 28 Bun regressions against production session, startup, routing, device,
  credential, and REST modules, substituting native storage/network boundaries.
  Cover migration/cache eviction, restart, invalid sessions, transient failures,
  read/write/cleanup errors, logout, Change Server, and concurrent/stale 401s.
- Check the production UserDefaults implementation with a temporary Swift test
  suite: persist/reopen, deletion markers, allowlist/size/corruption rejection,
  and rollback when synchronization fails.
- Add the native app test command, focused CI for regressions/typechecking and
  Swift checks, and instructions for device validation.

Validation: session regressions and native store checks pass; the user
confirms all physical Apple TV acceptance tests pass.
@SHRIVES93
SHRIVES93 force-pushed the fix/tvos-session-persistence branch from 70f679b to 55e6f82 Compare October 11, 2026 10:48
@SHRIVES93
SHRIVES93 force-pushed the fix/tvos-session-persistence branch from 55e6f82 to 79daca9 Compare October 11, 2026 10:59
@SHRIVES93 SHRIVES93 changed the title fix(tvos): preserve sessions and restore remote swipe navigation fix(tvos): persist server configuration and sessions Oct 11, 2026
…omatic#64)

On tvOS, AsyncStorage lives in a purgeable cache, so the server URL +
session were wiped on reboot and the TV fell back to onboarding. Back those
small values with core RN Settings (NSUserDefaults), the one durable tvOS
store, gated to Apple TV (Platform.OS==="ios" && isTV); empty-string
tombstones handle deletes; a one-time migration carries over surviving
AsyncStorage values. iPad/iPhone/Android unchanged.

Strips the bespoke native Swift module, its CI workflow, and the
multi-process test harness in favor of the built-in Settings module.

Claude-Session: https://claude.ai/code/session_0141ntBdutphMZLw7DW5jUYJ
The real bug is AsyncStorage being purged on tvOS; backing the session with
UserDefaults (via RN Settings) fixes it, and the original boot is correct
again. So drop the parts that overreached beyond persistence: the startup
retry wall, the 401 auto-logout in api.ts, and the token-write serialization
in auth.ts. The app/ screens revert to main byte-for-byte. auth.ts/cred-store
keep only the storage swap plus clearing better-auth's session on sign-out /
Change Server, all gated to Apple TV. Net change vs main is now just the four
storage files.
@Quixomatic

Copy link
Copy Markdown
Owner

@SHRIVES93, thank you for putting this together! You nailed the root cause that had been biting Apple TV: AsyncStorage on tvOS lives in a purgeable cache, so the server and session got wiped on reboot and the TV dropped back to onboarding. That was the hard part to figure out.

I reshaped the solution a bit before merging. What changed and why:

  • Same fix, via React Native's built-in storage. Your UserDefaults call was spot on, it's the one durable small-value store on tvOS. Instead of a dedicated native Swift/Expo module for it, I moved it to RN's built-in Settings module, which already wraps UserDefaults. Same durability, no native pod for us to own and maintain on the (already fragile) from-source-Hermes Apple TV build. The one-time migration from AsyncStorage on first launch is kept.
  • Scoped tight to the persistence bug. I reverted the pieces that went past it, the startup retry screen, the 401 auto-logout, and the token-write serialization, back to how main handles them, so this PR does one thing. Those are all reasonable on their own; happy to look at any of them as a separate PR if you want to take them further.
  • Kept: sign-out and Change Server now clear the full Better Auth session, gated to Apple TV like the rest.

Net result is your fix in its simplest form: the storage swap across four files. I'm merging now so I can cut a TestFlight build and check the power-cycle on a real Apple TV.

Really appreciate you digging into this and raising it the right way. Keep the contributions coming.

Footnote: I may well bring some of those trimmed pieces back in a separate follow-up PR once this lands, where they can get their own focused review rather than riding along with a storage fix.

@Quixomatic
Quixomatic merged commit 150cf76 into Quixomatic:main Oct 13, 2026
1 check failed
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.

tvOS: server configuration and session can be lost after restart

2 participants