Skip to content

Epic: Wavelength application integration and storage exploration #77

Closed

Description

@darioAnongba

Summary

Establish what developers need to embed Wavelength reliably in an existing application. Use a working native iOS app and targeted experiments in React Native, Android, web apps, and browser extensions to expose SDK, storage, lifecycle, and UX gaps. Record architectural decisions with evidence and deliver focused fixes in the repositories that own them.

Start from wavelength-mobile#6, paired with Wavelength v0.1.2. The native Swift app is the first integration baseline. Other platforms get focused probes where they answer a remaining question.

Current status — 2026-09-16

The native Swift app builds and runs with the published Wavelength v0.1.2 framework, using Xcode 26.2 and an iPhone 16 Pro Simulator on iOS 18.5. PR #6 now includes funded testing with two isolated native wallets.

Check Result
Automated baseline Passed at PR #6 commit cbff9bd: 14 unit tests plus the opt-in signet UI smoke test (53.8 seconds); three regtest tests skipped. The live check covers receive requests, invoice paste/review, foreground recovery, and process relaunch
Storage coexistence and relocation Passed at PR #6 commit 5fc9c99: 14 unit tests plus one isolated live storage probe (25.7 seconds). A host SQLite write transaction remained open during wallet operations; moving the closed managed directory preserved identity and the original invoice. Idle stop: 0.024 seconds; reopen/unlock/readiness: 2.279 seconds, a single Simulator observation
Funded boarding Two deposits totaling 1,224,348 sats confirmed at height 322191; the Ark round confirmed at 322192, producing 1,223,838 spendable sats
Send and receive A 25,000-sat BOLT11 invoice completed on both wallets using the In Ark route, with zero payment fee and matching balance changes
Receiver process absent A 10,000-sat return payment waited for a claim while the receiver was terminated; relaunching the existing wallet completed the same payment exactly once on both sides
Final test balances Primary 1,208,838 sats; isolated peer 15,000 sats
External Lightning Still unverified. The earlier 1,500-sat faucet reported sent, but the native receive remained unfunded; internal Ark settlement does not establish external Lightning routing
Chrome extension PR #81, commit a8ac8eb: six local extension tests passed (16.5 seconds), including real v0.1.2 wallet/invoice reopen against mocks after owner destruction and browser restart. Separate OPFS and app storage coexist; competing owners are rejected
Bounded ingress foundation Draft engine PR wavelength#1329, commit abf6e05b: deadline/batch-limited ingress, exclusive ownership and pause/resume. SQLite recovery tests, full connector race tests and the VTXO send system test passed locally. This API is not yet exposed through the mobile SDK
Device/background execution Physical-device behavior, OS-driven wake, network-loss recovery, and interruption at other operation phases remain unverified

The native integration log records the evidence, storage observations, and remaining test sequence.

Findings and disposition:

  • Fixed in PR core/web: expose server-assisted recovery in createWallet #6: compatible Simulator selection, XCTest environment forwarding, neutral expired-invoice presentation, independent Paste/Scan actions, bounded invoice-editor height, and the system paste control on iOS 16+.
  • Engine follow-up: sumDepositsByAddress sums amounts but retains one input's fee. The combined deposit displays 417 sats, while the ledger and funding-to-balance difference show 510 sats; the other input's 93 sats are omitted from the displayed fee. Track this as a focused engine correction, with a regression for summed amount/fee and persisted-activity repair. Related work: wavelength#866, wavelength#994. The framework stays pinned to preserve this integration baseline.
  • Startup readiness follow-up: the isolated probe reached WalletReady before indexer initialization, and an immediate receive failed. The probe now waits for wallet readiness plus server connectivity before its single request. Clarify operation readiness and apply suitable guards to host actions in a focused follow-up; do not retry state-creating calls as readiness probes. This is deferred from the storage-only change to keep the readiness behavior independently reviewable.
  • Storage/recovery follow-ups: daemon SQLite defaults to WAL/NORMAL while swaps use WAL/FULL; process recovery does not prove power-loss recovery after remote acknowledgement. The sample wallet password uses a device-only Keychain item, so restoring wallet files to another device cannot assume that password follows. Backup/export, durability policy and a true caller-database adapter remain open pending the recovery-contract experiments below.
  • Fixed in SDK PR #81: Manifest V3 rejected verified bootstrap scripts executed through blob URLs. Same-extension packaged scripts now retain digest checks and execute their installed URLs; ordinary web URLs keep exact-byte blob execution. Both runtime modes boot and reject modified bootstrap bytes.
  • Next funded probes: external Lightning routing, on-chain withdrawal, network interruption, and delayed recovery at additional phases. OS wake remains a separate platform investigation, with physical-device validation for real suspension and locked-device behavior.

Existing work to build on:

Acceptance criteria

Updated 2026-09-16: split the original broad criteria into verifiable steps so partial progress is visible. A checked item means the stated experiment or implementation was validated at the linked commit; draft PRs still require review/merge. It does not establish production background execution or completion of the broader lifecycle/storage contract.

  • Reproduce the Swift app build and tests against the pinned v0.1.2 framework; document the toolchain and commands. Evidence: mobile PR #6.
  • Exercise create/unlock, fund/board, send, receive, activity and restart against signet. Recorded payments used the In Ark route; external Lightning remains unverified. Evidence: native integration log.
  • Verify the tested receiver-process-absent scenario: relaunch the existing wallet and complete the original pending payment once, with matching history/balances. This covers that scenario, not all interrupted operation phases.
  • Extend recovery tests to network interruption, ambiguous outcomes and additional payment/signing phases; verify no duplicate financial actions or premature input release. Complete the broader foreground/background transition coverage.
  • Inventory the existing managed stores and record the working recommendation: engine-owned persistence alongside the host's business data, with host-controlled location/protection/lifecycle. Evidence: storage investigation.
  • Run a bounded native storage experiment: coexist with an open host SQLite write transaction, close serially, relocate the managed directory and reopen the original wallet/invoice. Evidence: mobile PR core/web: expose server-assisted recovery in createWallet #6 at 5fc9c99.
  • Complete the caller-owned storage contract: backup/export and key availability, power-loss durability, schema upgrade/recovery and ownership/close rules. Test or explicitly disposition shared authoritative-database injection; managed-directory coexistence does not prove that adapter.
  • Run the targeted Chrome-extension probe and fix the packaged-runtime bootstrap issue. Verify exclusive ownership and original wallet/invoice recovery after offscreen-owner loss and browser restart against mocks. Evidence: SDK PR #81 at a8ac8eb; funded payments and natural OS scheduling remain unverified.
  • Compare native Swift integration with the React Native demo and validate the embedded SDK on Android. Reproduce and resolve wavelength#1351; require real engine startup, database migrations, wallet create/unlock, a persisted write, process termination and reopen through the packaged AAR. Cover the reported API 34 x86_64 emulator and ARM64, and record runtime evidence for every ABI advertised as supported. Opening the demo UI or successfully building the AAR is insufficient. Background execution remains a separate criterion below.
  • Implement and locally validate bounded connector ingress, internal durable cursors, duplicate-wake exclusion and pause/resume. Exercise rollback/reopen around dispatch and ACK. Evidence: engine PR #1329 at abf6e05b. This is an ingress primitive; existing in-memory routes remain volatile, and review/CI acceptance is separate below.
  • Establish the full wallet lifecycle contract: durable consumer/operation handoff, runnable actor work, egress, peer responses, locked/unavailable keys or storage, bounded maintenance/close and actionable results. Expose the resulting wake API through the SDK and target lifecycle bindings; an empty mailbox is not wallet completion.
  • Validate platform notification/lifecycle integration and foreground catch-up on the chosen mobile and extension targets. Include delayed/missed/duplicate wakes and physical-device suspension/locked-device behavior; simulated callbacks do not establish real OS delivery guarantees.
  • Record a reviewable bindings-repository recommendation covering version pairing, releases, CI, ownership and example placement.
  • Triage remaining browser WASM performance issues and attach reproducible before/after measurements to completed fixes.
  • Complete the findings disposition/review pass: every actionable finding has a focused issue/PR or explicit deferral with its reason, and each completed implementation has its review/CI status recorded. The linked changes remain draft PRs.

Storage investigation

The embedded wallet currently owns multiple stores: daemon/Ark/activity/actor state in SQLite, separate swap-session SQLite state, and btcwallet key/on-chain state in native bbolt or browser SQLite/OPFS. The mobile configuration exposes paths, not a complete caller-provided storage implementation.

Distinguish three integration needs:

  1. Host-controlled location, protection, backup, and lifecycle for Wavelength-managed stores.
  2. Reusing a host application's SQL database while Wavelength owns its tables and migrations.
  3. Adapting an existing persistence implementation, such as Core Data, Room, IndexedDB, or a custom store.

For each, establish transaction/durability requirements, connection and migration ownership, concurrency rules, and the cross-language API. Identify state reconstructible from seed, chain, or server and state that requires backup. Test interrupted operations, reopen/recovery, and schema upgrades. Also distinguish sharing authoritative wallet persistence from projecting wallet activity into the app's own business database.

The initial hypothesis is managed storage by default with an explicit host-integration boundary. A generic get/set interface is not an accepted design: it must first demonstrate the atomic checkpoint and outgoing-work guarantees required by the wallet.

Native storage probe and working recommendation — 2026-09-15

The storage and lifecycle investigation records the source audit, proposed host contract and reproducible make test-storage-signet probe. It uses a disposable unfunded wallet, never the sample app's Keychain, and verifies independent app-database coexistence plus relocation after a serialized close. Both funded wallets retained their balances and original completed payments after the probe.

Keep managed stores as the default and let the host own their location/protection/lifecycle. An app can maintain its own business-data projection through public wallet APIs. Sharing the app's database for authoritative wallet state remains a separate engine capability; db.NewStore is not an injection path through the embedded daemon or native ABI.

Next bounded storage experiment: introduce a Go store-construction seam and test engine-owned migrations on a caller-created SQL database, explicit connection ownership, atomic checkpoint/outbox rollback, host writer contention, cancellation, close and reopen. Keep the separate swap/key stores visible. Resolve power-loss recovery and consistent backup semantics before promising a generic cross-language store adapter. The storage acceptance item stays open for these unproven boundaries.

Chrome extension probe and revised priorities — 2026-09-15

PR #81 adds a focused extension fixture and the bootstrap-loading correction it exposed. The probe report records the manifest, commands, ownership boundaries and evidence.

An offscreen document owns the dedicated wallet worker; the popup and service worker can be replaced independently. The real WASM wallet retained its identity and original invoice after offscreen-owner destruction and browser restart with the same disposable profile and original password. The host business record stayed in chrome.storage.local. A competing SDK client returned wallet_locked; the lower-level OPFS fixture also rejected a competing access handle.

This supports managed Wavelength stores alongside app-owned data in Chrome extensions as well as native mobile apps. The extra extension constraints are origin-wide storage/quota, a single runtime owner, worker lifetime, packaging/CSP and credential availability. A generic IndexedDB adapter is not needed for this demonstrated integration. Prioritize managed-storage lifecycle/backup guarantees and the bounded pump; shared authoritative-database injection remains a separate experiment.

Verification: six extension tests (16.5 seconds), eight existing web smoke tests (59.7 seconds), 168 web unit tests, package build, workspace typecheck and docs build passed locally. The browser tests use mocked services and remain local checks. Hosted build and pinned-runtime availability checks passed on PR #81. The automated Claude review failed during OIDC token setup before reviewing the change; it is not a code-review finding.

Limits: no funded extension payment, natural idle-scheduling measurement, power-loss/device-loss recovery, extension-update test, quota/eviction test, or production background credential policy. The test supplies the password again after owner loss and forbids automatic creation on reopen. Firefox and Safari remain separate probes.

Background lifecycle investigation

Background work is a core integration requirement. Enumerate the operations that must progress while the UI is absent, including mailbox processing, payment reconciliation, refresh, and recovery, with their deadlines and consequences of delayed execution.

Build on wavelength#802. Specify bounded wake-and-drain, durable checkpoints before acknowledgement, cancellation/retry, duplicate wakes, key availability while locked, and foreground catch-up. Evaluate iOS, Android, browser-extension workers, and ordinary web pages separately. Wakes must not be assumed guaranteed; document the fallback when execution is delayed or unavailable. A foreground restart test does not establish background execution support.

Simulator is useful for APNs integration: supported Apple silicon/T2 Macs can receive real APNs sandbox notifications, as documented in Apple's Xcode release notes. Notification handling can be developed there; physical-device tests are still needed for actual suspension, power-saving, locked-device access and delivery behavior. APNs registration/delivery and a bounded pump have not yet been implemented in this sample.

Bounded ingress foundation — 2026-09-15

Draft wavelength#1329, commit abf6e05b, adds Runtime.PumpIngress with a required deadline and positive batch limit. It reuses the existing transactional dispatch/checkpoint path and keeps cursors internal. Foreground polling and pumps share one owner; PauseIngress cancels and joins that owner, including startup checkpoint loading, before a later invocation. Duplicate invocations return ErrIngressBusy; terminal stop closes admission.

The host-ingress contract distinguishes an empty remote mailbox from completed wallet work. Tests use isolated SQLite stores and scripted transports to cover rollback before commit, timeout after commit before ACK, successful ACK followed by checkpoint failure, reopening, partial dispatch, batch limits, duplicate wakes and cancellation during startup. Local verification passed: full connector race suite (9.348 seconds), focused pump tests with trace logging (0.963 seconds), VTXO send system test (12.37 seconds), formatting, lint (zero issues), module-tidy and commit-message checks. Hosted CI update (2026-09-16): all other reported checks passed, including SQLite/PostgreSQL system tests, but the race-test job failed after its self-hosted runner lost communication. No failed test step was recorded and its log was unavailable. That job has been retried; CI acceptance remains pending. The native and extension examples remain on their v0.1.2 baseline.

The remaining consumer boundary is material: some existing routes use in-memory actor handoffs. A committed mailbox cursor does not make those actors' operation state durable. The pump preserves existing routing semantics; the SQLite recovery evidence applies to durable handoffs. Establish durable operation acceptance/reconciliation for volatile routes before treating a pump return as safe wallet suspension.

Next, coordinate actor and outbound work under the host budget, including unavailable keys/storage, pending peer responses and interruption after durable progress. Define bounded maintenance and storage-close behavior as part of that scheduler; context cancellation alone cannot impose a hard wall-clock deadline on an uncooperative handler or driver. Then expose the wallet-level wake API through the SDK and drive the same scheduler from APNs/other platform notifications. The background lifecycle acceptance item remains open.

Android embedded storage blocker — 2026-09-24

Wavelength #1351 reports a SIGSYS/seccomp process kill when the v0.1.2 embedded daemon first opens SQLite on an API 34 x86_64 Android emulator. The earlier reference-demo run only opened the UI and did not start the daemon. ARM64 reproduction is not yet established by that report. This is reported failure evidence plus source inspection; we have not reproduced the crash locally or validated a replacement driver.

The Android comparison criterion above is now required. The immediate proposed fix is an Android-compatible SQLite driver selected at build time behind the existing db.OpenSQLiteDatabase boundary, which is shared by the daemon and swap stores. github.com/mattn/go-sqlite3, built with the Android NDK, is a candidate with documented Android support. Verify per-connection pragmas, immediate transactions, error classification, migrations, backup/reopen and SQLite-version compatibility; replacing the opener import alone is insufficient. The native migration adapter also imports modernc and needs platform-specific selection or an appropriate driver-neutral implementation. Current main uses modernc SQLite v1.59.0/libc v1.75.7 after #1348; inspection of the Android/amd64-selected libc sources still finds the raw SYS_lstat path. That dependency upgrade is not Android runtime validation.

Add an instrumented application smoke test that actually starts the engine through the AAR and exercises storage under Android's app sandbox, then make it a gate for relevant changes and Android artifact publication. Start with the reported x86_64/API 34 environment and ARM64; validate every shipped supported ABI and document the tested API levels. Include fresh initialization and reopening an existing database. Use the existing mobile SQLite/storage tests to guard behavior on iOS and other targets.

The broader caller-owned storage investigation remains open. Platform driver selection and host ownership of the authoritative database are separate contracts. Managed storage alongside host business data remains the working default; this Android failure demonstrates that the default needs platform validation. Optional compiled-in adapters can later support host-selected storage once migration, transaction, durability and close ownership are defined across all stores. #1216 concerns the btcwallet database backend and does not itself replace Android's SQLite driver.

Decisions and delivery

Keep this body current; use dated comments for reproducible findings and link longer decisions to reviewed repository Markdown. Each decision records the question, options, evidence, recommendation, and remaining limitations.

Initial working choices:

  • Reuse PR #6 and start with native Swift.
  • Treat React Native's native gomobile transport separately from browser WASM.
  • Evaluate consolidating consumer bindings in wavelength-sdk while keeping the Go facade/builds with the engine; use wavelength-mobile#1 as the starting proposal.
  • Use this issue and reviewed documents initially. Add a litbucket presentation only when the accumulated material needs one.
  • App Store delivery, a full app on every platform, and executing a repository migration are follow-up decisions rather than prerequisites for completing the exploration.
Repository PR Status Purpose
wavelength-mobile #6 Draft/open Native Swift wallet and reproducible v0.1.2 integration baseline
wavelength-sdk #81 Draft/open MV3 packaged runtime loading and reproducible extension storage/recovery probe
wavelength #1329 Draft/open Bounded mailbox ingress and exclusive foreground/pump ownership; wallet scheduler and SDK integration remain open

Activity

  1. darioAnongba commented on Nov 23, 2026

    @darioAnongba
    ContributorAuthor

    closed, to be revisited in the context of daemon removal.

  2. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions