Repository navigation
Conversation
…ers back with their author, in batches Three gaps left by #3366 (store version 77): - The owner's choice always wins (contact-kinds plan, "Moving between entities" and "Mail categories"). sortRuleFor now walks every owner's rule in level order first, then every program's, then the header classifier. Within one author the first level that has a rule wins and within a level the newest. The index is split by author before the domain-suffix walk, so a program's rule on mail.shop.example no longer hides the owner's rule on shop.example. - Removing or undoing a sender rule moved senders back through moveToPerson and moveToBot, which log the owner as author, so the kind pass never sorted them again. An effect's `before` now keeps who put the sender there (`sender-bot:4 rules`, `person:9 owner`), and the new putBack in sender-bots.ts moves it back with that author through intoBot / outOfBot. A rules bot gone with its last identity comes back as a new rules bot. A sender the owner moved since the rule stays. - remove, undo and reset now mark the rule removed in one write, then put senders back 100 per write, as add already settles them. Pending put-backs are picked up by state, so a stopped run resumes on the next remove, undo or reset. No schema change: version 77 is not on npm yet, so `before` changes form without a migration. Docs: GLOSSARY "sorting rule", schema notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pped put-back Removes a 120-sender rule, two writes of 100, and finishes a put-back that a stopped run left behind. A chunk answers whether more may be left, so the last one does not run one empty write more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured with a second writer that goes through the store's own write (100,000 synthetic emails, load 10 to 16): a sender rule's add, 100 per write, still made that writer wait the full 5 s and give up, on the build before this branch too; the chunked undo made it wait 4.1 s. Each loop began its next write at once, and write pauses only when it waited itself, so the waiter never saw the lock free. transaction.ts now exports letWaitersIn, the 2 ms pause writeBatch already takes after a commit, and the sorting loops take it between two writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Task
Three gaps #3366 (mail sorting rules, store version 77) left open. The contact-kinds plan (#3323, "Moving between entities" and "Mail categories") says the owner's choice always wins, and names this follow-up: "the owner's rules win across levels, and a removed rule puts senders back with their earlier author."
Why
moveToPerson/moveToBot, which log the owner as author. The kind pass then treated them as the owner's choice and never sorted them again. Measured: all 500 senders of an undone rule kept the owner's mark.What
Order (
src/mail/sort-rules.ts):SortIndexis split by author before the level walk.sortRuleForchecks every owner's rule in level order, then every program's, then the header classifier. Within one author: the first level that has a rule wins, then the newest.overAddressesbeats the same author's address rules. A program's rule onmail.shop.exampleno longer hides the owner's rule onshop.example.Put back with the earlier author (
src/store/sqlite/sender-bots.ts,mail-sorting.ts):beforenow keeps who put the sender there:sender-bot:4 rules,person:9 owner. For a bot that is the bot's author. For a person it is the author of the identity's last move, orruleswhen nothing moved it.putBackmoves the sender back throughintoBot/outOfBotunder that author, with the side effects the public moves have: renaming after leaving, domain grouping, releasing domain holds. A rules bot that was deleted with its last identity comes back as a new rules bot.Batches:
remove,undoandresetmark the rule removed and clear its types in one write. Then they put senders back 100 per write. Pending put-backs are found by state (effects of removed rules not yet undone), so a stopped run resumes on the nextremove,undoorreset.A waiting writer gets in (
transaction.ts): a new export,letWaitersIn, is the 2 ms pausewriteBatchalready takes after a commit. The sorting loops (add, and the put-back) take it between two writes. Without it a second writer that goes throughwritestill gave up after 5 s during the add, onmaintoo.No schema change. Version 77 is not on npm yet (latest is 1.1.0), so
beforechanges form without a migration. The schema note and GLOSSARY "sorting rule" are updated.Timings
100,000 synthetic emails, 500 senders on one domain, load 8.6 to 15.8, with a second writer that goes through cli-core's
write(cli-testing#413,performance/mail/rules, "Round 2"):main(#3366)On a busy disk, the commit sets the lock time, not the senders. Each write of 100 is about 20 ms of work plus 55 ms of queued work, and the
COMMITtook 0.1 to 3.3 s. So writes of 100 did not keep each write under 1 s here. They also make an undo slower in total thanmain's single write. Whether to keep 100 is an open decision for the owner.Testing
src/store/mail-sorting.test.ts:main.src/mail/sort-rules.test.ts: the authors case now asserts the owner wins across levels, and a subdomain case.pnpm typecheck,biome check .(no errors),schema:check, the docs checks,cli-dev api-report --check, and the full vitest suite (996 files, 13,776 tests).Not in this PR
moveToPerson) writes an owner-authoredidentity_link_eventsrow. It stays after a removal. The CRM cleanup reads it (it never deletes a CRM contact the owner moved). Automatic sorting does not read it.🤖 Generated with Claude Code