Skip to content

feat(be): record that a session is still in use - #4244

Open
sea-snake wants to merge 4 commits into
feat/app-delegation-from-sessionfrom
feat/session-refresh-stamps
Open

feat(be): record that a session is still in use#4244
sea-snake wants to merge 4 commits into
feat/app-delegation-from-sessionfrom
feat/session-refresh-stamps

Conversation

@sea-snake

@sea-snake sea-snake commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Design: #4224. Overview: #4230.

"This browser used this app 3 minutes ago" against "5 weeks ago" is what makes a session list worth reading, and what lets someone spot a session they do not recognise still being used rather than merely still existing.

Every refresh stamps, and three consumers make coarsening it unattractive: the session cap orders live sessions on this field, so inside a coarsening interval every session would look equally idle; the browser registry cap orders on the same signal, where an hour is long enough to drop a browser in use; and a user-facing list that can be an hour stale does not answer the question it exists to answer. The write is small next to what the call already does, which inserts a canister signature and calls update_root_hash().

The same write carries three stamps:

Field Lives on Drives
last_used the account reference account eviction (#4235)
last_refreshed the session record the session cap (#4267) and the user-facing list
last_used the device record the registry cap (#4242) and the settings list

Stamping the device is the only reason refresh touches the anchor: it authenticates by session chain and never runs check_authorization. What that write buys is a use signal a sign-in stamp cannot give the browser list.

Stable writes scale with 1/T alongside the calls, so lowering the app-delegation TTL multiplies both.

Tests: session_refresh_stamp_tests (7), including a stamp for a session that is gone writing nothing, and a refresh advancing the device's last_used while leaving its enrolment timestamp alone. PocketIC drives two refreshes a minute apart and reads the device back off identity_info.

@sea-snake
sea-snake requested a review from a team as a code owner August 19, 2026 01:27
@zeropath-ai

zeropath-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 3cd69a2.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► src/internet_identity/src/sessions.rs
    Modify app_prepare_delegation to return locator and stamp session refresh
► src/internet_identity/src/storage.rs
    Add stamp_session_refresh and related logic
► src/internet_identity/src/storage/anchor.rs
    Add stamp_session_device_use method
► src/internet_identity/src/storage/tests.rs
    Add tests for session refresh stamping behavior
► src/internet_identity/tests/integration/sessions.rs
    Add integration tests to verify stamping on refresh

Copilot AI lite review requested due to automatic review settings August 19, 2026 01:47
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 7d6a294 to 0b043da Compare August 19, 2026 01:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 0b043da to 72c91a1 Compare August 19, 2026 02:57
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 72c91a1 to d8bd528 Compare August 19, 2026 03:47
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from d8bd528 to 474d22b Compare August 19, 2026 06:28
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 474d22b to 77d5897 Compare August 19, 2026 07:07
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 77d5897 to 78a570f Compare August 19, 2026 08:17
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 78a570f to b7b407e Compare August 19, 2026 08:37
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from b7b407e to 2676560 Compare August 19, 2026 10:21
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 2676560 to 41a2e22 Compare August 20, 2026 10:57
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 41a2e22 to 752fe5a Compare August 20, 2026 13:08
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 752fe5a to 0502a3f Compare August 20, 2026 13:52
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 0502a3f to 5c573c2 Compare August 20, 2026 15:24
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from ea03fb3 to 5b47998 Compare August 21, 2026 08:54
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 5b47998 to a6543f1 Compare August 21, 2026 10:38
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from a6543f1 to b54fca0 Compare August 21, 2026 17:06
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch 2 times, most recently from 16dfdea to 48b8e13 Compare August 22, 2026 12:52
@sea-snake sea-snake changed the title feat(be): record that a session is still in use, at hour resolution feat(be): record that a session is still in use Aug 22, 2026
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 48b8e13 to bcfc3c1 Compare August 22, 2026 17:24
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch 2 times, most recently from 3b1db8f to b23f33b Compare August 22, 2026 18:08
@sea-snake
sea-snake changed the base branch from feat/session-create-and-cap to feat/app-delegation-from-session August 22, 2026 18:10
@sea-snake sea-snake added the feature:revocable-app-sessions Design: revocable app sessions label Aug 22, 2026
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from b23f33b to 8649c71 Compare August 22, 2026 18:44
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 8649c71 to f0e74e2 Compare August 22, 2026 19:06
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from f0e74e2 to 24cdc5d Compare August 22, 2026 19:25
"This browser used this app 3 minutes ago" against "5 weeks ago" is what makes a
session list worth reading, and it is what lets someone spot a session they do
not recognise still being used rather than merely still existing. It is also what
the session cap evicts on, since ordering by creation would drop a months-old
session in daily use in favour of one created an hour ago and never touched.

Every refresh stamps it. An earlier revision of this design coalesced the write
to one an hour on the grounds that finer resolution had no reader; it now has
three. Two cap evictions order on these stamps, and an hour of slack there is
enough to drop the wrong session or the wrong browser. The third is the reading
above: a list that can be an hour stale does not answer the question it exists
to answer.

The write is small next to what the call already does, which inserts a canister
signature and rehashes the certified tree.

The same write carries the reference's `last_used`, which keeps account eviction
accurate for accounts only ever reached through a session, and the device
registry's `last_used`, so a browser that has an app open counts as in use rather
than as idle since its last sign-in. That is an anchor write on a call that
otherwise never touches the anchor; §9.3 traded it away to keep refresh cheap,
and the accounting above is why it is worth paying now.

Implements docs/ongoing/revocable-app-sessions.md §7.3 (S13).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sea-snake
sea-snake force-pushed the feat/session-refresh-stamps branch from 24cdc5d to 9f009c7 Compare August 22, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:revocable-app-sessions Design: revocable app sessions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants