Skip to content

refactor: mailbox.py becomes messages.py, so it no longer hides the standard library's mailbox - #22

Merged
BukeLy merged 1 commit into
mainfrom
refactor/messages-module
Nov 23, 2026
Merged

BukeLy merged 1 commit into
mainfrom
refactor/messages-module

Conversation

@BukeLy

@BukeLy BukeLy commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

server/mailbox.py is now server/messages.py, so it no longer has the same name as the standard library's mailbox.

  • Why. A script run from outside server/ that did import mailbox got the standard library's module. Ruff also needed known-first-party = ["mailbox"] to sort the import as ours.
  • What moves. The file keeps its contents; git sees a 100% rename. Every import and mailbox. reference now says messages, and so does the Dockerfile's COPY list. The ruff override is gone.
  • Tests. Three panel tests named a local variable messages. It is now transcript, 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 needs gh and PEERBOX_TEST_ORG)
  • ruff check and ruff format --check, without the known-first-party override
  • The Docker image builds, starts on an empty database and lists all 16 tools

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-23T06:26:06.636629Z f8cba88 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BukeLy
BukeLy merged commit 4a09bc0 into main Nov 23, 2026
3 checks passed
@BukeLy
BukeLy deleted the refactor/messages-module branch November 23, 2026 06:37
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant