Skip to content

fix: harden automatic allowance payments - #1738

Merged
ovitrif merged 17 commits into
masterfrom
fix/allowance-autopay-hardening
Nov 2, 2026
Merged

ovitrif merged 17 commits into
masterfrom
fix/allowance-autopay-hardening

Conversation

@ovitrif

@ovitrif ovitrif commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Twin: synonymdev/bitkit-ios#1175

Automatic allowance payments now also check state the wallet keeps itself, and backs up with the wallet, before they pay.

Description

  • Ledger revision floor: the wallet remembers the highest allowance ledger revision it has read per identity, and raises it on each read in automatic payment and recovery. While the ledger served is below that floor, or missing after one was read, a covered request stays on the manual flow and recovery leaves the ledger as it is. The check runs inside reconciliation, before anything is written (so auto-pay, recovery and manual reporting all stop on such a ledger), on the capacity read, and in the limit check used while the node cannot pay yet. A floor that cannot be saved also keeps the request manual.
  • Local spending: each automatic attempt is saved with its reservation, before the handoff, as a spend of its allowance; a failed attempt stops counting, also after its journal entry was trimmed. The monthly limit check counts each attempt of the ledger and of the wallet once, by attempt id, so attempts missing on either side still count. Spends are kept for 62 days, two of the longest monthly windows, so the 200-entry journal is not needed for this.
  • Ended allowances: the wallet remembers allowances it has seen ended or declined, saved before an End is sent and on every refresh that lists one. Such an allowance never pays automatically again, and an End saved while an attempt was being admitted stops that attempt before the handoff. The request stays manual, so it reaches the Send sheet.
  • Paid requests: a request the wallet's journal holds in any stage but failed never pays automatically again.
  • Recovery: an attempt the ledger still shows as prepared while the journal shows it sent is left as it is, so its spend keeps counting.
  • Unreadable state: allowance state this build cannot read is never replaced by a save; a restore may still replace it.
  • Paused payments: while the ledger is behind the wallet, the Allowances tab shows "Automatic payments paused" with Resume, and covered requests ask for approval. Resume asks for the payment PIN when payments require one, then takes the ledger read now; the wallet's own spends, paid requests and ended allowances still apply.
  • Backup: the floor, the spends and the ended allowances travel in the wallet backup's allowance state (ledgerRevisionFloor, automaticSpends, endedAllowanceIds; the same wire format as fix: harden automatic allowance payments bitkit-ios#1175). Restore merges them with any already stored: the higher floor, every spend and every ended allowance, so a restore never weakens them, and the restored wallet applies the same checks. A backup taken without Paykit SDK state restores without the floor, since the floor only holds next to the ledger it was read from.

Out of Scope

None.

Design

N/A — no design available.

Preview

Allowances tab with automatic payments paused, Resume tapped, and the notice gone (Android emulator, regtest):

Paused Resume Resumed
android-resume-2x.mp4

QA Notes

Setup

N/A — no device testing required: the checks change behaviour only when the allowance ledger read back is older than one the wallet already read, which no journey can produce. Existing allowance journeys cover the unchanged paths.

Journeys

N/A — the paused notice appears only when the allowance ledger read back is older than one the wallet already read, which no journey can produce; unit tests cover it.

Manual Tests

N/A

Automated Checks

  • updated PaykitAllowanceExecutorTest.kt — a floor that cannot be saved keeps the request manual; while the node cannot pay, a ledger behind the wallet hands the request back without Limit Reached; a ledger below the floor, one that drops below it during admission, or one missing after one was read keeps the request manual; an automatic payment raises the floor; local spending above the ledger's keeps the request manual; a spend counts until its attempt fails; an allowance seen ended never pays automatically; recovery drops the spend of a failed attempt the journal no longer holds; spending the ledger lacks adds to the ledger's own; a request this wallet already paid stays manual; recovery keeps a sent attempt the ledger still holds as prepared; resuming takes the ledger read now while the wallet's own spending still counts; an End started during a handoff reaches the SDK after it
  • updated BackupRepoTest.kt — a wallet restore without Paykit SDK state drops the floor and keeps the spends and ended allowances; one with SDK state keeps the floor
  • updated PaykitAllowanceStoreTest.kt — restore never lowers the floor and keeps every spend and ended allowance already stored; a save never replaces state this build cannot read
  • updated PaykitAllowanceTest.kt — capacity counts the ledger's and the wallet's payments together, each once
  • updated PaykitAllowanceStateBackupTest.kt — the golden wire format carries the floor, the spends and the ended allowances
  • updated AllowancesViewModelTest.kt — resuming automatic payments asks for the PIN first when payments require it
  • added AllowancesScreenTest.kt — tapping Resume on the Allowances tab shows the PIN check and resumes once it passes; back leaves payments paused; leaving the screen drops a pending PIN check; a tap on the PIN check never reaches the screen beneath it

