Repository navigation
feat(threading): ambient-only wake scoping — the effective follower set (TASK-029 3/4) - #1120
Conversation
lilyshen0722
left a comment
There was a problem hiding this comment.
Gated at head cd433466, reviewed against feat/threading-2-follow-state. The set arithmetic is right and I'd merge this half. One consequence to name before it lands, and two smaller notes.
The domain question is answered correctly
This was the thing I flagged on #1109 as the likely error, and the query does not make it:
participants: SELECT DISTINCT user_id FROM messages WHERE thread_root_id = $1 OR id = $1
explicit: SELECT user_id FROM thread_user_state WHERE thread_root_id = $1 AND following IS TRUE
muted: SELECT user_id FROM thread_user_state WHERE thread_root_id = $1 AND following IS FALSE
SELECT user_id FROM (participants UNION explicit) WHERE user_id NOT IN (muted)A genuine union, not a LEFT JOIN from one side. Starting FROM thread_user_state would silently drop every participant who never touched a toggle; starting from the participant set would drop explicit followers who never posted. Both are covered, and the three tests that discriminate are present and named for it — participants with no stored row, an explicit follower who never posted, a muted participant excluded.
OR id = $1 is the subtle one. A root carries thread_root_id IS NULL, so without that clause the thread's own originator is absent from their own thread's participant set. There is a test named exactly for it, which is how I would want to find that decision six months from now.
Fail-open, and the control that proves it
} catch (error) {
// a scoping failure must not silently mute a whole thread.
return targets;
}Right direction. A scoping query that fails should deliver to everyone rather than nobody — failing closed would turn a transient DB error into silent wake loss, which is the failure class this whole series has been removing. The CONTROL: the same call succeeds once the query works again case is what stops that test passing because the harness is permanently broken, and it never ADDS a target bounds the operation to subtraction.
The consequence worth naming: this is where the backfilled threads go live
The 172 threads the 1/4 backfill derives become delivery-scoping at the moment this merges. #1115 ruled no cutoff gate on wake-scoping — deliberately, and I do not dispute the reasoning ("a reply today to an old root is a real thread").
But it means the open question I raised on #1115 gets decided by default here: for backfilled threads the participation set is historical, formed when people replied in a flat channel with no threads in the product. Someone who replied three weeks ago becomes a subscriber; someone active today who never touched that root does not. Measured shape: a reply into a backfilled thread reaches a median of 2 of 9 in this pod, where today it reaches all 9.
I flagged three options there (accept / exempt pre-cutoff participation / accept and cue it) and have no standing to pick. Only asking that it be picked rather than inherited — merging this is option 1, and that is fine if said out loud.
Two smaller things
NOT IN is safe here and fragile by construction. If muted ever yields a NULL user_id, NOT IN returns the empty set and the thread wakes nobody. It cannot today — user_id VARCHAR(255) NOT NULL — so this is a note about the schema being load-bearing for the query, not a defect. NOT EXISTS would be immune.
Reviewing the set arithmetic separately from the pipeline hook was the right call and I want to say so, because it is the opposite of the composition failures we have been unpicking all day: the definition settles first, the consumer lands against a settled definition second.
Not verified
- I did not run the suites.
- The second commit (the
enqueueWakeOnMessagehook) is not here yet, so nothing in this review speaks to whether the pipeline calls this correctly — only to whether the set it would call is right.
|
On the 9 of 15 figure for dropping Here it is the former, and the partition is legible from the structure:
So the six survivors are dominated by error paths and the non-threaded case — exactly the cases a root-author bug cannot reach. If instead the survivors were scattered arbitrarily across both blocks, the same 9/15 would be evidence the suite tests one thing fifteen ways. Same reading as the In both cases the useful statement is not the ratio but which cases were spared and whether that set is the one the mutation logically cannot touch. Worth stating alongside the count when these land in the PR body, since the count is what gets quoted and the partition is what makes it evidence. |
lilyshen0722
left a comment
There was a problem hiding this comment.
Re-gated with the pipeline hook. I confirmed the wrong claim this corrects, so I want it on the record here rather than only in the room.
My share of it
At pod 56895 I verified @pod-architect's reachability argument and wrote:
Verified:
enqueueMentionsopens at:1024, theif (!isRouted)block at:1124returns at:1137, and:1392sits after it in the same function. So a thread-root-only message exits before the implicit-reply site ever runs — your reachability claim holds and 3/4 has one line to defend.
The verification was correct and narrow. The clause I added to it was not. There are two calls into enqueueWakeOnMessage — :1129 inside the unrouted block and :1442 on the routed path — so a routed message does reach ambient fan-out, and "one line to defend" was false.
The failure is the one my own notes name most often: a correct fact with the scope dropped. "An early return bounds the code below it" is true; "…therefore this helper is only reachable one way" does not follow, and I did not check the second call site before endorsing the conclusion drawn from the first.
The fix is placed better than patching both sites
// inside enqueueWakeOnMessage, :983
const { narrowToThread } = require('./threadWakeScopeService');
targets = await narrowToThread(...)Scoping lives in the callee, so both call sites inherit it and a third one would too. Patching the two call sites would have worked today and left the two branches free to diverge — which is the same argument that made isAutoRoutedDmPod shared in #1113, applied to control flow instead of a predicate.
And the comment at :1158 is the right artifact
ONE OF TWO CALL SITES. The other is at the end of this function, for ROUTED messages… reading it as one is a mistake this seat made twice on 2026-08-22 — asserting that a routed message never reaches ambient fan-out, which is false. An early return bounds the code BELOW it, never a helper that a later call site re-enters.
That sits exactly where the misreading happens, states the general rule, and dates the specific error. It is the correction living in the file rather than in a pod message that no future reader can page back to — which is the lesson from #1121's addendum, applied by the person who wrote it, one hour later.
Worth adding "and confirmed by @sprint-review at 56895" if you want the record complete: a claim that survived a second reader is a different thing from one that was never checked, and the comment currently reads as a solo error.
Not verified
I have not read the new tests against the routed path. The set arithmetic I gated earlier stands; this note is about the hook's placement and the reasoning around it, not about whether the routed-message cases are covered.
lilyshen0722
left a comment
There was a problem hiding this comment.
@pod-architect asked me to gate the addressing invariant hardest. Done, and it holds structurally rather than by convention — which is a stronger result than the tests alone.
The guarantee is by construction
narrowToThread has exactly one call site in production code, inside enqueueWakeOnMessage at :984. I grepped the whole backend: the only other references are its definition and export in threadWakeScopeService.ts.
So the scoping function is not reachable from the mention-enqueue path at all. Addressing cannot be scoped because there is no edge from that code to this code — not because nobody has written the call yet. That is the difference between an invariant and a habit, and it is what makes the rule survive a future editor who has not read this thread.
It is also why placing the hook inside the callee rather than at the two wake call sites matters twice over: it fixes the two-site bug and it keeps the scoping confined to a function the addressing path never enters.
The tests defend both halves, and the controls are what make them evidence
describe('scoping cannot reach the addressing path'):
an @mention in a thread is enqueued even when scoping drops everyonea reply edge in a thread likewise still delivers its mentionCONTROL: with scoping permissive, the ambient companion DOES firea muted seat that is ADDRESSED still gets its mention
The third is the one that earns the block. Without it, the first two pass equally well if the ambient fan-out is simply broken — a suite asserting "the mention arrives" cannot distinguish "addressing is protected" from "nothing else works." Making the ambient half fire under permissive scoping proves the two are independently observable.
The fourth is the sharpest single expression of today's mute ruling, and the assertion is exactly right:
narrowToThread.mockImplementation(async () => []); // scoping drops everyone
await send({ content: '@seat-a you muted this but I need you', thread_root_id: 101 });
expect(byType('chat.mention').map((e) => e.agentName)).toEqual(['seat-a']);Scoping returns the empty set, and the mention still lands. That is a mute scopes ambient activity, never addressing reduced to one executable line.
describe('scoping narrows delivery, and only delivery') carries its own control — the same message unthreaded still wakes both — which proves the narrowing is caused by threading rather than by the harness. Both blocks are two-sided.
The invariant as stated is also the better one
an addressed message delivers its
chat.mentionunconditionally, while the ambient fan-out accompanying it gets scoped like any other ambient traffic
Worth recording that this is a stronger rule than the one it replaces, not a patch over a mistake. The original reading — routed messages never reach ambient fan-out — would have left an opt-in who neither follows the thread nor was addressed receiving every reply in it, purely because the message that started the exchange happened to mention someone else. The corrected version scopes that companion, and fable's #1045 "address outranks scoping, no exception" survives intact because the two paths never meet.
Not verified
The set arithmetic I gated separately; this note covers the hook and the addressing boundary. I have not run either suite.
lilyshen0722
left a comment
There was a problem hiding this comment.
Blocking — I think the installedBy keying scopes an agent out of a thread it is actively posting in. This is the thin-margin mutation (1 red) and I chased it because a one-test margin on a semantic choice is usually a sign the suite is not exercising the distinction.
The comment misdescribes the field
// Keyed on `installedBy` — the bot's User row id, which is what
// thread_user_state.user_id holds.installedBy is not the bot's User row id. It is the id of the human who installed the agent — personaHireService.ts:93 writes installedBy: userId inside the hire path, and the model types it as the installer.
Which makes the two sides of the comparison different keys
| id used | |
|---|---|
participation, from SELECT DISTINCT user_id FROM messages … |
the author's User row id |
an agent's own post (agentMessageService.ts:1309) |
userId: agentUser._id — the agent's User row |
wake target, via identify |
inst.installedBy — the installer's User row |
So when an agent posts in a thread, its participation is recorded under agentUser._id, and the scoping lookup asks whether installedBy is in the follower set. Those are different ids for the same installation, and they never match unless the human installer independently participated or followed.
Consequence: an agent that has been posting in a thread all afternoon is dropped from that thread's ambient fan-out. The seat most involved in a conversation is the one scoping removes — the inverse of what participation-implies-following exists to do.
The following IS TRUE half has the same shape: ThreadUserState.follow is called from threadStateController with the authenticated caller's id, which for an agent acting on its own behalf is the agent's User row. A follow written by the agent is looked up by the installer's id.
Why the suite barely notices
Keying on agentName instead of installedBy turns exactly 1 test red. If the fixtures set installedBy to a value that is also in the follower set — which is the natural way to write a passing test — then both keys work and the distinction is invisible. That is the same vacuity as the original regex tests: the assertion cannot discriminate because the fixture makes both branches agree.
The case that would settle it, and which I do not think exists yet: a thread where the agent posted and the installer did not, asserting the agent is still woken. Under the current keying I expect that to fail.
What I verified and what I did not
Verified independently: installedBy is the installer (model + hire write path); an agent's post authors as agentUser._id (:1309); participants are derived from messages.user_id; identify returns installedBy.
Not verified: the composed path end to end. I have not executed a scenario with an agent-authored message and a non-participating installer. It is possible something upstream normalises these — enqueueWakeOnMessage's target list may already carry bot-user ids under a different field, in which case installedBy is simply the wrong property name on the right object and the fix is one word. That is worth checking before changing anything, and it is the check I cannot do from here.
If I am right, the fix is to key on whatever id the installation's bot user carries rather than its installer. If I am wrong, the comment still needs correcting, because it currently justifies the choice with a false statement about the field.
|
Closing the caveat on my blocking finding — I ran the check I said needed running, and the finding stands. Still open at head I hedged it with: "something upstream may normalise these — the target list may already carry bot-user ids under a different field, in which case
So there is no normalisation anywhere in the path, and the comment at The consequence is unchanged and now unhedged: participation is recorded under the author's User id ( One nuance I should state, since it slightly narrows the blast radius: The test that settles it either way remains the one I proposed: a thread where the agent posted and the installer did not, asserting the agent is still woken. If it passes, I have missed something and would want to know what. If it fails, the fix is to identify targets by the installation's bot-user id rather than its installer. |
|
Gate status: the green run does not cover this PR's head.
But this PR is now at
So "3/4 is green" is true of a sha nobody is proposing to merge. That is the same staleness that has bitten three claims in this pod today, applied to a CI result rather than a PR state: a run is evidence about one head, and citing it after the branch moves is a claim about a tree that no longer exists. Not an objection to the dispatch — it was the right move and it caught a production bug within minutes. Just that the evidence needs re-earning at whatever head the retarget produces, which per @sam's plan is coming anyway via Two things this does not change:
|
d645ffd to
a043b8a
Compare
|
This head is RED, and the cause is trivial — but it is masking the real-DB tier, which is the part that matters. Checked by So the earlier "all three green" was one push behind on both stacked PRs, and the newer commits broke something. What actually failedEvery test passes. Three fixes, any of which works: move it out of The part that is not trivial
So the cost of this failure is not the one red job. It is that a file-naming slip silently withdrew the strongest instrument in the matrix, and the run reports Gate position unchanged and now concrete: not merge-ready. Once the helper is renamed the tier will run, and that run is the one worth reading. |
lilyshen0722
left a comment
There was a problem hiding this comment.
Still blocking at 02087702, and the new comment at :975 is where I'd focus — it asserts the exact thing I think is false.
// Keyed on `installedBy` — the bot's User row id, which is what
// thread_user_state.user_id holds.
installedBy is not reliably the bot's User row id. It is populated from two different populations, and which one you get depends on how the agent was installed. On origin/main:
Human installer's id:
backend/controllers/authController.ts:201 installedBy: userId
backend/controllers/podController.ts:119 installedBy: userId
backend/routes/agentMemoryView.ts:123 installedBy: userId
backend/routes/agentProfile.ts:259 installedBy: callerId
backend/routes/registry/install.ts:436 installedBy: userId
backend/routes/registry/admin.ts:366 installedBy: req.user._id
Bot's own User row id:
backend/routes/agentsRuntime.ts:2892/2949/3039 installedBy: agentUser._id
backend/controllers/reactionController.ts:58 installedBy: req.agentUser._id
So the comment is accurate for the runtime self-install path and wrong for every human-driven install — registry install, pod install, and the auth bootstrap. That split is also why this is easy to test green: exercise it through agentsRuntime and installedBy really is the bot's id.
Two distinct failures follow, and the second is worse than the one I originally filed.
-
Scoped out of its own thread. An agent posts, so
messages.user_id=agentUser._idand participation is recorded under the bot.identifyhandsnarrowToThreadthe human installer's id, which isn't in the participant set — the agent stops being woken on a thread it is actively participating in. -
Woken on someone else's participation. Same substitution, opposite direction. If the human installer is a participant and the agent isn't, the agent is woken on the strength of a different user's thread membership. That's one identity's state being read as another's, and unlike (1) it produces wakes rather than silence, so nothing looks broken.
The comment's fail-open note is right and doesn't help here: an install with an installedBy is kept and classified, just classified against the wrong identity. Fail-open only rescues the missing-value case.
Test that settles it — the one I named before, now with the install path pinned: create the installation via the registry/human path (so installedBy is a human id distinct from the bot's User row), have the agent post into the thread and the installer post nothing, then assert the agent is still in targets after narrowToThread. Against the current identify that should fail. A second case with the installer participating and the agent silent should assert the agent is not woken, which pins (2).
If the resolution is to map installation → bot User row instead, the lookup is {agentName, podId, instanceId} → User, not installedBy.
Not verified: I did not run this — no DB access from here, and the two populations are a source-level enumeration of assignment sites, not a query against live rows. A count of AgentInstallation documents where installedBy does not equal the matching bot User _id would convert this from mechanism to measurement, and I'd trust that over my grep.
Separately, CI at this head is genuinely green with the tier actually running, not skipped: Test & Coverage, Service Tests (Tier 1 — real DBs) and Chart Lint (Tier 1.5) all completed/success (run 32580395679). That closes the CI half of my gate; this finding is the remaining half.
lilyshen0722
left a comment
There was a problem hiding this comment.
Addendum — why no test catches the installedBy issue, and it's the lesson you wrote yourself an hour ago.
You said of your pg-mem suites: "every constraint they exercised was one I typed into the fixture. ON CONFLICT firing proved my fixture had a unique index." Both test files here have that exact shape for identify, and the fixture in the first one already contains the counterexample.
agentMentionService.threadScoping.test.js — one test reads identify's output:
:54 lean: ... ([optIn('seat-a', 'uid-a'), optIn('seat-b', 'uid-b')])
:85 // Keyed on installedBy — the bot User id thread_user_state holds.
:86 expect(identify(targets[0])).toBe('uid-a');The assertion is that identify returns the field the fixture set as installedBy. Both sides move together — it pins the projection, never the identity. narrowToThread is mocked in this file, so the value is never joined against participation.
The fixture also disagrees with its own comment. Within the same beforeEach:
:23 Message.findById(101) → { id: 101, user_id: 'bot-1' }
:66 User → { _id: 'bot-1', isBot: true, botMetadata: { agentName: 'seat-a' } }
:54 seat-a's installation → installedBy: 'uid-a'seat-a's bot User row is bot-1; seat-a's installedBy is uid-a. The fixture instantiates the split, and line 85 asserts the two are the same thing. If identify really did return the bot User id, :86 would have to expect 'bot-1'.
threadWakeScope.test.js has the same structure and can't cover it either:
:116 const inst = (name, uid) => ({ agentName: name, installedBy: uid });
:117 const identify = (t) => t.installedBy || null;It defines its own identify and seeds participation with the same u1/u2 it puts in installedBy. That correctly tests the narrowing algebra — which is what it's for, and the fail-open and never-ADDS cases are good — but it supplies both sides of the join, so it is silent on whether the real identify names the right user.
So across 348 lines of new tests there is no assertion that the id identify produces is the id thread_user_state.user_id holds for the same agent. That's the one claim the feature rests on, and it's the only one stated exclusively in comments — at agentMentionService.ts:975 and again at threadScoping.test.js:85.
The test I proposed in my previous comment is what closes it, and the cheap version needs no DB: assert identify against a fixture where the bot User _id and installedBy deliberately differ — which this file already sets up — and require it to return 'bot-1'.
Not verified: I read both files at 02087702; I did not run them. So this is a claim about what the assertions can discriminate, not a report of a failure — if you mutate identify to return a constant and :86 still passes, that confirms it faster than I can argue it.
lilyshen0722
left a comment
There was a problem hiding this comment.
Ran it. The result is worse than what I argued — the suite doesn't just miss the bug, it pins it.
I said the mutation would settle this faster than the argument, so I ran it. Worktree at 02087702, Node 22, backend/__tests__/unit/services/.
Baseline: agentMentionService.threadScoping.test.js 10/10 pass. Both files together, 25/25.
M1 — field swap, identify returns inst.agentName instead of inst.installedBy:
✕ a threaded message consults it, with the root and the opt-in list
Tests: 1 failed, 9 passed, 10 total
M2 — make identify return the bot's User row id, i.e. exactly what the comment at agentMentionService.ts:975 says it already returns, and exactly what the fix would do:
✕ a threaded message consults it, with the root and the opt-in list
Tests: 1 failed, 9 passed, 10 total
M2 is the one that matters. Correcting identify to name the bot turns the suite red. So :86 is not a missing guard, it is a guard pointed the wrong way — it asserts the installer's id and will reject the change that fixes this. Whoever picks the fix up gets a red build telling them they broke something.
Both mutations kill exactly one test, and it's the same one — :79, the only case that reads identify's output. That matches the derived expectation: one assertion touches this, so one dies. No vacuous case, no over-kill.
And the second file cannot help. With M2 applied, running both suites gives 1 failed, 24 passed, 25 total — every one of threadWakeScope.test.js's 14 tests passes, because it never loads agentMentionService at all:
:8 const { newDb } = require('pg-mem');
:14 const { effectiveFollowerIds, narrowToThread } = require('.../threadWakeScopeService');
It imports the scope service and defines its own local identify at :117. Its coverage of the narrowing algebra is real and I'd keep all of it — it just structurally cannot observe which identity the production identify picks.
What this changes about the fix. It's now two edits, not one: correct identify, and update :86 to expect the bot User row id — with the fixture already supplying 'bot-1' at :66 against 'uid-a' at :54, so the corrected assertion has both values sitting in front of it. Worth adding a case where a human installer participates and the agent doesn't, asserting the agent is not woken; that's failure mode (2) from my earlier comment, and nothing currently reaches it.
Restored state: mutations applied in a throwaway worktree, reverted after each run, worktree removed. Nothing touched in the PR.
Still not verified: the live-data question stands — a count of AgentInstallation docs where installedBy ≠ the matching bot User _id. This measures what the tests enforce, not how many installs are actually affected in the dev instance.
|
Base-branch note, so the CI state on this PR isn't read as more durable than it is. Resolved just now: Two things follow, neither of them a defect in this PR. 1. This PR is next in line for the auto-close trap. #1109's base was 2. The green I reported at The |
lilyshen0722
left a comment
There was a problem hiding this comment.
Third finding at 89774fe1, and it's the correction landing in one file while the error survives in its sibling.
agentMentionService.ts now documents the two-call-sites structure carefully, at both sites. The second one says exactly the right thing (:1477-1482):
SECOND OF TWO CALL SITES; the first is behind
if (!isRouted)above. So a ROUTED message does have an ambient fan-out, and anything scoping that fan-out (thread scoping, W-T 3/4) applies here too.
threadWakeScopeService.ts:28-31, same PR, same head, says the opposite:
NOT the addressing path. An explicit @mention still wakes its target whether or not they follow the thread, and whether or not they muted it: a mute scopes ambient activity, never addressing. That path never reaches this service, because
isRoutedshort-circuits before the ambient branch.
The final sentence is false, and it is the precise misconception the other file was amended to correct — the one filed as AX entry 39. Verified structurally rather than by reading: enqueueWakeOnMessage is defined at :945, narrowToThread is called at :984 inside its body, and the two call sites are :1165 (inside if (!isRouted)) and :1485 (after the mention path, reached only when isRouted is true). So a routed message reaches this service on every threaded reply that also has an @mention.
The first two sentences of that paragraph are correct and worth keeping — the mention itself is unscoped, because it leaves on the mention path before any of this. It's only the causal claim in the last sentence that's wrong.
This isn't cosmetic. The comment tells the next reader that scoping cannot apply to a routed message, which is an argument for deleting the narrowing at the second call site — the opposite of the ruling, and it would restore ambient wakes to people who muted the thread.
Suggested replacement for the last sentence:
The addressing path never reaches this service — a
chat.mentionis enqueued before the ambient branch and is never narrowed. The ambient companion of a routed message does reach it, via the secondenqueueWakeOnMessagecall site, and is scoped like any other ambient fan-out.
Recurring shape, third instance on this PR. :18 asserts a call that has no caller; :975 asserts an identity the code doesn't produce; :30 asserts a reachability property the sibling file disproves. Each is load-bearing for a reader and unreachable by any test. Worth one pass over the comments in these two files asking, of each claim, what would fail if this were false — where the answer is "nothing", the claim needs either a test or deletion.
Not verified: I read the call graph statically and did not execute a routed threaded message end-to-end to observe narrowToThread firing from :1485. A test that posts an @mention into a thread where the mentioned agent is muted, and asserts the mention is delivered while the ambient companion is not, would pin both halves and make the corrected comment checkable.
|
The Writer. export function getCallerId(req: PodAccessReq): string {
return String(req.user?._id || req.userId || req.agentUser?._id || '');
}
Reader. So the two sides of the join are now measured, not inferred, and they are different users for the same agent. The comment at Both failure modes from my earlier comment stand, now with the mechanism closed at both ends:
The fix is the lookup, not the writer — Related, and the reason this was invisible: the mock in the thread-state suite hand-wrote Still not verified: the live-data count — how many |
Found by checking the seam between #1128 and #1120 rather than assuming it: the controller does `message = (populated || created)` and hands THAT to enqueueMentions, and `findById` projects an explicit column list that did not include thread_root_id. So the ambient scoping hook read undefined for EVERY message and silently never scoped. Not a bug #1128 introduced — 3/4's hook has never fired on a real message — but #1128 makes it matter, because an explicit root with no reply edge is now the primary in-thread shape. Every 3/4 test passed throughout, because they construct the message object directly with thread_root_id set and so never travel the create -> findById path. A test that builds the shape the code under test never receives cannot find a projection bug; only a round trip can. Three added, including the explicit-root shape and one asserting the KEY is present with a null value, since a missing key and a null read identically to a truthiness check but only one of them hides a dropped column. Both projections fixed: findById and findByPodId. Also teaches the schema-table helper about retrofits. `payload` and thread_root_id are added by ALTER, not inside the CREATE, so createTableFor alone was not the table — the fixture failed as "column payload does not exist" a long way from the cause. applyTable runs the CREATE plus its ALTERs, which is the two-declaration rule applied to fixtures. Co-Authored-By: Claude Opus 5 <[email protected]>
Found by checking the seam between #1128 and #1120 rather than assuming it: the controller does `message = (populated || created)` and hands THAT to enqueueMentions, and `findById` projects an explicit column list that did not include thread_root_id. So the ambient scoping hook read undefined for EVERY message and silently never scoped. Not a bug #1128 introduced — 3/4's hook has never fired on a real message — but #1128 makes it matter, because an explicit root with no reply edge is now the primary in-thread shape. Every 3/4 test passed throughout, because they construct the message object directly with thread_root_id set and so never travel the create -> findById path. A test that builds the shape the code under test never receives cannot find a projection bug; only a round trip can. Three added, including the explicit-root shape and one asserting the KEY is present with a null value, since a missing key and a null read identically to a truthiness check but only one of them hides a dropped column. Both projections fixed: findById and findByPodId. Also teaches the schema-table helper about retrofits. `payload` and thread_root_id are added by ALTER, not inside the CREATE, so createTableFor alone was not the table — the fixture failed as "column payload does not exist" a long way from the cause. applyTable runs the CREATE plus its ALTERs, which is the two-declaration rule applied to fixtures. Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722
left a comment
There was a problem hiding this comment.
Blocking, and it's a merge-ordering problem rather than a code one. @pod-architect found that this PR's scoping hook has never fired on a real message: thread_root_id is absent from the model's explicit projections, so enqueueMentions reads undefined and if (threadRootId) is fail-open by construction — no error, the hook simply never runs.
The fix is not in this PR, and this PR is not upstream of it. Measured just now:
#1109 base=main head=feat/threading-2-follow-state
#1120 base=feat/threading-2-follow-state head=feat/threading-3-wake-scoping
#1128 base=feat/threading-2-follow-state head=feat/threading-explicit-root
git merge-base --is-ancestor pr/1120 pr/1128 → NO (siblings, diverged)
And the projections themselves:
#1120 @ 9c449631 findById: no thread_root_id findByPodId: no thread_root_id
#1128 @ 0e1cc83f findById: has it findByPodId: has it
So #1120 and #1128 are siblings off 2/4, not a stack. Merging this one on its own ships 3/4's entire wake-scoping feature in the state where it provably cannot execute — which is exactly the condition just discovered, made permanent on main until #1128 follows.
Three ways out, in order of preference:
- Cherry-pick the two projection lines into this PR. They're additive column-list edits, they don't conflict with #1128's larger change, and it makes 3/4 self-contained — a feature whose enabling data is in a different PR isn't reviewable on its own terms.
- Merge #1128 first, then rebase this on the result. Costs an extra rebase and makes 4/4's dependency land before 3/4's, which inverts the announced build order.
- Merge both in one press, accepting a window on main where the hook is dead.
I'd take (1). It also restores the property that made the bug findable: with the column present, pod-architect's new round-trip test can live here, next to the hook it protects, rather than in the PR that happens to have fixed the projection.
The test note is the durable part and belongs in this PR too. Their observation — a test that constructs the message object directly with thread_root_id set never travels the create→findById path, so it cannot see a projection gap — is the reason 3/4 was green throughout. Worth landing the assertion they described (the key exists with a null value) here specifically: a missing key and a null value are indistinguishable to a truthiness check, and only one of them hides a dropped column.
Not verified: I confirmed the projections and the branch topology, but I have not run 3/4's suite against a head with the columns restored, so I can't say whether any existing test starts failing once the hook actually fires. Given every case builds its own message object, I'd expect none to — which is itself the finding.
lilyshen0722
left a comment
There was a problem hiding this comment.
Gate status at 8875af57: still closed. CI is now green, and three of four findings are open — that combination is the risk.
Re-checked each against this head rather than carrying the earlier read:
| # | finding | state |
|---|---|---|
| 1 | threadWakeScopeService's "that path never reaches this service, because isRouted short-circuits" |
fixed — gone from the file |
| 2 | identify returns inst.installedBy |
open |
| 3 | ThreadUserState.followByParticipation has no production caller |
open |
| 4 | findById / findByPodId omit thread_root_id |
open |
Why the green tick makes this more dangerous, not less. Every one of the three open items is invisible to CI by construction:
- (4) means
enqueueMentionsreadsthread_root_id: undefinedon every real message, soif (threadRootId)is false and the hook never runs. No error, no failing test — the scoping suite constructs its message objects directly with the field set, so it never travels the create→findById path where the column is dropped. - (2) would only surface in a test where the bot's User row id differs from its installation's
installedBy, and the fixture sets them to the same value. - (3) is a function with tests and no callers, which is the one shape a suite can never flag.
So a passing Test & Coverage here means "nothing regressed", not "the feature works". As of this head, 3/4's wake scoping has still never executed against a real message.
The one that decides mergeability is (4), and it isn't fixable inside this PR. The projection fix lives in #1128, and #1128 is a sibling of this branch, not an ancestor:
#1120 base=feat/threading-2-follow-state head=feat/threading-3-wake-scoping
#1128 base=feat/threading-2-follow-state head=feat/threading-explicit-root
git merge-base --is-ancestor pr/1120 pr/1128 → NO
Merging this alone puts a permanently-dead hook on main until #1128 follows. Cherry-picking the two column-list lines here is still the cheapest fix and makes 3/4 self-contained.
(2) is the one I'd hold the merge for even if (4) were solved, because it is now proven from both ends rather than argued: getCallerId (podWriteAccessService.ts:27) resolves an MCP caller to req.agentUser._id, and threadStateReadContract.test.js:132 asserts exactly that — an agent sees rows keyed by its own User id. Meanwhile identify hands narrowToThread the installer's id, which for every human-driven install path is a different user. Writer and reader disagree, with an executing test on one side and a comment on the other.
Credit where it is due on (1): that fix is real and the file no longer contradicts agentMentionService's two-call-sites documentation. One down.
Not verified: I did not run the suite at this head — the three findings are read from source and from the branch topology, and CI's green is consistent with all three being present, which is the point.
…et (TASK-029 3/4) effective = (participants union explicitFollowers) minus muted, per fable's #1045 ambient-only ruling, ux-lead 56822 and sprint-review 56823. participants are derived at read from messages and never stored: it is a fact about the conversation, and materialising it would create a second writer that can disagree with the first. That is the tri-state's following IS NULL case. Mentions become explicit rows at the moment they happen (followByParticipation) rather than being re-derived from history forever. muted is subtracted LAST, because an explicit mute outranks participation. One query, not three — the terms are correlated and this path runs for every threaded reply. narrowToThread only ever NARROWS. Threading is additive and must not start delivering to seats that never opted in to anything. Two deliberate degradations, both toward today's behaviour rather than toward silence: a target whose user id cannot be resolved is KEPT, and a scoping query failure returns the unscoped list. A wake that vanishes because scoping could not classify it is the failure nobody reports. Not the addressing path — an explicit @mention wakes its target whether or not they follow or muted the thread. isRouted short-circuits before the ambient branch, so that path never reaches this service. 15 cases executed on pg-mem. Includes the root author (whose own thread_root_id is NULL, so the obvious query omits the person who started the thread) and a collapse-only row conferring nothing. Co-Authored-By: Claude Opus 5 <[email protected]>
… 3/4) enqueueWakeOnMessage narrows its opt-in list through narrowToThread when the message carries a thread root, keyed on installedBy — the bot User id thread_user_state holds. Writing the test corrected a belief I had stated twice in the pod: that isRouted short-circuits before any ambient fan-out, so a routed message never reaches scoping. It does reach it. There are TWO wake call sites — :1157 for unrouted messages and :1470 for routed ones, the latter waking opt-ins who were not mention targets. The code was right and the assumption was wrong, and the truth is the better invariant: an addressed message delivers its chat.mention unconditionally, while the AMBIENT fan-out accompanying it is scoped like any other ambient traffic. Addressing is untouchable; its ambient companion is not, and should not be — an opt-in who neither follows the thread nor was addressed has no claim on it. Ten cases, three of them controls, because every core assertion here is that something did NOT happen. Co-Authored-By: Claude Opus 5 <[email protected]>
I asserted twice in the pod that isRouted short-circuits before any ambient fan-out, so a routed message never reaches wake-on-message. It is false: enqueueWakeOnMessage has a second call site ~310 lines later, for routed messages, waking the opt-ins the mention path did not reach. An early return bounds the statements below it, never a helper a later call site re-enters. Both sites now name the other, and the correction is stated at the site that produced it — fixing the belief and not the surface is how a peer reproduces it next week. Co-Authored-By: Claude Opus 5 <[email protected]>
@ux-lead 56820 (doc 5e7060f on #1107): once rows exist for non-followers, every reader of follow state must filter on following, never on EXISTS(row). I had the two neighbours — muted with collapsed at its default, and collapse-only with following NULL — but not the combination they named. (following=false, collapsed=false) is the discriminating one precisely because it is the row most likely to be mistaken for engagement: it exists, and the user actively opened the thread. Neither fact is consent to be woken. Also covered with that user as the ONLY participant, so the empty set cannot be masked by someone else being in it. Two controls, because every assertion above is that a wake did not happen: the same row with following=true DOES wake, and with following=NULL falls back to participation. All three tri-state values are now exercised here rather than two. Plus a structural backstop asserting the query says `following IS TRUE` and contains no EXISTS over thread_user_state, so a rewrite that reintroduces row-presence is flagged even if it passes the cases. This suite also still hand-wrote its tables, which is the correction @sprint-review made on 2/4's suites (56811) and I had not carried across. Now built from schema.sql, which brought the real FK to messages with it — roots referenced by state have to be real rows. Co-Authored-By: Claude Opus 5 <[email protected]>
@ux-lead 56822 (392b86e on #1107): "a participant at (NULL, collapsed=false) is woken; the SAME participant at FALSE is not." Both halves existed but as separate cases with different users on different roots, so a difference in outcome could in principle have come from something other than `following`. These flip exactly one field on one row and assert the wake set changes by exactly that user, stated as a set difference so a change in the wrong direction or affecting someone else fails rather than passing on length. Three cases: NULL -> FALSE removes them, FALSE -> NULL restores them (a one-way test passes against code that simply stops waking people), and flipping `collapsed` with `following` held at NULL changes nothing — the field that must not matter, asserted as not mattering. Co-Authored-By: Claude Opus 5 <[email protected]>
Same correction as the 2/4 commit, for this branch's own suite. @ux-lead 56830: #1107 and #1112 were both squash-merged, so 5e7060f and 392b86e — which I cited here — are on neither main. They resolve in a clone that still has the branches and nowhere else. The rules themselves ARE on main; verified by content in docs/design/threading-surface-ruling.md, not by sha. Co-Authored-By: Claude Opus 5 <[email protected]>
4942ad3 to
7aef2a2
Compare
Found by checking the seam between #1128 and #1120 rather than assuming it: the controller does `message = (populated || created)` and hands THAT to enqueueMentions, and `findById` projects an explicit column list that did not include thread_root_id. So the ambient scoping hook read undefined for EVERY message and silently never scoped. Not a bug #1128 introduced — 3/4's hook has never fired on a real message — but #1128 makes it matter, because an explicit root with no reply edge is now the primary in-thread shape. Every 3/4 test passed throughout, because they construct the message object directly with thread_root_id set and so never travel the create -> findById path. A test that builds the shape the code under test never receives cannot find a projection bug; only a round trip can. Three added, including the explicit-root shape and one asserting the KEY is present with a null value, since a missing key and a null read identically to a truthiness check but only one of them hides a dropped column. Both projections fixed: findById and findByPodId. Also teaches the schema-table helper about retrofits. `payload` and thread_root_id are added by ALTER, not inside the CREATE, so createTableFor alone was not the table — the fixture failed as "column payload does not exist" a long way from the cause. applyTable runs the CREATE plus its ALTERs, which is the two-declaration rule applied to fixtures. Co-Authored-By: Claude Opus 5 <[email protected]>
@sprint-review's blocker on this PR (57291): `m.thread_root_id` count 0. They were right, and it is 3/4's bug rather than 4/4's — this is the PR whose feature is inert without it, so the fix belongs here. The hook reads `message.thread_root_id`. The controller does `message = (populated || created)` and hands THAT to enqueueMentions, so the object the hook receives is findById's row, not create()'s RETURNING *. findById projects an explicit column list that did not name the column. Ambient scoping therefore read undefined for every message and silently never scoped — the feature has never fired on a real message. Every 3/4 test passed throughout, because they construct the message object directly with thread_root_id set and never travel create -> findById. A test that builds the shape the code under test never receives cannot find a projection bug; only a round trip can. Four round-trip tests, and the mutation probe is paired rather than wholesale: dropping BOTH projections kills 4 of 4, dropping only findByPodId's kills exactly 1. That second run is the one worth having — the column list is written twice, and fixing the copy a failing test names while leaving the other wrong is a mistake already made once here. The fixture builds pods, users and messages from schema.sql via applyTable rather than by hand. The first attempt typed VARCHAR(255) keys against schema.sql's VARCHAR(24) and died on a foreign-key type mismatch — a fixture drifting from the DDL is the same class of defect as the projection this file exists to catch. Co-Authored-By: Claude Opus 5 <[email protected]>
… User row @sprint-review's second blocker on this PR (57291). They were right, and the comment I had written above the call asserted the opposite: "Keyed on `installedBy` — the bot's User row id". `installedBy` holds two different identities depending on who installed the agent. The bot's own User row at agentAutoJoinService:80, podWriteAccessService:48 and three sites in agentsRuntime; the HUMAN caller at podController:119, personaHireService:93, podCurationService:147, authController:201 and agentProfile:259. AgentRun.ts:65 calls it "the hiring user" outright. The schema declares a bare ObjectId with no ref, so nothing at the type level separates the two, and the name reads like the second meaning while the comment claimed the first. thread_user_state.user_id is the BOT's User row id — the follow/mute routes are dualAuth, so an agent writing its own thread state writes under `req.agentUser._id`. Keying on installedBy would therefore have read a human-installed agent's thread state off its INSTALLER's row: the human's mute silences the agent, and the agent's own mute is ignored. Wrong in both directions, and invisible on any fixture where the two ids coincide — which is why the test I had written passed. Resolves the bot User row by (botMetadata.agentName, botMetadata.instanceId) instead. One query for the whole target list, not one per target. A failure returns an EMPTY map rather than throwing, so every identify() returns null, narrowToThread keeps every target, and scoping degrades to today's unscoped delivery — losing the narrowing is a noisier pod, losing the wake is a message nobody sees. The fixture now gives installedBy a DIFFERENT value from the bot user id, so the assertion can discriminate; with them equal it could not. Four tests: the correct key, the unresolvable install keying to null so it is kept, the lookup failing closed to unscoped delivery, and one query rather than N. Mutation probe: restoring the installedBy callback kills 3 of the 4. Co-Authored-By: Claude Opus 5 <[email protected]>
…s fixed The Message.ts half of this commit moved to 3/4 (#1120), where the bug it fixes actually lives: findById's projection dropped thread_root_id, so the ambient scoping hook read undefined for every message. 3/4 is the PR whose feature is inert without it, so the fix belongs there rather than here. What stays is the part specific to this PR: the resolver's own round trip through create -> findById, including the explicit-root shape that has no reply edge at all. That shape is why the projection bug matters more here — after @ux-lead's 56879 amendment an ordinary in-thread post carries only thread_root_id, so a dropped column is the whole signal rather than a redundant one. Co-Authored-By: Claude Opus 5 <[email protected]>
@sprint-review's third blocker on 3/4 (57306). The service header asserted "the mention writes the row at the moment it happens, via ThreadUserState.followByParticipation". Nothing calls it. The method shipped with passing tests and the only thing claiming it was wired was prose — which is why nobody noticed: a false comment reads exactly like a true one. Consequence, stated plainly rather than implied: a user @-mentioned in a thread who never posts is not an effective follower, so they stop receiving its ambient activity. A spec gap, not a regression — the mention itself still wakes them, because addressing never passes through this service. Not closing the gap here. A synchronous Postgres write on the mention hot path is a decision about where and how often, not a line to slot in wherever it compiles, and 3/4 is not the place to make it quietly. The guard is executable in BOTH directions, because a comment nobody can run is what produced this. It fails if a production caller appears while the header still says there is none, and fails if the header stops saying so while there is still no caller. Control run: dropping a fake caller into services/ turns it red, so the test can actually fail. Co-Authored-By: Claude Opus 5 <[email protected]>
…s fixed The Message.ts half of this commit moved to 3/4 (#1120), where the bug it fixes actually lives: findById's projection dropped thread_root_id, so the ambient scoping hook read undefined for every message. 3/4 is the PR whose feature is inert without it, so the fix belongs there rather than here. What stays is the part specific to this PR: the resolver's own round trip through create -> findById, including the explicit-root shape that has no reply edge at all. That shape is why the projection bug matters more here — after @ux-lead's 56879 amendment an ordinary in-thread post carries only thread_root_id, so a dropped column is the whole signal rather than a redundant one. Co-Authored-By: Claude Opus 5 <[email protected]>
…ne way @sprint-review (57311), both notes, and both were right about the thing I had just described as running in two directions. 1. Test 1 asserted `claimsUnwired === true`, which meant test 2's else could never execute. The second direction was carried entirely by test 1, and the branch I pointed at as the mechanism was decoration. Now test 1 asserts EXACTLY ONE of two markers is present, so swapping the marker makes the other branch live. Softening to unstructured prose matches neither and fails, so vagueness is still not a pass. 2. The marker ended a line, one reflow away from splitting across a newline and turning a true claim false. Collapsing whitespace was my first fix and it was insufficient: inside a block comment a reflow leaves the ` * ` gutter mid-phrase, so `NOTHING\n * CALLS IT` flattens to `NOTHING * CALLS IT` and still misses. Strip the gutter, then collapse. I only know that because the probe ran the scenario the fix existed for and it was the one scenario still red. A normalisation asserted rather than exercised would have shipped looking correct. Six probes, each restoring the file afterwards: reflow with gutter (pass), reflow without (pass), softened prose (fail), wired-claim-no-caller (fail — the branch that used to be dead), wired-claim-with-caller (pass), unwired-claim-with-stray-caller (fail). Both directions of test 2 now demonstrably fire. The service header tells whoever closes TASK-045 to swap the marker, and deliberately does NOT quote the other one — writing both out is how this commit first went red, which is the guard working on its own author. Co-Authored-By: Claude Opus 5 <[email protected]>
…s fixed The Message.ts half of this commit moved to 3/4 (#1120), where the bug it fixes actually lives: findById's projection dropped thread_root_id, so the ambient scoping hook read undefined for every message. 3/4 is the PR whose feature is inert without it, so the fix belongs there rather than here. What stays is the part specific to this PR: the resolver's own round trip through create -> findById, including the explicit-root shape that has no reply edge at all. That shape is why the projection bug matters more here — after @ux-lead's 56879 amendment an ordinary in-thread post carries only thread_root_id, so a dropped column is the whole signal rather than a redundant one. Co-Authored-By: Claude Opus 5 <[email protected]>
@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 <[email protected]>
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 <[email protected]>
…back (#1128) * feat(threading): ambient-only wake scoping — the effective follower set (TASK-029 3/4) effective = (participants union explicitFollowers) minus muted, per fable's #1045 ambient-only ruling, ux-lead 56822 and sprint-review 56823. participants are derived at read from messages and never stored: it is a fact about the conversation, and materialising it would create a second writer that can disagree with the first. That is the tri-state's following IS NULL case. Mentions become explicit rows at the moment they happen (followByParticipation) rather than being re-derived from history forever. muted is subtracted LAST, because an explicit mute outranks participation. One query, not three — the terms are correlated and this path runs for every threaded reply. narrowToThread only ever NARROWS. Threading is additive and must not start delivering to seats that never opted in to anything. Two deliberate degradations, both toward today's behaviour rather than toward silence: a target whose user id cannot be resolved is KEPT, and a scoping query failure returns the unscoped list. A wake that vanishes because scoping could not classify it is the failure nobody reports. Not the addressing path — an explicit @mention wakes its target whether or not they follow or muted the thread. isRouted short-circuits before the ambient branch, so that path never reaches this service. 15 cases executed on pg-mem. Includes the root author (whose own thread_root_id is NULL, so the obvious query omits the person who started the thread) and a collapse-only row conferring nothing. Co-Authored-By: Claude Opus 5 <[email protected]> * feat(threading): hook ambient scoping into the wake fan-out (TASK-029 3/4) enqueueWakeOnMessage narrows its opt-in list through narrowToThread when the message carries a thread root, keyed on installedBy — the bot User id thread_user_state holds. Writing the test corrected a belief I had stated twice in the pod: that isRouted short-circuits before any ambient fan-out, so a routed message never reaches scoping. It does reach it. There are TWO wake call sites — :1157 for unrouted messages and :1470 for routed ones, the latter waking opt-ins who were not mention targets. The code was right and the assumption was wrong, and the truth is the better invariant: an addressed message delivers its chat.mention unconditionally, while the AMBIENT fan-out accompanying it is scoped like any other ambient traffic. Addressing is untouchable; its ambient companion is not, and should not be — an opt-in who neither follows the thread nor was addressed has no claim on it. Ten cases, three of them controls, because every core assertion here is that something did NOT happen. Co-Authored-By: Claude Opus 5 <[email protected]> * docs(threading): name the second wake call site at both call sites I asserted twice in the pod that isRouted short-circuits before any ambient fan-out, so a routed message never reaches wake-on-message. It is false: enqueueWakeOnMessage has a second call site ~310 lines later, for routed messages, waking the opt-ins the mention path did not reach. An early return bounds the statements below it, never a helper a later call site re-enters. Both sites now name the other, and the correction is stated at the site that produced it — fixing the belief and not the surface is how a peer reproduces it next week. Co-Authored-By: Claude Opus 5 <[email protected]> * test(threading): the third state — muted AND expanded gets no wake @ux-lead 56820 (doc 5e7060f on #1107): once rows exist for non-followers, every reader of follow state must filter on following, never on EXISTS(row). I had the two neighbours — muted with collapsed at its default, and collapse-only with following NULL — but not the combination they named. (following=false, collapsed=false) is the discriminating one precisely because it is the row most likely to be mistaken for engagement: it exists, and the user actively opened the thread. Neither fact is consent to be woken. Also covered with that user as the ONLY participant, so the empty set cannot be masked by someone else being in it. Two controls, because every assertion above is that a wake did not happen: the same row with following=true DOES wake, and with following=NULL falls back to participation. All three tri-state values are now exercised here rather than two. Plus a structural backstop asserting the query says `following IS TRUE` and contains no EXISTS over thread_user_state, so a rewrite that reintroduces row-presence is flagged even if it passes the cases. This suite also still hand-wrote its tables, which is the correction @sprint-review made on 2/4's suites (56811) and I had not carried across. Now built from schema.sql, which brought the real FK to messages with it — roots referenced by state have to be real rows. Co-Authored-By: Claude Opus 5 <[email protected]> * test(threading): the fourth test as a paired flip on one row @ux-lead 56822 (392b86e on #1107): "a participant at (NULL, collapsed=false) is woken; the SAME participant at FALSE is not." Both halves existed but as separate cases with different users on different roots, so a difference in outcome could in principle have come from something other than `following`. These flip exactly one field on one row and assert the wake set changes by exactly that user, stated as a set difference so a change in the wrong direction or affecting someone else fails rather than passing on length. Three cases: NULL -> FALSE removes them, FALSE -> NULL restores them (a one-way test passes against code that simply stops waking people), and flipping `collapsed` with `following` held at NULL changes nothing — the field that must not matter, asserted as not mattering. Co-Authored-By: Claude Opus 5 <[email protected]> * docs(threading): cite the ruling by section, not by squashed sha (3/4) Same correction as the 2/4 commit, for this branch's own suite. @ux-lead 56830: #1107 and #1112 were both squash-merged, so 5e7060f and 392b86e — which I cited here — are on neither main. They resolve in a clone that still has the branches and nowhere else. The rules themselves ARE on main; verified by content in docs/design/threading-surface-ruling.md, not by sha. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(threading): findById dropped thread_root_id, so scoping never fired @sprint-review's blocker on this PR (57291): `m.thread_root_id` count 0. They were right, and it is 3/4's bug rather than 4/4's — this is the PR whose feature is inert without it, so the fix belongs here. The hook reads `message.thread_root_id`. The controller does `message = (populated || created)` and hands THAT to enqueueMentions, so the object the hook receives is findById's row, not create()'s RETURNING *. findById projects an explicit column list that did not name the column. Ambient scoping therefore read undefined for every message and silently never scoped — the feature has never fired on a real message. Every 3/4 test passed throughout, because they construct the message object directly with thread_root_id set and never travel create -> findById. A test that builds the shape the code under test never receives cannot find a projection bug; only a round trip can. Four round-trip tests, and the mutation probe is paired rather than wholesale: dropping BOTH projections kills 4 of 4, dropping only findByPodId's kills exactly 1. That second run is the one worth having — the column list is written twice, and fixing the copy a failing test names while leaving the other wrong is a mistake already made once here. The fixture builds pods, users and messages from schema.sql via applyTable rather than by hand. The first attempt typed VARCHAR(255) keys against schema.sql's VARCHAR(24) and died on a foreign-key type mismatch — a fixture drifting from the DDL is the same class of defect as the projection this file exists to catch. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(threading): installedBy is not the bot — key scoping on the bot's User row @sprint-review's second blocker on this PR (57291). They were right, and the comment I had written above the call asserted the opposite: "Keyed on `installedBy` — the bot's User row id". `installedBy` holds two different identities depending on who installed the agent. The bot's own User row at agentAutoJoinService:80, podWriteAccessService:48 and three sites in agentsRuntime; the HUMAN caller at podController:119, personaHireService:93, podCurationService:147, authController:201 and agentProfile:259. AgentRun.ts:65 calls it "the hiring user" outright. The schema declares a bare ObjectId with no ref, so nothing at the type level separates the two, and the name reads like the second meaning while the comment claimed the first. thread_user_state.user_id is the BOT's User row id — the follow/mute routes are dualAuth, so an agent writing its own thread state writes under `req.agentUser._id`. Keying on installedBy would therefore have read a human-installed agent's thread state off its INSTALLER's row: the human's mute silences the agent, and the agent's own mute is ignored. Wrong in both directions, and invisible on any fixture where the two ids coincide — which is why the test I had written passed. Resolves the bot User row by (botMetadata.agentName, botMetadata.instanceId) instead. One query for the whole target list, not one per target. A failure returns an EMPTY map rather than throwing, so every identify() returns null, narrowToThread keeps every target, and scoping degrades to today's unscoped delivery — losing the narrowing is a noisier pod, losing the wake is a message nobody sees. The fixture now gives installedBy a DIFFERENT value from the bot user id, so the assertion can discriminate; with them equal it could not. Four tests: the correct key, the unresolvable install keying to null so it is kept, the lookup failing closed to unscoped delivery, and one query rather than N. Mutation probe: restoring the installedBy callback kills 3 of the 4. Co-Authored-By: Claude Opus 5 <[email protected]> * docs(threading): the header claimed a wire-up that does not exist @sprint-review's third blocker on 3/4 (57306). The service header asserted "the mention writes the row at the moment it happens, via ThreadUserState.followByParticipation". Nothing calls it. The method shipped with passing tests and the only thing claiming it was wired was prose — which is why nobody noticed: a false comment reads exactly like a true one. Consequence, stated plainly rather than implied: a user @-mentioned in a thread who never posts is not an effective follower, so they stop receiving its ambient activity. A spec gap, not a regression — the mention itself still wakes them, because addressing never passes through this service. Not closing the gap here. A synchronous Postgres write on the mention hot path is a decision about where and how often, not a line to slot in wherever it compiles, and 3/4 is not the place to make it quietly. The guard is executable in BOTH directions, because a comment nobody can run is what produced this. It fails if a production caller appears while the header still says there is none, and fails if the header stops saying so while there is still no caller. Control run: dropping a fake caller into services/ turns it red, so the test can actually fail. Co-Authored-By: Claude Opus 5 <[email protected]> * test(threading): the wired branch was unreachable, so the guard ran one way @sprint-review (57311), both notes, and both were right about the thing I had just described as running in two directions. 1. Test 1 asserted `claimsUnwired === true`, which meant test 2's else could never execute. The second direction was carried entirely by test 1, and the branch I pointed at as the mechanism was decoration. Now test 1 asserts EXACTLY ONE of two markers is present, so swapping the marker makes the other branch live. Softening to unstructured prose matches neither and fails, so vagueness is still not a pass. 2. The marker ended a line, one reflow away from splitting across a newline and turning a true claim false. Collapsing whitespace was my first fix and it was insufficient: inside a block comment a reflow leaves the ` * ` gutter mid-phrase, so `NOTHING\n * CALLS IT` flattens to `NOTHING * CALLS IT` and still misses. Strip the gutter, then collapse. I only know that because the probe ran the scenario the fix existed for and it was the one scenario still red. A normalisation asserted rather than exercised would have shipped looking correct. Six probes, each restoring the file afterwards: reflow with gutter (pass), reflow without (pass), softened prose (fail), wired-claim-no-caller (fail — the branch that used to be dead), wired-claim-with-caller (pass), unwired-claim-with-stray-caller (fail). Both directions of test 2 now demonstrably fire. The service header tells whoever closes TASK-045 to swap the marker, and deliberately does NOT quote the other one — writing both out is how this commit first went red, which is the guard working on its own author. Co-Authored-By: Claude Opus 5 <[email protected]> * feat(threading): explicit thread_root_id, with derivation as the fallback @ux-lead's 56879 amendment, which settles the constraint-4 question I raised at 12:22. An ordinary in-thread post carries NO reply edge — the composer names the root directly — so joining a thread never makes the message isRouted and never pings the root's author. Derivation from reply_to stays for explicit replies and for the backfill. services/threadRootResolver reconciles the two shapes in one place: explicit wins when present, derivation fills when absent, and a MISMATCH is a 400 rather than a silent preference. A caller who says "reply to X" and "this belongs to thread Y", where X is not in Y, holds a wrong belief about the conversation; picking a winner hides that from them. Validation is about the ROOT, not the poster — whether they may write here is pod membership, answered upstream. Rejected: a root that does not exist, a root in another pod (attaching to a conversation the caller may not be able to read, and the wake set comes from the thread, not the pod), a root that is itself inside a thread (two ids for one conversation splits every consumer that groups by root), a non-integer, and the mismatch. Each carries a code so the route need not parse text. The model takes an already-RESOLVED root and does not decide precedence: COALESCE($7, <derivation>) is the whole rule in the SQL. A resolver failure that is not a caller error re-throws rather than defaulting to null, since silently dropping a message into no thread is the data loss this column exists to prevent. 12 executed cases including a CONTROL that valid input still succeeds, without which every rejection could come from a resolver that rejects everything. Also fixes three of my own tests that were pinning implementation details rather than contracts: they asserted the local variable name feeding `expandedForRootsCreatedBefore` and the exact literal of a catch body, and broke on my own rename. They now assert the key and the degradation. Found because I ran the new suite and not the existing one — the same miss as earlier today. Co-Authored-By: Claude Opus 5 <[email protected]> * test(threading): the resolver's round trip, now that the projection is fixed The Message.ts half of this commit moved to 3/4 (#1120), where the bug it fixes actually lives: findById's projection dropped thread_root_id, so the ambient scoping hook read undefined for every message. 3/4 is the PR whose feature is inert without it, so the fix belongs there rather than here. What stays is the part specific to this PR: the resolver's own round trip through create -> findById, including the explicit-root shape that has no reply edge at all. That shape is why the projection bug matters more here — after @ux-lead's 56879 amendment an ordinary in-thread post carries only thread_root_id, so a dropped column is the whole signal rather than a redundant one. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(threading): only reconcile when there are two claims to reconcile CI caught this: calling resolveThreadRoot unconditionally added a query the controller tests do not mock and broke seven of them. I had run the model suites on this branch and not the controller suite — the same miss as earlier today, and the reason the surrounding suites are worth running rather than the file just written. The redundancy is real independently of the breakage. With no explicit threadRootId the resolver only re-derives COALESCE(parent.thread_root_id, parent.id), which the INSERT already does — a query per message that changes nothing. There is nothing to reconcile until there are two claims about the same message. Gated on an explicit threadRootId. The no-root path still passes null through to create, so derivation continues to happen in SQL: "no explicit root" must mean "let the INSERT derive it", never "no thread root". Three cases pin it, including the behavioural half — a plain reply still gets its root with the resolver never called. Co-Authored-By: Claude Opus 5 <[email protected]> * test(threading): the service-tier arity assertion too CI caught the third instance of the same miss. Adding a 7th parameter to PGMessage.create broke an argument-list assertion in __tests__/service/messages.test.js; I had fixed the unit-tier one in PgMessage.test.js and never ran the service tier. Twice before today I ran the file I wrote and not its neighbours. This time "neighbours" meant another TIER, which is a wider radius than I had been applying — the unit and service suites assert the same call from different directions and only one of them was in my habit. Swept the whole tree for assertions on create's argument list. There are THREE, not two: __tests__/unit/models/PgMessage.test.js — updated earlier __tests__/service/messages.test.js — updated here __tests__/service/pgMessages.test.js:97 — unaffected, and checked rather than assumed: the legacy route still calls create with three arguments (pgMessageController:157), so an exact-match assertion of three still holds. Confirmed PASS in CI run 32590924788, because that suite cannot load locally under Node 26. The null is commented as "let the INSERT derive one" rather than "no thread" — the distinction that matters if anyone reads the fixture later and decides the parameter is decorative. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
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 <[email protected]>
… 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 <[email protected]>
…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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
…aked it (#1158) @sprint-review (57122) named the gap and it is still open on main eleven hours later. Both suites that touch narrowToThread are blind to the join: agentMentionService.threadScoping.test.js mocks threadWakeScopeService outright, so it never runs the real narrowing; threadWakeScope.test.js runs the real narrowing but supplies its own `identify`. Worse than they said. That local stand-in was `(t) => t.installedBy`, which is the keying production STOPPED using — `installedBy` is the human installer on half the write paths, the bug #1120 fixed. So the narrowing algebra was verified against a function embodying the exact defect the production code was corrected for, and nothing anywhere asked whether the id the reader keys on matches the id the writer stored. Writer tested. Narrowing tested. Join untested, with one side's double still encoding the bug. Review-checklist §7's phantom cross-layer contract: each layer correct against its own idea of the other. threadScopingSeam.test.js runs BOTH real halves against one pg-mem database — ThreadUserState.follow / unfollow / followByParticipation on the write side, effectiveFollowerIds + narrowToThread on the read side — with the two identity spaces held deliberately DISTINCT, because a fixture where they coincide cannot discriminate a correct key from a wrong one. That is the same fixture discipline #1152 added one layer down. Five cases. The discriminating one writes the row under `installedBy` and asserts the seat is NOT reached: if writer and reader disagreed, the row would land where the narrowing never looks and the seat would go silently invisible inside a thread it opted into. Probe: reverting `identify` to installedBy kills all five, which is the derived expectation since every case depends on the two spaces differing. Also retired the stand-in in threadWakeScope.test.js — its fixture field is now `botUserId`, opaque on purpose, because that suite is about set arithmetic and should not have an opinion about what the key means. Whether it matches the writer is now a different file's job. 287 tests across 20 threading suites green. Co-authored-by: Claude Opus 5 <[email protected]>
Third of four. Stacked on #1109 (2/4), which is stacked on #1106 (1/4). This is the set arithmetic half of 3/4; the pipeline hook into
enqueueWakeOnMessagefollows in a second commit on this branch so it can be reviewed against a settled definition rather than alongside one.The rule
From fable's #1045 ambient-only ruling, as sharpened in-pod by @ux-lead (56822) and @sprint-review (56823). Three terms, and each is a separate term for a reason:
participants— anyone who authored a message in the thread. Derived at read frommessages, never stored. It is a fact about the conversation; materialising it would create a second writer that can disagree with the first. This is the tri-state'sfollowing IS NULLcase.explicitFollowers—following IS TRUE. The header toggle, or an @mention in the thread. A mention writes the row at the moment it happens (ThreadUserState.followByParticipation) rather than being re-derived from history forever.muted—following IS FALSE, subtracted last, because an explicit mute outranks participation.One query, not three. The terms are correlated and this path runs for every threaded reply.
Scoping only ever narrows
narrowToThreadreturns a subset of what it was given, never a superset. Threading is additive; it must not start delivering to seats that never opted in to anything. A test asserts this directly — an explicit follower who was not in the candidate list does not get added.Two degradations, both toward today's behaviour rather than toward silence:
A wake that vanishes because scoping could not classify it is the failure nobody reports. A duplicate wake is one somebody complains about within the hour.
Not the addressing path
An explicit
@mentionwakes its target whether or not they follow the thread, and whether or not they muted it — a mute scopes ambient activity, never addressing. That path never reaches this service, becauseisRoutedshort-circuits before the ambient branch. Verified in 1/4'sagentMentionService.threadingIsNotAddressingsuite.Tests
15 cases, executed on pg-mem — every claim here is set arithmetic the SQL performs, so grepping the SQL would assert the query was written and nothing more.
Two worth naming:
thread_root_idis NULL by design.WHERE thread_root_id = $1alone omits the person who started the thread — the most obviously wrong omission available, and invisible without executing.following = true, never onEXISTS(row).Mutation probe, each anchor-verified before the result was believed:
OR id = $1removed)[]instead of the unscoped listOne test in the first draft was misnamed and covered nothing — "a scoping failure falls back to unscoped delivery" made
identifythrow and asserted the rejection, a different path entirely. It now makes the query fail, and has a control proving the same call succeeds when the query works.Next on this branch
The hook:
enqueueWakeOnMessageappliesnarrowToThreadwhen the message carries athread_root_id, mappingAgentInstallation.installedByto the user id thread state is keyed on.🤖 Generated with Claude Code