Skip to content

The bot leaves its diary session failed when another request signs it out while switching pupils #725

Closed

Description

@lumenpearson

Recovered while analysing the unmerged Claude Code branch server/stale-writes-bot-654 for #724.

The branch contains a regression absent from the release tree. In bot.handlers.diary._show, changing row.student_id calls session.commit directly. If another request or retention sweep deletes that DiarySession after it was read, SQLAlchemy raises StaleDataError. The broad upstream handler answers that the diary returned something unexpected, and the request session remains failed; the middleware's later commit raises PendingRollbackError.

Observed on55b4c799 with a synthetic upstream and a real separately committed SQLite deletion: the recovered test failed1case/15deselected in4.96s, at the middleware commit after the callback. No live diary or account was used.

Treat this as the existing signed-out state, roll back before answering and do not dereference expired class/session objects. Retain a focused regression asserting the signed-out callback, committed deletion and a usable session. The rest of the old branch needs semantic reconciliation with newer parent-retention fixes, not wholesale replacement.

Refs #654, #724.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions