Six things that looked like they worked

None of these fails loudly and two of them correct themselves if you reload,
which is why five were found by reading rather than by anybody reporting them.

The reply that lost its author is the one worth knowing about: the frame that
replaces a bubble when a reply lands was looking the models up as nobody, and
"no user" answers "no models" rather than "all models" -- so every finished
reply swapped the model's avatar for the plain mark and put the instance's name
where the model's should be, until the next page load put it back.

Beside it: a concurrency quota enforced on two of the six paths that start a
reply, including neither of the two most used; a custom theme whose success and
warning colours moved the text and left the background behind; a phone shell
sized to one viewport inside a document sized to another, which is the reported
scroll past the bottom of Settings; a whole conversation's Markdown rendered on
every page load and read by nothing; a skip guard inert since it was written;
and an endpoint nothing has ever called.

The scroll fix folded five near-identical scroller rules into one, which is
also where the containment they were all missing now lives.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 12:49:26 +00:00
co-authored by Claude Opus 5
parent d73a791c86
commit 92070d7879
14 changed files with 259 additions and 82 deletions
+43 -21
View File
@@ -308,6 +308,12 @@ async def start_chat(
if not content and not file_ids:
return Response(status_code=status.HTTP_204_NO_CONTENT)
# Before `_new_chat`, not after: a refusal that has already written the row
# leaves an empty chat in the sidebar as the visible result of being told
# no. There is no chat yet to exclude from the count, and none is needed --
# nothing can be running for a chat that does not exist.
_refuse_extra_reply(db, None, user)
chat = _new_chat(
db,
user,
@@ -981,7 +987,7 @@ def _note_rewind(chat: Chat) -> None:
chat.rewound_at = datetime.now(UTC)
def _too_many_replies(db: DBSession, chat: Chat, user: User) -> str:
def _too_many_replies(db: DBSession, chat: Chat | None, user: User) -> str:
"""Why this account may not start another reply right now, or "".
In-process, and that is exact rather than approximate only because this
@@ -998,10 +1004,13 @@ def _too_many_replies(db: DBSession, chat: Chat, user: User) -> str:
row[0]
for row in db.execute(select(Chat.id).where(Chat.user_id == user.id)).all()
}
# `chat` is None on the new-chat path, where there is no row yet and so
# nothing to exclude -- every running reply of theirs counts.
here = chat.id if chat is not None else None
running = sum(
1
for chat_id in mine
if chat_id != chat.id and generation_service.running_for(chat_id) is not None
if chat_id != here and generation_service.running_for(chat_id) is not None
)
if running < ceiling:
return ""
@@ -1011,6 +1020,22 @@ def _too_many_replies(db: DBSession, chat: Chat, user: User) -> str:
)
def _refuse_extra_reply(db: DBSession, chat: Chat | None, user: User) -> None:
"""Raise if this account is already writing as many replies as it may.
A function rather than two lines repeated, because it is repeated five
times now. It used to be called once -- from `_send`, which serves
`post_message` and `execute_plan` -- while four other routes start a
generation: `start_chat`, `edit_message`, `send_queued_now` and
`regenerate`. So a group's `concurrent_replies` was reached by sending into
a chat that already existed and walked straight past by pressing New chat,
which is the commonest way to start a reply there is. A quota you can step
over by using the obvious button is not a quota.
"""
if busy := _too_many_replies(db, chat, user):
raise HTTPException(status.HTTP_429_TOO_MANY_REQUESTS, busy)
def _send(
request: Request,
db: Db,
@@ -1042,8 +1067,7 @@ def _send(
# This chat's own reply does not count against it -- a second message here
# is queued rather than sent, a few lines down, and that path is what the
# queue is for.
if busy := _too_many_replies(db, chat, user):
raise HTTPException(status.HTTP_429_TOO_MANY_REQUESTS, busy)
_refuse_extra_reply(db, chat, user)
if queued := _reply_in_flight(db, chat):
waiting = db.scalar(
@@ -1328,8 +1352,16 @@ async def _follow(chat_id: str, message_id: str) -> AsyncIterator[str]:
# template shares both roles, and a missing `user` would only
# blow up on whichever branch is not being exercised here.
"user": owner,
# `owner`, never None. `models_visible_to` answers an absent
# user with [], so a None here is not "every model" but *no*
# model -- and this frame replaces the whole bubble at the
# moment a reply finishes. The template then finds no
# `speaking_model` and the finished reply swaps its avatar for
# the LLeMbas mark, its author for the instance name, and grows
# a raw model_id chip, all of which a reload silently corrects.
# That is why it went unreported for so long.
"models_by_id": {
m.model_id: m for m in chat_service.available_models(db, None)
m.model_id: m for m in chat_service.available_models(db, owner)
},
# This frame replaces the whole bubble, so it has to carry the
# speaker button's conditions too -- and the owner's, not the
@@ -1360,7 +1392,7 @@ def _render_bubble(db: DBSession, chat: Chat, owner: User | None, message: Messa
"message": message,
"chat": chat,
"user": owner,
"models_by_id": {m.model_id: m for m in chat_service.available_models(db, None)},
"models_by_id": {m.model_id: m for m in chat_service.available_models(db, owner)},
**audio_service.template_flags(db, owner),
}
)
@@ -1447,11 +1479,6 @@ def _thread_context(db: DBSession, chat: Chat, user: User) -> dict:
"user": user,
"messages": messages,
"compacted": compacted,
"bodies": {
m.id: render_markdown(m.content)
for m in everything
if m.role == ROLE_ASSISTANT and m.content
},
"models_by_id": {m.model_id: m for m in chat_service.available_models(db, user)},
**audio_service.template_flags(db, user),
}
@@ -1560,6 +1587,8 @@ async def edit_message(
raise HTTPException(
status.HTTP_409_CONFLICT, "Wait for the current reply to finish, or stop it."
)
# `_reply_in_flight` is about *this* chat; the quota is about the account.
_refuse_extra_reply(db, chat, user)
message.content = content
@@ -1703,6 +1732,7 @@ async def send_queued_now(
raise HTTPException(
status.HTTP_409_CONFLICT, "Wait for the current reply to finish, or stop it."
)
_refuse_extra_reply(db, chat, user)
message.queued = False
db.commit()
@@ -2123,16 +2153,6 @@ async def delete_chat(db: Db, user: RequiredUser, chat_id: str) -> Response:
return response
@router.get("/{chat_id}/messages/{message_id}/raw")
async def raw_message(db: Db, user: RequiredUser, chat_id: str, message_id: str) -> HTMLResponse:
"""The unrendered Markdown of a message, for the copy button."""
_owned_chat(db, chat_id, user.id)
message = db.get(Message, message_id)
if message is None or message.chat_id != chat_id:
raise HTTPException(status.HTTP_404_NOT_FOUND, "That message no longer exists.")
return HTMLResponse(escape_text(message.content))
@router.post("/{chat_id}/messages/{message_id}/regenerate")
async def regenerate(
request: Request,
@@ -2147,6 +2167,8 @@ async def regenerate(
if message is None or message.chat_id != chat.id or message.role != ROLE_ASSISTANT:
raise HTTPException(status.HTTP_404_NOT_FOUND, "That reply no longer exists.")
_refuse_extra_reply(db, chat, user)
message.content = ""
message.error = ""
message.complete = False