Skip to content

Honour the remember-decision duration when a request is refused - #476

Merged
kwsantiago merged 3 commits into
mainfrom
reject-honours-remember-duration
Aug 7, 2026
Merged

Honour the remember-decision duration when a request is refused#476
kwsantiago merged 3 commits into
mainfrom
reject-honours-remember-duration

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

The approval screen has a duration selector labelled "Remember this decision". A refusal is a decision, and the selector's value was passed only to approve; on the reject branch it was discarded and replaced with the one-shot value. So a user could choose "for 1 hour", refuse, and be asked again on the very next request.

That was invisible until the signer learned to remember refusals. Now that it does, the value has somewhere to go: a refusal carrying a duration is recorded and later requests of the same kind are refused without prompting, which is what stops a client that retries on failure from re-asking indefinitely. This is the surface half of that work; the core landed separately.

Two properties make this safe rather than a new way to lock yourself out.

The default records nothing. A signing request defaults the selector to the one-shot value, which yields no window, so an ordinary refusal behaves exactly as before. Only a duration the user deliberately chose is remembered.

Every internal refusal passes no duration, and there are several: the kill switch, a failed biometric, an unavailable cipher, a back press. Those map to the one-shot value and record nothing, which is correct, since none of them is the user deciding anything about this app.

The shape follows a reference signer for the same protocol, which hands one shared remember control to both its accept and reject callbacks. The control means "remember my decision for this long", and the decision is whichever button was pressed. Keep's label already said that; only the code disagreed.

Test plan

Two instrumented tests on the screen, pinning the wiring rather than the rendering, since what the reject button hands back is what decides whether the refusal is remembered.

The first is the negative and matters more: refusing without touching the selector must report the one-shot value. If reject forwarded anything else, every ordinary "no" would silently become a lasting block nobody asked for. The second chooses an hour, refuses, and requires that duration to reach the callback, so the selector is not decorative on that branch.

Compiles locally against freshly generated bindings. These need real Compose, so they run on the emulator in CI.

Summary by CodeRabbit

  • New Features

    • Rejection responses now support a selected duration, including “Just this time” and one-hour options.
    • The chosen duration is applied when declining permission requests, while internal refusals remain one-time responses.
  • Tests

    • Added coverage verifying default and selected rejection durations are reported correctly.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kwsantiago, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4a433fb-568e-4342-8f4c-e191c722ecfe

📥 Commits

Reviewing files that changed from the base of the PR and between 8f543dd and 1ec4be4.

📒 Files selected for processing (2)
  • app/src/androidTest/kotlin/io/privkey/keep/nip46/Nip46RejectDurationTest.kt
  • app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalScreen.kt

Walkthrough

NIP-46 rejection handling now forwards the selected PermissionDuration from the Compose screen through Nip46ApprovalActivity. Instrumentation tests verify JUST_THIS_TIME by default and ONE_HOUR when selected.

Changes

NIP-46 rejection duration

Layer / File(s) Summary
Screen rejection duration contract
app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalScreen.kt
The rejection callback now accepts PermissionDuration. The reject action passes the selected duration.
Activity duration response mapping
app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalActivity.kt
User refusals now use the selected duration. Internal failure, cancellation, timeout, and back-navigation paths remain one-shot.
Rejection duration instrumentation tests
app/src/androidTest/kotlin/io/privkey/keep/nip46/Nip46RejectDurationTest.kt
Compose tests verify default JUST_THIS_TIME and selected ONE_HOUR rejection durations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Nip46ApprovalScreen
  participant Nip46ApprovalActivity
  participant respond
  Nip46ApprovalScreen->>Nip46ApprovalActivity: reject(selectedDuration)
  Nip46ApprovalActivity->>respond: respond(rejection, selectedDuration)
  respond-->>Nip46ApprovalActivity: mapped PermissionDuration response
Loading

Possibly related PRs

Suggested reviewers: wksantiago

Poem

A rabbit taps Reject with care,
One hour hops through every layer.
The default stays brief and bright,
Tests confirm the duration right.
Thump, thump—the callback’s clear!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: applying the selected remember-decision duration to refused requests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reject-honours-remember-duration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalScreen.kt`:
- Around line 198-203: Update the rejection handler in Nip46ApprovalScreen so
onClick passes PermissionDuration.JUST_THIS_TIME when isConnectRequest is true,
while preserving selectedDuration for other refusals. Add a regression test
covering a connect-request refusal and verifying the one-shot duration is
recorded.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c9d4ab1b-1acf-45c3-b6e2-7abe5ae16ee2

📥 Commits

Reviewing files that changed from the base of the PR and between 045ad6d and 8f543dd.

📒 Files selected for processing (3)
  • app/src/androidTest/kotlin/io/privkey/keep/nip46/Nip46RejectDurationTest.kt
  • app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalActivity.kt
  • app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalScreen.kt

Comment thread app/src/main/kotlin/io/privkey/keep/nip46/Nip46ApprovalScreen.kt Outdated
@kwsantiago

Copy link
Copy Markdown
Contributor Author

Taken, and worth being precise about why, because the current behaviour was already safe.

A connect request hides the selector and defaults it to Forever, so forwarding that value records a decision from a control the user never saw. Nothing is stored today, because Forever yields no window and the signer only remembers bounded ones. So the outcome is correct and the reasoning is not: the safety lives in another crate, one release away from changing.

That coupling is the actual problem. Permanent refusals were deliberately left unsupported, on the grounds that an in-memory refusal claiming to last forever would quietly vanish on restart. If a later change adds persistence and honours Forever, this line silently converts a hidden default into a permanent block, and nothing here would fail. Passing the one-shot value explicitly makes the property local instead of borrowed.

A regression test covers it, asserting a connect refusal reports the one-shot value rather than the hidden default.

Also confirmed on the emulator in the previous run: the negative case passes, so refusing without touching the selector records nothing, and the positive case passes, so a chosen duration does reach the callback. That second one had failed earlier for a reason unrelated to the feature: the test clicked the label to open the menu, but the control is an exposed dropdown whose menu opens from the field showing the current selection. My assumption about the interaction, not the wiring.

@kwsantiago
kwsantiago merged commit 352514f into main Aug 7, 2026
4 checks passed
@kwsantiago
kwsantiago deleted the reject-honours-remember-duration branch August 7, 2026 03:14
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.

1 participant