Repository navigation
Conversation
… implement backfill for lastModified
|
@Aryainguz is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 62f81a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Review✅ No issues found. |
Deep ReviewReport-only multi-agent review of the session-store write-reduction change ( ✅ No critical issues found. 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (13): correctness, security, adversarial, performance, data-migrations, reliability, testing, maintainability, kieran-typescript, project-standards, agent-native, learnings-researcher, previous-comments. Testing gaps: backfill idempotency / zero-match no-op path is unasserted; the No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Summary
Closes #3837
On every request that leaves the session unchanged, express-session calls
store.touch()to push its expiry forward, and connect-mongo'stouch()runs anupdateOneunlesstouchAfteris set. So every API request from a signed-in browser wrote its session document, and the response waited for that write.touchAfterto one hour (SESSION_TOUCH_AFTER_SECinconfig.ts). The stored expiry moves forward at most once an hour, which is plenty for 30-day sessions. The cookie still rolls on every response, and a changed session (login, logout) is still saved right away.lastModified, andtouch()never adds that field. Sessions that existed before this change would keep writing on every request, and rolling sessions never expire while in use. A startup backfill inrunStartupMigrations()stampslastModifiedon them, following the same pattern asbackfillAlertDisplayFields.Opening a 12-tile dashboard in the browser (
yarn dev, a temporary counter on the store's write events), two runs each:mainSigned-in
GET /mein the integration environment, with 3 ms of network delay added to MongoDB (tc netem), two runs each:mainWithout the added delay, sequential latency went from 3.3 to 2.4 ms/req.
Trade-offs
$exists: falsefilter still scans thesessionscollection.How to reproduce
Starting point:
yarn dev, signed in.mongosh "<MONGO_URI>" --eval 'db.sessions.find({}, { expires: 1, lastModified: 1 })'On
main:expiresmoves on every API request.On this branch:
expiresstays the same until an hour has passed.Tests
__tests__/sessionStore.int.test.ts:main.lastModifiedstops being rewritten after the backfill. Fails without the backfill.The full API integration suite (71 suites), unit tests for all packages,
make ci-lintandknippass.How to test on Vercel preview
N/A, non-UI change.
References
Note
Medium Risk
Changes session persistence timing in MongoDB (stored expiry can lag the cookie by up to an hour), though logout and explicit session changes remain immediate.
Overview
Reduces per-request MongoDB writes for signed-in API traffic by configuring connect-mongo’s
touchAfterto one hour (SESSION_TOUCH_AFTER_SEC). Rolling cookies and immediate saves on login/logout/session changes are unchanged; only deferred expiry updates in thesessionscollection are throttled.Existing sessions lacked
lastModified, so they would still touch on every request without a migration. A startupbackfillSessionLastModifiedstampslastModified(same pattern as other startup backfills) so legacy rows benefit from the throttle after the first touch.Integration tests cover: no rewrite on repeated
/mecalls, backfill behavior, logout deletion, and extension after the interval elapses.Reviewed by Cursor Bugbot for commit 62f81a7. Bugbot is set up for automated code reviews on this repo. Configure here.