Skip to content

fix(threading): follow mentioned humans - #1157

Merged
lilyshen0722 merged 1 commit into
mainfrom
fix/human-thread-mention-follow
Aug 23, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
fix/human-thread-mention-follow

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • resolve unmatched explicit human @Handles to current pod members at the post-persistence mention-follow choke point
  • use the same handle alphabet as the composer ([a-z0-9_-]), so a selected username such as @casey_dev reaches that resolution
  • retain existing agent delivery routing and reuse ThreadUserState.followByParticipation, whose WHERE following IS NULL keeps explicit mutes intact
  • cover a mentioned human who has never posted, mute preservation in the wake-reader, non-members, and anchored non-prefix matching

Verification

  • 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:check

Follow-up

#1154 currently narrows the ruling to shipped behavior. Once it lands, this branch will rebase and restore the broader human-plus-agent wording.

@samxu01
samxu01 force-pushed the fix/human-thread-mention-follow branch 2 times, most recently from 07d834f to 7bd2f27 Compare August 23, 2026 01:19
@samxu01
samxu01 force-pushed the fix/human-thread-mention-follow branch from 7bd2f27 to 785ab9c Compare August 23, 2026 01:20

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lilyshen0722
lilyshen0722 merged commit 2301b51 into main Aug 23, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/human-thread-mention-follow branch August 23, 2026 04:00
lilyshen0722 added a commit that referenced this pull request Aug 23, 2026
…, agent or human — #1157 landed, the bullet widens back

Co-Authored-By: Claude Fable 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Aug 23, 2026
…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]>
lilyshen0722 added a commit that referenced this pull request Oct 23, 2026
… 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
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