Welcome to the team that owns sessions. A session store keeps sessions keyed by id; an expiry policy decides when a session is dead; sessions can be refreshed and expired ones cleaned up. Times are integer ticks.
Welcome to the team that owns sessions. A session store keeps sessions keyed by id; an expiry policy decides when a session is dead; sessions can be refreshed and expired ones cleaned up. Times are integer ticks.
This repository has three reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
sessions/
models.py domain types (Session: sid, expiry, data)
errors.py SessionError
expiry.py ExpiryPolicy: is_expired(session, now)
store.py SessionStore: put / get / delete / all / size
service.py SessionService: create / get / touch / cleanup / size
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
now >= expiry.get returns the session data; an expired one returns nothing.touch extends a session's life to now + ttl.cleanup reclaims expired sessions so the store does not grow without bound.A session is still considered valid at exactly its expiry tick. The policy should treat a session as expired once now >= expiry, but it uses a strict greater-than, so sessions survive one tick past their deadline.
now == 10.now == 9.Do not change touch or cleanup as part of this ticket.
Active users are being logged out on schedule even though they are still using the app. touch is a no-op, so a session never gets its life extended.
touch(sid, now, ttl), the session is valid until now + ttl.Do not change the expiry boundary rule as part of this ticket.
The session store grows without bound. cleanup does nothing, so expired sessions accumulate and leak memory over time.
cleanup(now) removes every session with now >= expiry.Do not change the expiry boundary rule as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.sessions/ are submitted; the shipped tests in tests/visible run as they are.Adapted from treasure567/bloomberg-practice (round-2/saffron @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
sessions-late-expiry-dead-refresh-and-unbounded-store
Changes under src/ are evaluated.