Skip to content

test(threading): a reply edge can only be created where the root is derived - #1159

Merged
lilyshen0722 merged 1 commit into
mainfrom
test/reply-edge-implies-root-guard
Aug 23, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
test/reply-edge-implies-root-guard

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

@sprint-review (57137) checked whether the threading cutoff could still move and found "exactly one production INSERT INTO messages, and it derives thread_root_id inline." Their instance is correct. This is the class — same reason #1138 exists: a sweep is a fact about today, and what breaks it is a second write path added later by someone who never read the sweep.

Two corrections while making it a rule

There are two INSERTs, not one — models/pg/Message.ts and testPG.ts. The second is harmless for a better reason than being a test script: it inserts only (pod_id, user_id, content), so it cannot create a reply edge at all. That's the property worth asserting, not the filename.

The sharper condition nobody had checked: nothing UPDATEs reply_to_message_id. An edge added after the insert would never pass through the derivation, and the row would sit un-rooted forever with no error anywhere. The only other occurrence in the tree is the schema declaration.

So the invariant holds because every path that can create an edge derives the root, and no path can add one later — stronger than "there is only one INSERT."

Guarded with controls

A negative from an unexercised matcher is worth nothing, so: the scan asserts it reaches Message.ts and sees >50 files, and each detector is fired against a known positive inline.

Probe Result
Drop an edge-without-root INSERT into services/ fails exactly 1
Drop an UPDATE … SET reply_to_message_id into services/ fails exactly 1
Control (both removed) 5 pass

TASK-040's Mongo write-fallback is the live reminder this isn't hypothetical — a second path to the same data already exists in this codebase.

🤖 Generated with Claude Code

…erived

@sprint-review (57137) checked whether the cutoff could still move and found
"exactly one production INSERT INTO messages, and it derives thread_root_id
inline." Their instance is right; this is the class, for the same reason
#1138 exists — a sweep is a fact about today, and what breaks it is a second
write path added later by someone who never read the sweep.

Two corrections to the instance while making it a rule.

There are TWO INSERTs, not one: models/pg/Message.ts and testPG.ts. The
second is harmless for a better reason than being a test script — it inserts
only (pod_id, user_id, content), so it cannot create a reply edge at all.
That is the property worth asserting, not the file's name.

And the sharper condition is one nobody had checked: nothing UPDATEs
reply_to_message_id. An edge added after the insert would never pass through
the derivation, and the row would sit un-rooted forever with no error
anywhere. Grepped: the only other occurrence in the tree is the schema
declaration. So the invariant holds because every path that CAN create an
edge derives the root, and no path can add one later — stronger than "there
is only one INSERT".

Both conditions guarded, with controls, because a negative from an
unexercised matcher is worth nothing: the scan asserts it reaches
Message.ts and sees >50 files, and each detector is fired against a known
positive inline. Probed live too — dropping an edge-without-root INSERT into
services/ fails exactly one test, and an UPDATE of the edge fails exactly
one, each restored after.

TASK-040's Mongo write-fallback is the live reminder this is not
hypothetical: a second path to the same data already exists in this codebase.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722
lilyshen0722 merged commit d0cd3a5 into main Aug 23, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the test/reply-edge-implies-root-guard branch August 23, 2026 04:45
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