Repository navigation
feat(people): sender bots apart from people (store version 74) - #3339
Merged
Merged
Conversation
leemour
force-pushed
the
feat/bots-entity
branch
from
November 25, 2026 03:09
1dff42b to
8b77bca
Compare
A program that writes to the owner (a no-reply or notification address, a messenger bot, signed Auto-Submitted mail, an empty Return-Path, memo's bulk_never_replied) becomes a sender_bots row instead of a person marked automated. The bot keeps the person row it was sorted from, so identity links, ingest, merges, purges and person:<uid> refs keep working, and people.list lists it as automated with bot: sender-bot:<id> and no ties. - Store version 74: sender_bots, sender_bot_moves (every move, rules or owner, with the reason), triggers in place of foreign keys so older builds can still erase and purge, kind-clearing triggers, and emails_by_list_id so a page of people no longer reads every stored List-Id. - Kept kinds move a person to a bot by rule only on a program's signal, when the owner wrote them nothing and every identity is the program's; a rule's bot goes back when the rules stop holding. KIND_RULES 7. - store.people.moveToBot / moveToPerson: the owner's choice, for a person, a bot or one identity, wins over the rules and KIND_RULES bumps. - The matcher never joins a bot, tasks.assign refuses one, people.similar and people.ties leave bots out. Part of #3314. Merge after #3288 (store version 73). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leemour
force-pushed
the
feat/bots-entity
branch
from
November 25, 2026 03:22
8b77bca to
83c62a4
Compare
leemour
added a commit
that referenced
this pull request
Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leemour
added a commit
that referenced
this pull request
Nov 25, 2026
## Task Plan step 5 of the contact-kinds plan ([plan #3323](#3323), "Grouping under an organization"): organizations from mail domains, with the three exceptions. Part of #3314. ## Why After #3339 a program that writes to the owner is a sender bot, but nothing says whose bot it is. Ten no-reply and `info@` addresses of one bank showed as ten unrelated senders. People at that bank had no link to it either. ## What **The rule** (`src/store/sqlite/domain-organizations.ts`, run from `keep()` in `people-list.ts` after the rule moves and before the kinds are written): - A sender bot, or a shared mailbox (kind `organization` by `role-address`), at a company domain joins the organization of its registrable domain (`registrableOf` / tldts `getDomain`: `mail.bank.ru` and `bank.ru` are one). - The organization is the one already holding an address at that domain. Otherwise a new `company` is made, named by the sender when the name is a company's (`isCompanyName`) or equals the domain's own word (`Bank` for `bank.ru`); otherwise it is named by the domain. - The addresses go to `organization_identities` with method `domain`, author `rules`, and the bot's `sender_bots.organization_id` is set. - This never goes to merge review and makes no proposal. - A human with an address at that domain gets a `member-of` link (author `rule`, `metadata.derived = "mail-domain"`, confirmed). They are never merged. A new organization also links the humans already stored at its domain. - **Exceptions:** `FREE_MAIL`; throwaway mail from `disposable-email-domains-js` (CC0, already a dependency, so nothing was vendored); and `SENDING_PLATFORMS`, a hand table. A platform domain never groups anything. - **The owner's word wins:** - The owner removes a membership (`knowledge.removeRelation`). The existing rejected `relationship` proposal is checked, and the link is never added again. - The owner erases an organization (`knowledge.eraseOrganization`). This leaves a rejected `proposed_actions` row of kind `organization-domain` for each company domain it held, and the rule never makes an organization for that domain again. The row is written only from the owner-facing erase, not from a CRM purge's clean-up. - The owner moves a bot to a person (`moveToPerson`). The rule's holds on those identities go. A person the owner kept as a person holds nothing; they can still be a member. - `KIND_RULES` goes to 8, so the first list after the upgrade groups the senders already stored. **Decisions I made (owner asleep):** - **No migration.** `sender_bots.organization_id`, `organization_identities.method/author` and `links.author` already exist, so I made no #3157 reservation. - **A human alone makes no organization.** Otherwise every correspondent's company becomes one. A human is linked only to an organization that already holds the domain. - **New organizations get scope `personal`**, the schema default. The other automatic creators use `work`, but these senders are mostly services the owner uses privately. - **`member-of` role is null.** The rule cannot tell an employee from a contact. - **The owner and test people are left out.** - **A domain that two organizations hold is skipped**, not guessed. - **Link source `owner`, author `rule`** follows the `tasks.ts` `answered-by` precedent. `LINK_ORIGINS` has no `rule`. - **Only `From` is matched.** The plan's DKIM-domain matching and grouping by `List-Id` or display name inside a platform are not built. The bounce and DKIM entries in the table guard mail whose `From` carries them. **Sending platforms, checked against vendor pages on 2026-11-25:** | Status | Domains | |---|---| | Verified on the vendor's own page | `amazonses.com` ([AWS](https://docs.aws.amazon.com/ses/latest/dg/mail-from.html)), `mandrillapp.com` ([Mailchimp](https://mailchimp.com/developer/transactional/docs/authentication-delivery/)), `mtasv.net` ([Postmark](https://postmarkapp.com/support/article/910-how-do-i-add-a-custom-return-path)), `ghost.io` ([Ghost](https://ghost.org/help/custom-sending-domains/)), `mcsv.net`, `mcdlv.net`, `mailchimpapp.net`, `rsgsv.net` ([Mailchimp](https://mailchimp.com/help/my-campaign-from-name-shows-mcsvnet/)) | | Partial | `sendgrid.net` ([Twilio](https://www.twilio.com/docs/sendgrid/ui/account-and-settings/how-to-set-up-domain-authentication); the page does not name the header), `buttondown.email` ([Buttondown blog](https://buttondown.com/blog/sending-email-address), not docs), `mailgun.org` ([sandbox only](https://documentation.mailgun.com/docs/mailgun/user-manual/domains/domains-sandbox)) | | Search excerpt of a vendor page only (the page refused the fetch or redirects) | `substack.com`, `sparkpostmail.com`, `brevosend.com`, `beehiiv.com` | | Unverified | `buttondown.com`, `list-manage.com`, `postmarkapp.com`, `mailgun.net`, `convertkit-mail.com`, `sendinblue.com`, `mlsend.com` | **PERF (found, not fixed here):** `isDisposableEmailDomain` builds its whole set on every call, about 0.5 ms each. The new module builds the set once. `src/mail/score.ts` still calls the slow function per sender. **Gaps left:** - The owner can take one bot or mailbox out of its organization only by erasing the organization or by `moveToPerson`. No store method detaches one address. memo needs one before it can offer "not this company". - No `category` from domain lists (out of scope). - memo and Desktop do not show organizations of bots yet. ## Testing All runs used `--maxWorkers=1`. - New `src/store/domain-organizations.test.ts` (7 integration tests): - a bot and an `info@` at `mail.bank.ru` / `bank.ru` → one organization named `Bank`, and the bot's `organization_id` is set; - a name that is no company's → named by the domain; - `gmail.com` and `mailinator.com` → none; - two newsletters on `substack.com` plus one on `ghost.io` → no organization, no membership; - a human at a company domain → `member-of`, whether the human came first or later, and no proposal; - the owner's separations (a removed membership, an erased organization, a bot moved to a person) are not undone after every kind is worked out again; - a second full pass changes no row. - `people-list.test.ts`: the shared mailbox `info@hotel.ru` now also has the `organization` signal, because an organization holds it. - Existing suites passed: sender-bots, people-list, people-kinds-stored, people-matching-rules, person-match-scan, person-doubts, person-merges, person-separation, person-erase, organization-erase, agent-links, crm-email-join, identity-links, identity-splits, same-email-join, mail-findings, mail, records-matching, people-owner, mail/own, mail/sender-signals, crm/relations, messenger, proposals registry, private-people, owner-labels, people-owner-guard, rollback-copy, store, upgrade, version-61, version-66, mcp-doctor, store-maintenance, store-tables. - `pnpm typecheck`, `pnpm lint`, `schema:check`, `docs:check`, and `command-lint`. **Cost**, on a synthetic store with 22,000 senders: 10,000 no-reply bots and 4,000 role mailboxes across 2,000 domains, 6,000 humans at those domains, and 2,000 at gmail. Load average was about 15. | Step | Time | |---|---| | First list after the upgrade (rule moves, kinds, grouping) | 1.6 s | | The grouping pass alone, making 2,000 organizations, 14,000 holds, 6,000 links | 0.64 s | | The same pass with nothing to do | 0.16 s | | The pass for 50 people | 30 ms | | A list after a small sync | 0.55 s | All of it runs under the write lock, well under the other writers' 5 s wait. Before the disposable-set fix, the pass with nothing to do took 13 s. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 2026
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.
Rebased onto main after #3338 (store version 73, which replaced #3288). Version 74 was regenerated from 73's snapshot. Its new tables use
AUTOINCREMENT, as 1.0 asks, andminCompatiblestays 73.api/store.api.txtanddocs/reasons.mdwere regenerated.version-73.test.tsnow migrates only up to 73, so a later version does not break it. The changelog entry is under "Changed — experimental":KindSignaland the people list are@experimental, and the rest only adds things, so no major is needed.Task
Plan steps 3 and 4 of the contact-kinds plan (plan #3323): bots as their own entity, and the owner's choice to move a sender between a person and a bot. Owner's ruling NEED-109 A. Part of #3314.
Why
A bot was a person with the kind
automated. Every list, merge scan and tie check had to remember to skip it, and each one that forgot was a bug (#3320 was one). The owner also had no way to say "this is a bot" or "this is a person" in a way that holds.What
Schema chosen (store version 74). Tables, an index and triggers added only.
minCompatiblestays 73.sender_bots(id,person_idunique, name,organization_id, authorrulesorowner, reason, times).botswas already taken by agents, andbot:<n>refs mean agents, so the table issender_botsand the ref issender-bot:<id>.identity_linkson that row. I chose this overidentity_links.bot_idor abot_identitiestable:identity_links.person_idisNOT NULL. Making it nullable needs a table rebuild.identity_links. Taking an identity out of it means ingest creates a new person on the next sync (ensurePerson). The emptied person also shows as "added by hand".person:<uid>refs (person_refinpeople.rs).people show person:<uid>keeps working.sender_bot_moves: one row per identity per move. It holds from (person or bot), to, authorrulesorowner, reason, and time.document_changesdoes, so an older build can still erase a person or purge an account. Triggers drop the rows with the person or identity, and clear the organization. Other triggers clear the stored kind when a bot or a move is written.emails_by_list_idon the exact List-Id expressionsentMailOfuses. No new column and no backfill:CREATE INDEXfills it. A test asserts thatEXPLAIN QUERY PLANof the real statement (LIST_SENDERS) uses the index. The schema codegen now passes an expression key through.Rule move (
people-list.ts,KIND_RULES7). When kinds are kept, a person moves to a bot when all of these hold:automatedby a program's signal: the platform bot flag, a no-reply or notification address, a signed Auto-Submitted, a null return path, orbulk_never_replied;ALWAYS_SHOWNreason applies;Other cases:
automated-nameor a bulk mailbox alone marks a person and moves nothing. A newsletter a human writes stays a person.Owner's choice.
store.people.moveToBot(subject, by, { bot?, name?, reason? })andmoveToPerson(subject, by, { person?, reason? }). Subject:person:<uid>,sender-bot:<id>or anIdentityRef. Owner only (identity.owner-only).author = 'owner'. An identity whose latest move is the owner's, to a person, is never moved by a rule. Both surviveKIND_RULESbumps (tested).Bots are left out of:
identity.not-a-personfor email and phone joins too; name scans already skipautomated);tasks.assign(new reasonsender-bot.assignee);people.similar;people.ties(empty).kind:automatedcompatibility. A bot is still listed asautomatedunder itsperson:<uid>ref, with the same counts and paging. The row gainsbot: "sender-bot:<id>" | nulland has emptyties. memo'spersonRowand Desktop'slisted()read named fields only, so both keep working unchanged.People counts.
people.listcounts are the only people tallies in cli-core. Bots count underautomatedand never underperson.Alias joining the owner later (item 4). I found no stale kind.
person_kind_email_auclears the recipients' kinds whenmarkOwnMailflipsoutgoing. A new test insrc/mail/own.test.tsproves it: stranger first, person after the alias joins. No fix was needed.Not in this PR (memo needs):
bots listand a command for the two moves (for examplepeople bot <ref>andpeople person <ref>), and a field for the bot ref onpeople listrows. Call that fieldsender_bot, notbot: Desktop'sListed.botalready means "has the messenger bot signal". Desktop needs a Bots tab (plan step 7). No downstream implementsPeopleStore(grep of cli-memo, wirecat-desktop, cli-template).RISK. The first list after the upgrade creates every bot under the write lock. A synthetic store with 20,000 no-reply senders took 1.4 s for that list, against 0.66 s with nothing to move (load average about 30). The lock part stays under the other writers' 5 s wait. Chunk it if a real store shows more.
Testing
All runs used
--maxWorkers=1.src/store/sender-bots.test.ts(8 tests):KIND_RULESchange, refused for an agent and for the owner's own person;EXPLAINshows the index is used;pnpm typecheck,ci:quick,schema:check,docs:check, and Biome on the changed files.spec.mjs(+2),schema.ts(+5) andreasons.ts(in the 1010 group), as version 72 did.🤖 Generated with Claude Code