Evidence

  • just compile, just test and just lint pass on this head.

Gaps

  • The paused state needs a ledger older than the wallet's floor, which staging cannot serve; the Preview run raised the floor with a local debug-only hook (not in this PR), and everything after it, including detection, the notice and Resume, ran this PR's code. The other changes have no device run: see Setup.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium)
  • Implementation: claude-opus-5-5 (reasoning: medium)
  • Review: claude-sonnet-5-5 (reasoning: Not exposed)

The review subagent's reasoning setting is not in the session metadata.

@ovitrif ovitrif added this to the 3.1.0 milestone Oct 30, 2026
@ovitrif ovitrif self-assigned this Oct 30, 2026
@ovitrif
ovitrif force-pushed the fix/allowance-autopay-hardening branch from 09f07b7 to 4f8ae14 Compare October 30, 2026 13:51
@ovitrif
ovitrif marked this pull request as ready for review October 30, 2026 14:00
@ovitrif
ovitrif requested review from a team, ben-kaufman and pwltr and removed request for a team October 30, 2026 14:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T14:04:01.650681Z 4f8ae14 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif
ovitrif requested review from piotr-iohk and removed request for pwltr October 30, 2026 14:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f8ae14822

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 1/5

[Critical impact] The changes affect automatic Bitcoin payments and how their limits are tracked.

Fix the lost payment checks, reconciliation order, failed-spend cleanup, and End race before merging.

Findings

  1. P1 Save failures erase payment checks ▶
  2. P1 Old ledgers reach the repair ▶
  3. P1 Failed payments use the budget ▶
  4. P1 An End misses the handoff ▶

Summary

Adds wallet-backed checks before automatic allowance payments:

  • Automatic payments pause when the allowance ledger falls behind.
  • Automatic payments count wallet-recorded spends against monthly limits.
  • Allowances the wallet has seen ended no longer pay automatically.
  • Wallet backups keep allowance checks through a restore.

Four fixes remain: save failures can discard checks, reconciliation can run before the floor check, failed spends can survive recovery, and an End can race with handoff.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Covered request] --> B[Check saved ledger floor]
    B --> C[Reconcile ledger]
    C --> D[Check returned ledger]
    D --> E[Check ended IDs and monthly spend]
    E --> F[Reserve attempt]
    F --> G[Save journal and local spend]
    G --> H[Check ended IDs]
    H --> I[Receive private messages]
    I --> J[Begin execution and pay]
    K[User ends allowance] --> L[Save ended ID]
    L --> M[Send End through SDK]
    N[Wallet backup] <--> O[Merge floor, spends, and ended IDs]
Loading

