Repository navigation
refactor: mailbox.py becomes messages.py, so it no longer hides the standard library's mailbox - #22
Merged
Merged
Conversation
…tandard library's mailbox Run from outside server/, import mailbox got the standard library's module, and ruff needed known-first-party to sort it as ours. The module keeps its contents. Three panel tests name their transcript transcript, not messages, so no local hides the module.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
4 tasks done
BukeLy
added a commit
that referenced
this pull request
Nov 23, 2026
… its time grows with the messages, not their square (#20) ## Summary The panel's conversation list takes 0.4 s at 20,000 messages instead of 29.6 s. | Messages | Before | After | |---:|---:|---:| | 5,000 | 2,173 ms | 95 ms | | 20,000 | 29,635 ms | 395 ms | One person in that many messages with 50 others, all unread. Postgres 18 in Docker, best of 3 calls. - **Cause**: `conversations` ran three subqueries over the `sides` CTE once per message, not once per conversation. `EXPLAIN ANALYZE` at 5,000 messages showed `CTE Scan on sides s (... rows=100.00 loops=5000)` under SubPlans 4, 5 and 6. - **Fix**: a `totals` CTE aggregates `sides` once, grouped by key, and the `distinct on (x.key)` query joins to it. Every node in the new plan runs with `loops=1`. The only SubPlan left is the hashed `id in (select message_id from deliveries ...)` filter in `_MINE`, which runs once. - **Output**: same keys, same order, same values. The join is inner because each message in `mine` was sent by the person or delivered to them, so every key has totals. - **Rebased onto main** after #19 and #22. #22 renamed `mailbox.py` to `messages.py`, so the change now lands in `messages.py`. ## Test plan - [x] `uv run pytest -q`: 74 passed, 1 skipped (the 73 from before plus one new test). - [x] The new test, `test_each_conversation_counts_only_what_waits_in_it`, checks sides, waiting and waiting_since in two conversations. I broke the query four ways and it failed every time. Without it, two of those breaks passed every test: waiting_since taken from read messages too, and `totals` joined on `true`. - [x] Same output on mixed data (agents, talk between one person's own agents, three groups, some deliveries read, times out of id order): `conversations` for 21 people, 118 conversations, returned identical results before and after. - [x] `uvx ruff@0.17.6 check .` and `uvx ruff@0.17.6 format --check .` pass.
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.
Summary
server/mailbox.pyis nowserver/messages.py, so it no longer has the same name as the standard library'smailbox.server/that didimport mailboxgot the standard library's module. Ruff also neededknown-first-party = ["mailbox"]to sort the import as ours.mailbox.reference now saysmessages, and so does the Dockerfile'sCOPYlist. The ruff override is gone.messages. It is nowtranscript, the panel's word for a conversation's messages, so no local hides the module.Test plan
uv run pytest: 73 passed, 1 skipped (the live organisation test needsghandPEERBOX_TEST_ORG)ruff checkandruff format --check, without theknown-first-partyoverride