Repository navigation
fix: keep inboxes alive past their session and compare ISO timestamps correctly - #4
Merged
Merged
Conversation
… correctly
CleanupService deleted every expired session. inboxes.session_id is
ON DELETE CASCADE, so a PRO inbox (90d TTL) created by a 24h anonymous
session was deleted along with its emails when the session expired.
Sessions are now deleted only if they own no unexpired inbox; expired
sessions are still rejected at auth by getSessionByToken.
Tier for inbox-scoped behaviour came from the creating session, which
falls back to FREE once the session is gone and left orphaned inboxes
out of retention cleanup. InboxService.tierForInbox now resolves
users.has_pro / has_agent via inboxes.user_id, then the session tier,
then FREE. It is used for attachment stripping and retention.
Timestamps are stored as ISO-8601 (Instant.toString()) but were compared
to datetime('now') ("YYYY-MM-DD HH:MM:SS"). 'T' sorts after ' ', so
same-day expiry was delayed by up to a day. Comparisons in cleanup,
listInboxes and getInboxByAddress now bind Instant.now().toString().
getInbox and getInboxByAddress treat expired inboxes as not found.
Tests run the real migrations on in-memory SQLite with foreign keys on.
bmc08gt
force-pushed
the
fix/inbox-lifetime-and-expiry
branch
from
October 1, 2026 02:20
b81e1fd to
35275fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expired sessions were deleted unconditionally, and
inboxes.session_idisON DELETE CASCADE. A PRO inbox (90-day TTL) created by a 24h anonymous session was deleted, with its emails, webhooks and forwarding rules, when that session expired.Changes
AND id NOT IN (SELECT session_id FROM inboxes WHERE expires_at > ?)). Kept sessions are still rejected at auth:SessionService.getSessionByTokenalready checksexpires_at.EmailRoutesfell back to FREE once the session was gone, and the retention query inner-joinedsessions, so orphaned inboxes were never retention-cleaned.InboxService.tierForInboxnow usesinboxes.user_id->users.has_pro/has_agentwhen a user is set, else the session tier, else FREE. If a user has both flags, PRO wins. Used for attachment stripping and the retention query. Webhook and forwarding tier checks only happen at rule creation, from the request's own session, so they are unchanged.Instant.toString()(2026-09-30T10:00:00Z) but were compared todatetime('now')(2026-09-30 11:00:00).'T' > ' ', so same-day expiry was delayed by up to a day. Cleanup (retention cutoffs, sniper sealing, inbox and session deletion),listInboxesandgetInboxByAddressnow bindInstant.now().toString(). The remainingdatetime('now')uses are thecreated_at/received_atcolumn defaults andverified_atinDomainService(writes, not comparisons), andwebhook_deliveries.next_retry_atinWebhookService.retryFailedDeliveries, which is written as ISO; that comparison is left alone here.getInboxandgetInboxByAddresstreat an expired inbox as not found, so ingest returns 404 for it.Must land as one PR
The timestamp fix alone would make cleanup start expiring sessions that today linger up to a day past expiry, flushing them and cascading away their inboxes. The session guard has to ship with it.
Tests
The existing tests mock
TursoClient, which cannot exercise cascades or string comparison. This addsSqliteTurso, an in-memory SQLite stand-in that runs the realMigrationswith foreign keys on, plus asqlite-jdbctest dependency, andInboxLifetimeSqlTestcovering: an expired session with a live inbox is kept (inbox and emails survive); an expired session with only expired inboxes is deleted; an inbox that expired an hour ago today is deleted;tierForInboxprefersusers.has_pro; retention follows the user tier;getInbox,getInboxByAddressandlistInboxeshide expired inboxes. Existing mock-based tests were updated for the new bound parameters. SQLite is not libSQL, but the statements used are plain SQL.Deploy
blip-cloud production pins blip via
blip.shaafter the pin PR, so this ships when blip-cloud bumps it.Out of scope
session_id). No schema change is made here: no table rebuild, no change to the foreign key.session_id; deleting an expired session that owns none of the live inboxes still cascades whatever hangs off that session.