Persist a structured selection_source beside the assistant prompt, and use
the legacy sidebar prompt's containing message, role and selection to
disambiguate repeated text. Scan every user message for a quote, refuse to
guess between several, and make the backfill conditional so a concurrent move
or detach wins.
Serialize PocketBase preference merges with a lock that spans event loops,
not one asyncio lock per loop, and validate client-supplied anchors on turns
and organization updates. Detach threads when the message they point at is
deleted.
quoted_message_id now follows the create_target rule: the key's presence
is authoritative. A value moves the thread, an explicit null clears it,
and omitting the key leaves the stored anchor untouched. A new selection
moves the thread to the passage just asked about.
The message-level popover gains a detach action that clears the anchor
through the organization PATCH without deleting the conversation, and a
deliberate clear also stops the legacy backfill from re-attaching it.
Threads created before the attribution existed kept only the passage:
selection threads store it in tutor_selected_text, newer side chats as a
quote attachment. Match that passage against the parent transcript with
the Markdown projection selection grounding uses, and record the source
only when exactly one message contains it.
The scan is recorded per thread and runs when the thread list is read,
so it happens once; touch=false keeps the thread's place in the list.