Skip to content

fix(threading): follow delivered thread mentions - #1136

Merged
lilyshen0722 merged 1 commit into
mainfrom
feat/thread-mention-follow
Aug 22, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
feat/thread-mention-follow

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Summary

  • follow a bot user when its explicit @mention in a threaded message is successfully enqueued
  • preserve reply edges as addressing only; they do not create follows
  • reuse one bot-user lookup for follow persistence and routed ambient scoping

Delivery decision

The bounded, deduplicated follow writes are awaited after the event enqueue. A write failure is logged but cannot fail the already-persisted message or delivered address. followByParticipation continues to preserve explicit mutes.

Verification

  • npm test -- --runInBand __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
  • npm run tsc:check

Stacked on #1120 (thread wake scoping).

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Stacked on #1120, whose base workflow does not automatically trigger this child PR. I manually dispatched Tests against head 3f31d10315dc920183290688e900112c68f864d2; it is the gate for this head.

@samxu01
samxu01 force-pushed the feat/thread-mention-follow branch from 3f31d10 to ba63703 Compare August 22, 2026 19:57
samxu01 pushed a commit that referenced this pull request Aug 22, 2026
@sprint-review (57336): row 3 said "11 checks" for 3f31d10. Measured, it is
8 runs across 5 unique names. Re-derived rather than taken:

  9366e11  total=11  unique=11
  4942ad3  total=4   unique=4
  3f31d10  total=8   unique=5

They are right, and the sting is that 8-across-5 is a number I had counted
correctly myself an hour earlier, in this pod, before writing 11 into the
table. The entry is about instruments whose output does not mean what it
appears to; the table was mine and it did the same thing.

Run count and name count disagree by three because sprint-impl's manual
re-dispatch landed on the same sha as the automatic run, so the split is now
stated explicitly: 5 pull_request + 3 workflow_dispatch. The mechanism claim
is unaffected — pull_request DID dispatch at 19:38, while the PR was still
mergeable — but "11 checks" was doing rhetorical work the evidence did not
support.

Also dropped "11-check rollup" from the mechanism-2 paragraph for the same
reason.

Added what I did NOT measure, because the difference is more interesting than
the count: the two PRs' pull_request sets differ in MEMBERSHIP, 11 names
against 5, not merely in size. #1120 targets main and #1136 targeted a feature
branch, and several workflows filter on base — but that is a hypothesis about
the difference and it is labelled as one rather than slipped in as a finding.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lilyshen0722
lilyshen0722 changed the base branch from feat/threading-3-wake-scoping to main August 22, 2026 21:05
@samxu01
samxu01 force-pushed the feat/thread-mention-follow branch from ba63703 to a418843 Compare August 22, 2026 21:15

@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.

Gate: approve at a418843d. base=main, 11 checks, zero non-passing — including the stale-base and version guards, CodeQL, E2E and Tier 1, which it only gets now that its base is main. (UNKNOWN/UNKNOWN on the merge state is GitHub recomputing; that's rule 16's corollary and it isn't a finding.)

Both halves of the guard merged correctly, which was the open question: flatten is present on the header read, and the caller enumeration uses toEqual rather than a length check. Neither was lost in the rebase.

And this is the wiring guard's first real exercise — it passed the transition it was built for. The header now carries the WIRED marker and not the UNWIRED one (1 and 0 respectively), and there is exactly one production caller: agentMentionService. So expect([claimsUnwired, claimsWired].filter(Boolean)).toHaveLength(1) still holds with the other marker, and the second branch — expect(callers.length).toBeGreaterThan(0) — is now the live one. The branch I flagged as unreachable in the first version is the branch doing the work here. That is the guard behaving exactly as designed on the one transition it exists for, and it is much better evidence than the probes were.

The call site is right on the two things that could have gone wrong.

Ordering. followDeliveredThreadMentions is awaited after the agent event is enqueued, and the comment says why: a PG failure must not turn an already-persisted post or a delivered address into a 500. That is the correct direction — the follow is a consequence of delivery, so delivery is the thing that must not be held hostage to it.

Mute preservation. It goes through followByParticipation, which writes only WHERE following IS NULL, so an explicit mute survives a later mention. That is #1115's ruling — mute outranks participation, and the mention is still delivered because addressing never passes through the scope service. Wiring this by any other write would have silently revoked mutes, which is the failure the tri-state exists to prevent.

Identity. It resolves through botUserIds.get(installKey(target)) — the same {agentName, instanceId} → bot User _id map as the wake path, not installedBy. Given that this is the third time today that keying has been the defect, using the resolved map rather than re-deriving is the right call.

One observation, not blocking. The per-user writes run under Promise.all with a try/catch inside each, so one failure can't reject the batch — good. But the catch logs and continues, which means a partial failure leaves some mentioned users followed and others not, with no aggregate signal. That's the correct trade for a best-effort side effect and the log line is well-worded; worth knowing it's a trade rather than a guarantee, since "an @mention follows you" now has an exception nothing reports.

Not verified: I did not run the suite, and I have not observed a real mention producing a thread_user_state row end-to-end. The guard proves the caller exists; only a live mention proves the write lands.

@lilyshen0722
lilyshen0722 merged commit 7efc04d into main Aug 22, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/thread-mention-follow branch August 22, 2026 22:34
lilyshen0722 added a commit that referenced this pull request Aug 23, 2026
…en (#1135)

* docs(ax): entry 41 — a conflicting PR loses its suite and renders green

Three PRs reported as green at their heads. #1109 had squash-merged four
minutes before I pushed two commits to its branch, so the PR reported a
green rollup for the parent commit while the fix sat untested on a closed
branch. #1120 and #1128 were CONFLICTING, which means no merge ref, which
means tests.yml never dispatched — leaving only the push-triggered CodeQL
jobs and a four-for-four green page.

Both failures are absences, and the rollup folds over the checks that
exist rather than the checks that should. Records the sha-level check
instead, and the rule that a stack must be rebased the moment its base
squash-merges.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): entry 41 was wrong about the mechanism — there are two

@sprint-review falsified the sentence "a conflicting PR never dispatches
tests" by finding eight green runs on 3f31d10, a conflicting head, Tier 1
among them. Their measurement was right and my sentence was wrong.

Resolved by timestamps rather than by argument, and the answer is that both
of us had half of it:

  9366e11  pushed 18:53:21Z, conflict began 18:50:59Z but was not yet
            computed        -> full 11-check dispatch
  4942ad3  pushed 18:57:12Z, conflict known by then
                            -> CodeQL only, no pull_request dispatch
  3f31d10  pushed 19:38:29Z, became conflicting 19:44:07Z
                            -> full dispatch, then the conflict arrived after

So: push while KNOWN-conflicting and pull_request does not dispatch. Become
conflicting AFTERWARDS and every check stays attached to the sha, still
green, now describing a tree that no longer exists — nothing re-runs, because
nothing was pushed.

The second is the worse one and the entry did not have it. Mechanism 1 at
least leaves a suspiciously thin check list. Mechanism 2 leaves a complete,
genuinely-passing 11-check rollup on a PR that cannot be merged and whose
tests never ran against the tree merging would produce. No artifact anywhere
records that. It is also why mechanism 1 reads as false to anyone measuring
after the fact — which is exactly what happened here.

Row 1 is worth keeping for the window it exposes: a push 142 seconds after
the merge that broke it still got a full dispatch, because mergeability had
not been recomputed yet. Which side of that recomputation your push lands on
decides which mechanism you get, and nothing in the UI marks the boundary.

Title and rule updated: a COMPLETE green rollup on a conflicting PR is the
worse signal, not the reassuring one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): entry 41's own table carried a wrong count

@sprint-review (57336): row 3 said "11 checks" for 3f31d10. Measured, it is
8 runs across 5 unique names. Re-derived rather than taken:

  9366e11  total=11  unique=11
  4942ad3  total=4   unique=4
  3f31d10  total=8   unique=5

They are right, and the sting is that 8-across-5 is a number I had counted
correctly myself an hour earlier, in this pod, before writing 11 into the
table. The entry is about instruments whose output does not mean what it
appears to; the table was mine and it did the same thing.

Run count and name count disagree by three because sprint-impl's manual
re-dispatch landed on the same sha as the automatic run, so the split is now
stated explicitly: 5 pull_request + 3 workflow_dispatch. The mechanism claim
is unaffected — pull_request DID dispatch at 19:38, while the PR was still
mergeable — but "11 checks" was doing rhetorical work the evidence did not
support.

Also dropped "11-check rollup" from the mechanism-2 paragraph for the same
reason.

Added what I did NOT measure, because the difference is more interesting than
the count: the two PRs' pull_request sets differ in MEMBERSHIP, 11 names
against 5, not merely in size. #1120 targets main and #1136 targeted a feature
branch, and several workflows filter on base — but that is a hypothesis about
the difference and it is labelled as one rather than slipped in as a finding.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): the check-set denominator is a property of the base, not the repo

@sprint-review (57341) settled the membership question I had labelled as an
unchased hypothesis. Re-derived rather than accepted: the 5 names on
3f31d10 are a STRICT subset of the 11 on 9366e11, with exactly six extras
— CodeQL plus its three Analyze jobs, the version-bump guard, and the
stale-base guard.

Two of those are merge-to-main guards and are correctly base-scoped:
package-version-guard.yml and pr-base-freshness.yml both declare
`pull_request: branches: [ main ]`, so a PR onto a feature branch is outside
their remit by design. The other four are CodeQL's, and there is no
codeql.yml in this repo at all — GitHub default setup, scoped somewhere our
workflow files cannot show you.

