Skip to content

Enforce session-mirror retention after short-lived visits #1499

Closed

Description

@jeonghun-jj-lee

Important

Problem — Session-mirror retention is only enforced by a delayed in-page task. Closing a page before that task runs can leave a scope above its cap across repeated short visits. The current test fixture can also leak a cached IndexedDB handle and timer state into other tests.
Approach — Preserve deferred pruning after writes, but ensure a previously over-cap scope receives bounded cleanup after the mirror database is available on a later visit. Add a test-only reset seam that restores module-level mirror state as well as the global IndexedDB override.
Scope — in: mirror-cap enforcement and mirror-test isolation · out: mirror schema migration, retention-policy changes, and session warming
Assumptions — Full-store pruning remains too expensive to perform after every completed save; per-scope behavior must remain independent.

Acceptance Criteria

  • Normal completed saves continue to defer full-store pruning rather than scanning the store after every write.
  • A scope left above the retention cap by a short-lived prior visit is pruned on a subsequent use without requiring the abandoned timer to fire.
  • Cleanup preserves records for other scopes and continues to enforce the existing per-scope retention cap.
  • Test setup and teardown restore IndexedDB and reset cached database, pending-save, and pending-prune state so no mirror fixture leaks across test files.

Testing Decisions

Extend the existing mirror unit harness with a reopen-after-short-visit scenario, cross-scope preservation, and sequential-test isolation coverage. Retain the current deferred-prune assertions.

Key Decisions

  • Use an amortized cleanup trigger tied to later database availability rather than turning every save into a full-store scan.
  • Expose reset capability only to tests; production code retains encapsulated mirror state.

Constraints & Invariants

  • Do not change the persisted mirror record format.
  • Do not regress debounced write behavior or scope isolation.
  • Keep the change independently reviewable from session warming and landing-page work.

Prior Art

The existing session-mirror persistence layer, retention helper, and IndexedDB test harness.

Source

Follow-up to the six CodeRabbit findings attached to #1473; the behavior originated in the current-main reliability recovery delivered by #1472.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hitlNeeds human review before merge

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions