Skip to content

test(threading): the writer/reader seam had no reader, and one side faked it - #1158

Merged
lilyshen0722 merged 1 commit into
mainfrom
test/threading-writer-reader-seam
Aug 23, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
test/threading-writer-reader-seam

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

@sprint-review (57122) named this 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 — never runs the real narrowing.
  • threadWakeScope.test.js runs the real narrowing but supplies its own identify.

Worse than reported

That local stand-in was (t) => t.installedBy — the keying production stopped using. installedBy is the human installer on half the write paths; that's 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.

The seam test

threadScopingSeam.test.js runs both real halves against one pg-mem database — ThreadUserState.follow / unfollow / followByParticipation writing, effectiveFollowerIds + narrowToThread reading — with the two identity spaces held deliberately distinct, because a fixture where they coincide can't discriminate a correct key from a wrong one. Same discipline #1152 added one layer down.

The discriminating case 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 — 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. That suite is about set arithmetic and shouldn't 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.

🤖 Generated with Claude Code

…aked it

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

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Stamped at 87b18ef4. All checks pass, mergeStateStatus: CLEAN. Gated on the completed run rather than the head — Test & Coverage and E2E Tests were still pending when I first read this, and they have since finished green.

Premise verified before the fix was read. On origin/main, backend/__tests__/unit/services/threadWakeScope.test.js:125 is:

const identify = (t) => t.installedBy || null;

So the claim holds exactly: the stand-in encoded the keying #1120 removed, and it was still there eleven hours after that fix merged. The narrowing algebra was being verified against a function embodying the defect the production code was corrected for. Retiring it to an opaque botUserId is the right call — that suite is about set arithmetic and should not carry an opinion about what the key means.

The seam suite is well constructed. Real ThreadUserState writer and real narrowToThread reader against one pg-mem database; applyTable sources the DDL from the shipped schema rather than a hand-written fixture; and the two identity spaces are held genuinely distinct (installedBy: 'human-who-installed-it' versus bot-user-a), which is what lets it discriminate at all.

:103 is the case that earns the file — writes under installedBy, asserts the seat is gone. :120 is the right complement: an unresolvable seat is KEPT, pinning that a keying gap degrades to noise rather than silence. That pair covers both directions of the failure.

One note, non-blocking. At :117:

expect(kept).toEqual([]);          // :114
expect(kept).not.toContain(SEAT);  // :117

:117 cannot fail while :114 passes — toEqual([]) already excludes SEAT. It reads as a second check and is a documentation assertion. Harmless, and worth knowing it is prose rather than coverage; same family as the vacuous-assertion shapes collected in #1149.

Not verified. "Probe kills all five" is the author's result, not confirmed on a second reader. I read the suite; I did not mutate it. My working tree predates the post-threading services and cannot host this file, which is the same limitation I noted when gating #1152.

@lilyshen0722
lilyshen0722 merged commit fbda0f7 into main Aug 23, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the test/threading-writer-reader-seam branch August 23, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant