Repository navigation
fix(threading): follow mentioned humans - #1157
Conversation
07d834f to
7bd2f27
Compare
7bd2f27 to
785ab9c
Compare
lilyshen0722
left a comment
There was a problem hiding this comment.
Gated at 785ab9cb. All 11 checks pass. The shape is right — resolving humans at the same post-persistence choke point, gating on pod membership, and routing both populations through followByParticipation so the NULL-only write keeps a mute intact. Four findings, none of which I'd block on, but the first two are worth closing before this merges rather than after.
1. The RegExp is injection-safe only because of a precondition this same commit changed
$or: handles.map((username) => ({ username: new RegExp(`^${username}$`, 'i') })),username is interpolated straight into a regex. That is safe today only because extractMentions constrains handles to [a-z0-9_-], and neither - nor _ is special outside a character class. Nothing states that dependency, nothing enforces it, and it spans two functions ~800 lines apart.
What makes it worth fixing now rather than noting: this PR widens that very character class ([a-z0-9-] → [a-z0-9_-], line 176). The precondition the regex safety rests on is being edited in the same commit that relies on it. The next widening — a ., a +, a unicode range — turns a mention into a regex the server executes against every User document.
Cheapest fix is to escape rather than to document: username.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'). Then the safety is local and survives any future change to the extractor.
2. The lookup cannot use the username index
User.username is { type: String, required: true, unique: true } with no collation (backend/models/User.ts:177). A case-insensitive regex cannot use a plain B-tree index even when anchored, so each $or term is a collection scan over users — on the message-send path, once per threaded message carrying mentions.
Small at today's scale and genuinely unbounded in shape. If the case-insensitivity is required (the comment says usernames are not normalized at write time), the durable answer is a case-insensitive index or a normalized usernameLower field, not a regex. Worth a comment at minimum so the next person profiling message-send finds it named.
3. The extractor widening reaches agents, not just humans
- const regex = /@([a-z0-9-]{2,})/gi;
+ const regex = /@([a-z0-9_-]{2,})/gi;extractMentions feeds agent resolution too. @nova_thanks previously extracted nova and resolved to that agent; it now extracts nova_thanks and does not. That is arguably a correctness improvement — the old behaviour was over-matching — but it is an agent-path behaviour change shipped inside a PR titled "follow mentioned humans", and nothing in the diff tests it. One case either way would pin the intent.
4. The spec named a test that isn't here
TASK-050 lists two: "mentioned human with no posts is woken after this; muted human is not." The first is :315. I can't find the second. :269 is a muted seat that is addressed, which is mention delivery rather than follow-write, and on the agent path.
The mute does survive — followByParticipation writes only where following IS NULL, and both populations now go through it — so this is a missing guard rather than a missing behaviour. But the human path is new, and the property the task called out is the one thing nothing exercises for it.
Not verified
I read the diff and the suite; I did not run either. My working tree predates the post-threading services and cannot host these files. CI at Node 22 is the execution evidence, and it is green on all 11.
…, agent or human — #1157 landed, the bullet widens back Co-Authored-By: Claude Fable 5 <[email protected]>
…r; the resolver refuses only disagreement (#1154) * docs(design): the composer's target exclusivity is the enforcing layer — the resolver refuses only disagreement #1153 found resolveThreadRoot rejects a reply edge + explicit root only when they disagree; an agreeing pair passes. So 'an in-thread post addresses nobody' is enforced by the composer's one-target-two-kinds rule, on every send path (text and upload), each pinned — not by a server refusal. Co-Authored-By: Claude Fable 5 <[email protected]> * docs(design): a send consumes the composer target on every path — text and image clear alike Co-Authored-By: Claude Fable 5 <[email protected]> * docs(design): the rail is the context — no quote block for a reply whose quoted message is the visible thread parent (Sam, 57487) Co-Authored-By: Claude Fable 5 <[email protected]> * docs(design): quote-and-thread independence is full both ways — any quote renders; only the root's redundant quote under its own rail is hidden (Sam, 57491) Co-Authored-By: Claude Fable 5 <[email protected]> * docs(design): mention-follows-you is agent-only today; a mentioned human who never posts follows nothing (pod-architect, 57535) Co-Authored-By: Claude Fable 5 <[email protected]> * docs(design): a delivered @-mention follows the mentioned participant, agent or human — #1157 landed, the bullet widens back Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
… away @sprint-review flagged this on #1157 before it merged; the press landed without it. `resolveHumanMentionUserIds` built `new RegExp(`^${username}$`)` by raw interpolation, injection-safe only because `extractMentions` constrains handles to `[a-z0-9_-]` — a precondition the same commit was widening. Not a live injection: none of those characters are metacharacters. It is a locality defect. Nothing at the call site fails when the class widens; the query just starts matching the wrong users, silently, on a path whose whole job is deciding who gets followed into a thread. Escapes the interpolation and exports the matcher, because the property that matters is unreachable through `enqueueMentions` while `extractMentions` still excludes metacharacters — a test restricted to today's inputs passes identically before and after the fix. Verified against the pre-fix form: 5 of the 8 cases fail, and the 3 that pass either way are exactly the reachable ones. Co-Authored-By: Claude Opus 5 <[email protected]> Co-authored-by: forge <[email protected]> Agent-Model: codex/gpt-6-sol/medium
Summary
[a-z0-9_-]), so a selected username such as@casey_devreaches that resolutionThreadUserState.followByParticipation, whoseWHERE following IS NULLkeeps explicit mutes intactVerification
PATH=/opt/homebrew/opt/node@22/bin:$PATH npx jest --runInBand --silent __tests__/unit/services/agentMentionService.test.js __tests__/unit/services/agentMentionService.wakeOnMessage.test.js __tests__/unit/services/agentMentionService.threadScoping.test.js __tests__/unit/services/agentMentionService.threadingIsNotAddressing.test.js __tests__/unit/services/threadFollowByParticipationWiring.test.js __tests__/unit/models/threadFollowByParticipation.test.js __tests__/unit/services/threadWakeScope.test.js(149 passed)PATH=/opt/homebrew/opt/node@22/bin:$PATH npm run tsc:checkFollow-up
#1154 currently narrows the ruling to shipped behavior. Once it lands, this branch will rebase and restore the broader human-plus-agent wording.