Reviews (1) · Last reviewed commit: "fix: harden automatic allowance payments" · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 598290d (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: Reviewed the full PR diff against its merge base, at 3c09544.

2 actionable findings — resolve or provide an evidence-backed rebuttal.

A Send-sheet payment of a request this change keeps manual still reconciles the allowance ledger. When a floor is already stored and the SDK serves no ledger, that call attests an empty history. Recovery and automatic payment were changed to leave that ledger alone.

While the node cannot pay, the above-limit handoff still uses ledger and local spend totals only. A request the new floor will force onto the manual flow stays off the Send sheet until a channel is usable.

Comparison with bitkit-ios#1175 at dd478be covered the allowance floor, local spends, ended allowances, and manual ledger reporting. beginManualPayment and exceedsLimits follow the same split.

These open threads still match this revision: floor save still accepts the ledger, reconciliation uses a later read, failed spend kept when the journal row is already failed, and End during receive. Recovery now drops a failed spend whose journal entry was trimmed (thread); that part matches syncSettledJournal when the journal entry is absent.

Validation: inspected PaykitAllowanceExecutorTest.kt, PaykitAllowanceStoreTest.kt, and PaykitAllowanceStateBackupTest.kt at this revision. This review did not execute them. The missing-ledger test asserts that automatic payment does not reconcile; it does not call beginManualPayment. No GitHub issue matched these mechanisms. Device testing: not performed in this review.

Suggested additional test cases:

  1. Android unit test in PaykitAllowanceExecutorTest. Setup: store a ledger revision floor and stub allowanceAccountingState() as null. Action: call beginManualPayment for a bitcoin incoming request. Expected: reconcileAllowanceAccounting is not called.
  2. Android unit test of the covered-request pass used when the node cannot pay. Setup: floor set, ledger missing or older, and the request amount within the ledger and local spend totals. Action: run that pass. Expected: the request is marked manual so it can be presented, including before a channel is usable.

Findings

  • [HIGH] Manual send rewrites a ledger the floor refused — Trigger: the wallet has a ledger revision floor, and the SDK serves no ledger or an older one. Automatic payment returns manual, the request is presented on the Send sheet, and the user confirms the payment.

Mechanism: proceedWithPayment calls beginManualAllowancePayment, which calls beginManualPayment and reportManualPayment. That function always calls ensureReconciled before reserveManualPayment. ensureReconciled does not consult the floor. A null ledger uses an empty history and a null expectedRevision, and the reconciliation is submitted. An older ledger that requires reconciliation is repaired from that older snapshot. reserveManualPayment then records the attempt on the resulting state.

Consequence: this path would replace a ledger the wallet has already read with an empty or older history. Allowance spends that exist only in the discarded ledger stop constraining the monthly cap once the rewritten revision reaches the floor and automatic payment accepts it again. Local automaticSpends still cover only the spends this wallet stored itself.

Expected behavior: a request kept manual because the ledger is missing or behind should leave that ledger untouched, as recovery does. The Send sheet can still pay. The allowance report should wait until a ledger at or above the floor is served. A failed report already lets the send continue.

Evidence basis: source analysis at 3c09544e3f37a65efb67c6c92e909f9fbf7f8087. a missing ledger after one was read keeps the request manual asserts that automatic payment performs no reconciliation. It does not call beginManualPayment. This review did not execute that test or a device. The same unguarded ensureReconciled call is present in bitkit-ios beginManualPayment at dd478be41ea60887baf613777cb87b7a930a1944.

Source. Summary placement: The write is ensureReconciled in reportManualPayment, which this PR does not modify. The new manual result is what reaches it after the floor refuses the ledger.

  • [MEDIUM] Channel wait ignores the ledger floor — inline at app/src/main/java/to/bitkit/repositories/PaykitAllowanceExecutor.kt:403.

Reviewer model: grok-4.7
Reasoning effort: high

@ovitrif

ovitrif commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

@piotr-iohk Addressed in 3c09544: both findings from your QA review at 3c09544 are fixed on this PR's current head:

  • Manual reporting on a ledger behind the floor: the floor check now runs inside ensureReconciled, right after its read and before any reconciliation is built or sent (5510d9c). A Send-sheet payment of such a request still goes out, but is no longer reported to that ledger, and a missing ledger after one was read is no longer reconciled as an empty history.
  • Channel wait: fixed in e93e255, answered in your thread.

The iOS twin, synonymdev/bitkit-ios#1175, has both fixes (0e18333a, e503eb7f).

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: Follow-up of e93e25509 since 3c09544e, on merge base c080139b. Inherited baseline review 5713748206 for allowance backup restore merge and the shared wire format. This pass covered the descendant delta: durable floor saves, reconciliation before any ledger write, failed-spend removal, the pre-handoff end check, above-limit handoff, manual reporting, and the new executor tests.

No new actionable code findings.

Reconciliation throws LedgerBehind before reconcileAllowanceAccounting when the served ledger is older than the floor, missing after a floor was saved, or the floor cannot be saved. Automatic payment and recovery stop there. Manual reporting stops as well and returns no attempt id, so the Send sheet still sends; that matches the existing unreported-ledger contract and bitkit-ios e503eb7f. While the node cannot pay, that behind ledger is handed back without Limit Reached. Recovery removes local spends for attempts the ledger has failed, including after the journal entry is gone. The private-message fetch runs before the ended-allowance check, the same order as iOS.

Validation: PaykitAllowanceExecutorTest was inspected at e93e255, including the unsaved-floor and behind-ledger cases, and was not executed in this review. Device testing: not performed. A journey cannot produce a ledger older than one this wallet has already read.

Suggested additional test cases:

  • Android unit test in PaykitAllowanceExecutorTest: set ledgerRevisionFloor to 5 and the accounting ledger revision to 4, then call beginManualPayment for an incoming bitcoin request. Expected: null attempt id, no reconcileAllowanceAccounting, and no reserveManualPayment.

Earlier findings reconciled at this revision: 2 verified fixed.

Reviewer model: grok-4.7
Reasoning effort: high

@ovitrif

ovitrif commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

@piotr-iohk Addressed in b431971: thanks, added your suggested case on both apps (b431971 here, d9265ab4 on synonymdev/bitkit-ios#1175): with a floor of 5 and a ledger at revision 4, beginManualPayment returns no attempt id and neither reconciles nor reserves.

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: Re-reviewed the full PR at b431971 after the merge base changed and no prior coverage baseline was available. The comparison base and merge base are fdc1012.

No new actionable code findings.

Automatic payment, recovery, and manual reporting stop before writing a ledger that is missing or older than the stored revision floor. A manual send still proceeds, with no allowance attempt id. While the node cannot pay, that ledger returns the request immediately and does not raise Limit Reached. The monthly check uses the higher of ledger usage and this wallet's own spends, a failed attempt stops counting after its journal row is gone, and an End saved during the private-message fetch stops the handoff. Restore keeps the higher floor and every stored spend and ended allowance. The same checks are on bitkit-ios#1175 at d9265ab.

The findings from the review at 3c09544 do not match this head. PaykitAllowanceExecutorTest.kt, PaykitAllowanceStoreTest.kt, and PaykitAllowanceStateBackupTest.kt were inspected, including the behind-ledger manual-payment case, and were not executed. Device testing: not performed. A journey cannot serve a ledger older than one this wallet has already read.

Reviewer model: grok-4.7
Reasoning effort: high

@ovitrif
ovitrif requested a review from piotr-iohk October 31, 2026 20:29
@ovitrif
ovitrif dismissed jvsena42’s stale review October 31, 2026 23:04

Addressed in c671bd5b and 8d9c93e; threads resolved. Dismissing so the fix can be re-reviewed on the current head.

@ovitrif
ovitrif requested a review from jvsena42 October 31, 2026 23:04

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed to 8dc7f7f. My MEDIUM is fixed, and no HIGH or MEDIUM is left. Approving with one LOW open (Resume skips the payment PIN). Fix it here or move it to a follow-up issue, your choice; please reply on the thread with which, and the issue link if it is a follow-up.

Checked, reviewed as a funds change:

  • The MEDIUM. A backup without Paykit state restores with ledgerRevisionFloor = null (BackupRepo.kt:1104-1110) and keeps the spends and ended ids. My regression test was added along with the positive case.
  • Resume pays nothing by itself. acceptCurrentLedger only moves the floor. automaticSpends, endedAllowanceIds, the journal and autoPaidRequestIds are untouched, and requests already handed to the Send sheet stay manual.
  • Cap. fits now unions ledger attempts and local spends by attemptId, with the ledger winning on a shared id. Every spend this wallet admitted still counts after Resume, so one install cannot exceed the limit.
  • Double payment. hasPaid checks autoPaidRequestIds and any non-FAILED journal entry, so a rolled-back ledger cannot re-pay a request this wallet paid.
  • Restart and restore. Spends are written with the journal entry before the handoff and removed only on FAILED. withChecksFrom unions them and keeps the higher floor.
  • loadAll now throws. An unreadable store blocks saves instead of wiping every identity's journal: a durable floor save fails, so auto-pay stays manual. The stored format only gained optional fields since v3.0.0, so upgrades read fine.
  • The merge 88b18f7 has an empty remerge-diff.

Performance: refresh() adds one allowanceAccountingState() SDK read per refresh. That is not a user wait.

⚠️ Device gate: not run — the only user-visible change is the "Automatic payments paused" card, which needs a ledger revision behind this wallet's floor, and no device run can produce one. The PR touches no journey. This approval rests on the code scan, the unit tests for pause and resume, and CI. l10n: the new subscriptions__allowances_paused_* strings could not be checked on screen for the same reason.
Skipped — covered by CI at 8dc7f7f: unit tests, lint, detekt, e2e.

@ovitrif

ovitrif commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

@jvsena42 pushed 2e3af69: Resume now asks for the payment PIN when payments require one, like the payer's other allowance actions. It answers your LOW on AllowancesViewModel.kt, and your test is included. The repository needs an approval after the last push, so this needs your approval again.

@ovitrif
ovitrif requested a review from jvsena42 November 1, 2026 09:20

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: Full reassessment of 2e3af6943 against 1337f121 because the comparison base changed; no coverage was inherited. Covered the complete PR diff, payment/recovery callers, persistence and restore, Resume UI, and tests. Comparison with iOS c8830f12 was limited to these allowance contracts and shared backup format, not a full iOS review.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

The earlier End/handoff synchronization concern is not fully cleared: the check now follows message receipt, but a suspending trusted-time save and SDK-lock acquisition still separate it from handoff. This existing concern is not reported again as a new finding.

Validation: CI build and unit-test logs passed on merge 47d60dd, containing the exact reviewed head/base. The added Resume test calls onAuthorized() directly and does not render the tab. Local focused unit tests could not execute because the Android SDK is absent. SDK contracts were inspected at Paykit 01de5dd, the pinned 0.1.1-rc2 dependency.

Suggested additional test cases:

  • Android Compose: provide an active allowance and paused state with PIN-for-payments enabled; tap Resume, assert the PIN screen appears, cancel and verify the floor is unchanged, then retry and authorize successfully. No allowance sheet should need to be opened first.
  • Android executor unit test: suspend between the final ended-ID check and SDK handoff, durably record End, then continue; assert no Lightning payment is submitted.

Device testing: not performed in this review.

Findings

  • [MEDIUM] Render payment authorization for Resume on the Allowances tab — inline at app/src/main/java/to/bitkit/ui/screens/subscriptions/AllowancesViewModel.kt:164.

Reviewer model: gpt-6-astra
Reasoning effort: high

@ovitrif

ovitrif commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed e479852: the Allowances tab now shows the payment PIN or biometric check when Resume needs one. Before this, Resume set a pending check that only the allowance sheet could draw, so on the tab it never resumed.

  • The overlay is shared with the allowance sheet and drawn over the whole Subscriptions screen; leaving the screen drops a pending check.
  • AllowancesScreenTest.kt clicks Resume through the UI: the PIN check shows and payments resume once it passes; back leaves them paused.

This answers #1738 (comment).

@ovitrif
ovitrif requested a review from piotr-iohk November 1, 2026 18:23

@piotr-iohk piotr-iohk left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: follow-up at e479852, covering the entire delta since 2e3af69 and affected authorization paths. Unchanged accounting, recovery, persistence and coverage surfaces are inherited from the completed baseline; ancestry and the unchanged base/merge base were verified locally.

Code review completed with unverified earlier concerns.

Compared Resume authorization with iOS c8830f1, limited to the affected contract, without a full iOS review.

Validation: inspected the new Compose PIN-success and Back/retry tests and affected ViewModel assertions. The focused JVM test command stopped before executing tests because no Android SDK was configured. Pinned-head CI unit tests were still running at the final check.

Suggested additional test cases

  • Android/Robolectric: with a paused allowance and payment PIN enabled, open Resume, remove the authorization host from composition, then recreate it with the same ViewModel. Assert no resume call occurred, the pending authorization cleared, and a fresh Resume tap asks for the PIN again.

Device testing: not performed in this review.

Earlier findings reconciled at this revision: 1 still present, 5 verified fixed, 1 could not be verified.

Reconciliation incomplete: the following earlier concerns remain unverified. This report does not establish that they are fixed or invalid, or establish approval or device readiness.

Could not verify earlier concern — Preserve observed ended IDs when their local save fails: The refresh-time save remains best-effort, so the floor fix does not remove this portion of the report. However, the SDK independently derives terminal allowance lifecycle and rejects it at handoff. Losing a local tombstone alone therefore does not establish an unauthorized payment. I could not establish the supported lifecycle-rollback transition needed to bypass that protection, and no failure/rollback test was executed. This remains unresolved; neither a complete fix nor a current payment bypass is claimed.

Existing concerns

  • [HIGH] Synchronize the saved End with automatic-payment handoff — the original thread is marked resolved, but the fix appears incomplete. The check now follows message receipt, yet a suspending trusted-time save and SDK-lock acquisition still separate it from handoff. Coordinate the final check and handoff with rememberEnding, and add a regression test that saves End during that gap and verifies no payment is submitted.

Reviewer model: gpt-6-astra
Reasoning effort: high

@ovitrif

ovitrif commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 4b078e4: an End and an automatic payment's handoff can no longer interleave.

  • One lock in the executor now covers the ended check through beginPaymentExecution, and an End's durable save through the SDK's endAllowance. The trusted-time save and the SDK lock wait no longer separate the check from the handoff.
  • PaykitAllowanceExecutorTest.kt: an End started during a blocked handoff saves and sends nothing until the handoff finishes.
  • AllowancesScreenTest.kt: leaving the screen while the PIN check is open drops it without resuming, and a fresh Resume asks again.

This answers #1738 (review) and #1738 (comment).

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: follow-up. Re-reviewed the changes since e479852, including affected code paths, at 4b078e4. The merge base 1337f12 is unchanged. Coverage of the rest of the PR is inherited from the baseline review. I also took an inventory of the current 35-file PR diff.

No new actionable code findings.

The delta is a single commit, an end saved during a payment handoff waits for it. It adds a handoffMutex. An automatic payment holds it from its ended-allowance check through beginPaymentExecution. PaykitAllowanceRepo.end holds it from the durable End save through the SDK endAllowance calls. I traced the lock order and every caller. Both paths take handoff, then state, then the SDK operation lock. The new lock has no other users, and nothing that already holds the SDK operation lock (wallet wipe, the automatic-acceptance admit callback) or stateMutex tries to take it, so I found no deadlock path. The early MANUAL return inside withLock releases the lock. An End saved before the handoff still fails the attempt and releases its reservation. An End that arrives during the handoff is saved and sent only after it, and the handed-off payment continues as the code comment says it should. Queued End messages are now flushed only after all of the entry's SDK Ends succeed. If one fails partway, the background outbound processor (PaykitPaymentRequestRepo) still sends what was queued, so I don't count this as a defect. The new Compose test, leaving the screen drops a pending pin check, matches the DisposableEffect cancellation in AllowanceAuthorizationHost.

Parity: the iOS twin synonymdev/bitkit-ios#1175 at 7d699c7 has the same structure: handoffLock in PaykitAllowanceExecutor.rememberEnding and the handoff, and Ends sent inside the lock with the outbound flush after it in PaykitAllowanceManager.end.

Validation: tests were not run locally because this workspace has no Android SDK or Gradle cache. CI ./gradlew testDevDebugUnitTest passed on the pull_request build for this head, and that build includes the new executor and screen tests. Device testing: not performed in this review.

Suggested additional test cases:

  • Android, two wallets with an accepted allowance (this wallet pays) and a contact that sends repeated payment requests. Tap End on the allowance just as a covered request is being paid automatically. Expected: the End completes after the payment hands off. At most that one in-flight payment is paid automatically. Later requests from the contact are shown for manual payment, and the allowance shows as Ended on both wallets.

Earlier findings reconciled at this revision: 7 verified fixed, 1 not substantiated.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 4b078e4 with one LOW open, inline. Fix it here or in a follow-up issue, your call; please reply on the thread with which.

  • My LOW is fixed: AllowancesViewModel.kt:164 now uses authorizeThen(isGated = true), and the PIN check is drawn for the whole Subscriptions screen through AllowanceAuthorizationHost.
    • Resume is the only path to acceptCurrentLedger.
    • Cancel and Back keep the pause, and leaving the screen drops a pending check (AllowancesScreenTest).
  • "An end saved during a payment handoff waits for it": one mutex covers the ended-id check through beginPaymentExecution, and the durable End save through the SDK endAllowance calls.
    • The outbound flush runs outside the lock, and the lock order is handoff → state → SDK lock. Nothing that holds the SDK lock takes the handoff lock.
    • Crash recovery never re-runs a handed-off attempt.

perf: not relevant.

⚠️ Device gate: not run. The paused state needs a ledger behind the floor, which no device run can produce, and the PR changes no journey. This approval rests on the code trace and the unit tests. CI is green at 4b078e4.

@ovitrif

ovitrif commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 598290d: the PIN check over the Subscriptions screen and the allowance sheet now blocks taps, so nothing beneath it can be opened while it shows, matching the app's other full-screen PIN checks. It answers @jvsena42's review comment. AllowancesScreenTest.kt gains their test, which fails without the change; the screen tests and detekt pass.

@ovitrif
ovitrif requested a review from jvsena42 November 2, 2026 09:02

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: follow-up. Re-reviewed the changes since 4b078e4, including affected code paths and earlier findings, at 598290d. The merge base 1337f12 is unchanged, and 4b078e4 is an ancestor of the new head. Coverage of the rest of the PR, including End/handoff serialization, accounting, recovery, persistence and restore, comes from the baseline review. The current PR still touches the same 35 files.

No new actionable code findings.

No new actionable code findings in the follow-up.

The delta is one commit, pin check keeps taps off the screen beneath. It adds blockPointerInputPassthrough() to the AllowanceAuthorizationOverlay box. That box fills its parent and is drawn above the content. Compose sends a touch only to the topmost sibling under it, so the overlay's pointerInput now receives taps that used to reach whatever was beneath. The overlay does not consume these events. The PIN keypad, its back button and the biometric view are children of the overlay, so they still get touches first. BackHandler still cancels. This is the same pattern AuthCheckView and the wallet screens already use.

The fix covers both places the overlay is used:

  • AllowanceAuthorizationHost wraps the whole Subscriptions screen, so allowance rows, the Add button, the tabs and the header are blocked.
  • In AllowanceSheet, the Review, Details/End and Set content beneath the overlay is blocked as well.

This resolves the pass-through thread only in the sense that the reported mechanism no longer holds at this head; that thread is already marked resolved. The behaviour now matches bitkit-ios#1175 at 7d699c7, where PaymentAuthorizationModifier shows the PIN screen as a modal sheet. That comparison covered only this contract; it was not a full iOS review.

Validation: I read the new Robolectric case in AllowancesScreenTest. At w360dp-h800dp it taps an allowance row lying under the empty part of the PIN check, then asserts that no allowance click happened and the PIN check is still shown. That test exercises only the screen host, not the sheet. CI testDevDebugUnitTest passed in the pull_request run for this head. I did not run tests locally because no Android SDK is configured here.

Device testing: not performed in this review.

Suggested additional test cases

  • Android, Allowances sheet: turn on PIN with "Also require for payments". Open an allowance you fund, choose Details, and swipe End so the PIN check opens inside the sheet. Tap the empty area of the overlay where the End control and the allowance details sit. Expected: nothing beneath reacts and the PIN check stays. Then enter the PIN. Expected: the End completes once.
  • Android, TalkBack: with payments paused and the payment PIN on, tap Resume on the Allowances tab so the PIN check opens. Swipe through the elements with TalkBack. Expected: focus does not reach the allowance rows, the Add button or the tabs beneath the overlay, and a double-tap cannot open an allowance sheet behind the PIN check.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@ovitrif

ovitrif commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

QA: Resume with the payment PIN

This is the device case @piotr-iohk suggested in the QA review. It ran on 598290d, on an Android emulator against staging regtest, with an Active allowance to an iOS contact. The paused state needs allowance records older than ones the wallet has already used, which staging cannot serve. A local debug-only hook (not in this PR) raised the wallet's floor once. Everything after it ran this PR's code.

✅ Resume asks for the PIN, a cancel keeps payments paused, and an authorized Resume clears the notice

  1. Turn on the PIN and "PIN for payments", and open Subscriptions → Allowances while automatic payments are paused.
  2. Tap Resume. The PIN check opens.
  3. Go back. The tab shows "Automatic payments paused" with Resume above the allowance row.
  4. Tap Resume and enter the PIN. The notice clears after about 6 s and the row stays Active.
After the cancel Recording (2x) After Resume
android-pin-2x.mp4

Not on device: that the wallet's own spends and ended allowances still keep covered requests manual after Resume. That part needs funded automatic payments; the PaykitAllowanceExecutorTest.kt resume tests cover it.

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 598290df2f4c578a7ac1f832558038d045cac916 based on the current code review, automated coverage, and the focused device results below. The four remaining device gaps are accepted for this approval; they remain unverified, and this is not a complete device-gate pass.

Tested on 2026-11-02 using the existing Pixel 6 emulator (Android API 33), to.bitkit.dev, and local regtest services. Installed CI local E2E build 6512, checkout a577ac8553b1c6dedd0c48e1f6d7b8f44f3f664b: app source matches this PR head; the only additional differences are the FCM tester package/lock files. A distinct funded iOS simulator wallet was the payment peer, not an iOS PR test target.

Passed:

  • Set/End PIN overlays: blank-area taps did not authorize changes; taps over hidden limit controls left $5/$10 unchanged. Cancellation preserved the allowance, retry worked, and the correct PIN completed End.
  • One incorrect PIN was rejected. After background/foreground, app unlock did not also authorize End: the allowance PIN was still required separately.
  • One 2,500-sat Lightning-capable request paid automatically, appeared once as Auto-paid, counted $1.95 against the allowance, and was received by the peer for the matching amount.
  • After End, a new 1,000-sat Lightning-capable request required Swipe To Pay and remained unpaid.

Remaining device gaps:

  1. TalkBack focus isolation on the Resume PIN overlay. The paused state was not staged; an End-overlay probe enabled TalkBack, but injected input did not reliably advance accessibility focus.
  2. Resume with a stale ledger missing locally retained spending, followed by a request exceeding the remaining monthly budget.
  3. Resume with a stale ledger after an allowance was remembered as ended, verifying that it cannot auto-pay again.
  4. End during a controlled in-flight automatic-payment handoff, verifying at most the already handed-off payment completes and later requests stay manual.

The stale-ledger fixture could not be established through the available keystore/runtime access, and no controlled handoff window was produced. Unit coverage and the reviewed locking/accounting protections support approval, but ordinary payment/End success does not replace these combined device scenarios. No confirmed new product defect was found. Focused run: three planned cases passed, four blocked by test setup/control limitations.

An initial request accidentally excluded Lightning and correctly stayed manual; the corrected request above retained Lightning and passed. Temporary PIN/TalkBack settings were restored, both test-created allowances were ended, and unpaid test requests were dismissed. Wallets were preserved. Recordings, screenshots and diagnostic evidence were retained locally.

@ovitrif

ovitrif commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved by @piotr-iohk on the current head, device run of the Resume PIN case passed on this head (#1738 (comment)), no open threads, CI green. Ships in 3.1.0 with its twin synonymdev/bitkit-ios#1175.

@ovitrif
ovitrif merged commit ddd4256 into master Nov 2, 2026
21 checks passed
@ovitrif
ovitrif deleted the fix/allowance-autopay-hardening branch November 2, 2026 10:21
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.

3 participants