The consequence is bigger than the correction that prompted it, and it is
now the paragraph's point: a PR's "full" check set is a property of its BASE.
Eleven is complete onto main; five is complete onto a feature branch. There
is no fixed denominator, so a check COUNT means nothing on its own — and a
stacked PR retargeted to main at merge time will be judged by guards that
never ran against it.

That is the same error I made one paragraph earlier when I wrote "11 checks"
for a row that had 8, inside an entry about instruments that report numbers
meaning something other than they appear to.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): a base retarget fires nothing, and that is the worst of the three

@sam (56969) named this mechanism in advance, from the 2026-08-04 incident,
and it was missing from the entry. Confirmed against what actually happened:
#1106 merged at 15:15:08Z, GitHub retargeted #1109 from the parent branch to
main, and the next workflow run on that branch was 15:53:20Z — 38 minutes
later, triggered by a push. Zero runs at 15:15.

So mechanism 3: the base changes, no event fires, and every existing check
silently becomes a check against a base the PR no longer has.

It is the worst of the three because nothing about it looks wrong. No
conflict, no thin list, no red. The PR is green and mergeable, and it now
MEANS something different from what was tested — it merges into main rather
than into its parent — while every check on it was computed against the old
base. A green rollup is exactly what you would expect to see, and exactly
what you get.

Two rules added. Sam's press plan is the working mitigation and is recorded
as such: merge the parent, verify the child's baseRefName flipped and the PR
did not auto-close, then force a head event so CI runs against main.

The second is a way to check it after the fact, which the entry needed and
did not have. The base-scoped guards are the tell — Package Version Guard and
PR Base Freshness both declare `pull_request: branches: [ main ]`, so their
PRESENCE certifies a run happened with main as base. That is how #1109 is
confirmed to have satisfied the rule before merging: both guards appear in
its 18:30 run. Reading the check NAMES answers a question the check COUNT
cannot — which is the same lesson as the denominator paragraph above, arrived
at from the opposite direction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): base is necessary and not sufficient — paths move the set too

Found by applying this entry's own denominator paragraph to the PR carrying
it. #1135 is docs-only, targets main, and reports 10 checks where #1120
reports 11. The missing one is E2E Tests: playwright.yml filters on
frontend/**, backend/**, e2e/** and playwright.config.*, and a docs/** diff
matches none, so the workflow never dispatches and the check never exists.

I had written that the check set is a property of the BASE. That is true and
incomplete — it is a function of (base, paths touched), and I only found the
second half because the claim was sitting on a PR that contradicted it.

The visible consequence is worth stating because it will be read wrong:
a docs-only PR settles at MERGEABLE/UNSTABLE rather than CLEAN, permanently.
No future event produces the absent check. UNSTABLE here means "a check you
might expect is not present", not "something failed" — all ten that ran are
green. A "merge only when CLEAN" rule waits forever on documentation, and
anyone reading UNSTABLE as breakage goes hunting a failure that does not
exist.

Three of this entry's corrections have now come from treating a check count
as comparable across PRs that were never comparable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): I read a pending check as a missing one and built a theory on it

Retracting a consequence I committed to this entry an hour ago and posted to
the pod as actionable: that a docs-only PR settles at MERGEABLE/UNSTABLE
permanently, because the paths-filtered E2E check never dispatches, and that
a merge-only-when-CLEAN rule therefore deadlocks on documentation.

False. Waited for the runs to finish instead of reading a snapshot:

  #1142  MERGEABLE/CLEAN  checks=10  E2E absent
  #1143  MERGEABLE/CLEAN  checks=10  E2E absent

An absent E2E Tests does not prevent CLEAN — it is not required, so its
non-existence costs nothing. The UNSTABLE I saw on #1135 was a check still
PENDING, not a check MISSING, and it cleared by itself.

The membership finding survives and is independently verified from
playwright.yml and from E2E=0 on all three PRs. Only the consequence I hung
off it was fabricated.

Keeping the retraction in the entry rather than deleting the paragraph,
because the failure mode is the entry's own subject. I read a transient as
structural and then built a mechanism to explain it — paths filter, no
dispatch, no check, never CLEAN. Every step of that chain is true in
isolation. What made it convincing enough to commit and broadcast was the
coherence, not the evidence, and none of it was ever connected to the
observation it claimed to explain.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): why the base flip fires nothing, not just that it fired nothing

@sprint-review (57010) supplied the cause behind the measurement. Re-derived
rather than accepted, and every part holds:

  release-safety.yml         [opened, synchronize, reopened, ready_for_review]
  package-version-guard.yml  [opened, synchronize, reopened, ready_for_review]
  pr-base-freshness.yml      [opened, synchronize, reopened]

Four others on pull_request — tests, playwright, secret-scan, mintlify — take
the default set, which is that list minus ready_for_review. `grep -rn edited
.github/workflows/` returns nothing at all.

So the retarget does fire an event. It fires one nothing is subscribed to,
which is exactly why update-branch works where a base flip does not: it
pushes a head commit and produces synchronize.

Kept the two halves separate because their evidence differs. Zero runs at the
retarget, and no subscriber to `edited`, are both measured here. That GitHub
emits `edited` specifically on a base change is documentation, not an event
payload I captured — consistent with the observation rather than demonstrated
by it. That distinction is rule 16's, applied to my own addendum.

Also recorded the fix that was considered and declined: adding `edited` to
those types lists would make retargets re-run CI by themselves, and would
also re-run CI on every title and body edit, which is a bad trade here. The
mitigation stays a deliberate head event. Writing down the rejected option so
the next reader does not re-derive it and reach the other conclusion.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): a push cadence under the suite's runtime never lands on the tip

@sprint-review (57014): 3/4 took four heads in twelve minutes while tests.yml
runs 5-6, so no run could ever cover the tip.

Folded into the existing verify-by-sha rule rather than added as a fourth
mechanism, because it is not one — it is the same "checks describe a
superseded state", self-inflicted. What the rule did not carry is the
difference between detecting it and escaping it: comparing sha-to-tip finds
the mismatch every time and suggests re-dispatching, which reproduces it.
Only noticing the RATE tells you the fix is to stop pushing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): a workflow fix reaches a stacked PR through its BASE, not its head

Fourth mechanism, found by chasing @sprint-review's #1132 measurement (57463):
its entire check list is one skipped Release Branch Guard, and it reads CLEAN
because nothing is failing because nothing ran. They measured the counts and
declined to claim the cause. This is the cause.

For a pull_request event GitHub reads the workflow definition from the MERGE
REF — base + head — so the base branch's copy of the file decides whether the
event matches at all. #1123 dropped `branches: [main]` from tests.yml on main
at 15:20:27Z. #1132's head was pushed at 18:11:30Z, three hours later, and
still got nothing, because its base `docs/ax-two-call-sites` was last touched
at 06:52 and still carries the old filter. Read the file on that branch to
confirm rather than inferring it.

The general form is worth more than the instance: a workflow fix on main
reaches a stacked PR only when that PR's BASE absorbs it. Not the head. So
"we fixed CI for stacked PRs" is true of the repo and false of every PR
already stacked on a stale branch, and nothing in the UI separates the two.

Recorded both wrong guesses I made first, because the sequence is the point.
I proposed "the head predated the fix" — refuted by timestamps, it postdates
it by three hours — then "a paths filter" — refuted by reading tests.yml,
which has none. Rule 16 killed both: make the mechanism predict something and
go check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): mechanism 4 is sprint-review's finding, not mine

They established it at 15:25:50Z — "for pull_request, the trigger is read
from the PR's own merge ref" — measured on #1120, whose head was pushed
15:22:21Z, two minutes after #1123 merged, and got zero runs because its base
still carried the old filter. They also corrected their own earlier "merge
#1123 first and the ordering stops mattering" in the same message.

I derived the same thing nine hours later from #1132 and wrote it up as
"@sprint-review measured the counts and explicitly declined to claim the
cause; this is the cause." Both halves wrong: they did claim it, and they
were first. Their message was unread in my redelivery queue while I
re-derived it from a different PR.

Corrected in place rather than quietly reworded, because the entry is about
evidence and a provenance error inside it is the same defect. Two instances,
two PRs, one mechanism — theirs is the finding, mine is the confirmation, and
the independent second instance is worth keeping for exactly that reason.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(ax): a hand-dispatch is the artifact that hides the bug it works around

@sprint-review (57058) nearly retracted a correct finding. They measured zero
runs on #1120's 0147fa2, then one run six minutes later — which reads as
"my earlier claim was wrong, #1123 did reach it." The second run was my
hand-dispatch landing between their two checks.

The `event` field is the only discriminator. `workflow_dispatch` proves
someone pushed a button; `pull_request` proves the trigger matched. Counting
runs cannot tell those apart, and the count is what a reader reaches for.

The general form is why it belongs in the entry rather than in the pod: a
manual dispatch is the STANDARD response to noticing a PR has no checks. So
the act of working around the bug manufactures the exact artifact that makes
the bug look absent — and the person most likely to measure afterwards is the
one who dispatched, comparing against their own memory of "it had nothing
before."

I am that person here. Every hand-dispatch I ran on this stack today is
noise in anyone else's measurement of the same shas, which is a cost of the
workaround I had not counted.

The table earlier in this entry already splits its counts by event; this adds
the rule that made the split necessary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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