Files
pad/internal/server
xarmian c1e57ee557 fix(comments): the "commented" activity and the comment commit in one transaction (BUG-2716) (#1388)
handleCreateComment and handleCreateReply wrote the activity row first, in
its own transaction, then the comment. The order is forced — the comment
carries the activity's id under a foreign key — so a comment failure left
an orphan "commented" entry on the item timeline with nothing behind it,
and the request answered 500. Measured before the change: after a forced
comment INSERT failure the item carried two "commented" activities and one
comment, at both sites.

One store call, CreateCommentWithActivity, writes both rows in one
transaction: the activity through an executor-taking split of
CreateActivity, then the existing comment body — attachment-ref stamp,
INSERT, read-back, comment.created outbox event — on the same *sql.Tx. A
failed comment now takes its activity with it. The user-write touch moves
after the commit so a failed comment is not counted as a write.

The third site the trail enumerates — an item update carrying a comment —
is deliberately unchanged (lead-ruled): its "updated" activity records a
write that has already committed and must survive a comment failure, on
both of its branches. Said in a comment at the site so it is not re-filed.

Tests, both dialects, per site: a comment-INSERT seam in the commit-hook
shape forces the failure; the request answers 500, the comment does not
exist, and the "commented" activity count is unchanged. The pre-fix
control was red on the activity-count line at both sites.
2026-09-15 16:36:26 -04:00
..