Skip to content

fix(reader-access): don't count a re-verified device against the device limit - #651

Merged
ashleyshaw merged 3 commits into
mainfrom
fix/session-test-suite-failures
Nov 21, 2026
Merged

ashleyshaw merged 3 commits into
mainfrom
fix/session-test-suite-failures

Conversation

@ashleyshaw

@ashleyshaw ashleyshaw commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Rescoped. This PR originally repaired the whole tests/session suite. #653 has since landed on main with an equivalent repair: Blobs list() result handling, prefix filtering, per-email serialisation of createSession, and the same test corrections. I resolved the merge conflict by taking main's version of every overlapping file. This PR now carries only the one fix main does not have.

The bug

createSession counted the reader's existing session on the same device towards MAX_CONCURRENT_DEVICES. With the default limit of 2, a reader already signed in on two devices who re-verifies on one of them gets 409 device_limit_exceeded. That's wrong: the device fingerprint is deterministic, so the new session is stored under the same key and replaces the old one in place. Re-verifying is not adding a device.

The fix

netlify/lib/reader-access/session-service.ts: leave sessions with the same deviceId out of the active count (one filter condition plus a comment).

Changes

  • netlify/lib/reader-access/session-service.ts: same-device exclusion in the device-limit check
  • tests/session/device-limit-tests.test.ts: regression test "should allow a new session on an already-registered device at the limit"
  • CHANGELOG.md: entry under [Unreleased] → ### Fixed

Verification

  • New test fails on main's code (Error: Device limit exceeded) and passes with the fix.
  • npx vitest run tests/session tests/performance/session-latency.test.ts → 142/142 passed.
  • Full npx vitest run: main 1060 passed / 120 skipped; this branch 1061 passed / 120 skipped (the skips already exist on main). 0 failures on both.
  • npm run validate:branch-name passes.

Notes for reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01CADHZe8PHngjvTuY2dcfYm

The session suite merged in #647 failed on main (66/140), which made the
"No new test failures" check fail for every PR that merged main.

Implementation:
- store.listSessionsByEmail: accept the real Netlify Blobs list() result
  ({ blobs: [{ key }] }) as well as a plain key array, and filter keys by
  the reader's prefix. Previously the real Blobs shape made createSession
  throw, and a prefix-ignoring adapter leaked other readers' sessions into
  the device count.
- createSession: do not count the device being re-verified towards
  MAX_CONCURRENT_DEVICES (its session is replaced in place), and serialise
  creations per reader so concurrent requests cannot all pass the check.

Tests (no skips, no removals):
- session.test.ts: in-memory Blobs double instead of an auto-mocked store;
  persist the expiry in the expired-session case.
- Await rejects assertions; step past the renewal coalesce window with a
  faked Date instead of sleeping inside it; expire beyond clock-skew
  tolerance; measure the rolling window from renewedAt.
- security.test.ts: reset rate-limiter state between tests; unpadded
  base64url fixture; empty tokens must not match; timing tests compare
  warmed-up interleaved medians (tests/session/helpers/timing.ts).
- New regression test for re-verifying on a registered device at the limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CADHZe8PHngjvTuY2dcfYm
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

Deployment failed for project thisonetimeonacidcom with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/lightspeedwp?upgradeToPro=build-rate-limit

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 815a3bb and b157467.

Files selected for processing: 3

  • CHANGELOG.md
  • netlify/lib/reader-access/session-service.ts
  • tests/session/device-limit-tests.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

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

@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@github-actions

Copy link
Copy Markdown

✅ PR Template Routing

Branch prefix: fix
Template selected: pr_bug.md
Type: Bug Fix PR


This PR's template has been automatically routed based on the canonical branching strategy defined in lightspeedwp/.github.

📋 Template routing rules:

✨ Automatic routing ensures all PRs follow the organization-wide governance structure.

@github-actions

Copy link
Copy Markdown

📋 Changelog Quality Validation

Metric Count
✅ Passing 1
❌ Failing 0
🆕 New failures in this PR 0
📦 Pre-existing failures 0

Status

✅ Validation PASSED - No new failures introduced by this PR.

No action required.

@ashleyshaw
ashleyshaw marked this pull request as ready for review November 20, 2026 11:37
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

Deployment failed for project thisonetimeonacidcom with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/lightspeedwp?upgradeToPro=build-rate-limit

@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

Copy link
Copy Markdown
Member Author

The red Vercel status on 11e4388 doesn't come from this PR's code. Vercel refused the deployment because the team has used its 100 free deployments for the day (api-deployments-free-per-day, "retry in 24 hours"). No build ran. This PR changes only netlify/lib/**, tests/session/** and CHANGELOG.md, and touches nothing in the Vercel build config. The status should clear on the next deployment after the quota resets, or after a manual redeploy from the Vercel dashboard.

On the current head (11e4388, after the merge of main), npx vitest run tests/session tests/performance/session-latency.test.ts passes 141/141 locally.


Generated by Claude Code

@mergify

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

PR #653 landed on main with an equivalent repair of the session test
suite (Blobs list() handling, prefix filtering, per-email serialisation
and the same test corrections). Resolve the conflicts by taking main's
version of every overlapping file and drop this branch's duplicate
helpers (tests/session/helpers/timing.ts).

Re-apply the one change main does not have: createSession no longer
counts the reader's existing session on the same device towards
MAX_CONCURRENT_DEVICES, with its regression test. CHANGELOG entry
narrowed to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CADHZe8PHngjvTuY2dcfYm
@ashleyshaw ashleyshaw changed the title fix(reader-access): make session management test suite pass fix(reader-access): don't count a re-verified device against the device limit Nov 20, 2026
@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@ashleyshaw
ashleyshaw merged commit 84eb204 into main Nov 21, 2026
28 of 31 checks passed
@ashleyshaw
ashleyshaw deleted the fix/session-test-suite-failures branch November 21, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants