Skip to content

fix: clean paired-tab pending requests, add reaper gap tests, buffer … - #715

Open
ajulaybeeb wants to merge 2 commits into
Vellar-Wallet:devfrom
ajulaybeeb:feat/585-694-700-701-background-cleanup-tests
Open

ajulaybeeb wants to merge 2 commits into
Vellar-Wallet:devfrom
ajulaybeeb:feat/585-694-700-701-background-cleanup-tests

Conversation

@ajulaybeeb

Copy link
Copy Markdown

Summary

This PR resolves 4 related issues across the extension, worker service, and Soroban attestation registry:

Why

  1. [medium] apps/extension/entrypoints/background.ts - add explicit cleanup when a paired tab closes mid-request #585: If a dApp tab initiates a request (e.g. connect, pair, sign_transaction) and the user closes the tab before responding in the approval popup, the pending request state leaked indefinitely in memory. Furthermore, closing the tab while signing is actively in-flight risked leaving dangling promises or uncaught errors.
  2. [medium] services/worker-service/src/cleanup.ts - add a test for the stranded-building-row reaper encountering a row that was manually edited to look fresh #694: The worker service uses an age-based reaper (reapStranded) to reclaim orphaned building jobs based on updated_at / startedBuildingAtMs. If an operator or script touched updated_at on a stuck job, staleness was deferred. The repository needed explicit test coverage and documentation establishing this as an accepted tradeoff against distributed heartbeating.
  3. [medium] apps/extension/lib/buffer-polyfill.ts - add a test confirming parity with Node's Buffer for the specific operations the extension actually uses #700: MV3 service workers lack Node globals, relying on buffer-polyfill.ts for @stellar/stellar-sdk and internal signing logic. A formal enumeration and unit test suite were needed to verify that all operations used by the extension behave identically to native Node Buffer.
  4. [hard] contracts/attestation-registry - add a test for two attestation writes for the same contract id arriving in the same ledger from different authorized attestors #701: In Stellar/Soroban ledgers, transactions are executed deterministically. If two authorized attestors write conflicting WASM hashes for the same contract ID within the same ledger, the contract's resolution rules needed verification to guarantee deterministic state outcomes.

Implementation

1. apps/extension (Issue #585)

  • Created PairedTabManager:
    • Tracks pending approval requests paired with their initiating tab IDs (tabId).
    • Tracks in-flight requests that have received user approval and are awaiting cryptographic execution.
    • Listens to browser.tabs.onRemoved: rejects pending requests from the closed tab with rejected: "The initiating tab was closed" and deletes them from the queue.
    • If the pending queue drains completely, automatically requests closing the open approval popup window (approvalWindowId).
    • If a tab closes while an approval is in-flight, marks the in-flight resolution and completes cleanly without throwing unhandled exceptions or dangling promises.
    • Replaces manual map handling in background.ts.
  • Added unit tests in paired-tab-manager.test.ts.

2. services/worker-service (Issue #694)

  • Documented age-based timestamp semantics and the accepted gap in cleanup.ts.
  • Added unit tests in memory-job-store.test.ts:
    • Verified that a genuinely fresh row is not reaped within the timeout.
    • Verified that an artificially updated timestamp on a stranded row defers reaping (accepted gap).
    • Verified that once the timeout elapses past the modified timestamp, the reaper reclaims the job.
  • Added test in cleanup.test.ts confirming non-terminal building rows are never touched by ETL cleanup regardless of timestamp.

3. apps/extension (Issue #700)

  • Enumerated in buffer-polyfill.ts all Buffer operations utilized across apps/extension (Buffer.from string/Uint8Array/ArrayBuffer/hex/base64/utf8, toString("hex"), toString("utf8"), toString("base64"), slice/subarray, byteLength, concat, alloc, empty inputs, and large 128KB payloads).
  • Added buffer-polyfill.test.ts asserting byte-level parity between Buffer from "buffer" and Node's node:buffer.

4. contracts/attestation-registry (Issue #701)

  • Documented same-ledger write resolution in lib.rs: Soroban sequential execution guarantees Last-Write-Wins (LWW) for authorized attestor writes, while de-authorized attestor writes fail with auth errors.
  • Added unit tests in test.rs:
    • same_ledger_conflicting_writes_resolve_last_write_wins: Attestor A writes, rotates to Attestor B in the same ledger, Attestor B writes a conflicting WASM hash; confirms the final state reflects Attestor B's hash and expiry, and subsequent writes by Attestor A fail with auth errors.
    • same_ledger_conflicting_attributed_writes_resolve_last_write_wins: Same-ledger conflict resolution with publisher attribution.

Testing

Commands executed:

  • corepack pnpm --filter @vellar/extension test: 12 test files passed, 115 tests passed (including paired-tab-manager.test.ts and buffer-polyfill.test.ts).
  • corepack pnpm --filter @vellar/extension typecheck: Clean (tsc --noEmit exited 0).
  • corepack pnpm prettier --check: Clean (All matched files use Prettier code style).
  • corepack pnpm --filter @vellar/worker-service test src/cleanup.test.ts src/memory-job-store.test.ts: 2 test files passed, 15 tests passed.
  • cargo test in contracts/attestation-registry: 19 tests passed, 0 failed (including both same-ledger conflicting write tests).

Note: Full worker-service suite has 3 pre-existing failures in src/attestor.test.ts present on upstream dev branch due to a duplicated call to deps.submitter.upsert; our changes did not touch attestor.ts.

Scope / Risk

  • Affected areas: Extension background service worker request lifecycle, worker-service cleanup tests/docs, buffer polyfill test suite, and attestation registry unit tests.
  • Breaking changes: None. All changes preserve existing API signatures and behavior.

Issue

Closes #585
Closes #694
Closes #700
Closes #701

…parity, and same-ledger attestation tests (Vellar-Wallet#585, Vellar-Wallet#694, Vellar-Wallet#700, Vellar-Wallet#701)

- apps/extension: add PairedTabManager to clean pending requests and cancel popup prompt on tab close, handle post-approval tab closing cleanly (Vellar-Wallet#585)
- apps/extension: enumerate Buffer operations and add strict parity unit tests with Node Buffer (Vellar-Wallet#700)
- services/worker-service: document age-based timestamp semantics and add tests for stranded building row reaper encountering artificially refreshed vs genuinely fresh rows (Vellar-Wallet#694)
- contracts/attestation-registry: document deterministic same-ledger conflicting writes resolution and add Soroban unit tests confirming last-write-wins (LWW) (Vellar-Wallet#701)
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@ajulaybeeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@AbuJulaybeeb is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment